Skip to content

Commit

Permalink
Pass this by reference to background thread (#141)
Browse files Browse the repository at this point in the history
* pass this by reference
  • Loading branch information
0xaa4eb committed Jul 7, 2024
1 parent 1df9f3d commit a57c4e0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.ulyp.core.mem.DirectBufMemPageAllocator;
import com.ulyp.core.mem.MemPageAllocator;
import com.ulyp.core.recorders.QueuedIdentityObject;
import com.ulyp.core.util.SystemPropertyUtil;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -24,7 +23,6 @@ public class RecordingEventProcessor {
private RecordingMetadata recordingMetadata;
private CallRecordBuffer buffer;
private MemPageAllocator pageAllocator;
private QueuedIdentityObject cachedQueuedIdentityCallee = new QueuedIdentityObject();

public RecordingEventProcessor(TypeResolver typeResolver, AgentDataWriter agentDataWriter) {
this.typeResolver = typeResolver;
Expand All @@ -41,15 +39,13 @@ void onEnterCallRecord(int recordingId, EnterMethodRecordingEvent enterRecord) {
if (buffer == null) {
buffer = new CallRecordBuffer(recordingId, pageAllocator);
}
cachedQueuedIdentityCallee.setTypeId(enterRecord.getCalleeTypeId());
cachedQueuedIdentityCallee.setIdentityHashCode(enterRecord.getCalleeIdentityHashCode());

long nanoTime = (enterRecord instanceof TimestampedEnterMethodRecordingEvent) ? ((TimestampedEnterMethodRecordingEvent) enterRecord).getNanoTime() : -1;
buffer.recordMethodEnter(
enterRecord.getCallId(),
typeResolver,
/* TODO remove after advice split */methodRepository.get(enterRecord.getMethodId()).getId(),
cachedQueuedIdentityCallee,
enterRecord.getCallee(),
enterRecord.getArgs(),
nanoTime
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,15 @@ public void enqueueRecordingFinished(int recordingId, long recordingFinishedTime
}

public void enqueueMethodEnter(int recordingId, int callId, int methodId, @Nullable Object callee, Object[] args) {
int calleeTypeId;
int calleeIdentityHashCode;
if (callee != null) {
calleeTypeId = typeResolver.get(callee).getId();
calleeIdentityHashCode = System.identityHashCode(callee);
} else {
calleeTypeId = -1;
calleeIdentityHashCode = 0;
}

Object[] argsPrepared = prepareArgs(args);

appendEvent(recordingId, new EnterMethodRecordingEvent(callId, methodId, calleeTypeId, calleeIdentityHashCode, argsPrepared));
appendEvent(recordingId, new EnterMethodRecordingEvent(callId, methodId, callee, argsPrepared));
}

public void enqueueMethodEnter(int recordingId, int callId, int methodId, @Nullable Object callee, Object[] args, long nanoTime) {
int calleeTypeId;
int calleeIdentityHashCode;
if (callee != null) {
calleeTypeId = typeResolver.get(callee).getId();
calleeIdentityHashCode = System.identityHashCode(callee);
} else {
calleeTypeId = -1;
calleeIdentityHashCode = 0;
}
Object[] argsPrepared = prepareArgs(args);

appendEvent(recordingId, new TimestampedEnterMethodRecordingEvent(
callId,
methodId,
calleeTypeId,
calleeIdentityHashCode,
argsPrepared,
nanoTime));
appendEvent(recordingId, new TimestampedEnterMethodRecordingEvent(callId, methodId, callee, argsPrepared, nanoTime));
}

public void enqueueMethodExit(int recordingId, int callId, Object returnValue, boolean thrown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ public class EnterMethodRecordingEvent implements RecordingEvent {

protected final int callId;
protected final int methodId;
protected final int calleeTypeId;
protected final int calleeIdentityHashCode;
protected final Object callee;
protected final Object[] args;

public EnterMethodRecordingEvent(int callId, int methodId, int calleeTypeId, int calleeIdentityHashCode, Object[] args) {
public EnterMethodRecordingEvent(int callId, int methodId, Object callee, Object[] args) {
this.callId = callId;
this.methodId = methodId;
this.calleeTypeId = calleeTypeId;
this.calleeIdentityHashCode = calleeIdentityHashCode;
this.callee = callee;
this.args = args;
}

Expand All @@ -26,8 +24,7 @@ public String toString() {
return "EnterRecordQueueEvent{" +
"callId=" + callId +
", methodId=" + methodId +
", calleeTypeId=" + calleeTypeId +
", calleeIdentityHashCode=" + calleeIdentityHashCode +
", callee=" + callee +
", args=" + Arrays.toString(args) +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class TimestampedEnterMethodRecordingEvent extends EnterMethodRecordingEv

private final long nanoTime;

public TimestampedEnterMethodRecordingEvent(int callId, int methodId, int calleeTypeId, int calleeIdentityHashCode, Object[] args, long nanoTime) {
super(callId, methodId, calleeTypeId, calleeIdentityHashCode, args);
public TimestampedEnterMethodRecordingEvent(int callId, int methodId, Object callee, Object[] args, long nanoTime) {
super(callId, methodId, callee, args);
this.nanoTime = nanoTime;
}

Expand All @@ -19,8 +19,7 @@ public String toString() {
return "EnterRecordQueueEvent{" +
"callId=" + callId +
", methodId=" + methodId +
", calleeTypeId=" + calleeTypeId +
", calleeIdentityHashCode=" + calleeIdentityHashCode +
", callee=" + callee +
", args=" + Arrays.toString(args) +
", nanoTime=" + nanoTime +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public class BenchmarkConstants {

public static final String ENABLE_AGENT_SYSTEM_PROP = "-javaagent:../ulyp-agent/build/libs/ulyp-agent-0.3.1-SNAPSHOT.jar";
public static final int FORKS = 1;
public static final int FORKS = 5;
}

0 comments on commit a57c4e0

Please sign in to comment.