Skip to content

Commit

Permalink
rename from ThreadJob to InvokeJob to ease readability
Browse files Browse the repository at this point in the history
  • Loading branch information
javeleon committed Oct 28, 2024
1 parent 85ef98c commit ebd01c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public final class DebuggerController implements ContextsListener {
private final Map<Object, SimpleLock> suspendLocks = Collections.synchronizedMap(new HashMap<>());
private final Map<Object, SuspendedInfo> suspendedInfos = Collections.synchronizedMap(new HashMap<>());
private final Map<Object, SteppingInfo> commandRequestIds = new HashMap<>();
private final Map<Object, ThreadJob<?>> threadJobs = new HashMap<>();
private final Map<Object, InvokeJob<?>> invokeJobs = new HashMap<>();
private final Map<Object, FieldBreakpointEvent> fieldBreakpointExpected = new HashMap<>();
private final Map<Object, MethodBreakpointEvent> methodBreakpointExpected = new HashMap<>();
private final Map<Breakpoint, BreakpointInfo> breakpointInfos = new HashMap<>();
Expand Down Expand Up @@ -698,9 +698,9 @@ private void lockThread(Object thread, boolean forceSuspend, List<Callable<Void>
// we have the actual suspension status and suspended information
threadSuspension.removeHardSuspendedThread(thread);
fine(() -> "lock.wait() for thread: " + getThreadName(thread));
// Having the thread lock, we can check if a thread job was posted outside of
// Having the thread lock, we can check if an invoke job was posted outside of
// locking, and if so, we postpone blocking the thread until next time around.
if (!threadJobs.containsKey(thread)) {
if (!invokeJobs.containsKey(thread)) {
lock.wait();
}
}
Expand All @@ -709,22 +709,22 @@ private void lockThread(Object thread, boolean forceSuspend, List<Callable<Void>
// make sure the interrupted flag is set though
Thread.currentThread().interrupt();
}
checkThreadJobsAndRun(thread);
checkInvokeJobsAndRun(thread);
}
fine(() -> "lock wakeup for thread: " + getThreadName(thread));
}

