Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/NMT/HugeArenaTracking.java
32284 views
/*1* Copyright (c) 2019, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223/*24* @test25* @key nmt jcmd26* @library /testlibrary /testlibrary/whitebox27* @build HugeArenaTracking28* @run main ClassFileInstaller sun.hotspot.WhiteBox29* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail HugeArenaTracking30*/3132import java.util.Random;33import com.oracle.java.testlibrary.*;34import sun.hotspot.WhiteBox;3536public class HugeArenaTracking {37private static final long GB = 1024 * 1024 * 1024;3839public static void main(String args[]) throws Exception {40OutputAnalyzer output;41final WhiteBox wb = WhiteBox.getWhiteBox();4243// Grab my own PID44String pid = Long.toString(ProcessTools.getProcessId());45ProcessBuilder pb = new ProcessBuilder();4647long arena1 = wb.NMTNewArena(1024);48long arena2 = wb.NMTNewArena(1024);4950// Run 'jcmd <pid> VM.native_memory summary'51pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});52output = new OutputAnalyzer(pb.start());53output.shouldContain("Test (reserved=2KB, committed=2KB)");5455Random rand = new Random();5657// Allocate 2GB+ from arena58long total = 0;59while (total < 2 * GB) {60// Cap to 10M61long inc = rand.nextInt(10 * 1024 * 1024);62wb.NMTArenaMalloc(arena1, inc);63total += inc;64}6566ProcessBuilder pb2 = new ProcessBuilder();67// Run 'jcmd <pid> VM.native_memory summary'68pb2.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary", "scale=GB"});69output = new OutputAnalyzer(pb2.start());70output.shouldContain("Test (reserved=2GB, committed=2GB)");7172wb.NMTFreeArena(arena1);7374output = new OutputAnalyzer(pb.start());75output.shouldContain("Test (reserved=1KB, committed=1KB)");76wb.NMTFreeArena(arena2);7778output = new OutputAnalyzer(pb.start());79output.shouldNotContain("Test (reserved");80}81}828384