From a78c260dbf15ce3d5a5275eb223775762afb2dc9 Mon Sep 17 00:00:00 2001 From: tripparsugo Date: Wed, 4 Jan 2023 17:23:12 +0100 Subject: [PATCH] Too tired to write descriptive message --- DiSLProject2022/source.sh | 2 ++ .../src-profiler/ex2/IsNotTriviallyThreadGuard.java | 6 ++++-- .../src-profiler/ex2/IsTriviallyThreadGuard.java | 8 +++++--- DiSLProject2022/src-profiler/ex2/Profiler.java | 6 ++---- DiSLProject2022/src-profiler/ex3/Instrumentation.java | 3 +-- 5 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 DiSLProject2022/source.sh diff --git a/DiSLProject2022/source.sh b/DiSLProject2022/source.sh new file mode 100644 index 0000000..3594821 --- /dev/null +++ b/DiSLProject2022/source.sh @@ -0,0 +1,2 @@ +#!/bin/sh +export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home" \ No newline at end of file diff --git a/DiSLProject2022/src-profiler/ex2/IsNotTriviallyThreadGuard.java b/DiSLProject2022/src-profiler/ex2/IsNotTriviallyThreadGuard.java index df6bc7a..99a76a9 100644 --- a/DiSLProject2022/src-profiler/ex2/IsNotTriviallyThreadGuard.java +++ b/DiSLProject2022/src-profiler/ex2/IsNotTriviallyThreadGuard.java @@ -2,11 +2,13 @@ package ex2; import ch.usi.dag.disl.annotation.GuardMethod; import ch.usi.dag.disl.staticcontext.ClassStaticContext; +import ch.usi.dag.disl.staticcontext.MethodStaticContext; public class IsNotTriviallyThreadGuard { @GuardMethod - public static boolean isNotTriviallyThread(final ClassStaticContext csc) { - return !IsTriviallyThreadGuard.isThread(csc); + public static boolean isNotTriviallyThread(final ClassStaticContext csc, final MethodStaticContext msc) { + return !msc.isMethodStatic() && !IsTriviallyThreadGuard.isThread(csc, msc); } + } diff --git a/DiSLProject2022/src-profiler/ex2/IsTriviallyThreadGuard.java b/DiSLProject2022/src-profiler/ex2/IsTriviallyThreadGuard.java index 15c8d36..86df968 100644 --- a/DiSLProject2022/src-profiler/ex2/IsTriviallyThreadGuard.java +++ b/DiSLProject2022/src-profiler/ex2/IsTriviallyThreadGuard.java @@ -1,12 +1,14 @@ package ex2; import ch.usi.dag.disl.annotation.GuardMethod; +import ch.usi.dag.disl.dynamiccontext.DynamicContext; import ch.usi.dag.disl.staticcontext.ClassStaticContext; +import ch.usi.dag.disl.staticcontext.MethodStaticContext; public class IsTriviallyThreadGuard { @GuardMethod - public static boolean isThread(ClassStaticContext csc) { - return csc.getInternalName().equals("java/lang/Thread") || - csc.getSuperClassInternalName().equals("java/lang/Thread"); + public static boolean isThread(final ClassStaticContext csc, final MethodStaticContext msc) { + return !msc.isMethodStatic() && (csc.getInternalName().equals("java/lang/Thread") || + csc.getSuperClassInternalName().equals("java/lang/Thread")); } } diff --git a/DiSLProject2022/src-profiler/ex2/Profiler.java b/DiSLProject2022/src-profiler/ex2/Profiler.java index 2ffe95e..43fc668 100644 --- a/DiSLProject2022/src-profiler/ex2/Profiler.java +++ b/DiSLProject2022/src-profiler/ex2/Profiler.java @@ -2,14 +2,12 @@ package ex2; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.LongAdder; public final class Profiler { - // not concurrent on purpose, since the value of the map is computed with a pure function - // on the map key, and thus we don't care if the value is overwritten as a result of a - // race condition - private static final Map, Boolean> isThread = new HashMap<>(); + private static final Map, Boolean> isThread = new ConcurrentHashMap<>(); private static final LongAdder reads = new LongAdder(); diff --git a/DiSLProject2022/src-profiler/ex3/Instrumentation.java b/DiSLProject2022/src-profiler/ex3/Instrumentation.java index 8eabf9e..a9634d8 100644 --- a/DiSLProject2022/src-profiler/ex3/Instrumentation.java +++ b/DiSLProject2022/src-profiler/ex3/Instrumentation.java @@ -3,11 +3,10 @@ package ex3; import ch.usi.dag.disl.annotation.Before; import ch.usi.dag.disl.dynamiccontext.DynamicContext; import ch.usi.dag.disl.marker.BytecodeMarker; -import ch.usi.dag.disl.staticcontext.InstructionStaticContext; public class Instrumentation { @Before(marker = BytecodeMarker.class, args = "astore", scope = "ex3.MainThread.checkAccess") - static void printVariable(final InstructionStaticContext isc, final DynamicContext dc) { + static void printVariable(final DynamicContext dc) { if ("granted".equals(dc.getStackValue(0, Object.class))) { System.out.printf("Thread: %s\n", Thread.currentThread().getName()); }