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; 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() )); } }