author | jjg |
Fri, 07 Nov 2014 14:51:35 -0800 | |
changeset 27547 | d07b3dcbc707 |
parent 25958 | 8dc85547d6d6 |
child 28190 | 5a6b07edeb21 |
permissions | -rw-r--r-- |
24671
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
1 |
/* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
4 |
* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
8 |
* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
13 |
* accompanied this code). |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
14 |
* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
18 |
* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
21 |
* questions. |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
22 |
*/ |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
23 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
24 |
/* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
25 |
* @test WBStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
26 |
* @summary verify that whitebox functions getThreadFullStackSize() and getThreadRemainingStackSize are working |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
27 |
* @library /testlibrary /testlibrary/whitebox |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
28 |
* @build WBStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
29 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
25958
8dc85547d6d6
8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot
mgerdin
parents:
25736
diff
changeset
|
30 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
24671
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
31 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xss512k WBStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
32 |
*/ |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
33 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
34 |
/* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
35 |
* The test may product a false failure if too big StackYellowPages/StackRedPages/ShackShadowPages |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
36 |
* VM options are specified. The proper test would retrieve the page size from VM and account for these options |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
37 |
* instead of check below: |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
38 |
* Math.abs(actualStackSize - configStackSize) > configStackSize * 0.1 |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
39 |
* |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
40 |
* Please file a test bug, if this is a problem. |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
41 |
*/ |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
42 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
43 |
import sun.hotspot.WhiteBox; |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
44 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
45 |
public class WBStackSize { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
46 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
47 |
static final long K = 1024; |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
48 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
49 |
static final long MIN_STACK_SIZE = 8 * K; |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
50 |
static final long MAX_STACK_SIZE_ALLOCATED_IN_MAIN = 200 * K; // current value is about 130k on 64-bit platforms |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
51 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
52 |
static final WhiteBox wb = WhiteBox.getWhiteBox(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
53 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
54 |
static long stackSizeOnOverflow = -1; |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
55 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
56 |
static int eatAllStack() { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
57 |
return eatAllStack() * 2; |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
58 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
59 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
60 |
static void testStackOverflow() { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
61 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
62 |
stackSizeOnOverflow = wb.getThreadRemainingStackSize(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
63 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
64 |
if (stackSizeOnOverflow > MIN_STACK_SIZE) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
65 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
66 |
try { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
67 |
testStackOverflow(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
68 |
} catch (StackOverflowError e) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
69 |
// We caught SOE too early. The error will be reported in main() |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
70 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
71 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
72 |
} else { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
73 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
74 |
try { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
75 |
eatAllStack(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
76 |
throw new RuntimeException("Haven't caught StackOverflowError at all"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
77 |
} catch (StackOverflowError e) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
78 |
// OK: we caught the anticipated error |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
79 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
80 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
81 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
82 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
83 |
public static void main(String[] args) { |
25736 | 84 |
long configStackSize = wb.getIntxVMFlag("ThreadStackSize") * K; |
24671
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
85 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
86 |
System.out.println("ThreadStackSize VM option: " + configStackSize); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
87 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
88 |
long actualStackSize = wb.getThreadStackSize(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
89 |
System.out.println("Full stack size: " + actualStackSize); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
90 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
91 |
if (Math.abs(actualStackSize - configStackSize) > configStackSize * 0.1) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
92 |
throw new RuntimeException("getThreadFullStackSize value [" + actualStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
93 |
+ "] should be within 90%..110% of the value returned by HotSpotDiagnosticMXBean"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
94 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
95 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
96 |
long remainingStackSize = wb.getThreadRemainingStackSize(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
97 |
System.out.println("Remaining stack size in main(): " + remainingStackSize); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
98 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
99 |
// Up to 200k can be already allocated by VM |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
100 |
if (remainingStackSize > configStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
101 |
|| (configStackSize > MAX_STACK_SIZE_ALLOCATED_IN_MAIN |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
102 |
&& remainingStackSize < configStackSize - MAX_STACK_SIZE_ALLOCATED_IN_MAIN)) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
103 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
104 |
throw new RuntimeException("getThreadRemainingStackSize value [" + remainingStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
105 |
+ "] should be at least ThreadStackSize value [" + configStackSize + "] minus [" |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
106 |
+ MAX_STACK_SIZE_ALLOCATED_IN_MAIN + "]"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
107 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
108 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
109 |
testStackOverflow(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
110 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
111 |
if (stackSizeOnOverflow > MIN_STACK_SIZE) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
112 |
throw new RuntimeException("Caught StackOverflowError too early: when there were " |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
113 |
+ stackSizeOnOverflow + " bytes in stack"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
114 |
} else if (stackSizeOnOverflow < 0) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
115 |
throw new RuntimeException("Internal test error: stackRemainingSize < 0"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
116 |
} else { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
117 |
System.out.println("Caught StackOverflowError as expected"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
118 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
119 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
120 |
} |