jdk
1/*
2* Copyright (c) 2014, 2024, Alibaba Group Holding Limited. All rights reserved.
3* Copyright (c) 2024, Red Hat Inc.
4* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5*
6* This code is free software; you can redistribute it and/or modify it
7* under the terms of the GNU General Public License version 2 only, as
8* published by the Free Software Foundation.
9*
10* This code is distributed in the hope that it will be useful, but WITHOUT
11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13* version 2 for more details (a copy is included in the LICENSE file that
14* accompanied this code).
15*
16* You should have received a copy of the GNU General Public License version
17* 2 along with this work; if not, write to the Free Software Foundation,
18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19*
20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21* or visit www.oracle.com if you need additional information or have any
22* questions.
23*/
24
25package gc;26
27/**
28* @test id=ParallelCollector
29* @summary tests AlwaysPreTouch
30* @requires vm.gc.Parallel
31* @requires os.maxMemory > 2G
32* @requires os.family != "aix"
33* @library /test/lib
34* @build jdk.test.whitebox.WhiteBox
35* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
36* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseParallelGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
37*/
38
39/**40* @test id=SerialCollector
41* @summary tests AlwaysPreTouch
42* @requires vm.gc.Serial
43* @requires os.maxMemory > 2G
44* @requires os.family != "aix"
45* @library /test/lib
46* @build jdk.test.whitebox.WhiteBox
47* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
48* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseSerialGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
49*/
50
51/**
52* @test id=Shenandoah
53* @summary tests AlwaysPreTouch
54* @requires vm.gc.Shenandoah
55* @requires os.maxMemory > 2G
56* @requires os.family != "aix"
57* @library /test/lib
58* @build jdk.test.whitebox.WhiteBox
59* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
60* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseShenandoahGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
61*/
62
63/**
64* @test id=G1
65* @summary tests AlwaysPreTouch
66* @requires vm.gc.G1
67* @requires os.maxMemory > 2G
68* @requires os.family != "aix"
69* @library /test/lib
70* @build jdk.test.whitebox.WhiteBox
71* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
72* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
73*/
74
75/**
76* @test id=ZGenerational
77* @summary tests AlwaysPreTouch
78* @requires vm.gc.ZGenerational
79* @requires os.maxMemory > 2G
80* @requires os.family != "aix"
81* @library /test/lib
82* @build jdk.test.whitebox.WhiteBox
83* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
84* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseZGC -XX:+ZGenerational -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
85*/
86
87/**
88* @test id=ZSinglegen
89* @summary tests AlwaysPreTouch
90* @requires vm.gc.ZSinglegen
91* @requires os.maxMemory > 2G
92* @requires os.family != "aix"
93* @library /test/lib
94* @build jdk.test.whitebox.WhiteBox
95* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
96* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseZGC -XX:-ZGenerational -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
97*/
98
99/**
100* @test id=Epsilon
101* @summary tests AlwaysPreTouch
102* @requires vm.gc.Epsilon
103* @requires os.maxMemory > 2G
104* @requires os.family != "aix"
105* @library /test/lib
106* @build jdk.test.whitebox.WhiteBox
107* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
108* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
109*/
110
111
112import jdk.test.lib.Asserts;113
114import jdk.test.whitebox.WhiteBox;115
116public class TestAlwaysPreTouchBehavior {117
118public static void main(String [] args) {119long rss = WhiteBox.getWhiteBox().rss();120System.out.println("RSS: " + rss);121if (rss == 0) {122System.out.println("cannot get RSS, just skip");123return; // Did not get available RSS, just ignore this test.124}125Runtime runtime = Runtime.getRuntime();126long committedMemory = runtime.totalMemory();127Asserts.assertGreaterThan(rss, committedMemory, "RSS of this process(" + rss + "b) should be bigger than or equal to committed heap mem(" + committedMemory + "b)");128}129}
130
131