Skip to content

Commit

Permalink
Remove instrument(ClassReader) and analyzeClass(ClassReader)
Browse files Browse the repository at this point in the history
* 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)`)
  • Loading branch information
Godin committed Mar 4, 2019
1 parent c30eb29 commit fd4947e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.jacoco.core.runtime.LoggerRuntime;
import org.jacoco.core.runtime.RuntimeData;
import org.jacoco.core.test.TargetLoader;
import org.objectweb.asm.ClassReader;

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

return (Callable<Void>) loader.add(target, instrumentedBuffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.jacoco.core.runtime.IRuntime;
import org.jacoco.core.runtime.LoggerRuntime;
import org.jacoco.core.test.TargetLoader;
import org.objectweb.asm.ClassReader;

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

public void run(IPerfOutput output) throws Exception {
final IRuntime runtime = new LoggerRuntime();
ClassReader reader = new ClassReader(TargetLoader.getClassData(target));
final Instrumenter instr = new Instrumenter(runtime);
instr.instrument(reader);
output.writeByteResult("instrumented class",
instr.instrument(reader).length, reader.b.length);
final byte[] original = TargetLoader.getClassDataAsBytes(target);
final byte[] instrumented = instr.instrument(original, "");
output.writeByteResult("instrumented class", instrumented.length,
original.length);
}

}
10 changes: 0 additions & 10 deletions org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ public void visitEnd() {
return new ClassProbesAdapter(analyzer, false);
}

/**
* Analyzes the class given as a ASM reader.
*
* @param reader
* reader with class definitions
*/
public void analyzeClass(final ClassReader reader) {
analyzeClass(reader.b);
}

private void analyzeClass(final byte[] source) {
final long classId = CRC64.classId(source);
final ClassReader reader = InstrSupport.classReaderFor(source);
Expand Down
12 changes: 0 additions & 12 deletions org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,6 @@ public void setRemoveSignatures(final boolean flag) {
signatureRemover.setActive(flag);
}

/**
* Creates a instrumented version of the given class if possible.
*
* @param reader
* definition of the class as ASM reader
* @return instrumented definition
*
*/
public byte[] instrument(final ClassReader reader) {
return instrument(reader.b);
}

private byte[] instrument(final byte[] source) {
final long classId = CRC64.classId(source);
final ClassReader reader = InstrSupport.classReaderFor(source);
Expand Down
9 changes: 8 additions & 1 deletion org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ <h1>Change History</h1>
<h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>

<h3>New Features</h3>

<ul>
<li>Branches added by the Kotlin compiler version 1.3.30 for suspending lambdas
and functions are filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/849">#849</a>).</li>
</ul>

<h3>API Changes</h3>
<ul>
<li>Methods <code>Instrumenter.instrument(org.objectweb.asm.ClassReader)</code>
and <code>Analyzer.analyzeClass(org.objectweb.asm.ClassReader)</code>
were removed
(GitHub <a href="https://github.com/jacoco/jacoco/issues/850">#850</a>).</li>
</ul>

<h2>Release 0.8.3 (2019/01/23)</h2>

<h3>New Features</h3>
Expand Down

0 comments on commit fd4947e

Please sign in to comment.