{"action":"created","comment":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/46620443","id":46620443,"diff_hunk":"@@ -215,6 +215,12 @@ void ti_threadfun(void *arg)\n     while (ta->state == TI_THREAD_INIT)\n         cpu_pause();\n     cpu_lfence();\n+\n+    // Assuming the functions called below doesn't contain unprotected GC\n+    // critical region. In general, the following part of this function\n+    // shouldn't call any managed code without calling `jl_gc_managed_enter`\n+    // first.\n+    jl_gc_state_set_and_save(3, 0);","path":"src/threading.c","position":9,"original_position":9,"commit_id":"39178b68d617ea08d6e774f66d2ba18467fe4f2c","original_commit_id":"39178b68d617ea08d6e774f66d2ba18467fe4f2c","user":{"login":"yuyichao","id":712232,"avatar_url":"https://avatars.githubusercontent.com/u/712232?v=3","gravatar_id":"","url":"https://api.github.com/users/yuyichao","html_url":"https://github.com/yuyichao","followers_url":"https://api.github.com/users/yuyichao/followers","following_url":"https://api.github.com/users/yuyichao/following{/other_user}","gists_url":"https://api.github.com/users/yuyichao/gists{/gist_id}","starred_url":"https://api.github.com/users/yuyichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuyichao/subscriptions","organizations_url":"https://api.github.com/users/yuyichao/orgs","repos_url":"https://api.github.com/users/yuyichao/repos","events_url":"https://api.github.com/users/yuyichao/events{/privacy}","received_events_url":"https://api.github.com/users/yuyichao/received_events","type":"User","site_admin":false},"body":"I originally meant unmanaged code but I don't think that distinction is important.","created_at":"2015-12-03T22:10:25Z","updated_at":"2015-12-03T22:10:25Z","html_url":"https://github.com/JuliaLang/julia/pull/14190#discussion_r46620443","pull_request_url":"https://api.github.com/repos/JuliaLang/julia/pulls/14190","_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/46620443"},"html":{"href":"https://github.com/JuliaLang/julia/pull/14190#discussion_r46620443"},"pull_request":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/14190"}}},"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/14190","id":52084676,"html_url":"https://github.com/JuliaLang/julia/pull/14190","diff_url":"https://github.com/JuliaLang/julia/pull/14190.diff","patch_url":"https://github.com/JuliaLang/julia/pull/14190.patch","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/14190","number":14190,"state":"open","locked":false,"title":"[WIP,RFC] GC safepoint and transition support","user":{"login":"yuyichao","id":712232,"avatar_url":"https://avatars.githubusercontent.com/u/712232?v=3","gravatar_id":"","url":"https://api.github.com/users/yuyichao","html_url":"https://github.com/yuyichao","followers_url":"https://api.github.com/users/yuyichao/followers","following_url":"https://api.github.com/users/yuyichao/following{/other_user}","gists_url":"https://api.github.com/users/yuyichao/gists{/gist_id}","starred_url":"https://api.github.com/users/yuyichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuyichao/subscriptions","organizations_url":"https://api.github.com/users/yuyichao/orgs","repos_url":"https://api.github.com/users/yuyichao/repos","events_url":"https://api.github.com/users/yuyichao/events{/privacy}","received_events_url":"https://api.github.com/users/yuyichao/received_events","type":"User","site_admin":false},"body":"This is a work in progress to make our GC a stop the world GC rather than a wait for the world (and maybe dead lock?) GC *(ok that probably doesn't sound too exciting...)*. The first two commits are #14181 which I made as a general improvement to our finalizers handling while trying to figure out how to synchronize finalizers and the GC with threading for this PR.\r\n\r\nThis is still missing the very important GC transition and safepoint support in codegen but I'm opening this as RFC now to make sure that the GC synchronization schematics I'm following makes sense.\r\n\r\nI described the schmatics in [the comment in `gc.c`](https://github.com/JuliaLang/julia/commit/a08e6ba38321c46349b34da207c183096aee0240#diff-31b93f4272eaeede3738531e90317e0cR41). To summarize, we need GC safe point and GC transitions so that the GC doesn't have to wait for other threads forever (especially if the thread doing the GC is holding a lock). The safepoint is implemented using a volatile load from a special page which we `mprotect` to `PROT_NONE` during a GC and catch the SegFault in the signal handler. (This is similar to how the Java HotSpot GC does it.) The GC also makes sure (with a combination of lock and safe point) that no other thread can run the GC at the same time or modifying GC related data structures when the GC is running.\r\n\r\n#### TODO/request for help:\r\n\r\n* The segfault handler for OSX is missing. It seems that I can't just wait in the signal handler since it's running on a different thread processing the messages from the kernel in series and it is necessary to do some low level stuff to make sure the thread can return to it's previous state after waiting for the GC to finish. Doing this on a platform that I can't test locally is beyond what I can confidently do so I need help from someone who's more familiar with this to implement it.\r\n\r\n* Codegen support:\r\n\r\n    I'm currently planning to emit a GC transition around each critical region (store to object or stack) and allow the GC to run everywhere else. We can do a optimization pass to merge unnecessary GC transitions after the whole function is generated. I'm still deciding what I can assume about GC awareness for a function call and what's the convension of changing the GC state in a function. Note that this shouldn't require the LLVM statepoint support so it should work on LLVM 3.3 as well.\r\n\r\nc.c. @vtjnash @kpamnany @carnaval @Keno \r\n","created_at":"2015-11-30T04:36:33Z","updated_at":"2015-12-03T22:10:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3a386c75f0524c8f37b6944f66eb27e0a93f6e62","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/JuliaLang/julia/pulls/14190/commits","review_comments_url":"https://api.github.com/repos/JuliaLang/julia/pulls/14190/comments","review_comment_url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/14190/comments","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/39178b68d617ea08d6e774f66d2ba18467fe4f2c","head":{"label":"JuliaLang:yyc/gc/safepoint","ref":"yyc/gc/safepoint","sha":"39178b68d617ea08d6e774f66d2ba18467fe4f2c","user":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"repo":{"id":1644196,"name":"julia","full_name":"JuliaLang/julia","owner":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JuliaLang/julia","description":"The Julia Language: A fresh approach to technical computing.","fork":false,"url":"https://api.github.com/repos/JuliaLang/julia","forks_url":"https://api.github.com/repos/JuliaLang/julia/forks","keys_url":"https://api.github.com/repos/JuliaLang/julia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuliaLang/julia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuliaLang/julia/teams","hooks_url":"https://api.github.com/repos/JuliaLang/julia/hooks","issue_events_url":"https://api.github.com/repos/JuliaLang/julia/issues/events{/number}","events_url":"https://api.github.com/repos/JuliaLang/julia/events","assignees_url":"https://api.github.com/repos/JuliaLang/julia/assignees{/user}","branches_url":"https://api.github.com/repos/JuliaLang/julia/branches{/branch}","tags_url":"https://api.github.com/repos/JuliaLang/julia/tags","blobs_url":"https://api.github.com/repos/JuliaLang/julia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuliaLang/julia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuliaLang/julia/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuliaLang/julia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/{sha}","languages_url":"https://api.github.com/repos/JuliaLang/julia/languages","stargazers_url":"https://api.github.com/repos/JuliaLang/julia/stargazers","contributors_url":"https://api.github.com/repos/JuliaLang/julia/contributors","subscribers_url":"https://api.github.com/repos/JuliaLang/julia/subscribers","subscription_url":"https://api.github.com/repos/JuliaLang/julia/subscription","commits_url":"https://api.github.com/repos/JuliaLang/julia/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuliaLang/julia/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuliaLang/julia/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuliaLang/julia/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuliaLang/julia/contents/{+path}","compare_url":"https://api.github.com/repos/JuliaLang/julia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuliaLang/julia/merges","archive_url":"https://api.github.com/repos/JuliaLang/julia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuliaLang/julia/downloads","issues_url":"https://api.github.com/repos/JuliaLang/julia/issues{/number}","pulls_url":"https://api.github.com/repos/JuliaLang/julia/pulls{/number}","milestones_url":"https://api.github.com/repos/JuliaLang/julia/milestones{/number}","notifications_url":"https://api.github.com/repos/JuliaLang/julia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuliaLang/julia/labels{/name}","releases_url":"https://api.github.com/repos/JuliaLang/julia/releases{/id}","created_at":"2011-04-21T07:01:50Z","updated_at":"2015-12-03T21:57:36Z","pushed_at":"2015-12-03T22:06:04Z","git_url":"git://github.com/JuliaLang/julia.git","ssh_url":"git@github.com:JuliaLang/julia.git","clone_url":"https://github.com/JuliaLang/julia.git","svn_url":"https://github.com/JuliaLang/julia","homepage":"http://julialang.org/","size":115488,"stargazers_count":6405,"watchers_count":6405,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1429,"mirror_url":null,"open_issues_count":1531,"forks":1429,"open_issues":1531,"watchers":6405,"default_branch":"master"}},"base":{"label":"JuliaLang:master","ref":"master","sha":"1a814cc83c474d1f27ed04cdc48ce2212b7df5b0","user":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"repo":{"id":1644196,"name":"julia","full_name":"JuliaLang/julia","owner":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JuliaLang/julia","description":"The Julia Language: A fresh approach to technical computing.","fork":false,"url":"https://api.github.com/repos/JuliaLang/julia","forks_url":"https://api.github.com/repos/JuliaLang/julia/forks","keys_url":"https://api.github.com/repos/JuliaLang/julia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuliaLang/julia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuliaLang/julia/teams","hooks_url":"https://api.github.com/repos/JuliaLang/julia/hooks","issue_events_url":"https://api.github.com/repos/JuliaLang/julia/issues/events{/number}","events_url":"https://api.github.com/repos/JuliaLang/julia/events","assignees_url":"https://api.github.com/repos/JuliaLang/julia/assignees{/user}","branches_url":"https://api.github.com/repos/JuliaLang/julia/branches{/branch}","tags_url":"https://api.github.com/repos/JuliaLang/julia/tags","blobs_url":"https://api.github.com/repos/JuliaLang/julia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuliaLang/julia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuliaLang/julia/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuliaLang/julia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/{sha}","languages_url":"https://api.github.com/repos/JuliaLang/julia/languages","stargazers_url":"https://api.github.com/repos/JuliaLang/julia/stargazers","contributors_url":"https://api.github.com/repos/JuliaLang/julia/contributors","subscribers_url":"https://api.github.com/repos/JuliaLang/julia/subscribers","subscription_url":"https://api.github.com/repos/JuliaLang/julia/subscription","commits_url":"https://api.github.com/repos/JuliaLang/julia/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuliaLang/julia/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuliaLang/julia/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuliaLang/julia/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuliaLang/julia/contents/{+path}","compare_url":"https://api.github.com/repos/JuliaLang/julia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuliaLang/julia/merges","archive_url":"https://api.github.com/repos/JuliaLang/julia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuliaLang/julia/downloads","issues_url":"https://api.github.com/repos/JuliaLang/julia/issues{/number}","pulls_url":"https://api.github.com/repos/JuliaLang/julia/pulls{/number}","milestones_url":"https://api.github.com/repos/JuliaLang/julia/milestones{/number}","notifications_url":"https://api.github.com/repos/JuliaLang/julia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuliaLang/julia/labels{/name}","releases_url":"https://api.github.com/repos/JuliaLang/julia/releases{/id}","created_at":"2011-04-21T07:01:50Z","updated_at":"2015-12-03T21:57:36Z","pushed_at":"2015-12-03T22:06:04Z","git_url":"git://github.com/JuliaLang/julia.git","ssh_url":"git@github.com:JuliaLang/julia.git","clone_url":"https://github.com/JuliaLang/julia.git","svn_url":"https://github.com/JuliaLang/julia","homepage":"http://julialang.org/","size":115488,"stargazers_count":6405,"watchers_count":6405,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1429,"mirror_url":null,"open_issues_count":1531,"forks":1429,"open_issues":1531,"watchers":6405,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/14190"},"html":{"href":"https://github.com/JuliaLang/julia/pull/14190"},"issue":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/14190"},"comments":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/14190/comments"},"review_comments":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/14190/comments"},"review_comment":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/14190/commits"},"statuses":{"href":"https://api.github.com/repos/JuliaLang/julia/statuses/39178b68d617ea08d6e774f66d2ba18467fe4f2c"}}}}