author | duke |
Wed, 05 Jul 2017 21:19:32 +0200 | |
changeset 35739 | db483b34fa71 |
parent 33730 | 30e064828045 |
child 38152 | 80e5da81fb2c |
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 |
33730
30e064828045
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents:
28497
diff
changeset
|
27 |
* @library /testlibrary /test/lib |
24671
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; |
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
50 |
static final long MAX_STACK_SIZE_ALLOCATED_IN_MAIN = 150 * K; // current value is about 130k on 64-bit platforms |
24671
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; |
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
85 |
System.out.println("ThreadStackSize VM option: " + configStackSize); |
24671
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
86 |
|
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
87 |
long stackProtectionSize = wb.getIntxVMFlag("StackShadowPages") * wb.getVMPageSize(); |
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
88 |
System.out.println("Size of protected shadow pages: " + stackProtectionSize); |
24671
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
89 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
90 |
long actualStackSize = wb.getThreadStackSize(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
91 |
System.out.println("Full stack size: " + actualStackSize); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
92 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
93 |
if (Math.abs(actualStackSize - configStackSize) > configStackSize * 0.1) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
94 |
throw new RuntimeException("getThreadFullStackSize value [" + actualStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
95 |
+ "] 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
|
96 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
97 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
98 |
long remainingStackSize = wb.getThreadRemainingStackSize(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
99 |
System.out.println("Remaining stack size in main(): " + remainingStackSize); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
100 |
|
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
101 |
// Up to 150k can be already allocated by VM and some space is used for stack protection. |
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
102 |
long spaceAlreadyOccupied = MAX_STACK_SIZE_ALLOCATED_IN_MAIN + stackProtectionSize; |
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
103 |
|
24671
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
104 |
if (remainingStackSize > configStackSize |
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
105 |
|| (configStackSize > spaceAlreadyOccupied |
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
106 |
&& remainingStackSize < configStackSize - spaceAlreadyOccupied)) { |
24671
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 |
throw new RuntimeException("getThreadRemainingStackSize value [" + remainingStackSize |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
109 |
+ "] should be at least ThreadStackSize value [" + configStackSize + "] minus [" |
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
28190
diff
changeset
|
110 |
+ spaceAlreadyOccupied + "]"); |
24671
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
111 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
112 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
113 |
testStackOverflow(); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
114 |
|
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
115 |
if (stackSizeOnOverflow > MIN_STACK_SIZE) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
116 |
throw new RuntimeException("Caught StackOverflowError too early: when there were " |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
117 |
+ stackSizeOnOverflow + " bytes in stack"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
118 |
} else if (stackSizeOnOverflow < 0) { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
119 |
throw new RuntimeException("Internal test error: stackRemainingSize < 0"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
120 |
} else { |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
121 |
System.out.println("Caught StackOverflowError as expected"); |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
122 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
123 |
} |
0ebd6fe70309
8032970: Add stack size check methods to WhiteBox API
iignatyev
parents:
diff
changeset
|
124 |
} |