Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,12 @@ private int flags() {
return UNSAFE.getInt(getConstantPoolPointer() + config().constantPoolFlagsOffset);
}

/**
* Represents a list of static arguments from a {@link BootstrapMethodInvocation} of the form
* {{@code arg_count}, {@code pool_index}}, meaning the arguments are not already resolved
* and that the JDK has to lookup the arguments when they are needed. The {@code bssIndex}
* corresponds to {@code pool_index} and the {@code size} corresponds to {@code arg_count}.
*/
static class CachedBSMArgs extends AbstractList<JavaConstant> {
Copy link
Member

Choose a reason for hiding this comment

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

This class needs documentation.

private final JavaConstant[] cache;
private final HotSpotConstantPool cp;
Expand All @@ -540,6 +546,17 @@ static class CachedBSMArgs extends AbstractList<JavaConstant> {
this.cache = new JavaConstant[size];
}

/**
* Lazily resolves and caches the argument at the given index and returns it. The method
* {@link CompilerToVM#bootstrapArgumentIndexAt} is used to obtain the constant pool
* index of the entry and the method {@link CompilerToVM#lookupConstantInPool} is used
* to resolve it. If the resolution failed, the index is returned as a
* {@link PrimitiveConstant}.
*
* @param index index of the element to return
* @return A {@link PrimitiveConstant} representing a {@code CONSTANT_Dynamic_info}
* entry or a {@link JavaConstant} representing the static argument requested
*/
@Override
public JavaConstant get(int index) {
JavaConstant res = cache[index];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,24 @@ interface BootstrapMethodInvocation {
* entry. To resolve this entry, the corresponding bootstrap method has to be called first:
*
* <pre>
* resolveIndyOrCondy(int index, int opcode) {
* bsmInvocation = cp.lookupBootstrapMethodInvocation(index, opcode);
* staticArguments = bsmInvocation.getStaticArguments();
* for each argument in staticArguments {
* if argument is PrimitiveArgument {
* // argument is a condy, so opcode becomes -1
* resolveIndyOrCondy(argument.asInt(), -1);
* lookupConstant(int index, boolean resolve) {
Copy link
Member

Choose a reason for hiding this comment

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

This example should focus on resolving the static arguments:

List<JavaConstant> args = cp.getStaticArguments();
List<JavaConstant> resolvedArgs = new ArrayList<>(args.size());
for (JavaConstant c : args) {
    JavaConstant r = c;
    if (c instanceof PrimitiveConstant pc) {
        r = ...
    }
    resolvedArgs.append(rc);
}

It should also use real Java code to remove all ambiguity.

* constant = cp.lookupConstant(index, resolve);
* if constant is null {
* bsmInvocation = cp.lookupBootstrapMethodInvocation(index, -1);
* staticArguments = bsmInvocation.getStaticArguments();
* for each argument in staticArguments {
* if argument is PrimitiveArgument {
* lookupConstant(argument.asInt(), resolve);
* }
* }
* call boostrap method with resolved arguments to get constant
* }
* call original boostrap method with resolved arguments
* return constant;
* }
* </pre>
*
* The other types of entries are already resolved an can be used directly.
*
* @jvms 5.4.3.6
*/
List<JavaConstant> getStaticArguments();
Expand Down