Skip to content
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

Add API getDefaultValueSlotAddress #15118

Merged

Conversation

a7ehuo
Copy link
Contributor

@a7ehuo a7ehuo commented May 25, 2022

getDefaultValueSlotAddress() returns the reference to the address of the default value instance for a value class.

[edited]
If the class is initialized, devalue value instance for the class is allocated. When generating aconst_init, we can load from the default value slot.

- [x] Depends on eclipse/omr#6530

@a7ehuo a7ehuo added comp:jit project:valhalla Used to track Project Valhalla related work labels May 25, 2022
@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 25, 2022

This change depends on

@hzongaro @0xdaryl May I ask you to review? Thanks!

@a7ehuo a7ehuo requested review from 0xdaryl and hzongaro May 25, 2022 21:06
@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 25, 2022

@mpirvu May I ask you to review the commit ccb6fde that adds API getDefaultValueSlotAddress? That commit has code related to JITServer. Thanks!

@a7ehuo a7ehuo requested a review from mpirvu May 25, 2022 21:10
Copy link
Contributor

@mpirvu mpirvu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update the MINOR_NUMBER as well in CommunicationStream.hpp ?
Also, is the value returned by vm->internalVMFunctions->getDefaultValueSlotAddress(j9class) immutable for a class? If it cannot change, we can cache it per class.

runtime/compiler/env/J9ClassEnv.cpp Outdated Show resolved Hide resolved
@0xdaryl
Copy link
Contributor

0xdaryl commented May 26, 2022

Just so we're clear: OMR 6530 can merge on its own, can't it? Or do you require a coordinated merge?

@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 26, 2022

is the value returned by vm->internalVMFunctions->getDefaultValueSlotAddress(j9class) immutable for a class?

It's immutable. I'll cache it per class

@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 26, 2022

OMR 6530 can merge on its own, can't it?

eclipse/omr#6530 should be merged first on its own. No coordinated merge is required

@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 26, 2022

@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 27, 2022

is the value returned by vm->internalVMFunctions->getDefaultValueSlotAddress(j9class) immutable for a class?

@mpirvu Sorry while I'm updating the code to cache the value, I realized that caching might not work because flattenedClassCache->defaultValue is not initialized until the class is initialized. When JITServerHelpers::getAndCacheRAMClassInfo is called at other places to cache ClientSessionData::ClassInfo, the default value instance for the class might not be allocated yet.

@mpirvu
Copy link
Contributor

mpirvu commented May 27, 2022

There is at least one other place in the code where we have a similar issue. I'll try to find that example.
The idea is to check whether the class is initialized (I believe that the server knows this) and if it's not, we ask the client for the answer. At the same time the client can answer if the class become initialized, in which case caching becomes possible.

@mpirvu
Copy link
Contributor

mpirvu commented May 27, 2022

ClassInfo._classInitialized field can be used to test whether the caches class is initialized.

The example I was referring to above is: TR_J9ServerVM::canAllocateInlineClass(TR_OpaqueClassBlock *clazz)
Here, we first test if class is initialized, if not we send a message specifically to find this information (and cache it if the class has become initialized) then proceed with the rest of the method.

@mpirvu
Copy link
Contributor

mpirvu commented May 27, 2022

