RFR: 8339205: Optimize StackMapGenerator$Frame

Shaojin Wen swen at openjdk.org
Wed Aug 28 23:37:29 UTC 2024


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

>> 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()`?
>
> I have tried isPrimitive(). The codeSize of the virtual function call isPrimitive() is 2 bytes larger than instanceof. The performance of instanceof should be better. But isPrimitive() is a public API and easier to understand. If you think isPrimitive is better, I think it's OK too.

ClassDesc {
    default boolean isPrimitive() {
        return descriptorString().length() == 1;
    }       
}


Using isPrimitive will result in three virtual function calls, isPrimitive/descriptorString/length. C2 can be optimized inline, but one more reference access to descriptorString is necessary. Considering the possible slowdown caused by cache miss, can we keep using instanceof?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20756#discussion_r1735388215


More information about the core-libs-dev mailing list