Too tired to write descriptive message

This commit is contained in:
tripparsugo 2023-01-04 17:23:12 +01:00
parent 6f3012cf9e
commit a78c260dbf
5 changed files with 14 additions and 11 deletions

View file

@ -0,0 +1,2 @@
#!/bin/sh
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home"

View file

@ -2,11 +2,13 @@ package ex2;
import ch.usi.dag.disl.annotation.GuardMethod; import ch.usi.dag.disl.annotation.GuardMethod;
import ch.usi.dag.disl.staticcontext.ClassStaticContext; import ch.usi.dag.disl.staticcontext.ClassStaticContext;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class IsNotTriviallyThreadGuard { public class IsNotTriviallyThreadGuard {
@GuardMethod @GuardMethod
public static boolean isNotTriviallyThread(final ClassStaticContext csc) { public static boolean isNotTriviallyThread(final ClassStaticContext csc, final MethodStaticContext msc) {
return !IsTriviallyThreadGuard.isThread(csc); return !msc.isMethodStatic() && !IsTriviallyThreadGuard.isThread(csc, msc);
} }
} }

View file

@ -1,12 +1,14 @@
package ex2; package ex2;
import ch.usi.dag.disl.annotation.GuardMethod; 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.ClassStaticContext;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class IsTriviallyThreadGuard { public class IsTriviallyThreadGuard {
@GuardMethod @GuardMethod
public static boolean isThread(ClassStaticContext csc) { public static boolean isThread(final ClassStaticContext csc, final MethodStaticContext msc) {
return csc.getInternalName().equals("java/lang/Thread") || return !msc.isMethodStatic() && (csc.getInternalName().equals("java/lang/Thread") ||
csc.getSuperClassInternalName().equals("java/lang/Thread"); csc.getSuperClassInternalName().equals("java/lang/Thread"));
} }
} }

View file

@ -2,14 +2,12 @@ package ex2;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.atomic.LongAdder;
public final class Profiler { public final class Profiler {
// not concurrent on purpose, since the value of the map is computed with a pure function private static final Map<Class<?>, Boolean> isThread = new ConcurrentHashMap<>();
// 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<Class<?>, Boolean> isThread = new HashMap<>();
private static final LongAdder reads = new LongAdder(); private static final LongAdder reads = new LongAdder();

View file

@ -3,11 +3,10 @@ package ex3;
import ch.usi.dag.disl.annotation.Before; import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.dynamiccontext.DynamicContext; import ch.usi.dag.disl.dynamiccontext.DynamicContext;
import ch.usi.dag.disl.marker.BytecodeMarker; import ch.usi.dag.disl.marker.BytecodeMarker;
import ch.usi.dag.disl.staticcontext.InstructionStaticContext;
public class Instrumentation { public class Instrumentation {
@Before(marker = BytecodeMarker.class, args = "astore", scope = "ex3.MainThread.checkAccess") @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))) { if ("granted".equals(dc.getStackValue(0, Object.class))) {
System.out.printf("Thread: %s\n", Thread.currentThread().getName()); System.out.printf("Thread: %s\n", Thread.currentThread().getName());
} }