New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1435: Cache instances of j.l.Class #1894
Fix #1435: Cache instances of j.l.Class #1894
Conversation
Looks like this change introduced significant regression in performance. CI jobs takes in debug mode around 15-25% longer and in release-fast it take ~50% more time. Due to this 3 last CI jobs has timed out (there's a limit of 50 minutes). I'll take a look at this |
Do you think it might be helpful to have some diagrams showing the runtime layout? Isn't one of the big advantages over the JVM is that the JVM carries a bunch of overhead in each object? I don't want to slow down the release maybe a follow on issue if you agree. |
nativelib/src/main/scala/java/lang/ClassInstancesRegistry.scala
Outdated
Show resolved
Hide resolved
nativelib/src/main/scala/java/lang/ClassInstancesRegistry.scala
Outdated
Show resolved
Hide resolved
nativelib/src/main/scala/java/lang/ClassInstancesRegistry.scala
Outdated
Show resolved
Hide resolved
nativelib/src/main/scala/java/lang/ClassInstancesRegistry.scala
Outdated
Show resolved
Hide resolved
nativelib/src/main/scala/java/lang/ClassInstancesRegistry.scala
Outdated
Show resolved
Hide resolved
fb06602
to
54398eb
Compare
54398eb
to
2bcc818
Compare
2bcc818
to
a6d1eea
Compare
This probably needs a rebase on top of master, now that #1946 has been merged. |
cdfb0ab
to
640b5d1
Compare
640b5d1
to
1e9c825
Compare
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.
Looks good. I only have two very small comments.
nativelib/src/main/scala/scala/scalanative/runtime/ClassInstancesRegistry.scala
Outdated
Show resolved
Hide resolved
1e9c825
to
4937ee3
Compare
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.
@WojciechMazur could you rebase this on top of latest master, just to make sure it still works with the latest CI setup?
…l.ClassOf -> Object.getClass conversion
…e conversion in genVal for Val.String)
…tore class instances" This reverts commit 58cc6c6.
…opy instead of Array.copy
4937ee3
to
6a49537
Compare
* 1435 - Move j.l.Class allocations to linker/runtime. Introduce caching of j.l.Classes * 1435 - Compare _Class instances using their rawPtr instead of Rt.Type ptr * 1435 - Updated immix/commix RTTI structures to contain additional class pointer * 1435 - Transform Vals in Lower with nir.Buffer in order to support Val.ClassOf -> Object.getClass conversion * Added classOf / Object.getClass tests * Use loadObject instead of loadrawPtr in Object.getClass * Workaround Object.getClass when clsPtr does not contain j.l.Class instance * Create registry for instances of j.l.Class to prevent GC from collecting them * Remove commented code * Lower.genMethodLookup uses original value to test targets (due to type conversion in genVal for Val.String) * Replace ClassInstancesRegistry Array with UnrolledBuffer to store class instances * Add Val.ClassOf support to NIR text parser * Add Object.getClass to Lower dependencies * Revert "Replace ClassInstancesRegistry Array with UnrolledBuffer to store class instances" This reverts commit 58cc6c6. * Move ClassInstancesRegistry to seperate file * Styling and access fixes to ClassInstancesRegistry. Use System.arraycopy instead of Array.copy * Move class caching and Rtti -> Class lookup to scalanative.runtime * After rebase fixes * Use same calling and styling convention for runtime.toClass as other Rt methods * After rebase fix * After rebase fix: Port new ClassSuite tests to JUnit * Comments styling fix * Simplify Class.is method * Fix comment
* 1435 - Move j.l.Class allocations to linker/runtime. Introduce caching of j.l.Classes * 1435 - Compare _Class instances using their rawPtr instead of Rt.Type ptr * 1435 - Updated immix/commix RTTI structures to contain additional class pointer * 1435 - Transform Vals in Lower with nir.Buffer in order to support Val.ClassOf -> Object.getClass conversion * Added classOf / Object.getClass tests * Use loadObject instead of loadrawPtr in Object.getClass * Workaround Object.getClass when clsPtr does not contain j.l.Class instance * Create registry for instances of j.l.Class to prevent GC from collecting them * Remove commented code * Lower.genMethodLookup uses original value to test targets (due to type conversion in genVal for Val.String) * Replace ClassInstancesRegistry Array with UnrolledBuffer to store class instances * Add Val.ClassOf support to NIR text parser * Add Object.getClass to Lower dependencies * Revert "Replace ClassInstancesRegistry Array with UnrolledBuffer to store class instances" This reverts commit 58cc6c6. * Move ClassInstancesRegistry to seperate file * Styling and access fixes to ClassInstancesRegistry. Use System.arraycopy instead of Array.copy * Move class caching and Rtti -> Class lookup to scalanative.runtime * After rebase fixes * Use same calling and styling convention for runtime.toClass as other Rt methods * After rebase fix * After rebase fix: Port new ClassSuite tests to JUnit * Comments styling fix * Simplify Class.is method * Fix comment
Resolves #1435
This PR moves allocation of java.lang.Class instances to linker phase and introduces caching of them.
In previous implementation Class instances were created by compiler backend, which lead to multiple instances of this type in runtime and made impossible to cache them.
Current implementation introduces new Val literal type
Val.ClassOf(n: Global)
which replaces allocations from previous implementation. At lowering phase this literals are transformed intoObject.getClass
calls with argument of RTTI object (as previous). RTTI type was also extended to store reference of associated with it java.lang.Class. InsideObject.getClass
it's checked whether RTTI class pointer is not empty and instantiated in otherwise. Newly created instance of j.l.Class is added to registry in order to prevent GC from collecting it.Immix/Commix implementation was fixed to handle new RTTI layout.