Skip to content

Commit

Permalink
8323835: Updating ASM to 9.6 for JDK 23
Browse files Browse the repository at this point in the history
  • Loading branch information
vicente-romero-oracle committed Jan 16, 2024
1 parent 19c9388 commit 8593b61
Show file tree
Hide file tree
Showing 129 changed files with 1,401 additions and 944 deletions.
Expand Up @@ -105,13 +105,28 @@ protected AnnotationVisitor(final int api, final AnnotationVisitor annotationVis
&& api != Opcodes.ASM7
&& api != Opcodes.ASM6
&& api != Opcodes.ASM5
&& api != Opcodes.ASM4) {
&& api != Opcodes.ASM4
&& api != Opcodes.ASM10_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM10_EXPERIMENTAL) {
Constants.checkAsmExperimental(this);
}
this.api = api;
this.av = annotationVisitor;
}

/**
* The annotation visitor to which this visitor must delegate method calls. May be {@literal
* null}.
*
* @return the annotation visitor to which this visitor must delegate method calls, or {@literal
* null}.
*/
public AnnotationVisitor getDelegate() {
return av;
}

/**
* Visits a primitive value of the annotation.
*
Expand Down
Expand Up @@ -403,4 +403,3 @@ private void enlarge(final int size) {
data = newData;
}
}

Expand Up @@ -220,13 +220,14 @@ public ClassReader(
* @param classFileOffset the offset in byteBuffer of the first byte of the ClassFile to be read.
* @param checkClassVersion whether to check the class version or not.
*/
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
ClassReader(
final byte[] classFileBuffer, final int classFileOffset, final boolean checkClassVersion) {
this.classFileBuffer = classFileBuffer;
this.b = classFileBuffer;
// Check the class' major_version. This field is after the magic and minor_version fields, which
// use 4 and 2 bytes respectively.
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V23) {
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V22) {
throw new IllegalArgumentException(
"Unsupported class file major version " + readShort(classFileOffset + 6));
}
Expand Down Expand Up @@ -407,7 +408,7 @@ public String getClassName() {
}

/**
* Returns the internal of name of the super class (see {@link Type#getInternalName()}). For
* Returns the internal name of the super class (see {@link Type#getInternalName()}). For
* interfaces, the super class is {@link Object}.
*
* @return the internal name of the super class, or {@literal null} for {@link Object} class.
Expand Down Expand Up @@ -2082,6 +2083,7 @@ private void readCode(
currentOffset = bytecodeStartOffset;
while (currentOffset < bytecodeEndOffset) {
final int currentBytecodeOffset = currentOffset - bytecodeStartOffset;
readBytecodeInstructionOffset(currentBytecodeOffset);

// Visit the label and the line number(s) for this bytecode offset, if any.
Label currentLabel = labels[currentBytecodeOffset];
Expand Down Expand Up @@ -2697,6 +2699,20 @@ private void readCode(
methodVisitor.visitMaxs(maxStack, maxLocals);
}

/**
* Handles the bytecode offset of the next instruction to be visited in {@link
* #accept(ClassVisitor,int)}. This method is called just before the instruction and before its
* associated label and stack map frame, if any. The default implementation of this method does
* nothing. Subclasses can override this method to store the argument in a mutable field, for
* instance, so that {@link MethodVisitor} instances can get the bytecode offset of each visited
* instruction (if so, the usual concurrency issues related to mutable data should be addressed).
*
* @param bytecodeOffset the bytecode offset of the next instruction to be visited.
*/
protected void readBytecodeInstructionOffset(final int bytecodeOffset) {
// Do nothing by default.
}

