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

47 lines
2 KiB
Java
Raw Normal View History

2023-01-02 09:46:59 +00:00
package ex11;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.dynamiccontext.DynamicContext;
import ch.usi.dag.disl.guardcontext.ReflectionStaticContext;
import ch.usi.dag.disl.marker.BytecodeMarker;
import ch.usi.dag.disl.staticcontext.InstructionStaticContext;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
2023-01-02 09:46:59 +00:00
public class Instrumentation {
@Before(marker = BytecodeMarker.class, args = "invokevirtual, invokespecial, invokeinterface", guard = TemporaryGuard.class)
static void atObjectRefCallSite(final InstructionStaticContext isc,
final MethodStaticContext msc,
final ArgumentLengthStaticContext ivc,
final DynamicContext dc) {
final Object objectRef = dc.getStackValue(ivc.getArgumentLength(), Object.class);
final String callTarget = objectRef.getClass().getName().replace('.', '/')
.concat(".")
.concat(ivc.getName());
// TODO: call target signature (handle covariant return types)
Profiler.registerCall(new Profiler.CallInfo(
isc.getOpcode(),
isc.getIndex(),
msc.thisMethodFullName().concat(msc.thisMethodDescriptor()),
ivc.getInternalNameWithDescriptor(),
callTarget
));
}
@Before(marker = BytecodeMarker.class, args = "invokestatic", guard = TemporaryGuard.class)
static void atStaticCallSite(final InstructionStaticContext isc,
final MethodStaticContext msc,
final ArgumentLengthStaticContext ivc) {
Profiler.registerCall(new Profiler.CallInfo(
isc.getOpcode(),
isc.getIndex(),
msc.thisMethodFullName().concat(msc.thisMethodDescriptor()),
ivc.getInternalNameWithDescriptor(),
ivc.getInternalNameWithDescriptor()
));
}
2023-01-02 09:46:59 +00:00
}