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

Use the right symbol for constant string placeholder #11092

Merged
merged 2 commits into from
Nov 25, 2020

Conversation

liqunl
Copy link
Contributor

@liqunl liqunl commented Nov 3, 2020

Constant string can be used as a placeholder and be patched to other
object. Set the flag on the symbol according to the actual object type.

Signed-off-by: Liqun Liu liqunl@ca.ibm.com

@DanHeidinga
Copy link
Member

@liqunl my understanding was that other values besides MHs can be stored in these "string" constants as the Unsafe.defineAnonymousClass allows any object to be stored there. The bytecode pattern will be something like:

ldc  #42 // Constant_String but patched to some other object
instanceof <real type>
....

We want to be careful to not rely on the resolved value only being a string or a MH.

@fengxue-IS / @babsingh to confirm

@fengxue-IS
Copy link
Contributor

for Java 8-14 where the InvokerBytecodeGenerator uses cp patching to reference dynamic object, the constant string placeholder can contain non-MH objects.
for Java 15+, the patch objects are stored into hiddenclass's classData field, so doesn't require checkcast.
@babsingh to confirm about the hiddenclass classData access

@babsingh
Copy link
Contributor

babsingh commented Nov 3, 2020

to confirm about the hiddenclass classData access

In JDK15+, InvokerBytecodeGenerator uses the below-mentioned fields of ClassData to generate the appropriate bytecodes with the required checkcast instructions. In the below bytecodes, the static init block loads the value from classData into the field (_DATA_LambdaForm_0) with the correct checkcast. So, a checkcast won't be needed during invocation in JDK15+.

An instance of ClassData contains:

        // Used to generate the field to access the object; e.g. _DATA_LambdaForm_0.
        final String name;

        // Describes if the object is a Class, MethodHandle, LambdaForm or Object.
        // Used to add a checkcast before storing the object value into the generated field.
        final String desc;

        // Stored object value.
        final Object value;

Sample generated bytecodes to access classData in JDK16:

  static {};
    descriptor: ()V
    flags: (0x0008) ACC_STATIC
    Code:
      stack=2, locals=1, args_size=0
         0: ldc           #2                  // class java/lang/invoke/LambdaForm$BMH003
         2: invokestatic  #32                 // Method java/lang/invoke/MethodHandleNatives.classData:(Ljava/lang/Class;)Ljava/lang/Object;
         5: checkcast     #34                 // class java/util/List
         8: astore_0
         9: aload_0
        10: iconst_0
        11: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
        16: checkcast     #40                 // class java/lang/invoke/LambdaForm
        19: putstatic     #42                 // Field _DATA_LambdaForm_0:Ljava/lang/invoke/LambdaForm;
        22: return

@liqunl
Copy link
Contributor Author

liqunl commented Nov 4, 2020

@DanHeidinga @fengxue-IS @babsingh Thanks for pointing that out. Will change the code to load any objects.

@liqunl liqunl force-pushed the adoptOpenjdkMH/ldc branch 4 times, most recently from e62af43 to 066e81e Compare November 9, 2020 15:37
@liqunl
Copy link
Contributor Author

liqunl commented Nov 9, 2020

Depends on eclipse-omr/omr#5664

@liqunl liqunl force-pushed the adoptOpenjdkMH/ldc branch 2 times, most recently from 299e801 to d19110c Compare November 11, 2020 04:40
@liqunl liqunl changed the title WIP: Use the right symbol for constant string placeholder Use the right symbol for constant string placeholder Nov 12, 2020
@liqunl
Copy link
Contributor Author

liqunl commented Nov 12, 2020

@andrewcraik @DanHeidinga May I ask for your review?
@dmitry-ten Could you review the JITServer change?

Copy link
Contributor

@andrewcraik andrewcraik left a comment

Choose a reason for hiding this comment

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

The non-JITServer parts look good to me

Copy link
Contributor

@dmitry-ten dmitry-ten left a comment

Choose a reason for hiding this comment

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

Overall LGTM,
please increment MINOR_NUMBER in JITServer::CommunicationStream and update message numbers.

runtime/compiler/net/MessageTypes.hpp Show resolved Hide resolved
runtime/compiler/net/MessageTypes.hpp Show resolved Hide resolved
@dmitry-ten
Copy link
Contributor

This commit results in 2 additional messages when a string is unresolved but if the increase is significant we'll deal with it later.

@liqunl
Copy link
Contributor Author

liqunl commented Nov 13, 2020

This commit results in 2 additional messages when a string is unresolved but if the increase is significant we'll deal with it later.

It's 2 additional messages when the cp entry is resolved. I can fix it by checking if the symref is first created, only do the check if symref is first created.

@dmitry-ten
Copy link
Contributor

It's 2 additional messages when the cp entry is resolved. I can fix it by checking if the symref is first created, only do the check if symref is first created.
If that's something that would potentially reduce the number of messages then sure, it'd be nice.

@liqunl liqunl force-pushed the adoptOpenjdkMH/ldc branch 2 times, most recently from 757022d to d16b22f Compare November 13, 2020 17:27
@liqunl liqunl changed the title Use the right symbol for constant string placeholder WIP: Use the right symbol for constant string placeholder Nov 13, 2020
@liqunl
Copy link
Contributor Author

liqunl commented Nov 13, 2020

Looking at a failure in my pbuild after updating the commits, WIP the PR now.

@liqunl liqunl changed the title WIP: Use the right symbol for constant string placeholder Use the right symbol for constant string placeholder Nov 16, 2020
@liqunl
Copy link
Contributor Author

liqunl commented Nov 16, 2020

Fixed the pbuild failure. @dmitry-ten @andrewcraik Could you take a look again?

@dmitry-ten
Copy link
Contributor

Liqun Liu added 2 commits November 16, 2020 19:09
Add function getObjectClassAt to get class of an object stored at an
address.

Signed-off-by: Liqun Liu <liqunl@ca.ibm.com>
Constant string can be used as a placeholder and be patched to other
object. Set the flag on the symbol according to the actual object type.

Signed-off-by: Liqun Liu <liqunl@ca.ibm.com>
@liqunl
Copy link
Contributor Author

liqunl commented Nov 16, 2020

@dmitry-ten Fixed the minor number

@dmitry-ten
Copy link
Contributor

LGTM

@liqunl
Copy link
Contributor Author

liqunl commented Nov 17, 2020

@DanHeidinga I have made changes to support any type of patched objects, could you review again?

@DanHeidinga
Copy link
Member

@DanHeidinga I have made changes to support any type of patched objects, could you review again?

Design wise, this seems right to me. I'll defer to @andrewcraik's already provided review.

@andrewcraik
Copy link
Contributor

LGTM

@liqunl
Copy link
Contributor Author

liqunl commented Nov 23, 2020

@DanHeidinga Andrew has approved this PR, may I ask you to help launching the PR build and merge if it passes?

@DanHeidinga
Copy link
Member

Jenkins test sanity all jdk11

@DanHeidinga
Copy link
Member

Builds have passed and given @andrewcraik's approval above, merging

@DanHeidinga DanHeidinga merged commit fb11ea2 into eclipse-openj9:master Nov 25, 2020
@liqunl liqunl deleted the adoptOpenjdkMH/ldc branch December 1, 2020 00:35
@harryyu1994 harryyu1994 mentioned this pull request Dec 9, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants