Upgrade to ASM master
This commit is contained in:
parent
edd66d96dd
commit
cb36ca31f6
|
@ -313,7 +313,7 @@ public class ClassReader {
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
throw new IOException("Class not found");
|
throw new IOException("Class not found");
|
||||||
}
|
}
|
||||||
int bufferSize = calculateBufferSize(inputStream);
|
int bufferSize = computeBufferSize(inputStream);
|
||||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
byte[] data = new byte[bufferSize];
|
byte[] data = new byte[bufferSize];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
|
@ -336,13 +336,12 @@ public class ClassReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int calculateBufferSize(final InputStream inputStream) throws IOException {
|
private static int computeBufferSize(final InputStream inputStream) throws IOException {
|
||||||
int expectedLength = inputStream.available();
|
int expectedLength = inputStream.available();
|
||||||
/*
|
/*
|
||||||
* Some implementations can return 0 while holding available data
|
* Some implementations can return 0 while holding available data (e.g. new
|
||||||
* (e.g. new FileInputStream("/proc/a_file"))
|
* FileInputStream("/proc/a_file")). Also in some pathological cases a very small number might
|
||||||
* Also in some pathological cases a very small number might be returned,
|
* be returned, and in this case we use a default size.
|
||||||
* and in this case we use default size
|
|
||||||
*/
|
*/
|
||||||
if (expectedLength < 256) {
|
if (expectedLength < 256) {
|
||||||
return INPUT_STREAM_DATA_CHUNK_SIZE;
|
return INPUT_STREAM_DATA_CHUNK_SIZE;
|
||||||
|
|
|
@ -65,6 +65,12 @@ public class ClassWriter extends ClassVisitor {
|
||||||
*/
|
*/
|
||||||
public static final int COMPUTE_FRAMES = 2;
|
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
|
// Note: fields are ordered as in the ClassFile structure, and those related to attributes are
|
||||||
// ordered as in Section 4.7 of the JVMS.
|
// ordered as in Section 4.7 of the JVMS.
|
||||||
|
|
||||||
|
@ -248,23 +254,39 @@ public class ClassWriter extends ClassVisitor {
|
||||||
* @param classReader the {@link ClassReader} used to read the original class. It will be used to
|
* @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 the entire constant pool and bootstrap methods from the original class and also to
|
||||||
* copy other fragments of original bytecode where applicable.
|
* 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
|
* @param flags option flags that can be used to modify the default behavior of this class. Must
|
||||||
* zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. <i>These option flags do
|
* be zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. <i>These option flags
|
||||||
* not affect methods that are copied as is in the new class. This means that neither the
|
* 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>.
|
* maximum stack size nor the stack frames will be computed for these methods</i>.
|
||||||
*/
|
*/
|
||||||
public ClassWriter(final ClassReader classReader, final int flags) {
|
public ClassWriter(final ClassReader classReader, final int flags) {
|
||||||
super(/* latest api = */ Opcodes.ASM9);
|
super(/* latest api = */ Opcodes.ASM9);
|
||||||
|
this.flags = flags;
|
||||||
symbolTable = classReader == null ? new SymbolTable(this) : new SymbolTable(this, classReader);
|
symbolTable = classReader == null ? new SymbolTable(this) : new SymbolTable(this, classReader);
|
||||||
if ((flags & COMPUTE_FRAMES) != 0) {
|
if ((flags & COMPUTE_FRAMES) != 0) {
|
||||||
this.compute = MethodWriter.COMPUTE_ALL_FRAMES;
|
compute = MethodWriter.COMPUTE_ALL_FRAMES;
|
||||||
} else if ((flags & COMPUTE_MAXS) != 0) {
|
} else if ((flags & COMPUTE_MAXS) != 0) {
|
||||||
this.compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL;
|
compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL;
|
||||||
} else {
|
} 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
|
// Implementation of the ClassVisitor abstract class
|
||||||
// -----------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue