1 /* |
|
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 import java.io.*; |
|
26 import java.util.*; |
|
27 import sun.hotspot.WhiteBox; |
|
28 |
|
29 // All strings in archived classes are shared |
|
30 public class GCStressApp { |
|
31 static WhiteBox wb = WhiteBox.getWhiteBox(); |
|
32 static int[] arr; |
|
33 |
|
34 static String get_shared_string() { |
|
35 String shared_str = "GCStressApp_shared_string"; |
|
36 return shared_str; |
|
37 } |
|
38 |
|
39 static String get_shared_string1() { |
|
40 String shared_str1 = "GCStressApp_shared_string1"; |
|
41 return shared_str1; |
|
42 } |
|
43 |
|
44 static void allocAlot() { |
|
45 try { |
|
46 Random random = new Random(); |
|
47 for (int i = 0; i < 1024 * 1024; i++) { |
|
48 int len = random.nextInt(10000); |
|
49 arr = new int[len]; |
|
50 } |
|
51 } catch (java.lang.OutOfMemoryError e) { } |
|
52 } |
|
53 |
|
54 static void runGC() { |
|
55 wb.fullGC(); |
|
56 } |
|
57 |
|
58 public static void main(String args[]) throws Exception { |
|
59 if (!wb.isSharedClass(GCStressApp.class)) { |
|
60 System.out.println("GCStressApp is not shared. Possibly there was a mapping failure."); |
|
61 return; |
|
62 } |
|
63 |
|
64 if (wb.areSharedStringsIgnored()) { |
|
65 System.out.println("Shared strings are ignored."); |
|
66 return; |
|
67 } |
|
68 |
|
69 Object refs = wb.getResolvedReferences(GCStressApp.class); |
|
70 if (wb.isShared(refs)) { |
|
71 String shared_str = get_shared_string(); |
|
72 String shared_str1 = get_shared_string1(); |
|
73 |
|
74 if (!wb.isShared(shared_str)) { |
|
75 throw new RuntimeException("FAILED. GCStressApp_shared_string is not shared"); |
|
76 } |
|
77 |
|
78 if (!wb.isShared(shared_str1)) { |
|
79 throw new RuntimeException("FAILED. GCStressApp_shared_string1 is not shared"); |
|
80 } |
|
81 |
|
82 allocAlot(); |
|
83 runGC(); |
|
84 runGC(); |
|
85 runGC(); |
|
86 |
|
87 System.out.println("Passed"); |
|
88 } else { |
|
89 System.out.println( |
|
90 "No cached resolved references. Open archive heap data is not used."); |
|
91 } |
|
92 } |
|
93 } |
|