author | coleenp |
Thu, 10 Mar 2016 13:43:47 -0500 | |
changeset 37064 | 5c82fa70d313 |
child 37298 | 8df0cc9da41e |
permissions | -rw-r--r-- |
37064
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
1 |
/* |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
4 |
* |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
8 |
* |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
14 |
* |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
18 |
* |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
21 |
* questions. |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
22 |
*/ |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
23 |
|
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
24 |
/* |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
25 |
* @test |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
26 |
* @bug 8150778 |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
27 |
* @summary check stacktrace logging |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
28 |
* @library /testlibrary |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
29 |
* @modules java.base/sun.misc |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
30 |
* java.management |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
31 |
* @build jdk.test.lib.OutputAnalyzer jdk.test.lib.ProcessTools |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
32 |
* @compile TestThrowable.java |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
33 |
* @run driver StackTraceLogging |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
34 |
*/ |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
35 |
|
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
36 |
import java.io.File; |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
37 |
import java.util.Map; |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
38 |
import jdk.test.lib.OutputAnalyzer; |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
39 |
import jdk.test.lib.ProcessTools; |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
40 |
|
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
41 |
public class StackTraceLogging { |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
42 |
static void updateEnvironment(ProcessBuilder pb, String environmentVariable, String value) { |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
43 |
Map<String, String> env = pb.environment(); |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
44 |
env.put(environmentVariable, value); |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
45 |
} |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
46 |
|
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
47 |
static void analyzeOutputOn(ProcessBuilder pb) throws Exception { |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
48 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
49 |
// These depths match the ones in TestThrowable.java |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
50 |
int[] depths = {10, 34, 100, 1024}; |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
51 |
for (int d : depths) { |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
52 |
output.shouldContain("java.lang.RuntimeException, " + d); |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
53 |
} |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
54 |
output.shouldHaveExitValue(0); |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
55 |
} |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
56 |
|
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
57 |
|
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
58 |
public static void main(String[] args) throws Exception { |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
59 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:stacktrace=info", |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
60 |
"-XX:MaxJavaStackTraceDepth=1024", |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
61 |
"TestThrowable"); |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
62 |
analyzeOutputOn(pb); |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
63 |
} |
5c82fa70d313
8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents:
diff
changeset
|
64 |
} |