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,
|
|
|
|
final MethodStaticContext msc,
|
|
|
|
final InvocationStaticContext ivc) {
|
|
|
|
opCode = isc.getOpcode();
|
|
|
|
index = isc.getIndex();
|
|
|
|
caller = msc.thisMethodFullName().concat(msc.thisMethodDescriptor());
|
|
|
|
callee = "[UNDETERMINED]";
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Before(marker = BodyMarker.class, guard = IsNotConstructorOrPrivateMethod.class)
|
|
|
|
static void beforeMethod(MethodStaticContext msc) {
|
|
|
|
// we can ignore here constructors and private methods since we know they must be invoked with "invokespecial"
|
|
|
|
// which performs static binding. Instrumenting the constructor of java.lang.Object would actually cause a
|
|
|
|
// segmentation fault of the JVM.
|
|
|
|
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
|
|
|
}
|