Skip to content

Commit 7f82f37

Browse files
authored
Add HCR mechanisms. (microsoft#130)
* Add HCR mechanisms. * Update from code review. * Fix access level
1 parent d98984d commit 7f82f37

File tree

3 files changed

+427
-37
lines changed

3 files changed

+427
-37
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/IHotCodeReplaceProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
package com.microsoft.java.debug.core.adapter;
1313

1414
import java.util.List;
15-
import java.util.concurrent.CompletableFuture;
15+
import java.util.function.Consumer;
1616

1717
public interface IHotCodeReplaceProvider extends IProvider {
18-
CompletableFuture<List<String>> redefineClasses();
18+
void onClassRedefined(Consumer<List<String>> consumer);
1919
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,25 @@ public class SetBreakpointsRequestHandler implements IDebugRequestHandler {
4545

4646
private BreakpointManager manager = new BreakpointManager();
4747

48+
private boolean isHcrInitialized = false;
49+
4850
@Override
4951
public List<Command> getTargetCommands() {
5052
return Arrays.asList(Command.SETBREAKPOINTS);
5153
}
5254

5355
@Override
5456
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
57+
// TODO: This part logic should be part of post launching handler.
58+
// Add post launch logic and move the reinstall breakpoints logic there.
59+
if (!isHcrInitialized) {
60+
IHotCodeReplaceProvider hcrProvider = context.getProvider(IHotCodeReplaceProvider.class);
61+
hcrProvider.onClassRedefined((typenames) -> {
62+
this.reinstallBreakpoints(context, typenames);
63+
});
64+
isHcrInitialized = true;
65+
}
66+
5567
if (context.getDebugSession() == null) {
5668
return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Empty debug session.");
5769
}
@@ -85,11 +97,6 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
8597
String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path));
8698
}
8799

88-
if (bpArguments.sourceModified) {
89-
IHotCodeReplaceProvider hcrProvider = context.getProvider(IHotCodeReplaceProvider.class);
90-
hcrProvider.redefineClasses().thenAcceptAsync((List<String> result) -> reinstallBreakpoints(context, result));
91-
}
92-
93100
try {
94101
List<Types.Breakpoint> res = new ArrayList<>();
95102
IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context);

0 commit comments

Comments
 (0)