Skip to content

Conversation

@iklam
Copy link
Member

@iklam iklam commented Aug 15, 2023

This PR is part of the clean up JVMCI to track JDK-8301993, where the constant pool cache is being removed (as of now, only method references use the CpCache).

  1. rawIndexToConstantPoolIndex() is used only for the invokedynamic bytecode. It should be renamed to indyIndexConstantPoolIndex()

  2. rawIndexToConstantPoolCacheIndex() should not be called for the invokedynamic bytecode, which doesn't use cpCache entries after JDK-8301995.

  3. Some cpi parameters should be renamed to rawIndex or which

  4. Added a test case for ConstantPool.lookupAppendix(), which was not tested in the JDK repo.

I added comments about the 4 types of indices used in HotSpotConstantPool.java: cpi, rawIndex, cpci and which. The latter two types will be removed after JDK-8301993 is complete.

Note that there are still some incorrect use of cpi in the implementation and test cases. Those will be cleaned up in JDK-8314172


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8314249: Refactor handling of invokedynamic in JVMCI ConstantPool (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15297/head:pull/15297
$ git checkout pull/15297

Update a local copy of the PR:
$ git checkout pull/15297
$ git pull https://git.openjdk.org/jdk.git pull/15297/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15297

View PR using the GUI difftool:
$ git pr show -t 15297

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15297.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 15, 2023

👋 Welcome back iklam! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 15, 2023

@iklam The following labels will be automatically applied to this pull request:

  • graal
  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added graal graal-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org labels Aug 15, 2023
@iklam iklam marked this pull request as ready for review August 15, 2023 22:17
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 15, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 15, 2023

Webrevs

* {@code constantPool}.
* Gets the appendix object (if any) associated with the entry identified by {@code which}.
*
* @param which if negative, is treated as an encoded indy index for INVONEDYNAMIC;
Copy link
Member

Choose a reason for hiding this comment

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

INVONEDYNAMIC -> INVOKEDYNAMIC

* <li>which - May be either a {@code rawIndex} or a {@code cpci}.</li>
* </ul>
*
* Note that {@code cpci} and {@code which} are used only in the HotSpot-specific implementation. They are not used by the public iterface in jdk.vm.ci.meta.*.
Copy link
Member

Choose a reason for hiding this comment

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

iterface -> iterface

* {@code cpi} was not decoded from an instruction stream
* @return the bootstrap method invocation details or {@code null} if the entry at {@code cpi}
* @param index if {@code opcode} is -1, {@code index} is a constant pool index. Otherwise {@code opcode}
* must be ${code Bytecodes.INVOKEDYNAMIC}, and {@code index} must be the operand of that
Copy link
Member

Choose a reason for hiding this comment

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

${code Bytecodes.INVOKEDYNAMIC} -> {@code INVOKEDYNAMIC} (in numerous places)

@dougxc
Copy link
Member

dougxc commented Aug 16, 2023

Thanks a lot for this cleanup and adding the extra tests.

@openjdk
Copy link

openjdk bot commented Aug 16, 2023

@iklam This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8314249: Refactor handling of invokedynamic in JVMCI ConstantPool

Reviewed-by: dnsimon, coleenp

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 22 new commits pushed to the master branch:

  • 6b396da: 8062795: (fs) Files.setPermissions requires read access when NOFOLLOW_LINKS specified
  • 7b28d36: 8314330: java/foreign tests should respect vm flags when start new processes
  • b32d641: 8311943: Cleanup usages of toLowerCase() and toUpperCase() in java.base
  • 13f6450: 8313765: Invalid CEN header (invalid zip64 extra data field size)
  • 24e896d: 8310275: Bug in assignment operator of ReservedMemoryRegion
  • 1925508: 8314144: gc/g1/ihop/TestIHOPStatic.java fails due to extra concurrent mark with -Xcomp
  • b80001d: 8314209: Wrong @SInCE tag for RandomGenerator::equiDoubles
  • ef6db5c: 8314211: Add NativeLibraryUnload event
  • 49ddb19: 8313760: [REDO] Enhance AES performance
  • d46f0fb: 8313720: C2 SuperWord: wrong result with -XX:+UseVectorCmov -XX:+UseCMoveUnconditionally
  • ... and 12 more: https://git.openjdk.org/jdk/compare/80809ef4ccdfd2ebfa9fd1eaf393d14e443dc760...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 16, 2023
Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

This makes sense. Do we run this test with hotspot testing?

public BootstrapMethodInvocation lookupBootstrapMethodInvocation(int rawCpi, int opcode) {
int cpi = opcode == -1 ? rawCpi : rawIndexToConstantPoolIndex(rawCpi, opcode);
public BootstrapMethodInvocation lookupBootstrapMethodInvocation(int index, int opcode) {
int cpi = opcode == -1 ? index : indyIndexConstantPoolIndex(index, opcode);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would opcode be -1 here?

Copy link
Member

Choose a reason for hiding this comment

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

So that tests such as TestDynamicConstant.java can iterate through the constant pool, looking for invokedynamic related entries.

@iklam
Copy link
Member Author

iklam commented Aug 16, 2023

This makes sense. Do we run this test with hotspot testing?

Yes, tests under test/hotspot/jtreg/compiler/jvmci are regularly tested.

@iklam
Copy link
Member Author

iklam commented Aug 17, 2023

Thanks @dougxc @coleenp for the review.
/integrate

@openjdk
Copy link

openjdk bot commented Aug 17, 2023

Going to push as commit 0299364.
Since your change was applied there have been 44 commits pushed to the master branch:

  • 96778dd: 8314169: Combine related RoundingMode logic in j.text.DigitList
  • 808bb1f: 8314246: javax/swing/JToolBar/4529206/bug4529206.java fails intermittently on Linux
  • 6445314: 8314477: Improve definition of "prototypical type"
  • d27daf0: 8314129: Make fields final in java.util.Scanner
  • a8ab3be: 8314261: Make fields final in sun.net.www
  • 3bb8afb: 8314489: Add javadoc index entries for java.lang.Math terms
  • 2505ceb: 8314533: ProblemList runtime/cds/appcds/customLoader/HelloCustom_JFR.java on linux-all with ZGC
  • b33ff30: 8313661: [REDO] Relax prerequisites for java.base-jmod target
  • 62ca001: 8313357: Revisit requiring SA tests on OSX to either run as root or use sudo
  • 388dcff: 8282712: VMConnection.open() does not detect if VM failed to be created, resulting in NPE
  • ... and 34 more: https://git.openjdk.org/jdk/compare/80809ef4ccdfd2ebfa9fd1eaf393d14e443dc760...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 17, 2023
@openjdk openjdk bot closed this Aug 17, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 17, 2023
@openjdk
Copy link

openjdk bot commented Aug 17, 2023

@iklam Pushed as commit 0299364.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

final int index = rawIndexToConstantPoolCacheIndex(cpi, opcode);
final HotSpotResolvedJavaMethod method = compilerToVM().lookupMethodInPool(this, index, (byte) opcode, (HotSpotResolvedJavaMethodImpl) caller);
public JavaMethod lookupMethod(int rawIndex, int opcode, ResolvedJavaMethod caller) {
final int cpci = rawIndexToConstantPoolCacheIndex(rawIndex, opcode);
Copy link
Member

Choose a reason for hiding this comment

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

@iklam we need to support opcode == INVOKEDYNAMIC here. After this change, we are seeing:

Caused by: java.lang.InternalError: java.lang.IllegalArgumentException: unexpected opcode 186
        at jdk.internal.vm.compiler/org.graalvm.compiler.serviceprovider.GraalServices.lookupMethodWithCaller(GraalServices.java:464)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.lookupMethodInPool(BytecodeParser.java:4274)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.lookupMethodInPool(SharedGraphBuilderPhase.java:209)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.lookupMethod(BytecodeParser.java:4266)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeDynamic(BytecodeParser.java:1725)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5363)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3431)
        ... 116 more
Caused by: java.lang.IllegalArgumentException: unexpected opcode 186
        at jdk.internal.vm.ci/jdk.vm.ci.hotspot.HotSpotConstantPool.rawIndexToConstantPoolCacheIndex(HotSpotConstantPool.java:275)
        at jdk.internal.vm.ci/jdk.vm.ci.hotspot.HotSpotConstantPool.lookupMethod(HotSpotConstantPool.java:722)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at jdk.internal.vm.compiler/org.graalvm.compiler.serviceprovider.GraalServices.lookupMethodWithCaller(GraalServices.java:457)
        ... 122 more

when building libgraal. The following patch seems to fix it:

diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java
index d4bb97f03c4..1d32211f1a0 100644
--- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java
+++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java
@@ -719,7 +719,15 @@ private static JavaType getJavaType(final Object type) {
 
     @Override
     public JavaMethod lookupMethod(int rawIndex, int opcode, ResolvedJavaMethod caller) {
-        final int cpci = rawIndexToConstantPoolCacheIndex(rawIndex, opcode);
+        final int cpci;
+        if (opcode == jdk.vm.ci.hotspot.HotSpotConstantPool.Bytecodes.INVOKEDYNAMIC) {
+            if (!isInvokedynamicIndex(rawIndex)) {
+                throw new IllegalArgumentException("expected a raw index for INVOKEDYNAMIC but got " + rawIndex);
+            }
+            cpci = rawIndex;
+        } else {
+            cpci = rawIndexToConstantPoolCacheIndex(rawIndex, opcode);
+        }
         final HotSpotResolvedJavaMethod method = compilerToVM().lookupMethodInPool(this, cpci, (byte) opcode, (HotSpotResolvedJavaMethodImpl) caller);
         if (method != null) {
             return method;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

graal graal-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants