{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/comments/33310176","id":33310176,"diff_hunk":"@@ -64,8 +79,17 @@ module J2ME {\n       }\n     }\n     // Emit class initializer.\n-    writer.enter(\"function \" + mangledClassName + \"() {\");\n-    writer.writeLn(\"this._address = ASM._gcMalloc(\" + classInfo.sizeOfFields + \");\");\n+    var klassId = generateKlassId();\n+    writer.enter(\"function \" + mangledClassName + \"(address) {\");\n+    writer.writeLn(\"if (address) {\");\n+    writer.writeLn(\"  this._address = address;\");\n+    // writer.writeLn(\"  this._hashCode = i32[this._address + HASH_CODE_OFFSET >> 2];\");\n+    writer.writeLn(\"} else {\");\n+    writer.writeLn(\"  this._address = ASM._gcMalloc(OBJ_HDR_SIZE + \" + classInfo.sizeOfFields + \");\");","path":"jit/compiler.ts","position":34,"original_position":34,"commit_id":"38571c133df5ce507c107b489568657fdca0356e","original_commit_id":"38571c133df5ce507c107b489568657fdca0356e","user":{"login":"brendandahl","id":942640,"avatar_url":"https://avatars.githubusercontent.com/u/942640?v=3","gravatar_id":"","url":"https://api.github.com/users/brendandahl","html_url":"https://github.com/brendandahl","followers_url":"https://api.github.com/users/brendandahl/followers","following_url":"https://api.github.com/users/brendandahl/following{/other_user}","gists_url":"https://api.github.com/users/brendandahl/gists{/gist_id}","starred_url":"https://api.github.com/users/brendandahl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendandahl/subscriptions","organizations_url":"https://api.github.com/users/brendandahl/orgs","repos_url":"https://api.github.com/users/brendandahl/repos","events_url":"https://api.github.com/users/brendandahl/events{/privacy}","received_events_url":"https://api.github.com/users/brendandahl/received_events","type":"User","site_admin":false},"body":"Use the actual OBJ_HDR_SIZE value here so there's no property lookup.","created_at":"2015-06-25T22:03:14Z","updated_at":"2015-06-25T22:03:14Z","html_url":"https://github.com/mozilla/pluotsorbet/pull/1659#discussion_r33310176","pull_request_url":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659","_links":{"self":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/comments/33310176"},"html":{"href":"https://github.com/mozilla/pluotsorbet/pull/1659#discussion_r33310176"},"pull_request":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659","id":38053469,"html_url":"https://github.com/mozilla/pluotsorbet/pull/1659","diff_url":"https://github.com/mozilla/pluotsorbet/pull/1659.diff","patch_url":"https://github.com/mozilla/pluotsorbet/pull/1659.patch","issue_url":"https://api.github.com/repos/mozilla/pluotsorbet/issues/1659","number":1659,"state":"open","locked":false,"title":"add header to object layout and reference objects by address","user":{"login":"mykmelez","id":305455,"avatar_url":"https://avatars.githubusercontent.com/u/305455?v=3","gravatar_id":"","url":"https://api.github.com/users/mykmelez","html_url":"https://github.com/mykmelez","followers_url":"https://api.github.com/users/mykmelez/followers","following_url":"https://api.github.com/users/mykmelez/following{/other_user}","gists_url":"https://api.github.com/users/mykmelez/gists{/gist_id}","starred_url":"https://api.github.com/users/mykmelez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mykmelez/subscriptions","organizations_url":"https://api.github.com/users/mykmelez/orgs","repos_url":"https://api.github.com/users/mykmelez/repos","events_url":"https://api.github.com/users/mykmelez/events{/privacy}","received_events_url":"https://api.github.com/users/mykmelez/received_events","type":"User","site_admin":false},"body":"@marco-c This is still rough but more-or-less ready for review. There's still lots to do, but I think it can be done in followups.\r\n\r\nThis is basically an intermediate state between \"every Java object has a corresponding JS object, and references are those JS objects\" and \"every Java object is allocated only in the ASM heap, and references are the heap addresses of those Java objects.\"\r\n\r\nThe branch doesn't create a persistent JS object for each Java object (except for Class objects), but it does frequently create JS handles, including a handle for the *this* object when it calls into a native and a handle for each object argument to the native.  It also automatically dereferences object return values from natives.\r\n\r\nThe goal was to avoid touching natives more than absolutely necessary.  The branch still has to touch natives that set properties on the JS representations of Java objects and expect them to persist across native method invocations, since the handles aren't persistent.  It does that by creating a map from Java object addresses to JS objects (which we'll need to figure out how to collect when we collect the Java objects).\r\n\r\nAlso, a handle property that references another object will contain its address rather than a handle to it.  So natives have to get those handles themselves. But other than that, they can mostly behave as before. Which minimizes the scope of this branch significantly.\r\n\r\nNote that the handles are still created by the same Klass constructors that the current implementation on master (and the intex branch) uses to construct the JS objects we currently pass as references. And those are fairly heavyweight constructors (with prototype chains that mirror the Java class hierarchy).  We should do something more lightweight.\r\n\r\nThere's also a lot of code to deal with references that may or may not be addresses, since primitive and object arrays are still represented by JS objects, as are null values (which are represented by the JS null object).  We should be able to get rid of that code once we stop passing around non-addresses.\r\n\r\nAnd there's a separate monitor map that stores monitor objects for Java objects with locks. We may be able to move lock state into the object headers. That'd need further research (looking at how other VMs do it).\r\n\r\nHere's a (probably incomplete) list of followups:\r\n\r\n* Stop wrapping the *this* object in a handle when calling natives.  This'll require us to update all natives that access the *this* object to wrap it themselves.\r\n* Stop unwrapping the return value after calling natives.  This'll require us to update all natives that return a value to return an unwrapped value themselves.\r\n* Remove the Thread.pid binding, which appears to not be used anymore.\r\n* Replace heavyweight Klass constructor handles with a lightweight approach.\r\n* Consider aligning memory to certain byte boundaries.\r\n* Replace getNative(getHandle()) calls with direct calls to NativeMap.get().\r\n* Replace J2ME.fromJavaString(getHandle(this.nativePath)) with handle-less conversion of strings.\r\n* Consolidate the objects we store in nativeConnectionMap with those in NativeMap.\r\n* Figure out if we can store lock state in the object header.\r\n","created_at":"2015-06-18T21:10:29Z","updated_at":"2015-06-25T22:03:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b982287b4189f7c6633a9a2863167be7544b525","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659/commits","review_comments_url":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659/comments","review_comment_url":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/pluotsorbet/issues/1659/comments","statuses_url":"https://api.github.com/repos/mozilla/pluotsorbet/statuses/38571c133df5ce507c107b489568657fdca0356e","head":{"label":"mykmelez:intex-object-layout","ref":"intex-object-layout","sha":"38571c133df5ce507c107b489568657fdca0356e","user":{"login":"mykmelez","id":305455,"avatar_url":"https://avatars.githubusercontent.com/u/305455?v=3","gravatar_id":"","url":"https://api.github.com/users/mykmelez","html_url":"https://github.com/mykmelez","followers_url":"https://api.github.com/users/mykmelez/followers","following_url":"https://api.github.com/users/mykmelez/following{/other_user}","gists_url":"https://api.github.com/users/mykmelez/gists{/gist_id}","starred_url":"https://api.github.com/users/mykmelez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mykmelez/subscriptions","organizations_url":"https://api.github.com/users/mykmelez/orgs","repos_url":"https://api.github.com/users/mykmelez/repos","events_url":"https://api.github.com/users/mykmelez/events{/privacy}","received_events_url":"https://api.github.com/users/mykmelez/received_events","type":"User","site_admin":false},"repo":{"id":22497156,"name":"pluotsorbet","full_name":"mykmelez/pluotsorbet","owner":{"login":"mykmelez","id":305455,"avatar_url":"https://avatars.githubusercontent.com/u/305455?v=3","gravatar_id":"","url":"https://api.github.com/users/mykmelez","html_url":"https://github.com/mykmelez","followers_url":"https://api.github.com/users/mykmelez/followers","following_url":"https://api.github.com/users/mykmelez/following{/other_user}","gists_url":"https://api.github.com/users/mykmelez/gists{/gist_id}","starred_url":"https://api.github.com/users/mykmelez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mykmelez/subscriptions","organizations_url":"https://api.github.com/users/mykmelez/orgs","repos_url":"https://api.github.com/users/mykmelez/repos","events_url":"https://api.github.com/users/mykmelez/events{/privacy}","received_events_url":"https://api.github.com/users/mykmelez/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mykmelez/pluotsorbet","description":"J2ME VM in JavaScript","fork":true,"url":"https://api.github.com/repos/mykmelez/pluotsorbet","forks_url":"https://api.github.com/repos/mykmelez/pluotsorbet/forks","keys_url":"https://api.github.com/repos/mykmelez/pluotsorbet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mykmelez/pluotsorbet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mykmelez/pluotsorbet/teams","hooks_url":"https://api.github.com/repos/mykmelez/pluotsorbet/hooks","issue_events_url":"https://api.github.com/repos/mykmelez/pluotsorbet/issues/events{/number}","events_url":"https://api.github.com/repos/mykmelez/pluotsorbet/events","assignees_url":"https://api.github.com/repos/mykmelez/pluotsorbet/assignees{/user}","branches_url":"https://api.github.com/repos/mykmelez/pluotsorbet/branches{/branch}","tags_url":"https://api.github.com/repos/mykmelez/pluotsorbet/tags","blobs_url":"https://api.github.com/repos/mykmelez/pluotsorbet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mykmelez/pluotsorbet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mykmelez/pluotsorbet/git/refs{/sha}","trees_url":"https://api.github.com/repos/mykmelez/pluotsorbet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mykmelez/pluotsorbet/statuses/{sha}","languages_url":"https://api.github.com/repos/mykmelez/pluotsorbet/languages","stargazers_url":"https://api.github.com/repos/mykmelez/pluotsorbet/stargazers","contributors_url":"https://api.github.com/repos/mykmelez/pluotsorbet/contributors","subscribers_url":"https://api.github.com/repos/mykmelez/pluotsorbet/subscribers","subscription_url":"https://api.github.com/repos/mykmelez/pluotsorbet/subscription","commits_url":"https://api.github.com/repos/mykmelez/pluotsorbet/commits{/sha}","git_commits_url":"https://api.github.com/repos/mykmelez/pluotsorbet/git/commits{/sha}","comments_url":"https://api.github.com/repos/mykmelez/pluotsorbet/comments{/number}","issue_comment_url":"https://api.github.com/repos/mykmelez/pluotsorbet/issues/comments{/number}","contents_url":"https://api.github.com/repos/mykmelez/pluotsorbet/contents/{+path}","compare_url":"https://api.github.com/repos/mykmelez/pluotsorbet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mykmelez/pluotsorbet/merges","archive_url":"https://api.github.com/repos/mykmelez/pluotsorbet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mykmelez/pluotsorbet/downloads","issues_url":"https://api.github.com/repos/mykmelez/pluotsorbet/issues{/number}","pulls_url":"https://api.github.com/repos/mykmelez/pluotsorbet/pulls{/number}","milestones_url":"https://api.github.com/repos/mykmelez/pluotsorbet/milestones{/number}","notifications_url":"https://api.github.com/repos/mykmelez/pluotsorbet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mykmelez/pluotsorbet/labels{/name}","releases_url":"https://api.github.com/repos/mykmelez/pluotsorbet/releases{/id}","created_at":"2014-08-01T06:02:22Z","updated_at":"2015-06-17T06:46:07Z","pushed_at":"2015-06-25T21:33:46Z","git_url":"git://github.com/mykmelez/pluotsorbet.git","ssh_url":"git@github.com:mykmelez/pluotsorbet.git","clone_url":"https://github.com/mykmelez/pluotsorbet.git","svn_url":"https://github.com/mykmelez/pluotsorbet","homepage":null,"size":32722,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"mozilla:intex","ref":"intex","sha":"849446cf321698975a857aa82cbecdaa8863e152","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":21724513,"name":"pluotsorbet","full_name":"mozilla/pluotsorbet","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/pluotsorbet","description":"PluotSorbet is a J2ME-compatible virtual machine written in JavaScript.","fork":false,"url":"https://api.github.com/repos/mozilla/pluotsorbet","forks_url":"https://api.github.com/repos/mozilla/pluotsorbet/forks","keys_url":"https://api.github.com/repos/mozilla/pluotsorbet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/pluotsorbet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/pluotsorbet/teams","hooks_url":"https://api.github.com/repos/mozilla/pluotsorbet/hooks","issue_events_url":"https://api.github.com/repos/mozilla/pluotsorbet/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/pluotsorbet/events","assignees_url":"https://api.github.com/repos/mozilla/pluotsorbet/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/pluotsorbet/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/pluotsorbet/tags","blobs_url":"https://api.github.com/repos/mozilla/pluotsorbet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/pluotsorbet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/pluotsorbet/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/pluotsorbet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/pluotsorbet/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/pluotsorbet/languages","stargazers_url":"https://api.github.com/repos/mozilla/pluotsorbet/stargazers","contributors_url":"https://api.github.com/repos/mozilla/pluotsorbet/contributors","subscribers_url":"https://api.github.com/repos/mozilla/pluotsorbet/subscribers","subscription_url":"https://api.github.com/repos/mozilla/pluotsorbet/subscription","commits_url":"https://api.github.com/repos/mozilla/pluotsorbet/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/pluotsorbet/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/pluotsorbet/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/pluotsorbet/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/pluotsorbet/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/pluotsorbet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/pluotsorbet/merges","archive_url":"https://api.github.com/repos/mozilla/pluotsorbet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/pluotsorbet/downloads","issues_url":"https://api.github.com/repos/mozilla/pluotsorbet/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/pluotsorbet/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/pluotsorbet/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/pluotsorbet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/pluotsorbet/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/pluotsorbet/releases{/id}","created_at":"2014-07-11T06:23:27Z","updated_at":"2015-06-25T01:23:21Z","pushed_at":"2015-06-25T21:33:47Z","git_url":"git://github.com/mozilla/pluotsorbet.git","ssh_url":"git@github.com:mozilla/pluotsorbet.git","clone_url":"https://github.com/mozilla/pluotsorbet.git","svn_url":"https://github.com/mozilla/pluotsorbet","homepage":"","size":37593,"stargazers_count":149,"watchers_count":149,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":274,"forks":32,"open_issues":274,"watchers":149,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659"},"html":{"href":"https://github.com/mozilla/pluotsorbet/pull/1659"},"issue":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/issues/1659"},"comments":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/issues/1659/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/pulls/1659/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/pluotsorbet/statuses/38571c133df5ce507c107b489568657fdca0356e"}}}}