Skip to content

Commit b8e9795

Browse files
Fix the perf for evaluation result (microsoft#269)
* Fix the perf for evaluation result Signed-off-by: Jinbo Wang <jinbwan@microsoft.com> * The indexedVariables should be a positive number Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
1 parent f921a67 commit b8e9795

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/EvaluateRequestHandler.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
import java.util.concurrent.CompletableFuture;
1818
import java.util.concurrent.CompletionException;
1919
import java.util.concurrent.ExecutionException;
20+
import java.util.logging.Level;
21+
import java.util.logging.Logger;
2022

2123
import org.apache.commons.lang3.StringUtils;
2224

25+
import com.microsoft.java.debug.core.Configuration;
2326
import com.microsoft.java.debug.core.DebugException;
2427
import com.microsoft.java.debug.core.DebugSettings;
2528
import com.microsoft.java.debug.core.adapter.AdapterUtils;
@@ -28,6 +31,7 @@
2831
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
2932
import com.microsoft.java.debug.core.adapter.IEvaluationProvider;
3033
import com.microsoft.java.debug.core.adapter.variables.IVariableFormatter;
34+
import com.microsoft.java.debug.core.adapter.variables.JavaLogicalStructureManager;
3135
import com.microsoft.java.debug.core.adapter.variables.StackFrameReference;
3236
import com.microsoft.java.debug.core.adapter.variables.VariableProxy;
3337
import com.microsoft.java.debug.core.adapter.variables.VariableUtils;
@@ -37,11 +41,18 @@
3741
import com.microsoft.java.debug.core.protocol.Requests.EvaluateArguments;
3842
import com.microsoft.java.debug.core.protocol.Responses;
3943
import com.sun.jdi.ArrayReference;
44+
import com.sun.jdi.ClassNotLoadedException;
45+
import com.sun.jdi.IncompatibleThreadStateException;
46+
import com.sun.jdi.IntegerValue;
47+
import com.sun.jdi.InvalidTypeException;
48+
import com.sun.jdi.InvocationException;
4049
import com.sun.jdi.ObjectReference;
4150
import com.sun.jdi.Value;
4251
import com.sun.jdi.VoidValue;
4352

4453
public class EvaluateRequestHandler implements IDebugRequestHandler {
54+
protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
55+
4556
@Override
4657
public List<Command> getTargetCommands() {
4758
return Arrays.asList(Command.EVALUATE);
@@ -80,12 +91,31 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
8091
long threadId = stackFrameReference.getThread().uniqueID();
8192
if (value instanceof ObjectReference) {
8293
VariableProxy varProxy = new VariableProxy(stackFrameReference.getThread(), "eval", value);
83-
int referenceId = VariableUtils.hasChildren(value, showStaticVariables)
84-
? context.getRecyclableIdPool().addObject(threadId, varProxy) : 0;
85-
int indexedVariableId = value instanceof ArrayReference ? ((ArrayReference) value).length() : 0;
94+
int indexedVariables = -1;
95+
if (value instanceof ArrayReference) {
96+
indexedVariables = ((ArrayReference) value).length();
97+
} else if (value instanceof ObjectReference && DebugSettings.getCurrent().showLogicalStructure
98+
&& engine != null
99+
&& JavaLogicalStructureManager.isIndexedVariable((ObjectReference) value)) {
100+
try {
101+
Value sizeValue = JavaLogicalStructureManager.getLogicalSize((ObjectReference) value, stackFrameReference.getThread(), engine);
102+
if (sizeValue != null && sizeValue instanceof IntegerValue) {
103+
indexedVariables = ((IntegerValue) sizeValue).value();
104+
}
105+
} catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException
106+
| InvocationException | InterruptedException | ExecutionException | UnsupportedOperationException e) {
107+
logger.log(Level.INFO,
108+
String.format("Failed to get the logical size for the type %s.", value.type().name()), e);
109+
}
110+
}
111+
int referenceId = 0;
112+
if (indexedVariables > 0 || (indexedVariables < 0 && VariableUtils.hasChildren(value, showStaticVariables))) {
113+
referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy);
114+
}
115+
86116
response.body = new Responses.EvaluateResponseBody(variableFormatter.valueToString(value, options),
87117
referenceId, variableFormatter.typeToString(value == null ? null : value.type(), options),
88-
indexedVariableId);
118+
Math.max(indexedVariables, 0));
89119
return response;
90120
}
91121
// for primitive value

0 commit comments

Comments
 (0)