summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Bruneton <ebruneton@free.fr>2022-12-13 07:25:19 +0000
committerEric Bruneton <ebruneton@free.fr>2022-12-13 07:25:19 +0000
commitd648961d310264c2d6d6db4c17b64a94c96c23ce (patch)
tree5012e30c0666aa61edfb84cbae8e58293952488e
parent09e972725530cd17189efb3c91ecddf34c59e9d8 (diff)
parent31063c1df6ac1d0cc52572e86fd2fe6082127b2a (diff)
downloadow2-asm-d648961d310264c2d6d6db4c17b64a94c96c23ce.tar.gz
Merge branch '317982-add-classreader-hook-to-get-bytecode-instruction-offsets' into 'master'
Add a hook in ClassReader to allow subclasses to get the bytecode offset of visited instructions. Closes #317982 See merge request asm/asm!368
-rw-r--r--asm/src/main/java/org/objectweb/asm/ClassReader.java15
-rw-r--r--build.gradle2
2 files changed, 16 insertions, 1 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..13b7cb34 100644
--- a/asm/src/main/java/org/objectweb/asm/ClassReader.java
+++ b/asm/src/main/java/org/objectweb/asm/ClassReader.java
@@ -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/build.gradle b/build.gradle
index 0e67ce83..a9928392 100644
--- a/build.gradle
+++ b/build.gradle
@@ -154,7 +154,7 @@ project(':benchmarks') {
resultFormat = 'CSV'
profilers = ['org.objectweb.asm.benchmarks.MemoryProfiler']
if (rootProject.hasProperty('jmhInclude')) {
- include = [jmhInclude]
+ includes = [jmhInclude]
}
}
}