diff options
author | Victor Chang <vichang@google.com> | 2023-06-08 16:21:52 +0100 |
---|---|---|
committer | Victor Chang <vichang@google.com> | 2023-06-08 16:26:12 +0100 |
commit | 09e8c429ce33bd2c68ed6e73cf4341242e04c3ee (patch) | |
tree | a1a569767f442e842b70624189dcf18611a070da /asm | |
parent | 10c13c0775349e2f94b6eae75caede64e71a01f1 (diff) | |
parent | 443339a964352dcec4dd3915de8f13188920d3ac (diff) | |
download | ow2-asm-09e8c429ce33bd2c68ed6e73cf4341242e04c3ee.tar.gz |
Import ASM 9.5
Merge '443339a964352dcec4dd3915de8f13188920d3ac' into aosp/master
This commmit is tagged as "ASM_9_5" in the upstream.
https://gitlab.ow2.org/asm/asm/-/tree/ASM_9_5?ref_type=tags
Update reason: ASM 9.5 version is required to read OpenJDK 21 class file format.
Release Note
- new Opcodes.V21 constant for Java 21
- new readBytecodeInstructionOffset hook in ClassReader
- more detailed exception messages
- Javadoc improvements and fixes
- bug fixes
- 317989: Silent removal of zero-valued entries from the line-number table
Test: m libcore-openjdk-analyzer
Change-Id: Iae4ea0f96608b5f6ab81ccaedea36077bfdfbce7
Diffstat (limited to 'asm')
5 files changed, 30 insertions, 8 deletions
diff --git a/asm/src/main/java/org/objectweb/asm/ClassReader.java b/asm/src/main/java/org/objectweb/asm/ClassReader.java index 7f0e4e72..2cfef457 100644 --- a/asm/src/main/java/org/objectweb/asm/ClassReader.java +++ b/asm/src/main/java/org/objectweb/asm/ClassReader.java @@ -194,7 +194,7 @@ public class 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.V20) { + if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V21) { throw new IllegalArgumentException( "Unsupported class file major version " + readShort(classFileOffset + 6)); } @@ -2050,6 +2050,7 @@ public class ClassReader { 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]; @@ -2666,6 +2667,20 @@ public class ClassReader { } /** + * 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. * diff --git a/asm/src/main/java/org/objectweb/asm/Frame.java b/asm/src/main/java/org/objectweb/asm/Frame.java index 07f256e5..89195006 100644 --- a/asm/src/main/java/org/objectweb/asm/Frame.java +++ b/asm/src/main/java/org/objectweb/asm/Frame.java @@ -367,11 +367,12 @@ class Frame { typeValue = REFERENCE_KIND | symbolTable.addType(internalName); break; default: - throw new IllegalArgumentException(); + throw new IllegalArgumentException( + "Invalid descriptor fragment: " + buffer.substring(elementDescriptorOffset)); } return ((elementDescriptorOffset - offset) << DIM_SHIFT) | typeValue; default: - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Invalid descriptor: " + buffer.substring(offset)); } } diff --git a/asm/src/main/java/org/objectweb/asm/Label.java b/asm/src/main/java/org/objectweb/asm/Label.java index 926f719e..4bcf7c56 100644 --- a/asm/src/main/java/org/objectweb/asm/Label.java +++ b/asm/src/main/java/org/objectweb/asm/Label.java @@ -81,6 +81,9 @@ public class Label { /** A flag indicating that the basic block corresponding to a label is the end of a subroutine. */ static final int FLAG_SUBROUTINE_END = 64; + /** A flag indicating that this label has at least one associated line number. */ + static final int FLAG_LINE_NUMBER = 128; + /** * The number of elements to add to the {@link #otherLineNumbers} array when it needs to be * resized to store a new source line number. @@ -145,9 +148,9 @@ public class Label { short flags; /** - * The source line number corresponding to this label, or 0. If there are several source line - * numbers corresponding to this label, the first one is stored in this field, and the remaining - * ones are stored in {@link #otherLineNumbers}. + * The source line number corresponding to this label, if {@link #FLAG_LINE_NUMBER} is set. If + * there are several source line numbers corresponding to this label, the first one is stored in + * this field, and the remaining ones are stored in {@link #otherLineNumbers}. */ private short lineNumber; @@ -332,7 +335,8 @@ public class Label { * @param lineNumber a source line number (which should be strictly positive). */ final void addLineNumber(final int lineNumber) { - if (this.lineNumber == 0) { + if ((flags & FLAG_LINE_NUMBER) == 0) { + flags |= FLAG_LINE_NUMBER; this.lineNumber = (short) lineNumber; } else { if (otherLineNumbers == null) { @@ -356,7 +360,7 @@ public class Label { */ final void accept(final MethodVisitor methodVisitor, final boolean visitLineNumbers) { methodVisitor.visitLabel(this); - if (visitLineNumbers && lineNumber != 0) { + if (visitLineNumbers && (flags & FLAG_LINE_NUMBER) != 0) { methodVisitor.visitLineNumber(lineNumber & 0xFFFF, this); if (otherLineNumbers != null) { for (int i = 1; i <= otherLineNumbers[0]; ++i) { diff --git a/asm/src/main/java/org/objectweb/asm/Opcodes.java b/asm/src/main/java/org/objectweb/asm/Opcodes.java index 4a85a445..7202784f 100644 --- a/asm/src/main/java/org/objectweb/asm/Opcodes.java +++ b/asm/src/main/java/org/objectweb/asm/Opcodes.java @@ -286,6 +286,7 @@ public interface Opcodes { int V18 = 0 << 16 | 62; int V19 = 0 << 16 | 63; int V20 = 0 << 16 | 64; + int V21 = 0 << 16 | 65; /** * Version flag indicating that the class is using 'preview' features. diff --git a/asm/src/test/java/org/objectweb/asm/ConstantsTest.java b/asm/src/test/java/org/objectweb/asm/ConstantsTest.java index f2ca92a2..54955c54 100644 --- a/asm/src/test/java/org/objectweb/asm/ConstantsTest.java +++ b/asm/src/test/java/org/objectweb/asm/ConstantsTest.java @@ -253,6 +253,7 @@ class ConstantsTest { case "V18": case "V19": case "V20": + case "V21": return ConstantType.CLASS_VERSION; case "ACC_PUBLIC": case "ACC_PRIVATE": |