2023-01-02 09:46:59 +00:00
|
|
|
package ex11;
|
|
|
|
|
2023-01-11 14:17:18 +00:00
|
|
|
import ch.usi.dag.disl.annotation.Before;
|
2023-01-20 17:26:55 +00:00
|
|
|
import ch.usi.dag.disl.annotation.ThreadLocal;
|
|
|
|
import ch.usi.dag.disl.marker.BodyMarker;
|
2023-01-11 14:17:18 +00:00
|
|
|
import ch.usi.dag.disl.marker.BytecodeMarker;
|
|
|
|
import ch.usi.dag.disl.staticcontext.InstructionStaticContext;
|
2023-01-20 17:26:55 +00:00
|
|
|
import ch.usi.dag.disl.staticcontext.InvocationStaticContext;
|
2023-01-11 14:17:18 +00:00
|
|
|
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
|
|
|
|
2023-01-02 09:46:59 +00:00
|
|
|
public class Instrumentation {
|
2023-01-11 14:17:18 +00:00
|
|
|
|
2023-01-20 17:26:55 +00:00
|
|
|
@ThreadLocal
|
|
|
|
private static int opCode;
|
2023-01-11 14:17:18 +00:00
|
|
|
|
2023-01-20 17:26:55 +00:00
|
|
|
@ThreadLocal
|
|
|
|
private static int index;
|
2023-01-11 14:17:18 +00:00
|
|
|
|
2023-01-20 17:26:55 +00:00
|
|
|
@ThreadLocal
|
|
|
|
private static String callee;
|
2023-01-11 14:17:18 +00:00
|
|
|
|
2023-01-20 17:26:55 +00:00
|
|
|
@ThreadLocal
|
|
|
|
private static String caller;
|
|
|
|
|
|
|
|
@ThreadLocal
|
|
|
|
private static boolean initialized;
|
|
|
|
|
|
|
|
@Before(marker = BytecodeMarker.class, args = "invokevirtual, invokeinterface")
|
|
|
|
static void atObjectRefCallSite(final InstructionStaticContext isc,
|
|
|
|
final MethodStaticContext msc,
|
|
|
|
final InvocationStaticContext ivc) {
|
|
|
|
opCode = isc.getOpcode();
|
|
|
|
index = isc.getIndex();
|
|
|
|
caller = msc.thisMethodFullName().concat(msc.thisMethodDescriptor());
|
|
|
|
callee = ivc.getInternalName().concat(ivc.getDescriptor());
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Before(marker = BytecodeMarker.class, args = "invokedynamic")
|
|
|
|
static void atObjectRefCallSiteDynamic(final InstructionStaticContext isc,
|
2023-02-01 15:38:20 +00:00
|
|
|
final MethodStaticContext msc) {
|
2023-01-20 17:26:55 +00:00
|
|
|
opCode = isc.getOpcode();
|
|
|
|
index = isc.getIndex();
|
|
|
|
caller = msc.thisMethodFullName().concat(msc.thisMethodDescriptor());
|
|
|
|
callee = "[UNDETERMINED]";
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
2023-02-01 15:38:20 +00:00
|
|
|
@Before(marker = BodyMarker.class, guard = IsDynamicTargetGuard.class)
|
2023-01-20 17:26:55 +00:00
|
|
|
static void beforeMethod(MethodStaticContext msc) {
|
|
|
|
// we can ignore here constructors and private methods since we know they must be invoked with "invokespecial"
|
2023-02-01 15:38:20 +00:00
|
|
|
// and static methods since they are called with "invokestatic" which performs static binding.
|
|
|
|
// Instrumenting the constructor of java.lang.Object would actually cause a segmentation fault of the JVM.
|
2023-01-20 17:26:55 +00:00
|
|
|
if (initialized) {
|
|
|
|
Profiler.registerCall(new CallInfo(opCode, index, caller, callee, msc.getUniqueInternalName()));
|
|
|
|
initialized = false;
|
|
|
|
}
|
2023-01-11 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
2023-01-20 17:26:55 +00:00
|
|
|
@Before(marker = BytecodeMarker.class, args = "invokestatic, invokespecial")
|
2023-01-11 14:17:18 +00:00
|
|
|
static void atStaticCallSite(final InstructionStaticContext isc,
|
|
|
|
final MethodStaticContext msc,
|
2023-01-20 17:26:55 +00:00
|
|
|
final InvocationStaticContext ivc) {
|
|
|
|
final String v = ivc.getInternalName().concat(ivc.getDescriptor());
|
|
|
|
Profiler.registerCall(new CallInfo(
|
2023-01-11 14:17:18 +00:00
|
|
|
isc.getOpcode(),
|
|
|
|
isc.getIndex(),
|
|
|
|
msc.thisMethodFullName().concat(msc.thisMethodDescriptor()),
|
2023-01-20 17:26:55 +00:00
|
|
|
v,
|
|
|
|
v
|
2023-01-11 14:17:18 +00:00
|
|
|
));
|
|
|
|
}
|
2023-01-02 09:46:59 +00:00
|
|
|
}
|