{"action":"created","comment":{"url":"https://api.github.com/repos/dropbox/pyston/pulls/comments/32056319","id":32056319,"diff_hunk":"@@ -342,26 +416,121 @@ void markPhase() {\n #endif\n }\n \n+void finalizationOrderingFirstPass(Box* obj) {\n+    std::shared_ptr<FirstPhaseStack> stack = std::make_shared<FirstPhaseStack>();\n+    GCVisitor visitor(stack);\n+\n+    stack->push(obj);\n+    while (void* p = stack->pop()) {\n+        visitByGCKind(p, visitor);\n+    }\n+}\n+\n+void finalizationOrderingSecondPass(Box* obj) {\n+    std::shared_ptr<SecondPhaseStack> stack = std::make_shared<SecondPhaseStack>();\n+    GCVisitor visitor(stack);\n+\n+    stack->push(obj);\n+    while (void* p = stack->pop()) {\n+        GCAllocation* al = GCAllocation::fromUserData(p);\n+        assert(orderingState(al) != FinalizationState::UNREACHABLE);\n+        visitByGCKind(p, visitor);\n+    }\n+}\n+\n+// Implementation of PyPy's finalization ordering algorithm:\n+// http://pypy.readthedocs.org/en/latest/discussion/finalizer-order.html\n+void finalizationOrderingPhase() {\n+    // TODO: Replace with iterator or something that takes a lambda for memory efficiency?.\n+    std::vector<Box*> objects_with_finalizers;\n+    global_heap.getOrderedFinalizers(objects_with_finalizers);","path":"src/gc/collector.cpp","position":350,"original_position":350,"commit_id":"c44672af197214265bd6da01b5a9bd5be32f12ee","original_commit_id":"c44672af197214265bd6da01b5a9bd5be32f12ee","user":{"login":"toshok","id":24245,"avatar_url":"https://avatars.githubusercontent.com/u/24245?v=3","gravatar_id":"","url":"https://api.github.com/users/toshok","html_url":"https://github.com/toshok","followers_url":"https://api.github.com/users/toshok/followers","following_url":"https://api.github.com/users/toshok/following{/other_user}","gists_url":"https://api.github.com/users/toshok/gists{/gist_id}","starred_url":"https://api.github.com/users/toshok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toshok/subscriptions","organizations_url":"https://api.github.com/users/toshok/orgs","repos_url":"https://api.github.com/users/toshok/repos","events_url":"https://api.github.com/users/toshok/events{/privacy}","received_events_url":"https://api.github.com/users/toshok/received_events","type":"User","site_admin":false},"body":"alas, this prints \"hello world\":\r\n```\r\nclass WithoutDelAtStart(object):\r\n    pass\r\n\r\ndef delobj(self):\r\n    print \"hello world\"\r\n\r\nWithoutDelAtStart.__del__ = delobj\r\n\r\nf = WithoutDelAtStart()\r\nf = None\r\n```","created_at":"2015-06-09T19:57:38Z","updated_at":"2015-06-09T19:57:38Z","html_url":"https://github.com/dropbox/pyston/pull/561#discussion_r32056319","pull_request_url":"https://api.github.com/repos/dropbox/pyston/pulls/561","_links":{"self":{"href":"https://api.github.com/repos/dropbox/pyston/pulls/comments/32056319"},"html":{"href":"https://github.com/dropbox/pyston/pull/561#discussion_r32056319"},"pull_request":{"href":"https://api.github.com/repos/dropbox/pyston/pulls/561"}}},"pull_request":{"url":"https://api.github.com/repos/dropbox/pyston/pulls/561","id":36359490,"html_url":"https://github.com/dropbox/pyston/pull/561","diff_url":"https://github.com/dropbox/pyston/pull/561.diff","patch_url":"https://github.com/dropbox/pyston/pull/561.patch","issue_url":"https://api.github.com/repos/dropbox/pyston/issues/561","number":561,"state":"open","locked":false,"title":"Call finalizers during garbage collection with ordering","user":{"login":"rudi-c","id":2747897,"avatar_url":"https://avatars.githubusercontent.com/u/2747897?v=3","gravatar_id":"","url":"https://api.github.com/users/rudi-c","html_url":"https://github.com/rudi-c","followers_url":"https://api.github.com/users/rudi-c/followers","following_url":"https://api.github.com/users/rudi-c/following{/other_user}","gists_url":"https://api.github.com/users/rudi-c/gists{/gist_id}","starred_url":"https://api.github.com/users/rudi-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudi-c/subscriptions","organizations_url":"https://api.github.com/users/rudi-c/orgs","repos_url":"https://api.github.com/users/rudi-c/repos","events_url":"https://api.github.com/users/rudi-c/events{/privacy}","received_events_url":"https://api.github.com/users/rudi-c/received_events","type":"User","site_admin":false},"body":"This PR implements finalizers, using PyPy's finalization ordering algorithm.\r\n\r\nRemoves the need for some workaround hacks like simple_destructors.\r\n\r\nThere's more optimization work to be done but this is functional and is getting quite big, so I figured this would be a good time for a code review.","created_at":"2015-05-27T23:33:38Z","updated_at":"2015-06-09T19:57:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"240e977c2b4444f63d9f035b849ade80e2d8c332","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dropbox/pyston/pulls/561/commits","review_comments_url":"https://api.github.com/repos/dropbox/pyston/pulls/561/comments","review_comment_url":"https://api.github.com/repos/dropbox/pyston/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dropbox/pyston/issues/561/comments","statuses_url":"https://api.github.com/repos/dropbox/pyston/statuses/c44672af197214265bd6da01b5a9bd5be32f12ee","head":{"label":"rudi-c:gcfinalizers","ref":"gcfinalizers","sha":"c44672af197214265bd6da01b5a9bd5be32f12ee","user":{"login":"rudi-c","id":2747897,"avatar_url":"https://avatars.githubusercontent.com/u/2747897?v=3","gravatar_id":"","url":"https://api.github.com/users/rudi-c","html_url":"https://github.com/rudi-c","followers_url":"https://api.github.com/users/rudi-c/followers","following_url":"https://api.github.com/users/rudi-c/following{/other_user}","gists_url":"https://api.github.com/users/rudi-c/gists{/gist_id}","starred_url":"https://api.github.com/users/rudi-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudi-c/subscriptions","organizations_url":"https://api.github.com/users/rudi-c/orgs","repos_url":"https://api.github.com/users/rudi-c/repos","events_url":"https://api.github.com/users/rudi-c/events{/privacy}","received_events_url":"https://api.github.com/users/rudi-c/received_events","type":"User","site_admin":false},"repo":{"id":35190032,"name":"pyston","full_name":"rudi-c/pyston","owner":{"login":"rudi-c","id":2747897,"avatar_url":"https://avatars.githubusercontent.com/u/2747897?v=3","gravatar_id":"","url":"https://api.github.com/users/rudi-c","html_url":"https://github.com/rudi-c","followers_url":"https://api.github.com/users/rudi-c/followers","following_url":"https://api.github.com/users/rudi-c/following{/other_user}","gists_url":"https://api.github.com/users/rudi-c/gists{/gist_id}","starred_url":"https://api.github.com/users/rudi-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudi-c/subscriptions","organizations_url":"https://api.github.com/users/rudi-c/orgs","repos_url":"https://api.github.com/users/rudi-c/repos","events_url":"https://api.github.com/users/rudi-c/events{/privacy}","received_events_url":"https://api.github.com/users/rudi-c/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rudi-c/pyston","description":"An open-source Python implementation using JIT techniques. ","fork":true,"url":"https://api.github.com/repos/rudi-c/pyston","forks_url":"https://api.github.com/repos/rudi-c/pyston/forks","keys_url":"https://api.github.com/repos/rudi-c/pyston/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rudi-c/pyston/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rudi-c/pyston/teams","hooks_url":"https://api.github.com/repos/rudi-c/pyston/hooks","issue_events_url":"https://api.github.com/repos/rudi-c/pyston/issues/events{/number}","events_url":"https://api.github.com/repos/rudi-c/pyston/events","assignees_url":"https://api.github.com/repos/rudi-c/pyston/assignees{/user}","branches_url":"https://api.github.com/repos/rudi-c/pyston/branches{/branch}","tags_url":"https://api.github.com/repos/rudi-c/pyston/tags","blobs_url":"https://api.github.com/repos/rudi-c/pyston/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rudi-c/pyston/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rudi-c/pyston/git/refs{/sha}","trees_url":"https://api.github.com/repos/rudi-c/pyston/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rudi-c/pyston/statuses/{sha}","languages_url":"https://api.github.com/repos/rudi-c/pyston/languages","stargazers_url":"https://api.github.com/repos/rudi-c/pyston/stargazers","contributors_url":"https://api.github.com/repos/rudi-c/pyston/contributors","subscribers_url":"https://api.github.com/repos/rudi-c/pyston/subscribers","subscription_url":"https://api.github.com/repos/rudi-c/pyston/subscription","commits_url":"https://api.github.com/repos/rudi-c/pyston/commits{/sha}","git_commits_url":"https://api.github.com/repos/rudi-c/pyston/git/commits{/sha}","comments_url":"https://api.github.com/repos/rudi-c/pyston/comments{/number}","issue_comment_url":"https://api.github.com/repos/rudi-c/pyston/issues/comments{/number}","contents_url":"https://api.github.com/repos/rudi-c/pyston/contents/{+path}","compare_url":"https://api.github.com/repos/rudi-c/pyston/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rudi-c/pyston/merges","archive_url":"https://api.github.com/repos/rudi-c/pyston/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rudi-c/pyston/downloads","issues_url":"https://api.github.com/repos/rudi-c/pyston/issues{/number}","pulls_url":"https://api.github.com/repos/rudi-c/pyston/pulls{/number}","milestones_url":"https://api.github.com/repos/rudi-c/pyston/milestones{/number}","notifications_url":"https://api.github.com/repos/rudi-c/pyston/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rudi-c/pyston/labels{/name}","releases_url":"https://api.github.com/repos/rudi-c/pyston/releases{/id}","created_at":"2015-05-07T00:30:38Z","updated_at":"2015-05-07T00:30:47Z","pushed_at":"2015-06-09T18:50:00Z","git_url":"git://github.com/rudi-c/pyston.git","ssh_url":"git@github.com:rudi-c/pyston.git","clone_url":"https://github.com/rudi-c/pyston.git","svn_url":"https://github.com/rudi-c/pyston","homepage":"https://tech.dropbox.com/2014/04/introducing-pyston-an-upcoming-jit-based-python-implementation/","size":20949,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dropbox:master","ref":"master","sha":"3a5b3e50e749ded943e7327dc3386c66486a8099","user":{"login":"dropbox","id":559357,"avatar_url":"https://avatars.githubusercontent.com/u/559357?v=3","gravatar_id":"","url":"https://api.github.com/users/dropbox","html_url":"https://github.com/dropbox","followers_url":"https://api.github.com/users/dropbox/followers","following_url":"https://api.github.com/users/dropbox/following{/other_user}","gists_url":"https://api.github.com/users/dropbox/gists{/gist_id}","starred_url":"https://api.github.com/users/dropbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dropbox/subscriptions","organizations_url":"https://api.github.com/users/dropbox/orgs","repos_url":"https://api.github.com/users/dropbox/repos","events_url":"https://api.github.com/users/dropbox/events{/privacy}","received_events_url":"https://api.github.com/users/dropbox/received_events","type":"Organization","site_admin":false},"repo":{"id":18320947,"name":"pyston","full_name":"dropbox/pyston","owner":{"login":"dropbox","id":559357,"avatar_url":"https://avatars.githubusercontent.com/u/559357?v=3","gravatar_id":"","url":"https://api.github.com/users/dropbox","html_url":"https://github.com/dropbox","followers_url":"https://api.github.com/users/dropbox/followers","following_url":"https://api.github.com/users/dropbox/following{/other_user}","gists_url":"https://api.github.com/users/dropbox/gists{/gist_id}","starred_url":"https://api.github.com/users/dropbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dropbox/subscriptions","organizations_url":"https://api.github.com/users/dropbox/orgs","repos_url":"https://api.github.com/users/dropbox/repos","events_url":"https://api.github.com/users/dropbox/events{/privacy}","received_events_url":"https://api.github.com/users/dropbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dropbox/pyston","description":"An open-source Python implementation using JIT techniques. ","fork":false,"url":"https://api.github.com/repos/dropbox/pyston","forks_url":"https://api.github.com/repos/dropbox/pyston/forks","keys_url":"https://api.github.com/repos/dropbox/pyston/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dropbox/pyston/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dropbox/pyston/teams","hooks_url":"https://api.github.com/repos/dropbox/pyston/hooks","issue_events_url":"https://api.github.com/repos/dropbox/pyston/issues/events{/number}","events_url":"https://api.github.com/repos/dropbox/pyston/events","assignees_url":"https://api.github.com/repos/dropbox/pyston/assignees{/user}","branches_url":"https://api.github.com/repos/dropbox/pyston/branches{/branch}","tags_url":"https://api.github.com/repos/dropbox/pyston/tags","blobs_url":"https://api.github.com/repos/dropbox/pyston/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dropbox/pyston/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dropbox/pyston/git/refs{/sha}","trees_url":"https://api.github.com/repos/dropbox/pyston/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dropbox/pyston/statuses/{sha}","languages_url":"https://api.github.com/repos/dropbox/pyston/languages","stargazers_url":"https://api.github.com/repos/dropbox/pyston/stargazers","contributors_url":"https://api.github.com/repos/dropbox/pyston/contributors","subscribers_url":"https://api.github.com/repos/dropbox/pyston/subscribers","subscription_url":"https://api.github.com/repos/dropbox/pyston/subscription","commits_url":"https://api.github.com/repos/dropbox/pyston/commits{/sha}","git_commits_url":"https://api.github.com/repos/dropbox/pyston/git/commits{/sha}","comments_url":"https://api.github.com/repos/dropbox/pyston/comments{/number}","issue_comment_url":"https://api.github.com/repos/dropbox/pyston/issues/comments{/number}","contents_url":"https://api.github.com/repos/dropbox/pyston/contents/{+path}","compare_url":"https://api.github.com/repos/dropbox/pyston/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dropbox/pyston/merges","archive_url":"https://api.github.com/repos/dropbox/pyston/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dropbox/pyston/downloads","issues_url":"https://api.github.com/repos/dropbox/pyston/issues{/number}","pulls_url":"https://api.github.com/repos/dropbox/pyston/pulls{/number}","milestones_url":"https://api.github.com/repos/dropbox/pyston/milestones{/number}","notifications_url":"https://api.github.com/repos/dropbox/pyston/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dropbox/pyston/labels{/name}","releases_url":"https://api.github.com/repos/dropbox/pyston/releases{/id}","created_at":"2014-04-01T07:17:20Z","updated_at":"2015-06-09T12:47:56Z","pushed_at":"2015-06-09T18:50:00Z","git_url":"git://github.com/dropbox/pyston.git","ssh_url":"git@github.com:dropbox/pyston.git","clone_url":"https://github.com/dropbox/pyston.git","svn_url":"https://github.com/dropbox/pyston","homepage":"https://tech.dropbox.com/2014/04/introducing-pyston-an-upcoming-jit-based-python-implementation/","size":29732,"stargazers_count":2988,"watchers_count":2988,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":213,"mirror_url":null,"open_issues_count":63,"forks":213,"open_issues":63,"watchers":2988,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dropbox/pyston/pulls/561"},"html":{"href":"https://github.com/dropbox/pyston/pull/561"},"issue":{"href":"https://api.github.com/repos/dropbox/pyston/issues/561"},"comments":{"href":"https://api.github.com/repos/dropbox/pyston/issues/561/comments"},"review_comments":{"href":"https://api.github.com/repos/dropbox/pyston/pulls/561/comments"},"review_comment":{"href":"https://api.github.com/repos/dropbox/pyston/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dropbox/pyston/pulls/561/commits"},"statuses":{"href":"https://api.github.com/repos/dropbox/pyston/statuses/c44672af197214265bd6da01b5a9bd5be32f12ee"}}}}