private void checkThreadJobsAndRun(Object thread) {
if (threadJobs.containsKey(thread)) {
ThreadJob<?> job = threadJobs.remove(thread);
private void checkInvokeJobsAndRun(Object thread) {
if (invokeJobs.containsKey(thread)) {
InvokeJob<?> job = invokeJobs.remove(thread);
job.runJob(this);
}
}

public void postJobForThread(ThreadJob<?> job) {
public void postInvokeJobForThread(InvokeJob<?> job) {
SimpleLock lock = getSuspendLock(job.getThread());
synchronized (lock) {
threadJobs.put(job.getThread(), job);
invokeJobs.put(job.getThread(), job);
lock.notifyAll();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import java.util.concurrent.Callable;

public final class ThreadJob<T> {
public final class InvokeJob<T> {

private final Object jobLock = new Object();
private final Object thread;
Expand All @@ -33,11 +33,11 @@ public final class ThreadJob<T> {
private boolean resultAvailable;
private JobResult<T> result;

public ThreadJob(Object guestThread, Callable<T> task) {
public InvokeJob(Object guestThread, Callable<T> task) {
this(guestThread, task, SuspendStrategy.EVENT_THREAD);
}

public ThreadJob(Object guestThread, Callable<T> task, byte suspensionStrategy) {
public InvokeJob(Object guestThread, Callable<T> task, byte suspensionStrategy) {
this.thread = guestThread;
this.callable = task;
this.suspensionStrategy = suspensionStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,8 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
try {
// we have to call the method in the correct thread, so post a
// Callable to the controller and wait for the result to appear
ThreadJob<Object> job = new ThreadJob<>(thread, () -> method.invokeMethodStatic(args), suspensionStrategy);
controller.postJobForThread(job);
InvokeJob<Object> job = new InvokeJob<>(thread, () -> method.invokeMethodStatic(args), suspensionStrategy);
controller.postInvokeJobForThread(job);

// invocation of a method can cause events with possible thread suspension
// to happen, e.g. class prepare events for newly loaded classes
Expand All @@ -1175,8 +1175,8 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
public void run() {
CommandResult commandResult = new CommandResult(reply);
try {
ThreadJob<?>.JobResult<?> result = job.getResult();
writeMethodResult(reply, context, result, thread, controller);
InvokeJob<?>.JobResult<?> result = job.getResult();
writeMethodResult(reply, context, result);
} catch (Throwable t) {
reply.errorCode(ErrorCodes.INTERNAL);
controller.severe(INVOKE_METHOD.class.getName() + ".createReply", t);
Expand Down Expand Up @@ -1246,15 +1246,15 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
try {
// we have to call the constructor in the correct thread, so post a
// Callable to the controller and wait for the result to appear
ThreadJob<?> job = new ThreadJob<>(thread, () -> {
InvokeJob<?> job = new InvokeJob<>(thread, () -> {
args[0] = context.allocateInstance(klass);
method.invokeMethodSpecial(args);
return args[0];
}, suspensionStrategy);
controller.postJobForThread(job);
ThreadJob<?>.JobResult<?> result = job.getResult();
controller.postInvokeJobForThread(job);
InvokeJob<?>.JobResult<?> result = job.getResult();

writeMethodResult(reply, context, result, thread, controller);
writeMethodResult(reply, context, result);
} catch (Throwable t) {
throw new RuntimeException("not able to invoke static method through jdwp", t);
}
Expand Down Expand Up @@ -1350,8 +1350,8 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
try {
// we have to call the method in the correct thread, so post a
// Callable to the controller and wait for the result to appear
ThreadJob<Object> job = new ThreadJob<>(thread, () -> method.invokeMethodStatic(args), suspensionStrategy);
controller.postJobForThread(job);
InvokeJob<Object> job = new InvokeJob<>(thread, () -> method.invokeMethodStatic(args), suspensionStrategy);
controller.postInvokeJobForThread(job);
// invocation of a method can cause events with possible thread suspension
// to happen, e.g. class prepare events for newly loaded classes
// to avoid blocking here, we fire up a new thread that will post
Expand All @@ -1361,8 +1361,8 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
public void run() {
CommandResult commandResult = new CommandResult(reply);
try {
ThreadJob<?>.JobResult<?> result = job.getResult();
writeMethodResult(reply, context, result, thread, controller);
InvokeJob<?>.JobResult<?> result = job.getResult();
writeMethodResult(reply, context, result);
} catch (Throwable t) {
reply.errorCode(ErrorCodes.INTERNAL);
controller.severe(INVOKE_METHOD.class.getName() + "." + "createReply", t);
Expand Down Expand Up @@ -1807,7 +1807,7 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
try {
// we have to call the method in the correct thread, so post a
// Callable to the controller and wait for the result to appear
ThreadJob<Object> job = new ThreadJob<>(thread, () -> {
InvokeJob<Object> job = new InvokeJob<>(thread, () -> {
if (invokeNonvirtual) {
return method.invokeMethodNonVirtual(args);
} else if (Modifier.isPrivate(method.getModifiers())) {
Expand All @@ -1818,7 +1818,7 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
return method.invokeMethodVirtual(args);
}
}, suspensionStrategy);
controller.postJobForThread(job);
controller.postInvokeJobForThread(job);
// invocation of a method can cause events with possible thread suspension
// to happen, e.g. class prepare events for newly loaded classes
// to avoid blocking here, we fire up a new thread that will post
Expand All @@ -1828,8 +1828,8 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
public void run() {
CommandResult commandResult = new CommandResult(reply);
try {
ThreadJob<?>.JobResult<?> result = job.getResult();
writeMethodResult(reply, context, result, thread, controller);
InvokeJob<?>.JobResult<?> result = job.getResult();
writeMethodResult(reply, context, result);
} catch (Throwable t) {
reply.errorCode(ErrorCodes.INTERNAL);
controller.severe(INVOKE_METHOD.class.getName() + "." + "createReply", t);
Expand Down Expand Up @@ -2393,11 +2393,11 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
}

// make sure owned monitors taken in frame are exited
ThreadJob<Void> job = new ThreadJob<>(thread, () -> {
InvokeJob<Void> job = new InvokeJob<>(thread, () -> {
controller.getContext().clearFrameMonitors(topFrame);
return null;
});
controller.postJobForThread(job);
controller.postInvokeJobForThread(job);
// don't return here before job completed
job.getResult();

Expand Down Expand Up @@ -3042,7 +3042,7 @@ public static void writeValue(byte tag, Object value, PacketStream reply, boolea
}
}

private static void writeMethodResult(PacketStream reply, JDWPContext context, ThreadJob<?>.JobResult<?> result, Object thread, DebuggerController controller) {
private static void writeMethodResult(PacketStream reply, JDWPContext context, InvokeJob<?>.JobResult<?> result) {
if (result.getException() != null) {
reply.writeByte(TagConstants.OBJECT);
reply.writeLong(0);
Expand Down

0 comments on commit ebd01c6

Please sign in to comment.