From 474c6eddb68a222d7ec3a6195527cda1c73d7e3c Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Mon, 9 Jan 2023 18:25:05 +0100 Subject: [PATCH] correction on ex9 --- .../src-profiler/ex9/Instrumentation.java | 27 +++---------------- ...tConstructorOrStaticInitializerGuard.java} | 4 +-- 2 files changed, 6 insertions(+), 25 deletions(-) rename DiSLProject2022/src-profiler/ex9/{IsNotConstructorOrStaticGuard.java => IsNotConstructorOrStaticInitializerGuard.java} (63%) diff --git a/DiSLProject2022/src-profiler/ex9/Instrumentation.java b/DiSLProject2022/src-profiler/ex9/Instrumentation.java index 86fd27d..9abec78 100644 --- a/DiSLProject2022/src-profiler/ex9/Instrumentation.java +++ b/DiSLProject2022/src-profiler/ex9/Instrumentation.java @@ -2,34 +2,15 @@ package ex9; import ch.usi.dag.disl.annotation.Before; import ch.usi.dag.disl.marker.BodyMarker; -import ch.usi.dag.disl.marker.BytecodeMarker; import ch.usi.dag.disl.staticcontext.InvocationStaticContext; import ch.usi.dag.disl.staticcontext.MethodStaticContext; public class Instrumentation { - @Before(marker = BytecodeMarker.class, - args = "invokevirtual, invokespecial, invokeinterface, invokestatic", - guard = IsNotConstructorOrStaticGuard.class, - scope = "ex9.MainThread.*") - static void logCall(final InvocationStaticContext isc) { - // this will log calls for all types of methods (including constructors and static initializers). - // However, constructors and static initializers will not be instrumented thanks to the included guard. - // Should calls to constructors and static methods not be instrumented, add the following line: - // - // if (isc.isConstructor()) return; - // - // and remove `invokestatic` from the BytecodeMarker argument list - - Profiler.logCall(Thread.currentThread(), isc.getInternalName()); - } - @Before(marker = BodyMarker.class, - guard = IsNotConstructorOrStaticGuard.class, - scope = "ex9.MainThread.run") - static void logThreadStart(final MethodStaticContext msc) { - // We separately instrument the Thread.run() method as there is no obvious way to instrument the caller of - // Thread.run(). Hence, we log the call at method start. - Profiler.logCall(Thread.currentThread(), msc.thisMethodFullName()); + guard = IsNotConstructorOrStaticInitializerGuard.class, + scope = "ex9.MainThread.*") + static void logCall(final MethodStaticContext isc) { + Profiler.logCall(Thread.currentThread(), isc.thisMethodFullName()); } } diff --git a/DiSLProject2022/src-profiler/ex9/IsNotConstructorOrStaticGuard.java b/DiSLProject2022/src-profiler/ex9/IsNotConstructorOrStaticInitializerGuard.java similarity index 63% rename from DiSLProject2022/src-profiler/ex9/IsNotConstructorOrStaticGuard.java rename to DiSLProject2022/src-profiler/ex9/IsNotConstructorOrStaticInitializerGuard.java index 18b1808..83749e1 100644 --- a/DiSLProject2022/src-profiler/ex9/IsNotConstructorOrStaticGuard.java +++ b/DiSLProject2022/src-profiler/ex9/IsNotConstructorOrStaticInitializerGuard.java @@ -3,9 +3,9 @@ package ex9; import ch.usi.dag.disl.annotation.GuardMethod; import ch.usi.dag.disl.staticcontext.MethodStaticContext; -public class IsNotConstructorOrStaticGuard { +public class IsNotConstructorOrStaticInitializerGuard { @GuardMethod public static boolean isNotConstructorOrStatic(final MethodStaticContext msc) { - return !msc.isMethodStatic() && !msc.isMethodConstructor(); + return !msc.isMethodInitializer() && !msc.isMethodConstructor(); } }