summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Bruneton <ebruneton@free.fr>2022-12-13 07:00:23 +0000
committerEric Bruneton <ebruneton@free.fr>2022-12-13 07:00:23 +0000
commit09e972725530cd17189efb3c91ecddf34c59e9d8 (patch)
tree8fc913eec3f6c58465fe6aeabb59a91b9d1905df
parent2c6decdfa7bedc671254da491bd34084332d30b0 (diff)
parent21a6f25008c649e5481ec457f9327b470713ae49 (diff)
downloadow2-asm-09e972725530cd17189efb3c91ecddf34c59e9d8.tar.gz
Merge branch '317989-support-line-number-zero' into 'master'
Add support for line numbers equal to 0. Closes #317989 See merge request asm/asm!367
-rw-r--r--asm-test/src/main/resources/jdk3/ArtificialStructures.classbin771 -> 771 bytes
-rw-r--r--asm-test/src/resources/java/jdk3/DumpArtificialStructures.java4
-rw-r--r--asm-util/src/test/resources/jdk3.ArtificialStructures.txt2
-rw-r--r--asm/src/main/java/org/objectweb/asm/Label.java14
4 files changed, 12 insertions, 8 deletions
diff --git a/asm-test/src/main/resources/jdk3/ArtificialStructures.class b/asm-test/src/main/resources/jdk3/ArtificialStructures.class
index 0ba4240b..68477215 100644
--- a/asm-test/src/main/resources/jdk3/ArtificialStructures.class
+++ b/asm-test/src/main/resources/jdk3/ArtificialStructures.class
Binary files differ
diff --git a/asm-test/src/resources/java/jdk3/DumpArtificialStructures.java b/asm-test/src/resources/java/jdk3/DumpArtificialStructures.java
index 3701472d..b316d1c0 100644
--- a/asm-test/src/resources/java/jdk3/DumpArtificialStructures.java
+++ b/asm-test/src/resources/java/jdk3/DumpArtificialStructures.java
@@ -47,7 +47,7 @@ import org.objectweb.asm.Opcodes;
* <li>non standard class, field, method and code attributes,
* <li>the nop and swap instructions,
* <li>some variants of the dup_x2 and dup2_x2 instructions,
- * <li>several line numbers per bytecode offset.
+ * <li>several line numbers per bytecode offset, and line numbers equal to 0.
* </ul>
*
* Ideally we should not use ASM to generate this class (which is later used to test ASM), but this
@@ -103,7 +103,7 @@ public class DumpArtificialStructures implements Opcodes {
Label endIfLabel = new Label();
methodVisitor.visitJumpInsn(GOTO, endIfLabel);
methodVisitor.visitLabel(elseLabel);
- methodVisitor.visitLineNumber(1, elseLabel);
+ methodVisitor.visitLineNumber(0, elseLabel);
methodVisitor.visitLineNumber(3, elseLabel);
methodVisitor.visitLdcInsn("0");
methodVisitor.visitLabel(endIfLabel);
diff --git a/asm-util/src/test/resources/jdk3.ArtificialStructures.txt b/asm-util/src/test/resources/jdk3.ArtificialStructures.txt
index ae5c1aa9..2f31e255 100644
--- a/asm-util/src/test/resources/jdk3.ArtificialStructures.txt
+++ b/asm-util/src/test/resources/jdk3.ArtificialStructures.txt
@@ -31,7 +31,7 @@ public class jdk3/ArtificialStructures {
LDC "1"
GOTO L1
L0
- LINENUMBER 1 L0
+ LINENUMBER 0 L0
LINENUMBER 3 L0
FRAME FULL [U I] [U]
LDC "0"
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) {