Search in sources :

Example 1 with IProbeArrayStrategy

use of org.jacoco.core.internal.instr.IProbeArrayStrategy in project jacoco by jacoco.

the class Instrumenter method instrument.

private byte[] instrument(final byte[] source) {
    final long classId = CRC64.classId(source);
    final int originalVersion = BytecodeVersion.get(source);
    final byte[] b = BytecodeVersion.downgradeIfNeeded(originalVersion, source);
    final ClassReader reader = new ClassReader(b);
    final ClassWriter writer = new ClassWriter(reader, 0) {

        @Override
        protected String getCommonSuperClass(final String type1, final String type2) {
            throw new IllegalStateException();
        }
    };
    final IProbeArrayStrategy strategy = ProbeArrayStrategyFactory.createFor(classId, reader, accessorGenerator);
    final ClassVisitor visitor = new ClassProbesAdapter(new ClassInstrumenter(strategy, writer), true);
    reader.accept(visitor, ClassReader.EXPAND_FRAMES);
    final byte[] instrumented = writer.toByteArray();
    BytecodeVersion.set(instrumented, originalVersion);
    return instrumented;
}
Also used : ClassInstrumenter(org.jacoco.core.internal.instr.ClassInstrumenter) ClassReader(org.objectweb.asm.ClassReader) IProbeArrayStrategy(org.jacoco.core.internal.instr.IProbeArrayStrategy) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassProbesAdapter(org.jacoco.core.internal.flow.ClassProbesAdapter) ClassWriter(org.objectweb.asm.ClassWriter)

Aggregations

ClassProbesAdapter (org.jacoco.core.internal.flow.ClassProbesAdapter)1 ClassInstrumenter (org.jacoco.core.internal.instr.ClassInstrumenter)1 IProbeArrayStrategy (org.jacoco.core.internal.instr.IProbeArrayStrategy)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1