1 /*
2 * Copyright (c) 2013, 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 * @test
26 * @key regression
27 * @key gc
28 * @bug 8027756
29 * @library /testlibrary /testlibrary/whitebox
30 * @build TestHumongousCodeCacheRoots
31 * @run main ClassFileInstaller sun.hotspot.WhiteBox
32 * @summary Humongous objects may have references from the code cache
33 * @run main TestHumongousCodeCacheRoots
34 */
35
36 import com.oracle.java.testlibrary.*;
37 import sun.hotspot.WhiteBox;
38
39 import java.util.ArrayList;
40 import java.util.Arrays;
41
42 class TestHumongousCodeCacheRootsHelper {
43
44 static final int n = 1000000;
45 static final int[] AA = new int[n];
46 static final int[] BB = new int[n];
47
48 public static void main(String args[]) throws Exception {
49 // do some work so that the compiler compiles this method, inlining the
50 // reference to the integer array (which is a humonguous object) into
51 // the code cache.
76 }
77
78 System.out.println();
79 }
80 }
81
82 public class TestHumongousCodeCacheRoots {
83
84 /**
85 * Executes a class in a new VM process with the given parameters.
86 * @param vmargs Arguments to the VM to run
87 * @param classname Name of the class to run
88 * @param arguments Arguments to the class
89 * @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
90 * @return The OutputAnalyzer with the results for the invocation.
91 */
92 public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
93 ArrayList<String> finalargs = new ArrayList<String>();
94
95 String[] whiteboxOpts = new String[] {
96 "-Xbootclasspath/a:.",
97 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
98 "-cp", System.getProperty("java.class.path"),
99 };
100
101 if (useTestDotJavaDotOpts) {
102 // System.getProperty("test.java.opts") is '' if no options is set,
103 // we need to skip such a result
104 String[] externalVMOpts = new String[0];
105 if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) {
106 externalVMOpts = System.getProperty("test.java.opts").split(" ");
107 }
108 finalargs.addAll(Arrays.asList(externalVMOpts));
109 }
110
111 finalargs.addAll(Arrays.asList(vmargs));
112 finalargs.addAll(Arrays.asList(whiteboxOpts));
113 finalargs.add(classname);
114 finalargs.addAll(Arrays.asList(arguments));
115
116 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
|
1 /*
2 * Copyright (c) 2014, 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 * @test
26 * @key regression
27 * @key gc
28 * @bug 8027756
29 * @library /testlibrary /testlibrary/whitebox
30 * @build TestHumongousCodeCacheRoots
31 * @summary Humongous objects may have references from the code cache
32 * @run main TestHumongousCodeCacheRoots
33 */
34
35 import com.oracle.java.testlibrary.*;
36 import sun.hotspot.WhiteBox;
37
38 import java.util.ArrayList;
39 import java.util.Arrays;
40
41 class TestHumongousCodeCacheRootsHelper {
42
43 static final int n = 1000000;
44 static final int[] AA = new int[n];
45 static final int[] BB = new int[n];
46
47 public static void main(String args[]) throws Exception {
48 // do some work so that the compiler compiles this method, inlining the
49 // reference to the integer array (which is a humonguous object) into
50 // the code cache.
75 }
76
77 System.out.println();
78 }
79 }
80
81 public class TestHumongousCodeCacheRoots {
82
83 /**
84 * Executes a class in a new VM process with the given parameters.
85 * @param vmargs Arguments to the VM to run
86 * @param classname Name of the class to run
87 * @param arguments Arguments to the class
88 * @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
89 * @return The OutputAnalyzer with the results for the invocation.
90 */
91 public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
92 ArrayList<String> finalargs = new ArrayList<String>();
93
94 String[] whiteboxOpts = new String[] {
95 "-Xbootclasspath/a:" + System.getProperty("test.classes"),
96 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
97 "-cp", System.getProperty("java.class.path"),
98 };
99
100 if (useTestDotJavaDotOpts) {
101 // System.getProperty("test.java.opts") is '' if no options is set,
102 // we need to skip such a result
103 String[] externalVMOpts = new String[0];
104 if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) {
105 externalVMOpts = System.getProperty("test.java.opts").split(" ");
106 }
107 finalargs.addAll(Arrays.asList(externalVMOpts));
108 }
109
110 finalargs.addAll(Arrays.asList(vmargs));
111 finalargs.addAll(Arrays.asList(whiteboxOpts));
112 finalargs.add(classname);
113 finalargs.addAll(Arrays.asList(arguments));
114
115 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
|