From 94160c620e66ea61cfcc7b706b21fadcd0883333 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Thu, 25 Jan 2018 19:12:10 +0300 Subject: [PATCH] capture agent: speedup on java 9, avoid calling getStackTraceDepth all the time --- .../rt/debugger/agent/CaptureStorage.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java index 2d840e68df60..34fd8e8e6b09 100644 --- a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java +++ b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java @@ -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 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 insertStack = myInsertMatch.myStack.getStackTrace(); - int insertPos = stackTrace.length - myInsertMatch.myDepth + 2; + int insertPos = stackTrace.length - myInsertMatch.getDepth() + 2; ArrayList res = new ArrayList(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); } }