Skip to content

Commit

Permalink
Upgrade to ASM master
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Mar 25, 2022
1 parent edd66d9 commit cb36ca3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
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 @@ -336,13 +336,12 @@ 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;
Expand Down Expand Up @@ -861,7 +860,7 @@ private void readModuleAttributes(
currentOffset += 2;
}

// Read the 'provides_count' and 'provides' fields.
// Read the 'provides_count' and 'provides' fields.
int providesCount = readUnsignedShort(currentOffset);
currentOffset += 2;
while (providesCount-- > 0) {
Expand Down
34 changes: 28 additions & 6 deletions spring-core/src/main/java/org/springframework/asm/ClassWriter.java
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

0 comments on commit cb36ca3

Please sign in to comment.