this doesn't really make things faster, but I tried

This commit is contained in:
tripparsugo 2023-02-01 16:38:20 +01:00
parent ff6f86ae2a
commit a4568c06b5
7 changed files with 17 additions and 52 deletions

View File

@ -38,8 +38,7 @@ public class Instrumentation {
@Before(marker = BytecodeMarker.class, args = "invokedynamic")
static void atObjectRefCallSiteDynamic(final InstructionStaticContext isc,
final MethodStaticContext msc,
final InvocationStaticContext ivc) {
final MethodStaticContext msc) {
opCode = isc.getOpcode();
index = isc.getIndex();
caller = msc.thisMethodFullName().concat(msc.thisMethodDescriptor());
@ -47,11 +46,11 @@ public class Instrumentation {
initialized = true;
}
@Before(marker = BodyMarker.class, guard = IsNotConstructorOrPrivateMethod.class)
@Before(marker = BodyMarker.class, guard = IsDynamicTargetGuard.class)
static void beforeMethod(MethodStaticContext msc) {
// we can ignore here constructors and private methods since we know they must be invoked with "invokespecial"
// which performs static binding. Instrumenting the constructor of java.lang.Object would actually cause a
// segmentation fault of the JVM.
// and static methods since they are called with "invokestatic" which performs static binding.
// Instrumenting the constructor of java.lang.Object would actually cause a segmentation fault of the JVM.
if (initialized) {
Profiler.registerCall(new CallInfo(opCode, index, caller, callee, msc.getUniqueInternalName()));
initialized = false;

View File

@ -1,12 +1,11 @@
package ex11;
import ch.usi.dag.disl.annotation.GuardMethod;
import ch.usi.dag.disl.staticcontext.ClassStaticContext;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class IsNotConstructorOrPrivateMethod {
public class IsDynamicTargetGuard {
@GuardMethod
public static boolean guard(final ClassStaticContext csc, final MethodStaticContext msc) {
return !msc.isMethodConstructor() && !msc.isMethodPrivate();
public static boolean guard(final MethodStaticContext msc) {
return !msc.isMethodConstructor() && !msc.isMethodPrivate() && !msc.isMethodStatic();
}
}

View File

@ -21,8 +21,7 @@ public final class Profiler {
public static void countException(Throwable e) {
final String exceptionName = e.getClass().getName();
exceptionNameToCount.computeIfAbsent(exceptionName, k -> new LongAdder());
exceptionNameToCount.get(exceptionName).increment();
exceptionNameToCount.computeIfAbsent(exceptionName, k -> new LongAdder()).increment();
}

View File

@ -9,8 +9,8 @@ public final class Profiler {
static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.printf("Safe allocation: %d%n", safeAllocations.intValue());
System.out.printf("Unsafe allocation: %d%n", unsafeAllocation.intValue());
System.out.printf("Safe allocation: %d%n", safeAllocations.longValue());
System.out.printf("Unsafe allocation: %d%n", unsafeAllocation.longValue());
}));
}

View File

@ -2,8 +2,6 @@ package ex6;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.BasicBlockMarker;
import ch.usi.dag.disl.marker.BytecodeMarker;
import ch.usi.dag.disl.staticcontext.LoopStaticContext;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class Instrumentation {
@ -11,7 +9,7 @@ public class Instrumentation {
@Before(marker = BasicBlockMarker.class,
scope = "ex6.MainThread.*",
guard = IsFirstInLoopGuard.class)
static void handleLoopInstruction(final LoopStaticContext lsc, final MethodStaticContext msc) {
static void handleLoopInstruction(final MethodStaticContext msc) {
Profiler.countLoop(msc.thisMethodFullName());
}
}

View File

@ -0,0 +1,3 @@
package ex7;
public record MonitorEntry (int monitorHashCode, String name){}

View File

@ -1,51 +1,19 @@
package ex7;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.LongAdder;
public final class Profiler {
private static final class MonitorEntry {
private final int hashCode;
private final String name;
public MonitorEntry(int hashCode, String name) {
this.hashCode = hashCode;
this.name = name;
}
public int getHashCode() {
return hashCode;
}
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MonitorEntry that = (MonitorEntry) o;
return hashCode == that.hashCode && Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(hashCode, name);
}
}
private static final Map<MonitorEntry, LongAdder> monitorToAccessCount = new ConcurrentHashMap<>();
static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
for (final var entry : monitorToAccessCount.entrySet()) {
System.out.printf("%d - %s - #Locks: %d%n",
entry.getKey().getHashCode(),
entry.getKey().getName(),
entry.getKey().monitorHashCode(),
entry.getKey().name(),
entry.getValue().intValue()
);
}
@ -58,8 +26,7 @@ public final class Profiler {
public static void countMonitorAccess(final Object obj) {
final MonitorEntry monitorEntry = new MonitorEntry(obj.hashCode(), obj.getClass().getName());
monitorToAccessCount.computeIfAbsent(monitorEntry, k -> new LongAdder());
monitorToAccessCount.get(monitorEntry).increment();
monitorToAccessCount.computeIfAbsent(monitorEntry, k -> new LongAdder()).increment();
}