RFR: 8339205: Optimize StackMapGenerator$Frame

Chen Liang liach at openjdk.org
Wed Aug 28 23:37:28 UTC 2024


On Wed, 28 Aug 2024 22:20:25 GMT, Shaojin Wen <swen at openjdk.org> wrote:

> A small optimization to reduce the code size of StackMapGenerator.Frame's pushStack and setLocalsFromArg methods
> 
> Below is the compiler log of C2
> 
> 
> # baseline
> jdk.internal.classfile.impl.StackMapGenerator$Frame::pushStack (27 bytes)   failed to inline: callee uses too much stack
> jdk.internal.classfile.impl.StackMapGenerator$Frame::pushStack (46 bytes)   failed to inline: callee is too large
> jdk.internal.classfile.impl.StackMapGenerator$Frame::pushStack (183 bytes)   failed to inline: callee is too large
> jdk.internal.classfile.impl.StackMapGenerator$Frame::setLocalsFromArg (367 bytes)   failed to inline: callee is too large
> 
> # current
> jdk.internal.classfile.impl.StackMapGenerator$Frame::pushStack (26 bytes)   inline
> jdk.internal.classfile.impl.StackMapGenerator$Frame::pushStack (37 bytes)   failed to inline: callee is too large
> jdk.internal.classfile.impl.StackMapGenerator$Frame::pushStack (82 bytes)
> jdk.internal.classfile.impl.StackMapGenerator$Frame::setLocalsFromArg (255 bytes)   failed to inline: callee is too large

src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java line 959:

> 957:                  : pushStack(
> 958:                          desc == CD_float ? Type.FLOAT_TYPE :
> 959:                          desc instanceof PrimitiveClassDescImpl ? Type.INTEGER_TYPE : Type.referenceType(desc));

I think you can first use a `desc.isPrimitive()` and then go through all primitive type checks; handling references first should be faster in general.

src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java line 1058:

> 1056:             for (int i = 0; i < methodDesc.parameterCount(); i++) {
> 1057:                 var desc = methodDesc.parameterType(i);
> 1058:                 if (desc == CD_void) throw new AssertionError("Should not reach here");

You can use
Suggestion:

                assert desc != CD_void;

So this fails in unit tests. But this takes code size.

src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java line 1060:

> 1058:                 if (desc == CD_void) throw new AssertionError("Should not reach here");
> 1059:                 Type type;
> 1060:                 if (desc instanceof PrimitiveClassDescImpl) {

Can we use `desc.isPrimitive()`?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20756#discussion_r1735361672
PR Review Comment: https://git.openjdk.org/jdk/pull/20756#discussion_r1735362742
PR Review Comment: https://git.openjdk.org/jdk/pull/20756#discussion_r1735362061


More information about the core-libs-dev mailing list