From 74637b1dedb232e1848f3ec1d12a9e5dc412aea0 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 1 Mar 2017 21:24:42 +0300 Subject: [PATCH] capture speedup - introduced lazy this object in evaluation context --- .../evaluation/EvaluationContextImpl.java | 22 +++++++++++++++---- .../StackCapturingLineBreakpoint.java | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java index a89cad15303d..a4184ef4a8d7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,20 +20,34 @@ import com.intellij.debugger.engine.DebuggerManagerThreadImpl; import com.intellij.debugger.engine.SuspendContextImpl; import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.NullableLazyValue; import com.sun.jdi.ClassLoaderReference; import com.sun.jdi.Value; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public final class EvaluationContextImpl implements EvaluationContext{ - private final Value myThisObject; + private final NullableLazyValue myThisObject; private final SuspendContextImpl mySuspendContext; private final StackFrameProxyImpl myFrameProxy; private boolean myAutoLoadClasses = true; private ClassLoaderReference myClassLoader; public EvaluationContextImpl(@NotNull SuspendContextImpl suspendContext, StackFrameProxyImpl frameProxy, @Nullable Value thisObject) { - myThisObject = thisObject; + myThisObject = NullableLazyValue.createValue(() -> thisObject); + myFrameProxy = frameProxy; + mySuspendContext = suspendContext; + } + + public EvaluationContextImpl(@NotNull SuspendContextImpl suspendContext, @NotNull StackFrameProxyImpl frameProxy) { + myThisObject = NullableLazyValue.createValue(() -> { + try { + return frameProxy.thisObject(); + } + catch (EvaluateException ignore) { + } + return null; + }); myFrameProxy = frameProxy; mySuspendContext = suspendContext; } @@ -41,7 +55,7 @@ public final class EvaluationContextImpl implements EvaluationContext{ @Nullable @Override public Value getThisObject() { - return myThisObject; + return myThisObject.getValue(); } @NotNull diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StackCapturingLineBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StackCapturingLineBreakpoint.java index 43585d6bfa77..a0ab800e6985 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StackCapturingLineBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StackCapturingLineBreakpoint.java @@ -113,7 +113,7 @@ public class StackCapturingLineBreakpoint extends WildcardMethodBreakpoint { stacks = new CapturedStacksMap(); process.putUserData(CAPTURED_STACKS, Collections.synchronizedMap(stacks)); } - Value key = myCaptureEvaluator.evaluate(new EvaluationContextImpl(suspendContext, frameProxy, frameProxy.thisObject())); + Value key = myCaptureEvaluator.evaluate(new EvaluationContextImpl(suspendContext, frameProxy)); if (key instanceof ObjectReference) { List frames = StackFrameItem.createFrames(suspendContext, true); if (frames.size() > MAX_STACK_LENGTH) { @@ -214,7 +214,7 @@ public class StackCapturingLineBreakpoint extends WildcardMethodBreakpoint { if ((StringUtil.isEmpty(insertClassName) || StringUtil.equals(insertClassName, className)) && StringUtil.equals(b.myCapturePoint.myInsertMethodName, methodName)) { try { - Value key = b.myInsertEvaluator.evaluate(new EvaluationContextImpl(suspendContext, frame, frame.thisObject())); + Value key = b.myInsertEvaluator.evaluate(new EvaluationContextImpl(suspendContext, frame)); if (key instanceof ObjectReference) { return capturedStacks.get(getKey((ObjectReference)key)); }