From ab06a878f888827026424530781f0af414a8a611 Mon Sep 17 00:00:00 2001 From: Shaojin Wen Date: Sun, 22 Sep 2024 01:01:31 +0000 Subject: [PATCH] 8340544: Optimize setLocalsFromArg Reviewed-by: redestad, liach --- .../classfile/impl/StackMapGenerator.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java index c6564c289d6f5..f5cd9b80af844 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java @@ -1043,34 +1043,37 @@ private void setLocalRawInternal(int index, Type type) { void setLocalsFromArg(String name, MethodTypeDesc methodDesc, boolean isStatic, Type thisKlass) { int localsSize = 0; // Pre-emptively create a locals array that encompass all parameter slots - checkLocal(methodDesc.parameterCount() + (isStatic ? -1 : 0)); + checkLocal(Util.parameterSlots(methodDesc) + (isStatic ? -1 : 0)); + Type type; + Type[] locals = this.locals; if (!isStatic) { - localsSize++; if (OBJECT_INITIALIZER_NAME.equals(name) && !CD_Object.equals(thisKlass.sym)) { - setLocal(0, Type.UNITIALIZED_THIS_TYPE); + type = Type.UNITIALIZED_THIS_TYPE; flags |= FLAG_THIS_UNINIT; } else { - setLocalRawInternal(0, thisKlass); + type = thisKlass; } + locals[localsSize++] = type; } for (int i = 0; i < methodDesc.parameterCount(); i++) { var desc = methodDesc.parameterType(i); - if (!desc.isPrimitive()) { - setLocalRawInternal(localsSize++, Type.referenceType(desc)); - } else switch (desc.descriptorString().charAt(0)) { - case 'J' -> { - setLocalRawInternal(localsSize++, Type.LONG_TYPE); - setLocalRawInternal(localsSize++, Type.LONG2_TYPE); - } - case 'D' -> { - setLocalRawInternal(localsSize++, Type.DOUBLE_TYPE); - setLocalRawInternal(localsSize++, Type.DOUBLE2_TYPE); + if (desc == CD_long) { + locals[localsSize ] = Type.LONG_TYPE; + locals[localsSize + 1] = Type.LONG2_TYPE; + localsSize += 2; + } else if (desc == CD_double) { + locals[localsSize ] = Type.DOUBLE_TYPE; + locals[localsSize + 1] = Type.DOUBLE2_TYPE; + localsSize += 2; + } else { + if (desc instanceof ReferenceClassDescImpl) { + type = Type.referenceType(desc); + } else if (desc == CD_float) { + type = Type.FLOAT_TYPE; + } else { + type = Type.INTEGER_TYPE; } - case 'I', 'Z', 'B', 'C', 'S' -> - setLocalRawInternal(localsSize++, Type.INTEGER_TYPE); - case 'F' -> - setLocalRawInternal(localsSize++, Type.FLOAT_TYPE); - default -> throw new AssertionError("Should not reach here"); + locals[localsSize++] = type; } } this.localsSize = localsSize;