-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8315771: [JVMCI] Resolution of bootstrap methods with int[] static arguments #15588
Changes from 4 commits
b0940de
2cdc0b4
b33ffed
093d0ce
4ec0a7b
079969c
d6aa593
d75e092
f4377fc
9e0627a
ea4aa98
7c27481
7a8d9f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,25 @@ default JavaMethod lookupMethod(int cpi, int opcode) { | |
|
||
/** | ||
* The details for invoking a bootstrap method associated with a {@code CONSTANT_Dynamic_info} | ||
* or {@code CONSTANT_InvokeDynamic_info} pool entry . | ||
* or {@code CONSTANT_InvokeDynamic_info} pool entry. | ||
* | ||
* The procedure to obtain and use a {@link BootstrapMethodInvocation} is the following: | ||
* | ||
* <pre> | ||
* bsmInvocation = constantpool.lookupBootstrapMethodInvocation(index, opcode); | ||
* staticArguments = bsmInvocation.getStaticArguments(); | ||
* if staticArguments are PrimitiveConstant { | ||
* argCount = staticArguments.get(0).asInt(); | ||
* cpi = staticArguments.get(1).asInt(); | ||
* for (int i = 0; i < argCount; ++i) { | ||
* argCpi = constantpool.bootstrapArgumentIndexAt(cpi, i); | ||
* arguments[i] = constantpool.lookupConstant(argCpi, resolve); | ||
* } | ||
* call bootstrap method with newly resolved arguments | ||
* } else { | ||
* call bootstrap method with provided arguments | ||
* } | ||
* </pre> | ||
* | ||
* @jvms 4.4.10 The {@code CONSTANT_Dynamic_info} and {@code CONSTANT_InvokeDynamic_info} | ||
* Structures | ||
|
@@ -170,6 +188,22 @@ interface BootstrapMethodInvocation { | |
List<JavaConstant> getStaticArguments(); | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very confusing documentation. It's not clear what index or entry you are referring to each time you say "index". Please provide a concrete example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have rewritten the documentation, I hope it is clearer. I also added a second argument to be able to access different different static arguments on the same bootstrap specifier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still needs an example showing how this API should be used. Please add a complete (pseudo-code) example to the javadoc of |
||
* Gets the constant pool index of a static argument of a {@code CONSTANT_Dynamic_info} or | ||
* @{code CONSTANT_InvokeDynamic_info} entry. Used when the list of static arguments in the | ||
* {@link BootstrapMethodInvocation} is a {@code List<PrimitiveConstant>} 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 cpi} corresponds to | ||
* {@code pool_index} and the {@code index} has to be smaller than {@code arg_count}. | ||
* | ||
* @param cpi the index of a {@code CONSTANT_Dynamic_info} or @{code CONSTANT_InvokeDynamic_info} entry | ||
* @param index the index of the static argument in the list of static arguments | ||
* @return the constant pool index associated with the static argument | ||
*/ | ||
default int bootstrapArgumentIndexAt(int cpi, int index) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** | ||
* Gets the details for invoking a bootstrap method associated with the | ||
* {@code CONSTANT_Dynamic_info} or {@code CONSTANT_InvokeDynamic_info} pool entry | ||
|
@@ -182,8 +216,6 @@ interface BootstrapMethodInvocation { | |
* {@code index} was not decoded from a bytecode stream | ||
* @return the bootstrap method invocation details or {@code null} if the entry specified by {@code index} | ||
* is not a {@code CONSTANT_Dynamic_info} or @{code CONSTANT_InvokeDynamic_info} | ||
* @throws IllegalArgumentException if the bootstrap method invocation makes use of | ||
* {@code java.lang.invoke.BootstrapCallInfo} | ||
* @jvms 4.7.23 The {@code BootstrapMethods} Attribute | ||
*/ | ||
default BootstrapMethodInvocation lookupBootstrapMethodInvocation(int index, int opcode) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when
index
is out of bounds?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, it returns another constant pool index or a random number. I can add a check in the
CachedBSMArgs.get
method to prevent this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please. We should opt for exceptions over undefined behavior whenever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After double checking, there is in fact already an
assert
for checking if the index is out of bounds. Should I change it to an exception?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the assertion in code that can throw exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion is here. I don't think we can throw exception there. I could check the size in
jvmciCompilerToVM.bootstrapArgumentIndexAt
, but it would require a bit of code duplication to obtain it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. You should just add a note in the javadoc that the result is undefined if
index
is out of bounds. This is all internal API so I assume we can guarantee the value is correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is only used in
CachedBSMArgs.get
, which will throw anArrayIndexOutOfBoundsException
before we arrive there.