Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Classfile API-related startup improvements #2

Draft
wants to merge 13 commits into
base: JDK-8294960-invoke
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -3423,6 +3423,7 @@ static boolean casAnnotationData(Class<?> clazz,
// Reflection data caches various derived names and reflective members. Cached
// values may be invalidated when JVM TI RedefineClasses() is called
private static class ReflectionData<T> {

volatile Field[] declaredFields;
volatile Field[] publicFields;
volatile Method[] declaredMethods;
Expand Down
20 changes: 5 additions & 15 deletions src/java.base/share/classes/java/lang/constant/ClassDesc.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,10 @@ static ClassDesc of(String packageName, String className) {
* @see ClassDesc#ofInternalName(String)
*/
static ClassDesc ofDescriptor(String descriptor) {
requireNonNull(descriptor);
if (descriptor.isEmpty()) {
throw new IllegalArgumentException(
"not a valid reference type descriptor: " + descriptor);
if (descriptor.length() == 1) {
return Wrapper.forPrimitiveType(descriptor.charAt(0)).primitiveClassDescriptor();
}
int depth = ConstantUtils.arrayDepth(descriptor);
if (depth > ConstantUtils.MAX_ARRAY_TYPE_DESC_DIMENSIONS) {
throw new IllegalArgumentException(
"Cannot create an array type descriptor with more than " +
ConstantUtils.MAX_ARRAY_TYPE_DESC_DIMENSIONS + " dimensions");
}
return (descriptor.length() == 1)
? new PrimitiveClassDescImpl(descriptor)
: new ReferenceClassDescImpl(descriptor);
return new ReferenceClassDescImpl(descriptor);
}

/**
Expand Down Expand Up @@ -279,7 +269,7 @@ default ClassDesc nested(String firstNestedName, String... moreNestedNames) {
* @return whether this {@linkplain ClassDesc} describes an array type
*/
default boolean isArray() {
return descriptorString().startsWith("[");
return descriptorString().charAt(0) == '[';
}

/**
Expand All @@ -297,7 +287,7 @@ default boolean isPrimitive() {
* @return whether this {@linkplain ClassDesc} describes a class or interface type
*/
default boolean isClassOrInterface() {
return descriptorString().startsWith("L");
return descriptorString().charAt(0) == 'L';
}

/**
Expand Down
104 changes: 52 additions & 52 deletions src/java.base/share/classes/java/lang/constant/ConstantDescs.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,125 +64,125 @@ private ConstantDescs() { }
// Don't change the order of these declarations!

/** {@link ClassDesc} representing {@link Object} */
public static final ClassDesc CD_Object = ClassDesc.of("java.lang.Object");
public static final ClassDesc CD_Object = new ReferenceClassDescImpl("Ljava/lang/Object;");

/** {@link ClassDesc} representing {@link String} */
public static final ClassDesc CD_String = ClassDesc.of("java.lang.String");
public static final ClassDesc CD_String = new ReferenceClassDescImpl("Ljava/lang/String;");

/** {@link ClassDesc} representing {@link Class} */
public static final ClassDesc CD_Class = ClassDesc.of("java.lang.Class");
public static final ClassDesc CD_Class = new ReferenceClassDescImpl("Ljava/lang/Class;");

/** {@link ClassDesc} representing {@link Number} */
public static final ClassDesc CD_Number = ClassDesc.of("java.lang.Number");
public static final ClassDesc CD_Number = new ReferenceClassDescImpl("Ljava/lang/Number;");

/** {@link ClassDesc} representing {@link Integer} */
public static final ClassDesc CD_Integer = ClassDesc.of("java.lang.Integer");
public static final ClassDesc CD_Integer = new ReferenceClassDescImpl("Ljava/lang/Integer;");

/** {@link ClassDesc} representing {@link Long} */
public static final ClassDesc CD_Long = ClassDesc.of("java.lang.Long");
public static final ClassDesc CD_Long = new ReferenceClassDescImpl("Ljava/lang/Long;");

/** {@link ClassDesc} representing {@link Float} */
public static final ClassDesc CD_Float = ClassDesc.of("java.lang.Float");
public static final ClassDesc CD_Float = new ReferenceClassDescImpl("Ljava/lang/Float;");

/** {@link ClassDesc} representing {@link Double} */
public static final ClassDesc CD_Double = ClassDesc.of("java.lang.Double");
public static final ClassDesc CD_Double = new ReferenceClassDescImpl("Ljava/lang/Double;");

/** {@link ClassDesc} representing {@link Short} */
public static final ClassDesc CD_Short = ClassDesc.of("java.lang.Short");
public static final ClassDesc CD_Short = new ReferenceClassDescImpl("Ljava/lang/Short;");

/** {@link ClassDesc} representing {@link Byte} */
public static final ClassDesc CD_Byte = ClassDesc.of("java.lang.Byte");
public static final ClassDesc CD_Byte = new ReferenceClassDescImpl("Ljava/lang/Byte;");

/** {@link ClassDesc} representing {@link Character} */
public static final ClassDesc CD_Character = ClassDesc.of("java.lang.Character");
public static final ClassDesc CD_Character = new ReferenceClassDescImpl("Ljava/lang/Character;");

/** {@link ClassDesc} representing {@link Boolean} */
public static final ClassDesc CD_Boolean = ClassDesc.of("java.lang.Boolean");
public static final ClassDesc CD_Boolean = new ReferenceClassDescImpl("Ljava/lang/Boolean;");

/** {@link ClassDesc} representing {@link Void} */
public static final ClassDesc CD_Void = ClassDesc.of("java.lang.Void");
public static final ClassDesc CD_Void = new ReferenceClassDescImpl("Ljava/lang/Void;");

/** {@link ClassDesc} representing {@link Throwable} */
public static final ClassDesc CD_Throwable = ClassDesc.of("java.lang.Throwable");
public static final ClassDesc CD_Throwable = new ReferenceClassDescImpl("Ljava/lang/Throwable;");

/** {@link ClassDesc} representing {@link Exception} */
public static final ClassDesc CD_Exception = ClassDesc.of("java.lang.Exception");
public static final ClassDesc CD_Exception = new ReferenceClassDescImpl("Ljava/lang/Exception;");

/** {@link ClassDesc} representing {@link Enum} */
public static final ClassDesc CD_Enum = ClassDesc.of("java.lang.Enum");
public static final ClassDesc CD_Enum = new ReferenceClassDescImpl("Ljava/lang/Enum;");

/** {@link ClassDesc} representing {@link VarHandle} */
public static final ClassDesc CD_VarHandle = ClassDesc.of("java.lang.invoke.VarHandle");
public static final ClassDesc CD_VarHandle = new ReferenceClassDescImpl("Ljava/lang/invoke/VarHandle;");

/** {@link ClassDesc} representing {@link MethodHandles} */
public static final ClassDesc CD_MethodHandles = ClassDesc.of("java.lang.invoke.MethodHandles");
public static final ClassDesc CD_MethodHandles = new ReferenceClassDescImpl("Ljava/lang/invoke/MethodHandles;");

/** {@link ClassDesc} representing {@link MethodHandles.Lookup} */
public static final ClassDesc CD_MethodHandles_Lookup = CD_MethodHandles.nested("Lookup");
public static final ClassDesc CD_MethodHandles_Lookup = new ReferenceClassDescImpl("Ljava/lang/invoke/MethodHandles$Lookup;");

/** {@link ClassDesc} representing {@link MethodHandle} */
public static final ClassDesc CD_MethodHandle = ClassDesc.of("java.lang.invoke.MethodHandle");
public static final ClassDesc CD_MethodHandle = new ReferenceClassDescImpl("Ljava/lang/invoke/MethodHandle;");

/** {@link ClassDesc} representing {@link MethodType} */
public static final ClassDesc CD_MethodType = ClassDesc.of("java.lang.invoke.MethodType");
public static final ClassDesc CD_MethodType = new ReferenceClassDescImpl("Ljava/lang/invoke/MethodType;");

/** {@link ClassDesc} representing {@link CallSite} */
public static final ClassDesc CD_CallSite = ClassDesc.of("java.lang.invoke.CallSite");
public static final ClassDesc CD_CallSite = new ReferenceClassDescImpl("Ljava/lang/invoke/CallSite;");

/** {@link ClassDesc} representing {@link Collection} */
public static final ClassDesc CD_Collection = ClassDesc.of("java.util.Collection");
public static final ClassDesc CD_Collection = new ReferenceClassDescImpl("Ljava/util/Collection;");

/** {@link ClassDesc} representing {@link List} */
public static final ClassDesc CD_List = ClassDesc.of("java.util.List");
public static final ClassDesc CD_List = new ReferenceClassDescImpl("Ljava/util/List;");

/** {@link ClassDesc} representing {@link Set} */
public static final ClassDesc CD_Set = ClassDesc.of("java.util.Set");
public static final ClassDesc CD_Set = new ReferenceClassDescImpl("Ljava/util/Set;");

/** {@link ClassDesc} representing {@link Map} */
public static final ClassDesc CD_Map = ClassDesc.of("java.util.Map");
public static final ClassDesc CD_Map = new ReferenceClassDescImpl("Ljava/util/Map;");

/** {@link ClassDesc} representing {@link ConstantDesc} */
public static final ClassDesc CD_ConstantDesc = ClassDesc.of("java.lang.constant.ConstantDesc");
public static final ClassDesc CD_ConstantDesc = new ReferenceClassDescImpl("Ljava/lang/constant/ConstantDesc;");

/** {@link ClassDesc} representing {@link ClassDesc} */
public static final ClassDesc CD_ClassDesc = ClassDesc.of("java.lang.constant.ClassDesc");
public static final ClassDesc CD_ClassDesc = new ReferenceClassDescImpl("Ljava/lang/constant/ClassDesc;");

/** {@link ClassDesc} representing {@link EnumDesc} */
public static final ClassDesc CD_EnumDesc = CD_Enum.nested("EnumDesc");
public static final ClassDesc CD_EnumDesc = new ReferenceClassDescImpl("Ljava/lang/Enum$EnumDesc;");

/** {@link ClassDesc} representing {@link MethodTypeDesc} */
public static final ClassDesc CD_MethodTypeDesc = ClassDesc.of("java.lang.constant.MethodTypeDesc");
public static final ClassDesc CD_MethodTypeDesc = new ReferenceClassDescImpl("Ljava/lang/constant/MethodTypeDesc;");

/** {@link ClassDesc} representing {@link MethodHandleDesc} */
public static final ClassDesc CD_MethodHandleDesc = ClassDesc.of("java.lang.constant.MethodHandleDesc");
public static final ClassDesc CD_MethodHandleDesc = new ReferenceClassDescImpl("Ljava/lang/constant/MethodHandleDesc;");

/** {@link ClassDesc} representing {@link DirectMethodHandleDesc} */
public static final ClassDesc CD_DirectMethodHandleDesc = ClassDesc.of("java.lang.constant.DirectMethodHandleDesc");
public static final ClassDesc CD_DirectMethodHandleDesc = new ReferenceClassDescImpl("Ljava/lang/constant/DirectMethodHandleDesc;");

/** {@link ClassDesc} representing {@link VarHandleDesc} */
public static final ClassDesc CD_VarHandleDesc = CD_VarHandle.nested("VarHandleDesc");
public static final ClassDesc CD_VarHandleDesc = new ReferenceClassDescImpl("Ljava/lang/invoke/VarHandle$VarHandleDesc;");

/** {@link ClassDesc} representing {@link DirectMethodHandleDesc.Kind} */
public static final ClassDesc CD_MethodHandleDesc_Kind = CD_DirectMethodHandleDesc.nested("Kind");
public static final ClassDesc CD_MethodHandleDesc_Kind = new ReferenceClassDescImpl("Ljava/lang/constant/DirectMethodHandleDesc$Kind;");

/** {@link ClassDesc} representing {@link DynamicConstantDesc} */
public static final ClassDesc CD_DynamicConstantDesc = ClassDesc.of("java.lang.constant.DynamicConstantDesc");
public static final ClassDesc CD_DynamicConstantDesc = new ReferenceClassDescImpl("Ljava/lang/constant/DynamicConstantDesc;");

/** {@link ClassDesc} representing {@link DynamicCallSiteDesc} */
public static final ClassDesc CD_DynamicCallSiteDesc = ClassDesc.of("java.lang.constant.DynamicCallSiteDesc");
public static final ClassDesc CD_DynamicCallSiteDesc = new ReferenceClassDescImpl("Ljava/lang/constant/DynamicCallSiteDesc;");

/** {@link ClassDesc} representing {@link ConstantBootstraps} */
public static final ClassDesc CD_ConstantBootstraps = ClassDesc.of("java.lang.invoke.ConstantBootstraps");
public static final ClassDesc CD_ConstantBootstraps = new ReferenceClassDescImpl("Ljava/lang/invoke/ConstantBootstraps;");

private static final ClassDesc[] INDY_BOOTSTRAP_ARGS = {
ConstantDescs.CD_MethodHandles_Lookup,
ConstantDescs.CD_String,
ConstantDescs.CD_MethodType};
CD_MethodHandles_Lookup,
CD_String,
CD_MethodType};

private static final ClassDesc[] CONDY_BOOTSTRAP_ARGS = {
ConstantDescs.CD_MethodHandles_Lookup,
ConstantDescs.CD_String,
ConstantDescs.CD_Class};
CD_MethodHandles_Lookup,
CD_String,
CD_Class};

/** {@link MethodHandleDesc} representing {@link ConstantBootstraps#primitiveClass(Lookup, String, Class) ConstantBootstraps.primitiveClass} */
public static final DirectMethodHandleDesc BSM_PRIMITIVE_CLASS
Expand Down Expand Up @@ -236,31 +236,31 @@ private ConstantDescs() { }
CD_Object, CD_Object);

/** {@link ClassDesc} representing the primitive type {@code int} */
public static final ClassDesc CD_int = ClassDesc.ofDescriptor("I");
public static final ClassDesc CD_int = new PrimitiveClassDescImpl("I");

/** {@link ClassDesc} representing the primitive type {@code long} */
public static final ClassDesc CD_long = ClassDesc.ofDescriptor("J");
public static final ClassDesc CD_long = new PrimitiveClassDescImpl("J");

/** {@link ClassDesc} representing the primitive type {@code float} */
public static final ClassDesc CD_float = ClassDesc.ofDescriptor("F");
public static final ClassDesc CD_float = new PrimitiveClassDescImpl("F");

/** {@link ClassDesc} representing the primitive type {@code double} */
public static final ClassDesc CD_double = ClassDesc.ofDescriptor("D");
public static final ClassDesc CD_double = new PrimitiveClassDescImpl("D");

/** {@link ClassDesc} representing the primitive type {@code short} */
public static final ClassDesc CD_short = ClassDesc.ofDescriptor("S");
public static final ClassDesc CD_short = new PrimitiveClassDescImpl("S");

/** {@link ClassDesc} representing the primitive type {@code byte} */
public static final ClassDesc CD_byte = ClassDesc.ofDescriptor("B");
public static final ClassDesc CD_byte = new PrimitiveClassDescImpl("B");

/** {@link ClassDesc} representing the primitive type {@code char} */
public static final ClassDesc CD_char = ClassDesc.ofDescriptor("C");
public static final ClassDesc CD_char = new PrimitiveClassDescImpl("C");

/** {@link ClassDesc} representing the primitive type {@code boolean} */
public static final ClassDesc CD_boolean = ClassDesc.ofDescriptor("Z");
public static final ClassDesc CD_boolean = new PrimitiveClassDescImpl("Z");

/** {@link ClassDesc} representing the primitive type {@code void} */
public static final ClassDesc CD_void = ClassDesc.ofDescriptor("V");
public static final ClassDesc CD_void = new PrimitiveClassDescImpl("V");

/**
* {@link MethodHandleDesc} representing {@link MethodHandles#classData(Lookup, String, Class) MethodHandles.classData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public static String validateModuleName(String name) {
* @throws IllegalArgumentException if the member name is invalid
*/
public static String validateMemberName(String name, boolean method) {
requireNonNull(name);
if (name.length() == 0)
throw new IllegalArgumentException("zero-length member name");
for (int i=0; i<name.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected DynamicConstantDesc(DirectMethodHandleDesc bootstrapMethod,
this.bootstrapMethod = requireNonNull(bootstrapMethod);
this.constantName = validateMemberName(requireNonNull(constantName), true);
this.constantType = requireNonNull(constantType);
this.bootstrapArgs = requireNonNull(bootstrapArgs).clone();
this.bootstrapArgs = bootstrapArgs.length == 0 ? EMPTY_CONSTANTDESC : bootstrapArgs.clone();

if (constantName.length() == 0)
throw new IllegalArgumentException("Illegal invocation name: " + constantName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ static DirectMethodHandleDesc ofMethod(DirectMethodHandleDesc.Kind kind,
String name,
MethodTypeDesc lookupMethodType) {
switch (kind) {
case GETTER:
case SETTER:
case STATIC_GETTER:
case STATIC_SETTER:
throw new IllegalArgumentException(kind.toString());
case VIRTUAL:
case SPECIAL:
case INTERFACE_VIRTUAL:
Expand All @@ -133,6 +128,10 @@ static DirectMethodHandleDesc ofMethod(DirectMethodHandleDesc.Kind kind,
case STATIC:
case CONSTRUCTOR:
return new DirectMethodHandleDescImpl(kind, owner, name, lookupMethodType);
case GETTER:
case SETTER:
case STATIC_GETTER:
case STATIC_SETTER:
default:
throw new IllegalArgumentException(kind.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ static MethodTypeDesc of(ClassDesc returnDesc, ClassDesc... paramDescs) {
* @return the human-readable descriptor for this method type
*/
default String displayDescriptor() {
return String.format("(%s)%s",
Stream.of(parameterArray())
.map(ClassDesc::displayName)
.collect(Collectors.joining(",")),
returnType().displayName());
int count = parameterCount();
StringBuilder sb = new StringBuilder(24).append('(');
for (int i = 0; i < count; i++) {
sb.append(parameterType(i).displayName());
}
return sb.append(')').append(returnType().displayName()).toString();
}

/**
Expand Down
Loading