[code-reflection] RFR: Support bytecode generation for invocation of varArg method [v2]

Paul Sandoz psandoz at openjdk.org
Fri Nov 8 21:53:51 UTC 2024


On Thu, 7 Nov 2024 20:37:00 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

>> Support bytecode generation for invocation of varArg method.
>
> Mourad Abbay has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Add test cases for empty var arg, long and double
>  - Move code related to InvokeOp from processOperands(Op).

src/java.base/share/classes/java/lang/reflect/code/bytecode/BytecodeGenerator.java line 864:

> 862:                     case InvokeOp op -> {
> 863:                         if (op.isVarArgs()) {
> 864:                             processOperands(op.operands().subList(0, op.operands().size() - op.varArgOperands().size()));

Suggest we add the compliment to `varArgOperands()`, called say `argOperands()` such that `operands().equals(<argOperands() + varArgOperands()>)`

src/java.base/share/classes/java/lang/reflect/code/bytecode/BytecodeGenerator.java line 874:

> 872:                             } else {
> 873:                                 cob.newarray(typeKind);
> 874:                             }

Do this:

var compTypeDesc = compType.toNominalDescriptor();
if (compTypeDesc.isPrimitive()) {
  cob.newarray(TypeKind.from(ctd));
} else {
  cob.anewarray(compTypeDesc);
}

See code for case of NewOp when constructing an array.

src/java.base/share/classes/java/lang/reflect/code/bytecode/BytecodeGenerator.java line 876:

> 874:                             }
> 875:                             for (int j = 0; j < varArgOperands.size(); j++) {
> 876:                                 cob.dup();

Add a comment that this is duplicating the array value on the stack for the next loop iteration *and* subsequent the invoke instruction.

test/jdk/java/lang/reflect/code/bytecode/TestVarArg.java line 58:

> 56:         r += k();
> 57: 
> 58:         r += w(11L, 12L);

I meant add another method whose signature is `(double... )` or `(long... )` and test calls against that.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/272#discussion_r1835079373
PR Review Comment: https://git.openjdk.org/babylon/pull/272#discussion_r1835089996
PR Review Comment: https://git.openjdk.org/babylon/pull/272#discussion_r1835083650
PR Review Comment: https://git.openjdk.org/babylon/pull/272#discussion_r1835092267


More information about the babylon-dev mailing list