correction on ex9
This commit is contained in:
parent
2de11a50ec
commit
474c6eddb6
2 changed files with 6 additions and 25 deletions
|
@ -2,34 +2,15 @@ package ex9;
|
||||||
|
|
||||||
import ch.usi.dag.disl.annotation.Before;
|
import ch.usi.dag.disl.annotation.Before;
|
||||||
import ch.usi.dag.disl.marker.BodyMarker;
|
import ch.usi.dag.disl.marker.BodyMarker;
|
||||||
import ch.usi.dag.disl.marker.BytecodeMarker;
|
|
||||||
import ch.usi.dag.disl.staticcontext.InvocationStaticContext;
|
import ch.usi.dag.disl.staticcontext.InvocationStaticContext;
|
||||||
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
||||||
|
|
||||||
public class Instrumentation {
|
public class Instrumentation {
|
||||||
|
|
||||||
@Before(marker = BytecodeMarker.class,
|
|
||||||
args = "invokevirtual, invokespecial, invokeinterface, invokestatic",
|
|
||||||
guard = IsNotConstructorOrStaticGuard.class,
|
|
||||||
scope = "ex9.MainThread.*")
|
|
||||||
static void logCall(final InvocationStaticContext isc) {
|
|
||||||
// this will log calls for all types of methods (including constructors and static initializers).
|
|
||||||
// However, constructors and static initializers will not be instrumented thanks to the included guard.
|
|
||||||
// Should calls to constructors and static methods not be instrumented, add the following line:
|
|
||||||
//
|
|
||||||
// if (isc.isConstructor()) return;
|
|
||||||
//
|
|
||||||
// and remove `invokestatic` from the BytecodeMarker argument list
|
|
||||||
|
|
||||||
Profiler.logCall(Thread.currentThread(), isc.getInternalName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before(marker = BodyMarker.class,
|
@Before(marker = BodyMarker.class,
|
||||||
guard = IsNotConstructorOrStaticGuard.class,
|
guard = IsNotConstructorOrStaticInitializerGuard.class,
|
||||||
scope = "ex9.MainThread.run")
|
scope = "ex9.MainThread.*")
|
||||||
static void logThreadStart(final MethodStaticContext msc) {
|
static void logCall(final MethodStaticContext isc) {
|
||||||
// We separately instrument the Thread.run() method as there is no obvious way to instrument the caller of
|
Profiler.logCall(Thread.currentThread(), isc.thisMethodFullName());
|
||||||
// Thread.run(). Hence, we log the call at method start.
|
|
||||||
Profiler.logCall(Thread.currentThread(), msc.thisMethodFullName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ package ex9;
|
||||||
import ch.usi.dag.disl.annotation.GuardMethod;
|
import ch.usi.dag.disl.annotation.GuardMethod;
|
||||||
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
||||||
|
|
||||||
public class IsNotConstructorOrStaticGuard {
|
public class IsNotConstructorOrStaticInitializerGuard {
|
||||||
@GuardMethod
|
@GuardMethod
|
||||||
public static boolean isNotConstructorOrStatic(final MethodStaticContext msc) {
|
public static boolean isNotConstructorOrStatic(final MethodStaticContext msc) {
|
||||||
return !msc.isMethodStatic() && !msc.isMethodConstructor();
|
return !msc.isMethodInitializer() && !msc.isMethodConstructor();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in a new issue