Skip to content

Commit faf49f9

Browse files
Godinmarchof
authored andcommitted
Remove instrument(ClassReader) and analyzeClass(ClassReader) (bazel-contrib#850)
* they use field `ClassReader.b` which is marked as deprecated in ASM 7.1 * they don't work when field contains more than just bytes of one class (see `ClassReader(byte[] classFileBuffer, int classFileOffset, int classFileLength)`)
1 parent c30eb29 commit faf49f9

File tree

5 files changed

+14
-31
lines changed

5 files changed

+14
-31
lines changed

org.jacoco.core.test/src/org/jacoco/core/test/perf/ExecuteInstrumentedCodeScenario.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.jacoco.core.runtime.LoggerRuntime;
1919
import org.jacoco.core.runtime.RuntimeData;
2020
import org.jacoco.core.test.TargetLoader;
21-
import org.objectweb.asm.ClassReader;
2221

2322
/**
2423
* This scenario runs a given scenario twice and reports the execution time:
@@ -37,11 +36,11 @@ protected ExecuteInstrumentedCodeScenario(String description,
3736
@Override
3837
@SuppressWarnings("unchecked")
3938
protected Callable<Void> getInstrumentedCallable() throws Exception {
40-
ClassReader reader = new ClassReader(TargetLoader.getClassData(target));
4139
IRuntime runtime = new LoggerRuntime();
4240
runtime.startup(new RuntimeData());
4341
final Instrumenter instr = new Instrumenter(runtime);
44-
final byte[] instrumentedBuffer = instr.instrument(reader);
42+
final byte[] original = TargetLoader.getClassDataAsBytes(target);
43+
final byte[] instrumentedBuffer = instr.instrument(original, "");
4544
final TargetLoader loader = new TargetLoader();
4645

4746
return (Callable<Void>) loader.add(target, instrumentedBuffer)

org.jacoco.core.test/src/org/jacoco/core/test/perf/InstrumentationSizeSzenario.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.jacoco.core.runtime.IRuntime;
1616
import org.jacoco.core.runtime.LoggerRuntime;
1717
import org.jacoco.core.test.TargetLoader;
18-
import org.objectweb.asm.ClassReader;
1918

2019
/**
2120
* Scenario to measure the overhead in terms of additional byte code size
@@ -31,11 +30,11 @@ public InstrumentationSizeSzenario(Class<?> target) {
3130

3231
public void run(IPerfOutput output) throws Exception {
3332
final IRuntime runtime = new LoggerRuntime();
34-
ClassReader reader = new ClassReader(TargetLoader.getClassData(target));
3533
final Instrumenter instr = new Instrumenter(runtime);
36-
instr.instrument(reader);
37-
output.writeByteResult("instrumented class",
38-
instr.instrument(reader).length, reader.b.length);
34+
final byte[] original = TargetLoader.getClassDataAsBytes(target);
35+
final byte[] instrumented = instr.instrument(original, "");
36+
output.writeByteResult("instrumented class", instrumented.length,
37+
original.length);
3938
}
4039

4140
}

org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@ public void visitEnd() {
101101
return new ClassProbesAdapter(analyzer, false);
102102
}
103103

104-
/**
105-
* Analyzes the class given as a ASM reader.
106-
*
107-
* @param reader
108-
* reader with class definitions
109-
*/
110-
public void analyzeClass(final ClassReader reader) {
111-
analyzeClass(reader.b);
112-
}
113-
114104
private void analyzeClass(final byte[] source) {
115105
final long classId = CRC64.classId(source);
116106
final ClassReader reader = InstrSupport.classReaderFor(source);

org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,6 @@ public void setRemoveSignatures(final boolean flag) {
6969
signatureRemover.setActive(flag);
7070
}
7171

72-
/**
73-
* Creates a instrumented version of the given class if possible.
74-
*
75-
* @param reader
76-
* definition of the class as ASM reader
77-
* @return instrumented definition
78-
*
79-
*/
80-
public byte[] instrument(final ClassReader reader) {
81-
return instrument(reader.b);
82-
}
83-
8472
private byte[] instrument(final byte[] source) {
8573
final long classId = CRC64.classId(source);
8674
final ClassReader reader = InstrSupport.classReaderFor(source);

org.jacoco.doc/docroot/doc/changes.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ <h1>Change History</h1>
2121
<h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>
2222

2323
<h3>New Features</h3>
24-
2524
<ul>
2625
<li>Branches added by the Kotlin compiler version 1.3.30 for suspending lambdas
2726
and functions are filtered out during generation of report
2827
(GitHub <a href="https://github.com/jacoco/jacoco/issues/849">#849</a>).</li>
2928
</ul>
3029

30+
<h3>API Changes</h3>
31+
<ul>
32+
<li>Methods <code>Instrumenter.instrument(org.objectweb.asm.ClassReader)</code>
33+
and <code>Analyzer.analyzeClass(org.objectweb.asm.ClassReader)</code>
34+
were removed
35+
(GitHub <a href="https://github.com/jacoco/jacoco/issues/850">#850</a>).</li>
36+
</ul>
37+
3138
<h2>Release 0.8.3 (2019/01/23)</h2>
3239

3340
<h3>New Features</h3>

0 commit comments

Comments
 (0)