Path: blob/master/test/hotspot/jtreg/gc/g1/TestHumongousCodeCacheRoots.java
40942 views
/*1* Copyright (c) 2013, 2021, 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*/2223package gc.g1;2425/*26* @test27* @bug 802775628* @requires vm.gc.G129* @library /test/lib30* @modules java.base/jdk.internal.misc31* java.management32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @summary Humongous objects may have references from the code cache35* @run driver gc.g1.TestHumongousCodeCacheRoots36*/3738import jdk.test.lib.process.OutputAnalyzer;39import jdk.test.lib.process.ProcessTools;40import sun.hotspot.WhiteBox;4142import java.util.ArrayList;43import java.util.Arrays;4445class TestHumongousCodeCacheRootsHelper {4647static final int n = 1000000;48static final int[] AA = new int[n];49static final int[] BB = new int[n];5051public static void main(String args[]) throws Exception {52// do some work so that the compiler compiles this method, inlining the53// reference to the integer array (which is a humonguous object) into54// the code cache.55for(int i = 0; i < n; i++) {56AA[i] = 0;57BB[i] = 0;58}59// trigger a GC that checks that the verification code allows humongous60// objects with code cache roots; objects should be all live here.61System.gc();6263// deoptimize everyhing: this should make all compiled code zombies.64WhiteBox wb = WhiteBox.getWhiteBox();65wb.deoptimizeAll();6667// trigger a GC that checks that the verification code allows humongous68// objects with code cache roots; objects should be all live here.69System.gc();7071// wait a little for the code cache sweeper to try to clean up zombie nmethods72// and unregister the code roots.73try { Thread.sleep(5000); } catch (InterruptedException ex) { }7475// do some work on the arrays to make sure that they need to be live after the GCs76for(int i = 0; i < n; i++) {77AA[i] = 1;78BB[i] = 10;79}8081System.out.println();82}83}8485public class TestHumongousCodeCacheRoots {8687/**88* Executes a class in a new VM process with the given parameters.89* @param vmargs Arguments to the VM to run90* @param classname Name of the class to run91* @param arguments Arguments to the class92* @return The OutputAnalyzer with the results for the invocation.93*/94public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments) throws Exception {95ArrayList<String> finalargs = new ArrayList<String>();9697String[] whiteboxOpts = new String[] {98"-Xbootclasspath/a:.",99"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",100"-cp", System.getProperty("java.class.path"),101};102103finalargs.addAll(Arrays.asList(vmargs));104finalargs.addAll(Arrays.asList(whiteboxOpts));105finalargs.add(classname);106finalargs.addAll(Arrays.asList(arguments));107108ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs);109OutputAnalyzer output = new OutputAnalyzer(pb.start());110output.shouldHaveExitValue(0);111return output;112}113114public static void main(String[] args) throws Exception {115final String[] baseArguments = new String[] {116"-XX:+UseG1GC", "-XX:G1HeapRegionSize=1M", "-Xmx100M", // make sure we get a humongous region117"-XX:+UnlockDiagnosticVMOptions",118"-XX:InitiatingHeapOccupancyPercent=1", // strong code root marking119"-XX:+G1VerifyHeapRegionCodeRoots", "-XX:+VerifyAfterGC", // make sure that verification is run120};121122runWhiteBoxTest(baseArguments, TestHumongousCodeCacheRootsHelper.class.getName(), new String[] { });123}124}125126127128