this doesn't really make things faster, but I tried
This commit is contained in:
parent
ff6f86ae2a
commit
a4568c06b5
7 changed files with 17 additions and 52 deletions
|
@ -38,8 +38,7 @@ public class Instrumentation {
|
||||||
|
|
||||||
@Before(marker = BytecodeMarker.class, args = "invokedynamic")
|
@Before(marker = BytecodeMarker.class, args = "invokedynamic")
|
||||||
static void atObjectRefCallSiteDynamic(final InstructionStaticContext isc,
|
static void atObjectRefCallSiteDynamic(final InstructionStaticContext isc,
|
||||||
final MethodStaticContext msc,
|
final MethodStaticContext msc) {
|
||||||
final InvocationStaticContext ivc) {
|
|
||||||
opCode = isc.getOpcode();
|
opCode = isc.getOpcode();
|
||||||
index = isc.getIndex();
|
index = isc.getIndex();
|
||||||
caller = msc.thisMethodFullName().concat(msc.thisMethodDescriptor());
|
caller = msc.thisMethodFullName().concat(msc.thisMethodDescriptor());
|
||||||
|
@ -47,11 +46,11 @@ public class Instrumentation {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before(marker = BodyMarker.class, guard = IsNotConstructorOrPrivateMethod.class)
|
@Before(marker = BodyMarker.class, guard = IsDynamicTargetGuard.class)
|
||||||
static void beforeMethod(MethodStaticContext msc) {
|
static void beforeMethod(MethodStaticContext msc) {
|
||||||
// we can ignore here constructors and private methods since we know they must be invoked with "invokespecial"
|
// 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
|
// and static methods since they are called with "invokestatic" which performs static binding.
|
||||||
// segmentation fault of the JVM.
|
// Instrumenting the constructor of java.lang.Object would actually cause a segmentation fault of the JVM.
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
Profiler.registerCall(new CallInfo(opCode, index, caller, callee, msc.getUniqueInternalName()));
|
Profiler.registerCall(new CallInfo(opCode, index, caller, callee, msc.getUniqueInternalName()));
|
||||||
initialized = false;
|
initialized = false;
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package ex11;
|
package ex11;
|
||||||
|
|
||||||
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.MethodStaticContext;
|
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
||||||
|
|
||||||
public class IsNotConstructorOrPrivateMethod {
|
public class IsDynamicTargetGuard {
|
||||||
@GuardMethod
|
@GuardMethod
|
||||||
public static boolean guard(final ClassStaticContext csc, final MethodStaticContext msc) {
|
public static boolean guard(final MethodStaticContext msc) {
|
||||||
return !msc.isMethodConstructor() && !msc.isMethodPrivate();
|
return !msc.isMethodConstructor() && !msc.isMethodPrivate() && !msc.isMethodStatic();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,8 +21,7 @@ public final class Profiler {
|
||||||
|
|
||||||
public static void countException(Throwable e) {
|
public static void countException(Throwable e) {
|
||||||
final String exceptionName = e.getClass().getName();
|
final String exceptionName = e.getClass().getName();
|
||||||
exceptionNameToCount.computeIfAbsent(exceptionName, k -> new LongAdder());
|
exceptionNameToCount.computeIfAbsent(exceptionName, k -> new LongAdder()).increment();
|
||||||
exceptionNameToCount.get(exceptionName).increment();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ public final class Profiler {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
System.out.printf("Safe allocation: %d%n", safeAllocations.intValue());
|
System.out.printf("Safe allocation: %d%n", safeAllocations.longValue());
|
||||||
System.out.printf("Unsafe allocation: %d%n", unsafeAllocation.intValue());
|
System.out.printf("Unsafe allocation: %d%n", unsafeAllocation.longValue());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@ package ex6;
|
||||||
|
|
||||||
import ch.usi.dag.disl.annotation.Before;
|
import ch.usi.dag.disl.annotation.Before;
|
||||||
import ch.usi.dag.disl.marker.BasicBlockMarker;
|
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;
|
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
||||||
|
|
||||||
public class Instrumentation {
|
public class Instrumentation {
|
||||||
|
@ -11,7 +9,7 @@ public class Instrumentation {
|
||||||
@Before(marker = BasicBlockMarker.class,
|
@Before(marker = BasicBlockMarker.class,
|
||||||
scope = "ex6.MainThread.*",
|
scope = "ex6.MainThread.*",
|
||||||
guard = IsFirstInLoopGuard.class)
|
guard = IsFirstInLoopGuard.class)
|
||||||
static void handleLoopInstruction(final LoopStaticContext lsc, final MethodStaticContext msc) {
|
static void handleLoopInstruction(final MethodStaticContext msc) {
|
||||||
Profiler.countLoop(msc.thisMethodFullName());
|
Profiler.countLoop(msc.thisMethodFullName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
DiSLProject2022/src-profiler/ex7/MonitorEntry.java
Normal file
3
DiSLProject2022/src-profiler/ex7/MonitorEntry.java
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package ex7;
|
||||||
|
|
||||||
|
public record MonitorEntry (int monitorHashCode, String name){}
|
|
@ -1,51 +1,19 @@
|
||||||
package ex7;
|
package ex7;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
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 {
|
||||||
|
|
||||||
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<>();
|
private static final Map<MonitorEntry, LongAdder> monitorToAccessCount = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
for (final var entry : monitorToAccessCount.entrySet()) {
|
for (final var entry : monitorToAccessCount.entrySet()) {
|
||||||
System.out.printf("%d - %s - #Locks: %d%n",
|
System.out.printf("%d - %s - #Locks: %d%n",
|
||||||
entry.getKey().getHashCode(),
|
entry.getKey().monitorHashCode(),
|
||||||
entry.getKey().getName(),
|
entry.getKey().name(),
|
||||||
entry.getValue().intValue()
|
entry.getValue().intValue()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -58,8 +26,7 @@ public final class Profiler {
|
||||||
|
|
||||||
public static void countMonitorAccess(final Object obj) {
|
public static void countMonitorAccess(final Object obj) {
|
||||||
final MonitorEntry monitorEntry = new MonitorEntry(obj.hashCode(), obj.getClass().getName());
|
final MonitorEntry monitorEntry = new MonitorEntry(obj.hashCode(), obj.getClass().getName());
|
||||||
monitorToAccessCount.computeIfAbsent(monitorEntry, k -> new LongAdder());
|
monitorToAccessCount.computeIfAbsent(monitorEntry, k -> new LongAdder()).increment();
|
||||||
monitorToAccessCount.get(monitorEntry).increment();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue