This repository was archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Implement support for classOf and getClass. #19
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tanishiking
reviewed
Mar 18, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much @sjrd !
One question is that I'm not sure why do we need element section for getComponentType
, but otherwise looks great! (+ I left some small questions)
* Handling of the function signature and signature type. * Building of the `WasmFunction` and registration to the context. * Small DSL for emitting structured control flow instructions.
Mostly for forward declarations of functions to be used in `ref.func` instructions.
Including elementary support of methods of `java.lang.Class`. We implement this in a way that is similar to the JavaScript back-end: we have an internal `typeData` structure, which contains the raw metadata that will be needed by a `java.lang.Class` instance. It also contains a lazily evaluated pointer to the unique `java.lang.Class` and the `typeData` of an array of that type. If we need the `typeData` of a multi-dimensional array, we follow the chain of `arrayOf` pointers. The name is initially stored as an `(array u16)` so that it can be initialized as a constant expression in globals. The `string` value is lazily initialized from that raw data the first time it is requested. This machinery requires quite a bit of run-time helper functions. These are hard-coded in `HelperFunctions.scala`. Again, this is similar to the JS back-end, which defines a bunch of helper JS functions in its `CoreJSLib.scala`. The `typeData` of classes that have a `vtable` are inserted into the `vtable` itself, making the latter a subtype of `typeData`. This is done in anticipation of the support for `GetClass`: it will be able to fetch the `vtable` field of the object as the `typeData` from which to extract the `java.lang.Class` instance. The `typeData` of other classes are stored as independent globals.
When the value is one of our objects, we look at its `vtable` field, which is also the appropriate `typeData` reference. When it is a JS value, we implement the dispatch in a dedicated helper function.
tanishiking
approved these changes
Mar 18, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you very much for working on this quite difficult part of new backend!
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Including elementary support of methods of
java.lang.Class
.We implement this in a way that is similar to the JavaScript back-end: we have an internal
typeData
structure, which contains the raw metadata that will be needed by ajava.lang.Class
instance. It also contains a lazily evaluated pointer to the uniquejava.lang.Class
and thetypeData
of an array of that type. If we need thetypeData
of a multi-dimensional array, we follow the chain ofarrayOf
pointers.The name is initially stored as an
(array u16)
so that it can be initialized as a constant expression in globals. Thestring
value is lazily initialized from that raw data the first time it is requested.This machinery requires quite a bit of run-time helper functions. These are hard-coded in
HelperFunctions.scala
. Again, this is similar to the JS back-end, which defines a bunch of helper JS functions in itsCoreJSLib.scala
.The
typeData
of classes that have avtable
are inserted into thevtable
itself, making the latter a subtype oftypeData
. This is used for the support ofGetClass
: we fetch thevtable
field of the object as thetypeData
from which to extract thejava.lang.Class
instance. ThetypeData
of other classes are stored as independent globals.