2023-01-02 09:46:59 +00:00
|
|
|
package ex8;
|
|
|
|
|
2023-01-11 11:02:10 +00:00
|
|
|
import ch.usi.dag.disl.annotation.After;
|
2023-01-09 07:01:15 +00:00
|
|
|
import ch.usi.dag.disl.annotation.Before;
|
2023-01-11 11:02:10 +00:00
|
|
|
import ch.usi.dag.disl.annotation.ThreadLocal;
|
|
|
|
import ch.usi.dag.disl.dynamiccontext.DynamicContext;
|
|
|
|
import ch.usi.dag.disl.marker.BodyMarker;
|
2023-01-09 07:01:15 +00:00
|
|
|
import ch.usi.dag.disl.marker.BytecodeMarker;
|
2023-01-11 11:02:10 +00:00
|
|
|
import ch.usi.dag.disl.staticcontext.InstructionStaticContext;
|
2023-01-09 07:01:15 +00:00
|
|
|
import org.objectweb.asm.Opcodes;
|
|
|
|
|
2023-01-02 09:46:59 +00:00
|
|
|
public class Instrumentation {
|
2023-01-09 07:01:15 +00:00
|
|
|
|
2023-01-11 11:02:10 +00:00
|
|
|
@ThreadLocal
|
|
|
|
private static long staticCount;
|
|
|
|
|
|
|
|
@ThreadLocal
|
|
|
|
private static long dynamicCount;
|
|
|
|
|
|
|
|
@ThreadLocal
|
|
|
|
private static long specialCount;
|
|
|
|
|
|
|
|
@ThreadLocal
|
|
|
|
private static long virtualCount;
|
|
|
|
|
|
|
|
@Before(marker = BytecodeMarker.class,
|
|
|
|
args = "invokestatic, invokespecial, invokevirtual, invokedynamic")
|
|
|
|
static void handleInvoke(final InstructionStaticContext isc) {
|
|
|
|
switch (isc.getOpcode()) {
|
|
|
|
case Opcodes.INVOKESTATIC -> staticCount++;
|
|
|
|
case Opcodes.INVOKEDYNAMIC -> dynamicCount++;
|
|
|
|
case Opcodes.INVOKESPECIAL -> specialCount++;
|
|
|
|
case Opcodes.INVOKEVIRTUAL -> virtualCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@After(marker = BodyMarker.class, scope = "void run()", guard = IsNonStaticGuard.class)
|
|
|
|
static void endThread(final DynamicContext dc) {
|
|
|
|
if (dc.getThis() instanceof Thread) {
|
|
|
|
System.out.printf("Thread: %20s - static: %6d - special: %6d - virtual: %6d - dynamic: %6d\n",
|
|
|
|
((Thread) dc.getThis()).getName(),
|
|
|
|
staticCount,
|
|
|
|
specialCount,
|
|
|
|
virtualCount,
|
|
|
|
dynamicCount);
|
2023-01-09 07:01:15 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-02 09:46:59 +00:00
|
|
|
}
|