RFR: 8357660: [JVMCI] Add Support for Retrieving All Indy BootstrapMethodInvocations directly from the ConstantPool

Tom Shull duke at openjdk.org
Fri May 30 15:06:30 UTC 2025


On Sat, 24 May 2025 08:49:54 GMT, Doug Simon <dnsimon at openjdk.org> wrote:

>> This PR adds support for directly retrieving all invokedynamic BootstrapMethodInvocations from a ConstantPool.
>> 
>> In addition, two methods are added to the BootstrapMethodInvocations:
>> 1. `void resolveInvokeDynamic()`
>> 2. `JavaConstant lookupInvokeDynamicAppendix()`
>> 
>> The combination of these two features allows one to directly interact with all invokedynamic information of a given ConstantPool without having to iterate through all of the Classfile's methods to find all invokedynamic bytecodes
>
> Please add some tests for the new methods to `test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.hotspot.test/src/jdk/vm/ci/hotspot/test/TestDynamicConstant.java`.

@dougxc I integrated testing for the new methods into `TestDynamicConstant.java` now

@dougxc I cleaned up the PR to now have the symmetric lookup option and updated the tests

> src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotConstantPool.java line 657:
> 
>> 655:         } else {
>> 656:             return IntStream.range(1, length())
>> 657:                             .filter(this::isDynamicEntry)
> 
> Looks like you forgot to add the definition of `isDynamicEntry` that I suggested:
> 
>     private boolean isDynamicEntry(int cpi) {
>         JvmConstant tagAt = getTagAt(cpi);
>         return tagAt != null && tagAt.name.equals("Dynamic");
>     }

Yes, I applied the suggested change via github, and am just validating it works now (which of course it doesn't). I'll fix it

> src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ConstantPool.java line 198:
> 
>> 196:          * If this bootstrap method invocation is for a {@code
>> 197:          * CONSTANTAdd_InvokeDynamic_info} pool entry, then this method ensures the
>> 198:          * invoke dynamic is resolved. This can be used to compile time resolve the
> 
> What exactly does resolving an invoke dynamic mean?
> Also I would leave out the sentence about "compile time" unless you clarify exactly what that means.

Would you want me to add a reference to https://docs.oracle.com/javase/specs/jvms/se24/html/jvms-5.html#jvms-5.4.3.6?

I removed the compile time sentence; I had it to be consistent with `loadReferencedType`

> src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ConstantPool.java line 237:
> 
>> 235:      * is returned.
>> 236:      */
>> 237:     BootstrapMethodInvocation[] lookupAllIndyBootstrapMethodInvocations();
> 
> Why not make this return all `BootstrapMethodInvocation`s? The caller can then filter out the indy ones with `isInvokeDynamic`. Also, please return a `List<BootstrapMethodInvocation>` instead of an array - we should never return arrays from JVMCI (see #23159 as an example of addressing existing API). Lastly, return `List.of()` instead of null.

Changed to return a list.

> Why not make this return all BootstrapMethodInvocations
1. Within HotSpot it is very easy to pick off all indy BootstrapMethodInvocations via [the ConstantPoolCache](https://github.com/openjdk/jdk/blob/72a3022dc6a1521d8e3f08fe5d592f760fc462d2/src/hotspot/share/oops/cpCache.hpp#L74)
2. Each invokedynamic bytecode location has a unique BootstrapMethodInvocation instance, but they may share the same constant pool entry, so it's not trivial to find all BootstrapMethodInvocations. One would have to iterate both all method bytecodes and constant pool slots, and do some additional filtering.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/25420#issuecomment-2909796813
PR Comment: https://git.openjdk.org/jdk/pull/25420#issuecomment-2918426821
PR Review Comment: https://git.openjdk.org/jdk/pull/25420#discussion_r2114780251
PR Review Comment: https://git.openjdk.org/jdk/pull/25420#discussion_r2109301347
PR Review Comment: https://git.openjdk.org/jdk/pull/25420#discussion_r2109317539


More information about the graal-dev mailing list