8339168: Optimize ClassFile Util slotSize
Reviewed-by: liach, redestad
This commit is contained in:
parent
a1eebbdf8a
commit
febbd998ee
@ -98,6 +98,9 @@ public final class DirectMethodBuilder
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int parameterSlot(int paramNo) {
|
public int parameterSlot(int paramNo) {
|
||||||
|
if (paramNo == 0) {
|
||||||
|
return ((flags & ClassFile.ACC_STATIC) != 0) ? 0 : 1;
|
||||||
|
}
|
||||||
if (parameterSlots == null)
|
if (parameterSlots == null)
|
||||||
parameterSlots = Util.parseParameterSlots(methodFlags(), methodTypeSymbol());
|
parameterSlots = Util.parseParameterSlots(methodFlags(), methodTypeSymbol());
|
||||||
return parameterSlots[paramNo];
|
return parameterSlots[paramNo];
|
||||||
|
@ -55,6 +55,10 @@ import java.lang.classfile.attribute.CodeAttribute;
|
|||||||
import java.lang.classfile.components.ClassPrinter;
|
import java.lang.classfile.components.ClassPrinter;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import static jdk.internal.constant.PrimitiveClassDescImpl.CD_double;
|
||||||
|
import static jdk.internal.constant.PrimitiveClassDescImpl.CD_long;
|
||||||
|
import static jdk.internal.constant.PrimitiveClassDescImpl.CD_void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to create and manipulate type descriptors, where type descriptors are
|
* Helper to create and manipulate type descriptors, where type descriptors are
|
||||||
* represented as JVM type descriptor strings and symbols are represented as
|
* represented as JVM type descriptor strings and symbols are represented as
|
||||||
@ -105,9 +109,11 @@ public class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int parameterSlots(MethodTypeDesc mDesc) {
|
public static int parameterSlots(MethodTypeDesc mDesc) {
|
||||||
int count = 0;
|
int count = mDesc.parameterCount();
|
||||||
for (int i = 0; i < mDesc.parameterCount(); i++) {
|
for (int i = count - 1; i >= 0; i--) {
|
||||||
count += slotSize(mDesc.parameterType(i));
|
if (isDoubleSlot(mDesc.parameterType(i))) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@ -117,17 +123,13 @@ public class Util {
|
|||||||
int count = ((flags & ACC_STATIC) != 0) ? 0 : 1;
|
int count = ((flags & ACC_STATIC) != 0) ? 0 : 1;
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
result[i] = count;
|
result[i] = count;
|
||||||
count += slotSize(mDesc.parameterType(i));
|
count += paramSlotSize(mDesc.parameterType(i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int maxLocals(int flags, MethodTypeDesc mDesc) {
|
public static int maxLocals(int flags, MethodTypeDesc mDesc) {
|
||||||
int count = ((flags & ACC_STATIC) != 0) ? 0 : 1;
|
return parameterSlots(mDesc) + ((flags & ACC_STATIC) == 0 ? 1 : 0) ;
|
||||||
for (int i = 0; i < mDesc.parameterCount(); i++) {
|
|
||||||
count += slotSize(mDesc.parameterType(i));
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,16 +254,15 @@ public class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int slotSize(ClassDesc desc) {
|
public static int slotSize(ClassDesc desc) {
|
||||||
return switch (desc.descriptorString().charAt(0)) {
|
return desc == CD_void ? 0 : isDoubleSlot(desc) ? 2 : 1;
|
||||||
case 'V' -> 0;
|
}
|
||||||
case 'D','J' -> 2;
|
|
||||||
default -> 1;
|
public static int paramSlotSize(ClassDesc desc) {
|
||||||
};
|
return isDoubleSlot(desc) ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDoubleSlot(ClassDesc desc) {
|
public static boolean isDoubleSlot(ClassDesc desc) {
|
||||||
char ch = desc.descriptorString().charAt(0);
|
return desc == CD_double || desc == CD_long;
|
||||||
return ch == 'D' || ch == 'J';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dumpMethod(SplitConstantPool cp,
|
public static void dumpMethod(SplitConstantPool cp,
|
||||||
|
Loading…
Reference in New Issue
Block a user