Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/test/gc/whitebox/TestWBGC.java
48799 views
/*1* Copyright (c) 2014, 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* @test TestWBGC25* @bug 805509826* @summary Test verify that WB methods isObjectInOldGen and youngGC works correctly.27* @library /testlibrary /testlibrary/whitebox28* @build TestWBGC29* @run main ClassFileInstaller sun.hotspot.WhiteBox30* @run driver TestWBGC31*/32import com.oracle.java.testlibrary.*;33import sun.hotspot.WhiteBox;3435public class TestWBGC {3637public static void main(String args[]) throws Exception {38ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(39true,40"-Xbootclasspath/a:.",41"-XX:+UnlockDiagnosticVMOptions",42"-XX:+WhiteBoxAPI",43"-XX:MaxTenuringThreshold=1",44"-XX:+PrintGC",45GCYoungTest.class.getName());4647OutputAnalyzer output = new OutputAnalyzer(pb.start());48System.out.println(output.getStdout());49output.shouldHaveExitValue(0);50output.shouldContain("WhiteBox Initiated Young GC");51output.shouldNotContain("Full");52// To be sure that we don't provoke Full GC additionaly to young53}5455public static class GCYoungTest {56static WhiteBox wb = WhiteBox.getWhiteBox();57public static Object obj;5859public static void main(String args[]) {60obj = new Object();61Asserts.assertFalse(wb.isObjectInOldGen(obj));62wb.youngGC();63wb.youngGC();64// 2 young GC is needed to promote object into OldGen65Asserts.assertTrue(wb.isObjectInOldGen(obj));66}67}68}697071