mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-156071 Simple static method renderers are much slower than toString - cache TypeEvaluator result
This commit is contained in:
+15
-1
@@ -26,12 +26,19 @@ import com.intellij.debugger.engine.JVMName;
|
||||
import com.intellij.debugger.engine.evaluation.EvaluateException;
|
||||
import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil;
|
||||
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
|
||||
import com.intellij.reference.SoftReference;
|
||||
import com.sun.jdi.ClassLoaderReference;
|
||||
import com.sun.jdi.ReferenceType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class TypeEvaluator implements Evaluator {
|
||||
private final JVMName myTypeName;
|
||||
|
||||
private WeakReference<ReferenceType> myLastResult;
|
||||
private WeakReference<ClassLoaderReference> myLastClassLoader;
|
||||
|
||||
public TypeEvaluator(@NotNull JVMName typeName) {
|
||||
myTypeName = typeName;
|
||||
}
|
||||
@@ -44,12 +51,19 @@ public class TypeEvaluator implements Evaluator {
|
||||
* @return ReferenceType in the target VM, with the given fully qualified name
|
||||
*/
|
||||
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
|
||||
ClassLoaderReference classLoader = context.getClassLoader();
|
||||
Object lastRes = SoftReference.dereference(myLastResult);
|
||||
if (lastRes != null && classLoader == SoftReference.dereference(myLastClassLoader)) {
|
||||
return lastRes;
|
||||
}
|
||||
DebugProcessImpl debugProcess = context.getDebugProcess();
|
||||
String typeName = myTypeName.getName(debugProcess);
|
||||
final ReferenceType type = debugProcess.findClass(context, typeName, context.getClassLoader());
|
||||
ReferenceType type = debugProcess.findClass(context, typeName, classLoader);
|
||||
if (type == null) {
|
||||
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("error.class.not.loaded", typeName));
|
||||
}
|
||||
myLastClassLoader = new WeakReference<>(classLoader);
|
||||
myLastResult = new WeakReference<>(type);
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user