This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
AJP/DiSLProject2022/src-profiler/ex11/Instrumentation.java

75 lines
2.9 KiB
Java
Raw Normal View History

2023-01-02 09:46:59 +00:00
package ex11;
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;
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;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
2023-01-02 09:46:59 +00:00
public class Instrumentation {
2023-01-20 17:26:55 +00:00
@ThreadLocal
private static int opCode;
2023-01-20 17:26:55 +00:00
@ThreadLocal
private static int index;
2023-01-20 17:26:55 +00:00
@ThreadLocal
private static String callee;
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-20 17:26:55 +00:00
@Before(marker = BytecodeMarker.class, args = "invokestatic, invokespecial")
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(
isc.getOpcode(),
isc.getIndex(),
msc.thisMethodFullName().concat(msc.thisMethodDescriptor()),
2023-01-20 17:26:55 +00:00
v,
v
));
}
2023-01-02 09:46:59 +00:00
}