Skip to content

Commit

Permalink
Adopt ASM 9.3
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol authored and senivam committed May 18, 2022
1 parent c0ed81d commit 31f6557
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 83 deletions.
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ KineticJS, v4.7.1
* Project: http://www.kineticjs.com, https://github.com/ericdrowell/KineticJS
* Copyright: Eric Rowell

org.objectweb.asm Version 8.0
org.objectweb.asm Version 9.3
* License: Modified BSD (https://asm.ow2.io/license.html)
* Copyright (c) 2000-2011 INRIA, France Telecom. All rights reserved.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
public abstract class AnnotationVisitor {

/**
* The ASM API version implemented by this visitor. The value of this field must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* The ASM API version implemented by this visitor. The value of this field must be one of the
* {@code ASM}<i>x</i> values in {@link Opcodes}.
*/
protected final int api;

Expand All @@ -52,22 +52,22 @@ public abstract class AnnotationVisitor {
/**
* Constructs a new {@link AnnotationVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* @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);
}

/**
* Constructs a new {@link AnnotationVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
* @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
Original file line number Diff line number Diff line change
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 @@ -352,6 +361,9 @@ public ByteVector putByteArray(
* @param size number of additional bytes that this byte vector should be able to receive.
*/
private void enlarge(final int size) {
if (length > data.length) {
throw new AssertionError("Internal error");
}
int doubleCapacity = 2 * data.length;
int minimalCapacity = length + size;
byte[] newData = new byte[doubleCapacity > minimalCapacity ? doubleCapacity : minimalCapacity];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public ClassReader(
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.V18) {
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V19) {
throw new IllegalArgumentException(
"Unsupported class file major version " + readShort(classFileOffset + 6));
}
Expand Down Expand Up @@ -308,12 +308,13 @@ public ClassReader(final String className) throws IOException {
* @return the content of the given input stream.
* @throws IOException if a problem occurs during reading.
*/
@SuppressWarnings("PMD.UseTryWithResources")
private static byte[] readStream(final InputStream inputStream, final boolean close)
throws IOException {
if (inputStream == null) {
throw new IOException("Class not found");
}
int bufferSize = calculateBufferSize(inputStream);
int bufferSize = computeBufferSize(inputStream);
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
byte[] data = new byte[bufferSize];
int bytesRead;
Expand All @@ -334,19 +335,19 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
}
}

private static int calculateBufferSize(final InputStream inputStream) throws IOException {
private static int computeBufferSize(final InputStream inputStream) throws IOException {
int expectedLength = inputStream.available();
/*
* Some implementations can return 0 while holding available data
* (e.g. new FileInputStream("/proc/a_file"))
* Also in some pathological cases a very small number might be returned,
* and in this case we use default size
* Some implementations can return 0 while holding available data (e.g. new
* FileInputStream("/proc/a_file")). Also in some pathological cases a very small number might
* be returned, and in this case we use a default size.
*/
if (expectedLength < 256) {
return INPUT_STREAM_DATA_CHUNK_SIZE;
}
return Math.min(expectedLength, MAX_BUFFER_SIZE);
}

// -----------------------------------------------------------------------------------------------
// Accessors
// -----------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
public abstract class ClassVisitor {

/**
* The ASM API version implemented by this visitor. The value of this field must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* The ASM API version implemented by this visitor. The value of this field must be one of the
* {@code ASM}<i>x</i> values in {@link Opcodes}.
*/
protected final int api;

Expand All @@ -51,23 +51,22 @@ public abstract class ClassVisitor {
/**
* Constructs a new {@link ClassVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* @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);
}

/**
* Constructs a new {@link ClassVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7}, {@link
* Opcodes#ASM8} or {@link Opcodes#ASM9}.
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public class ClassWriter extends ClassVisitor {
*/
public static final int COMPUTE_FRAMES = 2;

/**
* The flags passed to the constructor. Must be zero or more of {@link #COMPUTE_MAXS} and {@link
* #COMPUTE_FRAMES}.
*/
private final int flags;

// Note: fields are ordered as in the ClassFile structure, and those related to attributes are
// ordered as in Section 4.7 of the JVMS.

Expand Down Expand Up @@ -248,23 +254,39 @@ public ClassWriter(final int flags) {
* @param classReader the {@link ClassReader} used to read the original class. It will be used to
* copy the entire constant pool and bootstrap methods from the original class and also to
* copy other fragments of original bytecode where applicable.
* @param flags option flags that can be used to modify the default behavior of this class.Must be
* zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. <i>These option flags do
* not affect methods that are copied as is in the new class. This means that neither the
* @param flags option flags that can be used to modify the default behavior of this class. Must
* be zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. <i>These option flags
* do not affect methods that are copied as is in the new class. This means that neither the
* maximum stack size nor the stack frames will be computed for these methods</i>.
*/
public ClassWriter(final ClassReader classReader, final int flags) {
super(/* latest api = */ Opcodes.ASM9);
this.flags = flags;
symbolTable = classReader == null ? new SymbolTable(this) : new SymbolTable(this, classReader);
if ((flags & COMPUTE_FRAMES) != 0) {
this.compute = MethodWriter.COMPUTE_ALL_FRAMES;
compute = MethodWriter.COMPUTE_ALL_FRAMES;
} else if ((flags & COMPUTE_MAXS) != 0) {
this.compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL;
compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL;
} else {
this.compute = MethodWriter.COMPUTE_NOTHING;
compute = MethodWriter.COMPUTE_NOTHING;
}
}

// -----------------------------------------------------------------------------------------------
// Accessors
// -----------------------------------------------------------------------------------------------

/**
* Returns true if all the given flags were passed to the constructor.
*
* @param flags some option flags. Must be zero or more of {@link #COMPUTE_MAXS} and {@link
* #COMPUTE_FRAMES}.
* @return true if all the given flags, or more, were passed to the constructor.
*/
public boolean hasFlags(final int flags) {
return (this.flags & flags) == flags;
}

// -----------------------------------------------------------------------------------------------
// Implementation of the ClassVisitor abstract class
// -----------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
public abstract class FieldVisitor {

/**
* The ASM API version implemented by this visitor. The value of this field must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7}, {@link
* Opcodes#ASM8} or {@link Opcodes#ASM9}.
* The ASM API version implemented by this visitor. The value of this field must be one of the
* {@code ASM}<i>x</i> values in {@link Opcodes}.
*/
protected final int api;

Expand All @@ -49,24 +48,22 @@ public abstract class FieldVisitor {
/**
* Constructs a new {@link FieldVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7}, {@link
* Opcodes#ASM8} or {@link Opcodes#ASM9}.
* @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);
}

/**
* Constructs a new {@link FieldVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7} or {@link
* Opcodes#ASM8}.
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public abstract class MethodVisitor {
private static final String REQUIRES_ASM5 = "This feature requires ASM5";

/**
* The ASM API version implemented by this visitor. The value of this field must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* The ASM API version implemented by this visitor. The value of this field must be one of the
* {@code ASM}<i>x</i> values in {@link Opcodes}.
*/
protected final int api;

Expand All @@ -64,22 +64,22 @@ public abstract class MethodVisitor {
/**
* Constructs a new {@link MethodVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* @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);
}

/**
* Constructs a new {@link MethodVisitor}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* @param api the ASM API version implemented by this visitor. Must be one of the {@code
* ASM}<i>x</i> values in {@link Opcodes}.
* @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 @@ -351,12 +351,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 Expand Up @@ -554,12 +554,12 @@ public void visitLdcInsn(final Object value) {
/**
* Visits an IINC instruction.
*
* @param var index of the local variable to be incremented.
* @param varIndex index of the local variable to be incremented.
* @param increment amount to increment the local variable by.
*/
public void visitIincInsn(final int var, final int increment) {
public void visitIincInsn(final int varIndex, final int increment) {
if (mv != null) {
mv.visitIincInsn(var, increment);
mv.visitIincInsn(varIndex, increment);
}
}

Expand Down
Loading

0 comments on commit 31f6557

Please sign in to comment.