Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ public CompletableFuture<IBreakpoint> install() {
|| localClassPrepareRequest.equals(debugEvent.event.request())))
.subscribe(debugEvent -> {
ClassPrepareEvent event = (ClassPrepareEvent) debugEvent.event;
List<BreakpointRequest> newRequests = createBreakpointRequests(event.referenceType(),
lineNumber, hitCount);
List<BreakpointRequest> newRequests = createBreakpointRequests(event.referenceType(), lineNumber,
hitCount, false);
requests.addAll(newRequests);
if (!newRequests.isEmpty() && !future.isDone()) {
this.putProperty("verified", true);
Expand All @@ -144,8 +144,9 @@ public CompletableFuture<IBreakpoint> install() {
subscriptions.add(subscription);

List<ReferenceType> refTypes = vm.classesByName(className);
List<BreakpointRequest> newRequests = createBreakpointRequests(refTypes, lineNumber, hitCount);
List<BreakpointRequest> newRequests = createBreakpointRequests(refTypes, lineNumber, hitCount, true);
requests.addAll(newRequests);

if (!newRequests.isEmpty() && !future.isDone()) {
this.putProperty("verified", true);
future.complete(this);
Expand All @@ -167,30 +168,44 @@ private static List<Location> collectLocations(ReferenceType refType, int lineNu
return locations;
}

private static List<Location> collectLocations(List<ReferenceType> refTypes, int lineNumber) {
private static List<Location> collectLocations(List<ReferenceType> refTypes, int lineNumber, boolean includeNestedTypes) {
List<Location> locations = new ArrayList<>();
try {
refTypes.forEach(refType -> {
locations.addAll(collectLocations(refType, lineNumber));
locations.addAll(collectLocations(refType.nestedTypes(), lineNumber));
List<Location> newLocations = collectLocations(refType, lineNumber);
if (!newLocations.isEmpty()) {
locations.addAll(newLocations);
} else if (includeNestedTypes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the advice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean why here it is else if rather than if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the breakpoint located in the refType, no need to search the nested type.

// ReferenceType.nestedTypes() will invoke vm.allClasses() to list all loaded classes,
// should avoid using nestedTypes for performance.
for (ReferenceType nestedType : refType.nestedTypes()) {
List<Location> nestedLocations = collectLocations(nestedType, lineNumber);
if (!nestedLocations.isEmpty()) {
locations.addAll(nestedLocations);
break;
}
}
}
});
} catch (VMDisconnectedException ex) {
// collect locations operation may be executing while JVM is running, thus the VMDisconnectedException may be
// collect locations operation may be executing while JVM is terminating, thus the VMDisconnectedException may be
// possible, in case of VMDisconnectedException, this method will return an empty array which turns out a valid
// response in vscode, causing no error log in trace.
}

return locations;
}

private List<BreakpointRequest> createBreakpointRequests(ReferenceType refType, int lineNumber, int hitCount) {
private List<BreakpointRequest> createBreakpointRequests(ReferenceType refType, int lineNumber, int hitCount,
boolean includeNestedTypes) {
List<ReferenceType> refTypes = new ArrayList<>();
refTypes.add(refType);
return createBreakpointRequests(refTypes, lineNumber, hitCount);
return createBreakpointRequests(refTypes, lineNumber, hitCount, includeNestedTypes);
}

private List<BreakpointRequest> createBreakpointRequests(List<ReferenceType> refTypes, int lineNumber, int hitCount) {
List<Location> locations = collectLocations(refTypes, lineNumber);
private List<BreakpointRequest> createBreakpointRequests(List<ReferenceType> refTypes, int lineNumber,
int hitCount, boolean includeNestedTypes) {
List<Location> locations = collectLocations(refTypes, lineNumber, includeNestedTypes);

// find out the existing breakpoint locations
List<Location> existingLocations = new ArrayList<>(requests.size());
Expand All @@ -217,7 +232,7 @@ private List<BreakpointRequest> createBreakpointRequests(List<ReferenceType> ref
request.enable();
newRequests.add(request);
} catch (VMDisconnectedException ex) {
// enable breakpoint operation may be executing while JVM is running, thus the VMDisconnectedException may be
// enable breakpoint operation may be executing while JVM is terminating, thus the VMDisconnectedException may be
// possible, in case of VMDisconnectedException, this method will return an empty array which turns out a valid
// response in vscode, causing no error log in trace.
}
Expand Down