From 8be73ff432a2b843179adf4b8259ba548c04e422 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Thu, 26 Sep 2019 15:31:56 +0300 Subject: [PATCH] preload classes info GitOrigin-RevId: 2662e1310fb805811635476b097ef1bc26afa608 --- .../debugger/jdi/VirtualMachineProxyImpl.java | 52 ++++++++++++++++++- .../util/resources/misc/registry.properties | 1 + 2 files changed, 52 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 64e8cc32f414..45b9ab0d37ff 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. /* * @author Eugene Zhuravlev @@ -12,9 +12,12 @@ import com.intellij.debugger.engine.DebuggerManagerThreadImpl; import com.intellij.debugger.engine.DebuggerUtils; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.jdi.VirtualMachineProxy; +import com.intellij.debugger.impl.DebuggerUtilsImpl; +import com.intellij.debugger.impl.PrioritizedTask; import com.intellij.debugger.impl.attach.SAJDWPRemoteConnection; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.ThrowableComputable; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ReflectionUtil; import com.intellij.util.ThreeState; @@ -713,6 +716,10 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy { } //myAllThreadsDirty = true; myTimeStamp++; + + if (Registry.is("debugger.types.preload")) { + scheduleTypesDataPreload(); + } } @Override @@ -777,4 +784,47 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy { protected abstract boolean calcValue(); } + private long myLastTypesCheckTime; + private int myLastTypesSize; + + // Preload all supertypes information for faster queries (especially for emulated method breakpoints) + private void scheduleTypesDataPreload() { + if (DebuggerUtilsImpl.isRemote(myDebugProcess)) { + return; + } + DebuggerManagerThreadImpl.assertIsManagerThread(); + long time = System.currentTimeMillis(); + if (time > myLastTypesCheckTime + 10000) { + List types = allClasses(); + if (time > myLastTypesCheckTime + 60000 || Math.abs(types.size() - myLastTypesSize) > 1000) { + scheduleTypesDataPreload(types.iterator()); + myLastTypesCheckTime = time; + myLastTypesSize = types.size(); + } + } + } + + private void scheduleTypesDataPreload(Iterator iterator) { + if (iterator.hasNext()) { + myDebugProcess.getManagerThread().schedule(PrioritizedTask.Priority.LOWEST, () -> { + long start = System.currentTimeMillis(); + do { + ReferenceType type = iterator.next(); + if (type.isPrepared()) { + try { + DebuggerUtilsImpl.supertypes(type); + } + catch (ObjectCollectedException ignored) { + } + } + if (System.currentTimeMillis() - start > 50) { // batch process for 50ms + // schedule here to allow other LOWEST priority commands to be processed + scheduleTypesDataPreload(iterator); + return; + } + } + while (iterator.hasNext()); + }); + } + } } diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index a6de7d6aed4e..c67ddf4b0044 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -387,6 +387,7 @@ debugger.call.tracing=false debugger.call.tracing.arguments=true debugger.renderers.annotations=true debugger.smart.step.inplace=true +debugger.types.preload=true execution.java.always.debug=false execution.java.always.debug.description=Always run java processes with the debug agent