capture agent: speedup on java 9, avoid calling getStackTraceDepth all the time

This commit is contained in:
Egor Ushakov
2018-01-25 19:28:12 +03:00
parent 14f5a8c4c5
commit 94160c620e
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 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-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.
package com.intellij.rt.debugger.agent;
import sun.misc.JavaLangAccess;
@@ -73,7 +71,7 @@ public class CaptureStorage {
Deque<InsertMatch> currentStacks = CURRENT_STACKS.get();
if (stack != null) {
Throwable exception = new Throwable();
currentStacks.add(new InsertMatch(stack, getStackTraceDepth(exception)));
currentStacks.add(new InsertMatch(stack, exception));
if (DEBUG) {
System.out.println("insert " + getCallerDescriptor(exception) + " -> " + key + ", stack saved (" + currentStacks.size() + ")");
}
@@ -165,7 +163,7 @@ public class CaptureStorage {
}
else {
List<StackTraceElement> insertStack = myInsertMatch.myStack.getStackTrace();
int insertPos = stackTrace.length - myInsertMatch.myDepth + 2;
int insertPos = stackTrace.length - myInsertMatch.getDepth() + 2;
ArrayList<StackTraceElement> res = new ArrayList<StackTraceElement>(insertPos + insertStack.size() + 1);
res.addAll(Arrays.asList(stackTrace).subList(1, insertPos));
res.add(null);
@@ -177,13 +175,22 @@ public class CaptureStorage {
private static class InsertMatch {
private final CapturedStack myStack;
private final int myDepth;
private final Throwable myException;
static final InsertMatch EMPTY = new InsertMatch(null, 0);
static final InsertMatch EMPTY = new InsertMatch(null, null) {
@Override
int getDepth() {
return 0;
}
};
private InsertMatch(CapturedStack stack, int depth) {
private InsertMatch(CapturedStack stack, Throwable exception) {
myStack = stack;
myDepth = depth;
myException = exception;
}
int getDepth() {
return getStackTraceDepth(myException);
}
}