Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestHumongousCodeCacheRoots.java
32284 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key regression26* @key gc27* @bug 802775628* @library /testlibrary /testlibrary/whitebox29* @build TestHumongousCodeCacheRoots30* @run main ClassFileInstaller sun.hotspot.WhiteBox31* @summary Humongous objects may have references from the code cache32* @run main TestHumongousCodeCacheRoots33*/3435import com.oracle.java.testlibrary.*;36import sun.hotspot.WhiteBox;3738import java.util.ArrayList;39import java.util.Arrays;4041class TestHumongousCodeCacheRootsHelper {4243static final int n = 1000000;44static final int[] AA = new int[n];45static final int[] BB = new int[n];4647public static void main(String args[]) throws Exception {48// do some work so that the compiler compiles this method, inlining the49// reference to the integer array (which is a humonguous object) into50// the code cache.51for(int i = 0; i < n; i++) {52AA[i] = 0;53BB[i] = 0;54}55// trigger a GC that checks that the verification code allows humongous56// objects with code cache roots; objects should be all live here.57System.gc();5859// deoptimize everyhing: this should make all compiled code zombies.60WhiteBox wb = WhiteBox.getWhiteBox();61wb.deoptimizeAll();6263// trigger a GC that checks that the verification code allows humongous64// objects with code cache roots; objects should be all live here.65System.gc();6667// wait a little for the code cache sweeper to try to clean up zombie nmethods68// and unregister the code roots.69try { Thread.sleep(5000); } catch (InterruptedException ex) { }7071// do some work on the arrays to make sure that they need to be live after the GCs72for(int i = 0; i < n; i++) {73AA[i] = 1;74BB[i] = 10;75}7677System.out.println();78}79}8081public class TestHumongousCodeCacheRoots {8283/**84* Executes a class in a new VM process with the given parameters.85* @param vmargs Arguments to the VM to run86* @param classname Name of the class to run87* @param arguments Arguments to the class88* @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string89* @return The OutputAnalyzer with the results for the invocation.90*/91public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {92ArrayList<String> finalargs = new ArrayList<String>();9394String[] whiteboxOpts = new String[] {95"-Xbootclasspath/a:.",96"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",97"-cp", System.getProperty("java.class.path"),98};99100if (useTestDotJavaDotOpts) {101// System.getProperty("test.java.opts") is '' if no options is set,102// we need to skip such a result103String[] externalVMOpts = new String[0];104if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) {105externalVMOpts = System.getProperty("test.java.opts").split(" ");106}107finalargs.addAll(Arrays.asList(externalVMOpts));108}109110finalargs.addAll(Arrays.asList(vmargs));111finalargs.addAll(Arrays.asList(whiteboxOpts));112finalargs.add(classname);113finalargs.addAll(Arrays.asList(arguments));114115ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));116OutputAnalyzer output = new OutputAnalyzer(pb.start());117output.shouldHaveExitValue(0);118119return output;120}121122public static void runTest(String compiler, String[] other) throws Exception {123ArrayList<String> joined = new ArrayList<String>();124joined.add(compiler);125joined.addAll(Arrays.asList(other));126runWhiteBoxTest(joined.toArray(new String[0]), TestHumongousCodeCacheRootsHelper.class.getName(),127new String[] {}, false);128}129130public static void main(String[] args) throws Exception {131final String[] baseArguments = new String[] {132"-XX:+UseG1GC", "-XX:G1HeapRegionSize=1M", "-Xmx100M", // make sure we get a humongous region133"-XX:+UnlockDiagnosticVMOptions",134"-XX:InitiatingHeapOccupancyPercent=1", // strong code root marking135"-XX:+G1VerifyHeapRegionCodeRoots", "-XX:+VerifyAfterGC", // make sure that verification is run136"-XX:NmethodSweepFraction=1", "-XX:NmethodSweepCheckInterval=1", // make the code cache sweep more predictable137};138runTest("-client", baseArguments);139runTest("-server", baseArguments);140}141}142143144145