[debugger] avoid scanning all classes in vm for nested sub classes

GitOrigin-RevId: b2d68e635d37947226c0e53b5a7c4ecd777a8f9a
This commit is contained in:
Egor Ushakov
2024-10-04 10:48:22 +00:00
committed by intellij-monorepo-bot
parent 080e021501
commit e45924a30e
@@ -15,6 +15,7 @@ import com.intellij.debugger.impl.attach.SAJDWPRemoteConnection;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.jdi.ReferenceTypeImpl;
import com.jetbrains.jdi.ThreadReferenceImpl;
import com.sun.jdi.*;
import com.sun.jdi.request.EventRequestManager;
@@ -111,9 +112,10 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy {
if (!candidates.isEmpty()) {
// keep only direct nested types
// do not traverse all classes in vm, only the candidates list
final Set<ReferenceType> nested2 = new HashSet<>();
for (final ReferenceType candidate : candidates) {
nested2.addAll(nestedTypes(candidate));
addNestedTypes(candidate, candidates, nested2);
}
candidates.removeAll(nested2);
}
@@ -128,6 +130,24 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy {
return nestedTypes;
}
/**
* Check {@link ReferenceTypeImpl#nestedTypes()}
*/
private static void addNestedTypes(ReferenceType base, Collection<ReferenceType> classes, Set<ReferenceType> nested) {
String baseName = base.name();
int baseLength = baseName.length();
classes.forEach(type -> {
String name = type.name();
int length = name.length();
if (length > baseLength && name.startsWith(baseName)) {
char c = name.charAt(baseLength);
if (c == '$' || c == '#') {
nested.add(type);
}
}
});
}
@Override
public List<ReferenceType> allClasses() {
List<ReferenceType> allClasses = myAllClasses;