IDEA-234689 Batch toString traffic optimization - removed disableCollection from the string result

GitOrigin-RevId: 936d1aad319e5757490df796ee0a05a17e5d0880
This commit is contained in:
Egor Ushakov
2020-03-06 18:15:58 +03:00
committed by intellij-monorepo-bot
parent f566c5185d
commit fc17a02477
3 changed files with 43 additions and 28 deletions

View File

@@ -1,16 +1,16 @@
// 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.
// Copyright 2000-2020 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.
package com.intellij.debugger.engine.evaluation;
import com.intellij.debugger.EvaluatingComputable;
import com.intellij.debugger.engine.DebugProcessImpl;
import com.intellij.debugger.engine.DebuggerManagerThreadImpl;
import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.debugger.engine.SuspendContextImpl;
import com.intellij.debugger.jdi.StackFrameProxyImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ThrowableComputable;
import com.sun.jdi.ClassLoaderReference;
import com.sun.jdi.ObjectCollectedException;
import com.sun.jdi.ObjectReference;
import com.sun.jdi.Value;
import org.jetbrains.annotations.NotNull;
@@ -140,19 +140,10 @@ public final class EvaluationContextImpl implements EvaluationContext {
@Override
public <T extends Value> T computeAndKeep(@NotNull ThrowableComputable<T, EvaluateException> computable) throws EvaluateException {
int retries = 10;
while (true) {
T res = computable.compute();
try {
keep(res);
return res;
}
catch (ObjectCollectedException oce) {
if (--retries < 0) {
throw oce;
}
}
}
return DebuggerUtils.processCollectibleValue(computable, value -> {
keep(value);
return value;
});
}
public boolean isEvaluationPossible() {

View File

@@ -146,10 +146,12 @@ public class BatchEvaluator {
ArrayReference argArray = DebuggerUtilsEx.mirrorOfArray(objectArrayClass, values.size(), evaluationContext);
argArray.setValues(values);
Value value = evaluationContext.computeAndKeep(() -> debugProcess.invokeMethod(
evaluationContext, myBatchEvaluatorClass, myBatchEvaluatorMethod, Collections.singletonList(argArray)));
if (value instanceof StringReference) {
byte[] bytes = ((StringReference)value).value().getBytes(StandardCharsets.ISO_8859_1);
String value = DebuggerUtils.processCollectibleValue(
() -> debugProcess.invokeMethod(evaluationContext, myBatchEvaluatorClass, myBatchEvaluatorMethod, Collections.singletonList(argArray)),
result -> result instanceof StringReference ? ((StringReference)result).value() : null
);
if (value != null) {
byte[] bytes = value.getBytes(StandardCharsets.ISO_8859_1);
int pos = 0;
Iterator<ToStringCommand> iterator = requests.iterator();
while (pos < bytes.length) {

View File

@@ -1,4 +1,4 @@
// 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.
// Copyright 2000-2020 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.
package com.intellij.debugger.engine;
import com.intellij.debugger.JavaDebuggerBundle;
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -39,6 +40,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Function;
public abstract class DebuggerUtils {
private static final Logger LOG = Logger.getInstance(DebuggerUtils.class);
@@ -104,14 +106,17 @@ public abstract class DebuggerUtils {
JavaDebuggerBundle.message("evaluation.error.cannot.evaluate.tostring", objRef.referenceType().name()));
}
Method finalToStringMethod = toStringMethod;
final Value result = evaluationContext.computeAndKeep(
() -> debugProcess.invokeInstanceMethod(evaluationContext, objRef, finalToStringMethod, Collections.emptyList(), 0));
// while result must be of com.sun.jdi.StringReference type, it turns out that sometimes (jvm bugs?)
// it is a plain com.sun.tools.jdi.ObjectReferenceImpl
if (result == null) {
return "null";
}
return result instanceof StringReference ? ((StringReference)result).value() : result.toString();
return processCollectibleValue(
() -> debugProcess.invokeInstanceMethod(evaluationContext, objRef, finalToStringMethod, Collections.emptyList(), 0),
result -> {
// while result must be of com.sun.jdi.StringReference type, it turns out that sometimes (jvm bugs?)
// it is a plain com.sun.tools.jdi.ObjectReferenceImpl
if (result == null) {
return "null";
}
return result instanceof StringReference ? ((StringReference)result).value() : result.toString();
}
);
}
throw EvaluateExceptionUtil.createEvaluateException(JavaDebuggerBundle.message("evaluation.error.unsupported.expression.type"));
}
@@ -120,6 +125,23 @@ public abstract class DebuggerUtils {
}
}
public static <R, T extends Value> R processCollectibleValue(
@NotNull ThrowableComputable<? extends T, ? extends EvaluateException> valueComputable,
@NotNull Function<T, R> processor) throws EvaluateException {
int retries = 10;
while (true) {
T result = valueComputable.compute();
try {
return processor.apply(result);
}
catch (ObjectCollectedException oce) {
if (--retries < 0) {
throw oce;
}
}
}
}
public static void ensureNotInsideObjectConstructor(@NotNull ObjectReference reference, @NotNull EvaluationContext context)
throws EvaluateException {
StackFrameProxy frameProxy = context.getFrameProxy();