CodeBuilder.loadParameter and loadReceiver
-
liangchenblue at gmail.com
Sun Apr 30 21:35:58 UTC 2023
Since now we decide to cache MethodTypeDesc symbols in MethodInfo to
reduce creation overheads at stackmap generation, these symbols
inadvertently, and to our convenience, allow us to more easily load
method arguments:
Before:
for (int j = 0; j < mi.desc.parameterCount(); j++) {
bcb.loadInstruction(TypeKind.from(mi.desc.parameterType(j)),
bcb.parameterSlot(j));
}
Now:
for (int j = 0; j < mi.desc.parameterCount(); j++) {
bcb.loadParameter(j);
}
Where loadParameter implementation can be: (except delegation implementations)
public CodeBuilder loadParameter(int paramNo) {
var kind = TypeKind.from(methodInfo.methodTypeSymbol().parameterType(paramNo));
loadInstruction(kind, parameterSlot(paramNo));
return this;
}
Hence, with the implementation changes in 8306842
https://github.com/openjdk/jdk/pull/13671 that added
methodInfo.methodTypeSymbol(), we have an opportunity for this more
convenient method.
Similarly, we can add a "loadReceiver"/"loadThis" that performs
aload(0) for instance methods and throws for static methods.
Brian, can you evaluate if this is a good addition API-wise? I think
this new API can cover most usages of the old parameterSlot() calls;
at least this is the case in 6983726 and 8301703 patches.
Chen Liang
More information about the classfile-api-dev
mailing list