I see that the code in TR_J9ByteCodeIlGenerator::genAconst_init already has a test for comp()->fej9()->isClassInitialized(TR::Compiler->cls.convertClassPtrToClassOffset(clazz).
If the defaultvalueSlotAddress is not valid before the class gets initialized, is it worth adding a FATAL_ASSERT in J9::ClassEnv::getDefaultValueSlotAddress to make sure that the class is initialized (to prevent future mistakes)?

@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 30, 2022

Thanks @mpirvu! I'll update the code to retrieve defaultValueSlotAddress from the client if it's NULL on the server side. Otherwise, return the cached value.

When class info is cached, the class might not have been initialized and the defaultValueSlotAddress is cached as NULL. defaultValueSlotAddress() is only called at the server if TR_J9ServerVM::isClassInitialized() returns true. But it doesn't mean defaultValueSlotAddress is valid because isClassInitialized could be cached as FALSE first then updated later when canAllocateInlineClass() is called. So

  • if defaultValueSlotAddress is NULL, check the client and update the cached value on the server side
  • if defaultValueSlotAddress is non-NULL, return the cached value

@a7ehuo a7ehuo force-pushed the static-allocation-defaultvalue branch 3 times, most recently from b6a7e3a to 8e025a6 Compare May 30, 2022 22:22
@a7ehuo
Copy link
Contributor Author

a7ehuo commented May 30, 2022

@mpirvu @hzongaro Addressed the above comments. Ready for another review. Thanks!

Copy link
Contributor

@mpirvu mpirvu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@hzongaro hzongaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Annabelle. I think this looks good overall. Just one question about whether setCanCGandReturn should be getting set on the default value symbol reference.

runtime/compiler/compile/J9SymbolReferenceTable.cpp Outdated Show resolved Hide resolved
@a7ehuo a7ehuo force-pushed the static-allocation-defaultvalue branch from 8e025a6 to 4a3eb12 Compare May 31, 2022 19:11
@a7ehuo a7ehuo changed the title WIP: Use pre allocate default value instance for aconst_init in ILGen Use pre allocate default value instance for aconst_init in ILGen May 31, 2022
@a7ehuo a7ehuo changed the title Use pre allocate default value instance for aconst_init in ILGen WIP: Use pre allocate default value instance for aconst_init in ILGen Jun 1, 2022
@a7ehuo
Copy link
Contributor Author

a7ehuo commented Jun 1, 2022

Change the status to WIP to explore other possibilities of the implementation in ILGen after offline discussion

@hzongaro hzongaro self-assigned this Jul 27, 2022
@a7ehuo
Copy link
Contributor Author

a7ehuo commented Jul 27, 2022

@hzongaro @mpirvu Just a heads up. I'm planning to use this PR to only submit the first commit "Add API getDefaultValueSlotAddress". The reason is that I have found that the other two commits require more factoring and AOT implementation which will require OMR change as well. I'll put them in another PR when it's ready.

I'll clean up the branch used in this PR and push another commit shortly.

`getDefaultValueSlotAddress()` returns the reference to the address
of the default value instance for a value class.

Signed-off-by: Annabelle Huo <Annabelle.Huo@ibm.com>
@a7ehuo a7ehuo force-pushed the static-allocation-defaultvalue branch from 4a3eb12 to bf552d6 Compare July 27, 2022 20:23
@a7ehuo a7ehuo changed the title WIP: Use pre allocate default value instance for aconst_init in ILGen Add API getDefaultValueSlotAddress Jul 27, 2022
@a7ehuo
Copy link
Contributor Author

a7ehuo commented Jul 27, 2022

@hzongaro @mpirvu As mentioned on the above, I've cleaned up this branch to include only the first commit that adds the classEnv API getDefaultValueSlotAddress(). It's ready for review. Thank you!

Copy link
Member

@hzongaro hzongaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changes look good. Thanks!

@hzongaro
Copy link
Member

hzongaro commented Aug 3, 2022

Marius @mpirvu, I just thought I'd follow up - do you have any further comments?

@mpirvu
Copy link
Contributor

mpirvu commented Aug 3, 2022

I see that the JITServer related files have not been modified since my last review, so I ok with the changes

@hzongaro hzongaro added this to TODO: VM in Valhalla L-World via automation Aug 4, 2022
@hzongaro
Copy link
Member

hzongaro commented Aug 4, 2022

Jenkins test sanity all jdk17

@hzongaro
Copy link
Member

hzongaro commented Aug 4, 2022

Jenkins test sanity xlinuxval jdknext

@hzongaro hzongaro merged commit 21749c7 into eclipse-openj9:master Aug 4, 2022
Valhalla L-World automation moved this from TODO: VM to Done Aug 4, 2022
@a7ehuo a7ehuo deleted the static-allocation-defaultvalue branch February 7, 2023 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:jit depends:omr project:valhalla Used to track Project Valhalla related work
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants