From e45924a30e7d019ec251a86be768af90cf58176f Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Tue, 1 Oct 2024 20:02:28 +0200 Subject: [PATCH] [debugger] avoid scanning all classes in vm for nested sub classes GitOrigin-RevId: b2d68e635d37947226c0e53b5a7c4ecd777a8f9a --- .../debugger/jdi/VirtualMachineProxyImpl.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java index 4246648c016a..e8a5f81a0fec 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java @@ -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 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 classes, Set 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 allClasses() { List allClasses = myAllClasses;