Skip to content

Commit

Permalink
Upgrade to ASM 9.3
Browse files Browse the repository at this point in the history
Closes gh-28390
  • Loading branch information
jhoeller committed May 5, 2022
1 parent 2874217 commit b55eee1
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 34 deletions.
Expand Up @@ -55,7 +55,7 @@ public abstract class AnnotationVisitor {
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
*/
public AnnotationVisitor(final int api) {
protected AnnotationVisitor(final int api) {
this(api, null);
}

Expand All @@ -67,7 +67,7 @@ public AnnotationVisitor(final int api) {
* @param annotationVisitor the annotation visitor to which this visitor must delegate method
* calls. May be {@literal null}.
*/
public AnnotationVisitor(final int api, final AnnotationVisitor annotationVisitor) {
protected AnnotationVisitor(final int api, final AnnotationVisitor annotationVisitor) {
if (api != Opcodes.ASM9
&& api != Opcodes.ASM8
&& api != Opcodes.ASM7
Expand Down
Expand Up @@ -65,6 +65,15 @@ public ByteVector(final int initialCapacity) {
this.length = data.length;
}

/**
* Returns the actual number of bytes in this vector.
*
* @return the actual number of bytes in this vector.
*/
public int size() {
return length;
}

/**
* Puts a byte into this byte vector. The byte vector is automatically enlarged if necessary.
*
Expand Down
Expand Up @@ -54,7 +54,7 @@ public abstract class ClassVisitor {
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
*/
public ClassVisitor(final int api) {
protected ClassVisitor(final int api) {
this(api, null);
}

Expand All @@ -66,7 +66,7 @@ public ClassVisitor(final int api) {
* @param classVisitor the class visitor to which this visitor must delegate method calls. May be
* null.
*/
public ClassVisitor(final int api, final ClassVisitor classVisitor) {
protected ClassVisitor(final int api, final ClassVisitor classVisitor) {
if (api != Opcodes.ASM9
&& api != Opcodes.ASM8
&& api != Opcodes.ASM7
Expand Down
Expand Up @@ -51,7 +51,7 @@ public abstract class FieldVisitor {
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
*/
public FieldVisitor(final int api) {
protected FieldVisitor(final int api) {
this(api, null);
}

Expand All @@ -63,7 +63,7 @@ public FieldVisitor(final int api) {
* @param fieldVisitor the field visitor to which this visitor must delegate method calls. May be
* null.
*/
public FieldVisitor(final int api, final FieldVisitor fieldVisitor) {
protected FieldVisitor(final int api, final FieldVisitor fieldVisitor) {
if (api != Opcodes.ASM9
&& api != Opcodes.ASM8
&& api != Opcodes.ASM7
Expand Down
Expand Up @@ -67,7 +67,7 @@ public abstract class MethodVisitor {
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
*/
public MethodVisitor(final int api) {
protected MethodVisitor(final int api) {
this(api, null);
}

Expand All @@ -79,7 +79,7 @@ public MethodVisitor(final int api) {
* @param methodVisitor the method visitor to which this visitor must delegate method calls. May
* be null.
*/
public MethodVisitor(final int api, final MethodVisitor methodVisitor) {
protected MethodVisitor(final int api, final MethodVisitor methodVisitor) {
if (api != Opcodes.ASM9
&& api != Opcodes.ASM8
&& api != Opcodes.ASM7
Expand Down Expand Up @@ -349,12 +349,12 @@ public void visitIntInsn(final int opcode, final int operand) {
*
* @param opcode the opcode of the local variable instruction to be visited. This opcode is either
* ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
* @param var the operand of the instruction to be visited. This operand is the index of a local
* variable.
* @param varIndex the operand of the instruction to be visited. This operand is the index of a
* local variable.
*/
public void visitVarInsn(final int opcode, final int var) {
public void visitVarInsn(final int opcode, final int varIndex) {
if (mv != null) {
mv.visitVarInsn(opcode, var);
mv.visitVarInsn(opcode, varIndex);
}
}

Expand Down
35 changes: 18 additions & 17 deletions spring-core/src/main/java/org/springframework/asm/MethodWriter.java
Expand Up @@ -466,7 +466,8 @@ final class MethodWriter extends MethodVisitor {

/**
* Indicates what must be computed. Must be one of {@link #COMPUTE_ALL_FRAMES}, {@link
* #COMPUTE_INSERTED_FRAMES}, {@link #COMPUTE_MAX_STACK_AND_LOCAL} or {@link #COMPUTE_NOTHING}.
* #COMPUTE_INSERTED_FRAMES}, {@link COMPUTE_MAX_STACK_AND_LOCAL_FROM_FRAMES}, {@link
* #COMPUTE_MAX_STACK_AND_LOCAL} or {@link #COMPUTE_NOTHING}.
*/
private final int compute;

Expand Down Expand Up @@ -904,26 +905,26 @@ public void visitIntInsn(final int opcode, final int operand) {
}

@Override
public void visitVarInsn(final int opcode, final int var) {
public void visitVarInsn(final int opcode, final int varIndex) {
lastBytecodeOffset = code.length;
// Add the instruction to the bytecode of the method.
if (var < 4 && opcode != Opcodes.RET) {
if (varIndex < 4 && opcode != Opcodes.RET) {
int optimizedOpcode;
if (opcode < Opcodes.ISTORE) {
optimizedOpcode = Constants.ILOAD_0 + ((opcode - Opcodes.ILOAD) << 2) + var;
optimizedOpcode = Constants.ILOAD_0 + ((opcode - Opcodes.ILOAD) << 2) + varIndex;
} else {
optimizedOpcode = Constants.ISTORE_0 + ((opcode - Opcodes.ISTORE) << 2) + var;
optimizedOpcode = Constants.ISTORE_0 + ((opcode - Opcodes.ISTORE) << 2) + varIndex;
}
code.putByte(optimizedOpcode);
} else if (var >= 256) {
code.putByte(Constants.WIDE).put12(opcode, var);
} else if (varIndex >= 256) {
code.putByte(Constants.WIDE).put12(opcode, varIndex);
} else {
code.put11(opcode, var);
code.put11(opcode, varIndex);
}
// If needed, update the maximum stack size and number of locals, and stack map frames.
if (currentBasicBlock != null) {
if (compute == COMPUTE_ALL_FRAMES || compute == COMPUTE_INSERTED_FRAMES) {
currentBasicBlock.frame.execute(opcode, var, null, null);
currentBasicBlock.frame.execute(opcode, varIndex, null, null);
} else {
if (opcode == Opcodes.RET) {
// No stack size delta.
Expand All @@ -945,9 +946,9 @@ public void visitVarInsn(final int opcode, final int var) {
|| opcode == Opcodes.DLOAD
|| opcode == Opcodes.LSTORE
|| opcode == Opcodes.DSTORE) {
currentMaxLocals = var + 2;
currentMaxLocals = varIndex + 2;
} else {
currentMaxLocals = var + 1;
currentMaxLocals = varIndex + 1;
}
if (currentMaxLocals > maxLocals) {
maxLocals = currentMaxLocals;
Expand Down Expand Up @@ -1307,21 +1308,21 @@ public void visitLdcInsn(final Object value) {
}

@Override
public void visitIincInsn(final int var, final int increment) {
public void visitIincInsn(final int varIndex, final int increment) {
lastBytecodeOffset = code.length;
// Add the instruction to the bytecode of the method.
if ((var > 255) || (increment > 127) || (increment < -128)) {
code.putByte(Constants.WIDE).put12(Opcodes.IINC, var).putShort(increment);
if ((varIndex > 255) || (increment > 127) || (increment < -128)) {
code.putByte(Constants.WIDE).put12(Opcodes.IINC, varIndex).putShort(increment);
} else {
code.putByte(Opcodes.IINC).put11(var, increment);
code.putByte(Opcodes.IINC).put11(varIndex, increment);
}
// If needed, update the maximum stack size and number of locals, and stack map frames.
if (currentBasicBlock != null
&& (compute == COMPUTE_ALL_FRAMES || compute == COMPUTE_INSERTED_FRAMES)) {
currentBasicBlock.frame.execute(Opcodes.IINC, var, null, null);
currentBasicBlock.frame.execute(Opcodes.IINC, varIndex, null, null);
}
if (compute != COMPUTE_NOTHING) {
int currentMaxLocals = var + 1;
int currentMaxLocals = varIndex + 1;
if (currentMaxLocals > maxLocals) {
maxLocals = currentMaxLocals;
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ public abstract class ModuleVisitor {
* @param api the ASM API version implemented by this visitor. Must be one of {@link Opcodes#ASM6}
* or {@link Opcodes#ASM7}.
*/
public ModuleVisitor(final int api) {
protected ModuleVisitor(final int api) {
this(api, null);
}

Expand All @@ -65,7 +65,7 @@ public ModuleVisitor(final int api) {
* @param moduleVisitor the module visitor to which this visitor must delegate method calls. May
* be null.
*/
public ModuleVisitor(final int api, final ModuleVisitor moduleVisitor) {
protected ModuleVisitor(final int api, final ModuleVisitor moduleVisitor) {
if (api != Opcodes.ASM9
&& api != Opcodes.ASM8
&& api != Opcodes.ASM7
Expand Down
Expand Up @@ -53,7 +53,7 @@ public abstract class RecordComponentVisitor {
* @param api the ASM API version implemented by this visitor. Must be one of {@link Opcodes#ASM8}
* or {@link Opcodes#ASM9}.
*/
public RecordComponentVisitor(final int api) {
protected RecordComponentVisitor(final int api) {
this(api, null);
}

Expand All @@ -64,7 +64,7 @@ public RecordComponentVisitor(final int api) {
* @param recordComponentVisitor the record component visitor to which this visitor must delegate
* method calls. May be null.
*/
public RecordComponentVisitor(
protected RecordComponentVisitor(
final int api, final RecordComponentVisitor recordComponentVisitor) {
if (api != Opcodes.ASM9
&& api != Opcodes.ASM8
Expand Down
Expand Up @@ -440,7 +440,7 @@ private static Type getTypeInternal(
case '(':
return new Type(METHOD, descriptorBuffer, descriptorBegin, descriptorEnd);
default:
throw new IllegalArgumentException();
throw new IllegalArgumentException("Invalid descriptor: " + descriptorBuffer);
}
}

Expand Down

0 comments on commit b55eee1

Please sign in to comment.