Skip to content

Commit

Permalink
Merge pull request #16 from saeg/feature/enable-exception-handler
Browse files Browse the repository at this point in the history
Enable `CatchAndThrowMethodVisitor` by default
  • Loading branch information
andrioli authored Sep 3, 2021
2 parents 60983f5 + 2ba7e34 commit 1abc38e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class CoverageTransformer implements ClassFileTransformer {
public CoverageTransformer(
final IExecutionDataAccessorGenerator accessorGenerator, final String skipPackageName) {
this.skipPackageName = skipPackageName.replace('.', '/');
instrumenter = new Instrumenter(accessorGenerator,
Boolean.valueOf(System.getProperty("badua.experimental.exception_handler")));
instrumenter = new Instrumenter(accessorGenerator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public class Instrument {
public Instrument(final InstrumentOptions options) {
this.src = options.getSource();
this.dest = options.getDestination();
instrumenter = new Instrumenter(new StaticAccessGenerator(Offline.class.getName()),
Boolean.valueOf(System.getProperty("badua.experimental.exception_handler")));
instrumenter = new Instrumenter(new StaticAccessGenerator(Offline.class.getName()));
}

public int instrument() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,14 @@ public class Instrumenter {

private final IExecutionDataAccessorGenerator accessorGenerator;

private final boolean exceptionHandler;

public Instrumenter(final IExecutionDataAccessorGenerator accessorGenerator) {
this(accessorGenerator, false);
}

public Instrumenter(
final IExecutionDataAccessorGenerator accessorGenerator, final boolean exceptionHandler) {
this.accessorGenerator = accessorGenerator;
this.exceptionHandler = exceptionHandler;
}

public byte[] instrument(final ClassReader reader) {
final long classId = CRC64.checksum(reader.b);
final ClassWriter writer = new ClassWriter(reader, DEFAULT);
final ClassVisitor ci = new ClassInstrumenter(classId, writer, accessorGenerator, exceptionHandler);
final ClassVisitor ci = new ClassInstrumenter(classId, writer, accessorGenerator);
reader.accept(ci, ClassReader.EXPAND_FRAMES);
return writer.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class ClassInstrumenter extends ClassVisitor implements IdGenerator {

private final IExecutionDataAccessorGenerator accessorGenerator;

private final boolean exceptionHandler;

private String className;

private boolean withFrames;
Expand All @@ -36,17 +34,10 @@ public class ClassInstrumenter extends ClassVisitor implements IdGenerator {

public ClassInstrumenter(final long classId, final ClassVisitor cv,
final IExecutionDataAccessorGenerator accessorGenerator) {
this(classId, cv, accessorGenerator, false);
}

public ClassInstrumenter(final long classId, final ClassVisitor cv,
final IExecutionDataAccessorGenerator accessorGenerator,
final boolean exceptionHandler) {

super(Opcodes.ASM6, cv);
this.classId = classId;
this.accessorGenerator = accessorGenerator;
this.exceptionHandler = exceptionHandler;
}

@Override
Expand Down Expand Up @@ -106,9 +97,8 @@ else if (name.equals("<clinit>"))

// There is some edge cases with constructors and stack map frames
// So we will ignore constructors. We must address these issues in the future
return exceptionHandler && !name.equals("<init>")
? new CatchAndThrowMethodVisitor("java/lang/Throwable", instrumenter, withFrames)
: instrumenter;
return name.equals("<init>") ? instrumenter
: new CatchAndThrowMethodVisitor("java/lang/Throwable", instrumenter, withFrames);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public abstract class ValidationTest {

protected ValidationTestClassLoader loader;

protected boolean exceptionHandler = true;

public void setUp() throws Exception {
loader = new ValidationTestClassLoader();
}
Expand All @@ -32,7 +30,7 @@ public Class<?> addClass(final String name, final byte[] bytes) {

private byte[] instrument(final String name, final byte[] bytes) {
final Instrumenter instrumenter = new Instrumenter(
new StaticAccessGenerator(RT.class.getName()), exceptionHandler);
new StaticAccessGenerator(RT.class.getName()));

try {
return instrumenter.instrument(bytes, name);
Expand Down

0 comments on commit 1abc38e

Please sign in to comment.