/**
* Returns the label corresponding to the given bytecode offset. The default implementation of
* this method creates a label for the given offset if it has not been already created.
Expand Down Expand Up @@ -3882,4 +3898,3 @@ public Object readConst(final int constantPoolEntryIndex, final char[] charBuffe
}
}
}

Expand Up @@ -74,7 +74,8 @@ public final class ClassTooLargeException extends IndexOutOfBoundsException {
/**
* Constructs a new {@link ClassTooLargeException}.
*
* @param className the internal name of the class.
* @param className the internal name of the class (see {@link
* jdk.internal.org.objectweb.asm.Type#getInternalName()}).
* @param constantPoolCount the number of constant pool items of the class.
*/
public ClassTooLargeException(final String className, final int constantPoolCount) {
Expand All @@ -84,7 +85,7 @@ public ClassTooLargeException(final String className, final int constantPoolCoun
}

/**
* Returns the internal name of the class.
* Returns the internal name of the class (see {@link jdk.internal.org.objectweb.asm.Type#getInternalName()}).
*
* @return the internal name of the class.
*/
Expand All @@ -101,4 +102,3 @@ public int getConstantPoolCount() {
return constantPoolCount;
}
}

Expand Up @@ -104,13 +104,26 @@ protected ClassVisitor(final int api, final ClassVisitor classVisitor) {
&& api != Opcodes.ASM7
&& api != Opcodes.ASM6
&& api != Opcodes.ASM5
&& api != Opcodes.ASM4) {
&& api != Opcodes.ASM4
&& api != Opcodes.ASM10_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM10_EXPERIMENTAL) {
Constants.checkAsmExperimental(this);
}
this.api = api;
this.cv = classVisitor;
}

/**
* The class visitor to which this visitor must delegate method calls. May be {@literal null}.
*
* @return the class visitor to which this visitor must delegate method calls, or {@literal null}.
*/
public ClassVisitor getDelegate() {
return cv;
}

/**
* Visits the header of the class.
*
Expand Down Expand Up @@ -185,7 +198,8 @@ public ModuleVisitor visitModule(final String name, final int access, final Stri
* implicitly its own nest, so it's invalid to call this method with the visited class name as
* argument.
*
* @param nestHost the internal name of the host class of the nest.
* @param nestHost the internal name of the host class of the nest (see {@link
* Type#getInternalName()}).
*/
public void visitNestHost(final String nestHost) {
if (api < Opcodes.ASM7) {
Expand All @@ -197,14 +211,19 @@ public void visitNestHost(final String nestHost) {
}

/**
* Visits the enclosing class of the class. This method must be called only if the class has an
* enclosing class.
* Visits the enclosing class of the class. This method must be called only if this class is a
* local or anonymous class. See the JVMS 4.7.7 section for more details.
*
* @param owner internal name of the enclosing class of the class.
* @param owner internal name of the enclosing class of the class (see {@link
* Type#getInternalName()}).
* @param name the name of the method that contains the class, or {@literal null} if the class is
* not enclosed in a method of its enclosing class.
* not enclosed in a method or constructor of its enclosing class (e.g. if it is enclosed in
* an instance initializer, static initializer, instance variable initializer, or class
* variable initializer).
* @param descriptor the descriptor of the method that contains the class, or {@literal null} if
* the class is not enclosed in a method of its enclosing class.
* the class is not enclosed in a method or constructor of its enclosing class (e.g. if it is
* enclosed in an instance initializer, static initializer, instance variable initializer, or
* class variable initializer).
*/
public void visitOuterClass(final String owner, final String name, final String descriptor) {
if (cv != null) {
Expand Down Expand Up @@ -271,7 +290,7 @@ public void visitAttribute(final Attribute attribute) {
* the visited class is the host of a nest. A nest host is implicitly a member of its own nest, so
* it's invalid to call this method with the visited class name as argument.
*
* @param nestMember the internal name of a nest member.
* @param nestMember the internal name of a nest member (see {@link Type#getInternalName()}).
*/
public void visitNestMember(final String nestMember) {
if (api < Opcodes.ASM7) {
Expand All @@ -286,7 +305,8 @@ public void visitNestMember(final String nestMember) {
* Visits a permitted subclasses. A permitted subclass is one of the allowed subclasses of the
* current class.
*
* @param permittedSubclass the internal name of a permitted subclass.
* @param permittedSubclass the internal name of a permitted subclass (see {@link
* Type#getInternalName()}).
*/
public void visitPermittedSubclass(final String permittedSubclass) {
if (api < Opcodes.ASM9) {
Expand All @@ -299,15 +319,18 @@ public void visitPermittedSubclass(final String permittedSubclass) {

/**
* Visits information about an inner class. This inner class is not necessarily a member of the
* class being visited.
* class being visited. More precisely, every class or interface C which is referenced by this
* class and which is not a package member must be visited with this method. This class must
* reference its nested class or interface members, and its enclosing class, if any. See the JVMS
* 4.7.6 section for more details.
*
* @param name the internal name of an inner class (see {@link Type#getInternalName()}).
* @param outerName the internal name of the class to which the inner class belongs (see {@link
* Type#getInternalName()}). May be {@literal null} for not member classes.
* @param innerName the (simple) name of the inner class inside its enclosing class. May be
* {@literal null} for anonymous inner classes.
* @param access the access flags of the inner class as originally declared in the enclosing
* class.
* @param name the internal name of C (see {@link Type#getInternalName()}).
* @param outerName the internal name of the class or interface C is a member of (see {@link
* Type#getInternalName()}). Must be {@literal null} if C is not the member of a class or
* interface (e.g. for local or anonymous classes).
* @param innerName the (simple) name of C. Must be {@literal null} for anonymous inner classes.
* @param access the access flags of C originally declared in the source code from which this
* class was compiled.
*/
public void visitInnerClass(
final String name, final String outerName, final String innerName, final int access) {
Expand Down Expand Up @@ -405,4 +428,3 @@ public void visitEnd() {
}
}
}

Expand Up @@ -249,6 +249,7 @@ public class ClassWriter extends ClassVisitor {
/**
* Indicates what must be automatically computed in {@link MethodWriter}. Must be one of {@link
* MethodWriter#COMPUTE_NOTHING}, {@link MethodWriter#COMPUTE_MAX_STACK_AND_LOCAL}, {@link
* MethodWriter#COMPUTE_MAX_STACK_AND_LOCAL_FROM_FRAMES}, {@link
* MethodWriter#COMPUTE_INSERTED_FRAMES}, or {@link MethodWriter#COMPUTE_ALL_FRAMES}.
*/
private int compute;
Expand Down Expand Up @@ -874,7 +875,7 @@ public int newUTF8(final String value) {
* constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
* sub classes, and is normally not needed by class generators or adapters.</i>
*
* @param value the internal name of the class.
* @param value the internal name of the class (see {@link Type#getInternalName()}).
* @return the index of a new or already existing class reference item.
*/
public int newClass(final String value) {
Expand Down Expand Up @@ -926,7 +927,8 @@ public int newPackage(final String packageName) {
* Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC}, {@link
* Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC}, {@link Opcodes#H_INVOKESPECIAL},
* {@link Opcodes#H_NEWINVOKESPECIAL} or {@link Opcodes#H_INVOKEINTERFACE}.
* @param owner the internal name of the field or method owner class.
* @param owner the internal name of the field or method owner class (see {@link
* Type#getInternalName()}).
* @param name the name of the field or method.
* @param descriptor the descriptor of the field or method.
* @return the index of a new or already existing method type reference item.
Expand All @@ -948,7 +950,8 @@ public int newHandle(
* Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC}, {@link
* Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC}, {@link Opcodes#H_INVOKESPECIAL},
* {@link Opcodes#H_NEWINVOKESPECIAL} or {@link Opcodes#H_INVOKEINTERFACE}.
* @param owner the internal name of the field or method owner class.
* @param owner the internal name of the field or method owner class (see {@link
* Type#getInternalName()}).
* @param name the name of the field or method.
* @param descriptor the descriptor of the field or method.
* @param isInterface true if the owner is an interface.
Expand Down Expand Up @@ -1010,7 +1013,7 @@ public int newInvokeDynamic(
* constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
* sub classes, and is normally not needed by class generators or adapters.</i>
*
* @param owner the internal name of the field's owner class.
* @param owner the internal name of the field's owner class (see {@link Type#getInternalName()}).
* @param name the field's name.
* @param descriptor the field's descriptor.
* @return the index of a new or already existing field reference item.
Expand All @@ -1024,7 +1027,8 @@ public int newField(final String owner, final String name, final String descript
* constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
* sub classes, and is normally not needed by class generators or adapters.</i>
*
* @param owner the internal name of the method's owner class.
* @param owner the internal name of the method's owner class (see {@link
* Type#getInternalName()}).
* @param name the method's name.
* @param descriptor the method's descriptor.
* @param isInterface {@literal true} if {@code owner} is an interface.
Expand Down Expand Up @@ -1060,9 +1064,10 @@ public int newNameType(final String name, final String descriptor) {
* currently being generated by this ClassWriter, which can of course not be loaded since it is
* under construction.
*
* @param type1 the internal name of a class.
* @param type2 the internal name of another class.
* @return the internal name of the common super class of the two given classes.
* @param type1 the internal name of a class (see {@link Type#getInternalName()}).
* @param type2 the internal name of another class (see {@link Type#getInternalName()}).
* @return the internal name of the common super class of the two given classes (see {@link
* Type#getInternalName()}).
*/
protected String getCommonSuperClass(final String type1, final String type2) {
ClassLoader classLoader = getClassLoader();
Expand Down Expand Up @@ -1105,4 +1110,3 @@ protected ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

Expand Up @@ -208,4 +208,3 @@ public String toString() {
+ Arrays.toString(bootstrapMethodArguments);
}
}

Expand Up @@ -223,15 +223,15 @@ static void checkAsmExperimental(final Object caller) {
}

static boolean isWhitelisted(final String internalName) {
if (!internalName.startsWith("jdk/internal/org/objectweb/asm/")) {
if (!internalName.startsWith("org/objectweb/asm/")) {
return false;
}
String member = "(Annotation|Class|Field|Method|Module|RecordComponent|Signature)";
return internalName.contains("Test$")
|| Pattern.matches(
"jdk/internal/org/objectweb/asm/util/Trace" + member + "Visitor(\\$.*)?", internalName)
"org/objectweb/asm/util/Trace" + member + "Visitor(\\$.*)?", internalName)
|| Pattern.matches(
"jdk/internal/org/objectweb/asm/util/Check" + member + "Adapter(\\$.*)?", internalName);
"org/objectweb/asm/util/Check" + member + "Adapter(\\$.*)?", internalName);
}

static void checkIsPreview(final InputStream classInputStream) {
Expand All @@ -251,4 +251,3 @@ static void checkIsPreview(final InputStream classInputStream) {
}
}
}

Expand Up @@ -166,4 +166,3 @@ final class Context {
*/
Object[] currentFrameStackTypes;
}

Expand Up @@ -85,4 +85,3 @@ void execute(
copyFrom(successor);
}
}

Expand Up @@ -121,4 +121,3 @@ final class Edge {
this.nextEdge = nextEdge;
}
}

Expand Up @@ -101,13 +101,26 @@ protected FieldVisitor(final int api, final FieldVisitor fieldVisitor) {
&& api != Opcodes.ASM7
&& api != Opcodes.ASM6
&& api != Opcodes.ASM5
&& api != Opcodes.ASM4) {
&& api != Opcodes.ASM4
&& api != Opcodes.ASM10_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM10_EXPERIMENTAL) {
Constants.checkAsmExperimental(this);
}
this.api = api;
this.fv = fieldVisitor;
}

/**
* The field visitor to which this visitor must delegate method calls. May be {@literal null}.
*
* @return the field visitor to which this visitor must delegate method calls, or {@literal null}.
*/
public FieldVisitor getDelegate() {
return fv;
}

/**
* Visits an annotation of the field.
*
Expand Down Expand Up @@ -168,4 +181,3 @@ public void visitEnd() {
}
}
}

Expand Up @@ -314,4 +314,3 @@ final void collectAttributePrototypes(final Attribute.Set attributePrototypes) {
attributePrototypes.addAttributes(firstAttribute);
}
}

0 comments on commit 8593b61

Please sign in to comment.