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

Implement MethodHandleNatives native code #10690

Merged
merged 14 commits into from
Jan 30, 2021

Conversation

fengxue-IS
Copy link
Contributor

Related: #7352

Co-authored-by: Babneet Singh sbabneet@ca.ibm.com
Signed-off-by: Jack Lu Jack.S.Lu@ibm.com

@fengxue-IS
Copy link
Contributor Author

I've noticed that Java_java_lang_invoke_MethodHandleNatives_checkClassBytes have been added as part of Java 15, will have to look into if that should be merged into MethodHandleNatives.cpp

Copy link
Member

@DanHeidinga DanHeidinga left a comment

Choose a reason for hiding this comment

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

I reviewed about 1/2 this before stopping as I need more context on what the operations are expected to do.

A good next step would be to document each of the functions so it's clear what the expected behaviour is

@fengxue-IS
Copy link
Contributor Author

Thanks for the review @DanHeidinga, I will add documentation comments for the function to provide details on the expected behavior

Copy link
Contributor Author

@fengxue-IS fengxue-IS left a comment

Choose a reason for hiding this comment

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

I have updated the code to include a function header that describe the expected behavior of each function and added comments to large code block to make it more readable. Also fixed some formatting issues.

While I was updating the comments, I realized there are more potential places where GC could occur and invalidate the native object reference. I will push the fix for these (either refetch the data or push objects to special frame) once local testing passed

Copy link
Member

@DanHeidinga DanHeidinga left a comment

Choose a reason for hiding this comment

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

Taking a break for lunch. Will pick up the review from sigForPrimitiveOrVoid later

runtime/oti/jclprots.h Show resolved Hide resolved
Copy link
Member

@DanHeidinga DanHeidinga left a comment

Choose a reason for hiding this comment

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

@fengxue-IS there's a lot of feedback here already so I'll stop reviewing at this point.

Please look at all the allocations and check for allocations failures. Figuring out how to report that back to the callers will help clarify your apis.

It's also good to minimize the lifetimes of every fetched object so they are less likely to be lost by a GC. It'll also make the code easier to reason about

@DanHeidinga DanHeidinga self-assigned this Nov 27, 2020
@DanHeidinga DanHeidinga added the project:MH Used to track Method Handles related work label Nov 27, 2020
@fengxue-IS
Copy link
Contributor Author

Thanks @DanHeidinga for the indepth review, I will look into the issues pointed out and also go through all the allocation codes to make sure to check for any potential failures.

@fengxue-IS
Copy link
Contributor Author

  • Added checks for allocation failure and handle exception from helper functions
  • Added support for CallerSensitive annotation
  • Moved createFieldObject to reflecthelp.c and added to the J9ReflectionFunctions table
  • Modified variable declaration to minimize refetch required after potential GC points
  • Use existing objects from reflect object rather than generating new objects
  • Fixed formating
  • Created TODO for JSR 292 MethodHandleNatives APIs #11443 to track todo items to be completed in future PR

@DanHeidinga can you take another look please

fengxue-IS and others added 4 commits January 12, 2021 12:29
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
- use reflect object's name/type/signature field instead of constructing
new object
- fill in name/signature for method/constructor rather than lazily
computing during resolve
- idFromReflectObject can't fail as long as the object is not null

Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
fengxue-IS and others added 9 commits January 12, 2021 12:29
- expand reflectFunctions table
- reflectFunctions->createFieldObject

Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
- replace copyStringToUTF8Helper with copyStringToUTF8WithMemAlloc
- add MN_CALLER_SENSITIVE check
- add OOM checks and exit with goto
- throw and handle nativeOOMError
- fix all missing Error checking and refetch after any GC point
- fix tracepoint modifiers
- fix use of bool in c code
- fix declaration skipped by goto

Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
- use Class.classNameString if possible
- check if arrayClass to set proper classNameString format

Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
@fengxue-IS
Copy link
Contributor Author

Fix all issues in review comments, local build passed
@DanHeidinga can you please take a look?

- create common helper for setCallSiteTargetNormal & setCallSiteTargetVolatile
- add static keyword for helper functions
- fix array store index

Co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
@fengxue-IS
Copy link
Contributor Author

Addressed review comments, local compile/basic testing passed.
@DanHeidinga do you see any other issues I should fix?

Comment on lines +481 to +482
UDATA offset = (UDATA)vmFuncs->instanceFieldOffset(currentThread, J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, callsiteObject), (U_8*)"target", strlen("target"), (U_8*)"Ljava/lang/invoke/MethodHandle;", strlen("Ljava/lang/invoke/MethodHandle;"), NULL, NULL, 0);
MM_ObjectAccessBarrierAPI objectAccessBarrier = MM_ObjectAccessBarrierAPI(currentThread);
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good candidate to put these in the VMConstantpool

@DanHeidinga
Copy link
Member

I don't see any holes where objects will be lost now so I'm OK with proceeding with this change.

Having said that, I'm not 100% onboard with this approach. The heavy string allocation and copying should be looked at again to see if there's a better way to solve this. Given the other up-calls to the VM, I'd be tempted to implement this in Java and cache the signature per MT to make this cleaner.

All that can wait for a later PR though.

@DanHeidinga
Copy link
Member

Jenkins test sanity xlinux jdk16

@DanHeidinga
Copy link
Member

Jenkins test sanity xlinux jdk8,jdk11

@DanHeidinga DanHeidinga merged commit 5e0957a into eclipse-openj9:master Jan 30, 2021
@fengxue-IS
Copy link
Contributor Author

Having said that, I'm not 100% onboard with this approach. The heavy string allocation and copying should be looked at again to see if there's a better way to solve this. Given the other up-calls to the VM, I'd be tempted to implement this in Java and cache the signature per MT to make this cleaner.

Thanks for the suggestions Dan, I have added this to the TODO list (#11443) to be investigated later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:vm project:MH Used to track Method Handles related work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants