Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/NMT/VirtualAllocCommitUncommitRecommit.java
32285 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* @test25* @summary Test reserve/commit/uncommit/release of virtual memory and that we track it correctly26* @key nmt jcmd27* @library /testlibrary /testlibrary/whitebox28* @build VirtualAllocCommitUncommitRecommit29* @run main ClassFileInstaller sun.hotspot.WhiteBox30* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail VirtualAllocCommitUncommitRecommit31*32*/3334import com.oracle.java.testlibrary.*;3536import sun.hotspot.WhiteBox;3738public class VirtualAllocCommitUncommitRecommit {3940public static WhiteBox wb = WhiteBox.getWhiteBox();4142public static void main(String args[]) throws Exception {43OutputAnalyzer output;44long commitSize = 128 * 1024; // 128KB45long reserveSize = 4 * 1024 * 1024; // 4096KB46long addr;4748String pid = Integer.toString(ProcessTools.getProcessId());49ProcessBuilder pb = new ProcessBuilder();5051boolean has_nmt_detail = wb.NMTIsDetailSupported();52if (has_nmt_detail) {53System.out.println("NMT detail support detected.");54} else {55System.out.println("NMT detail support not detected.");56}5758// reserve59addr = wb.NMTReserveMemory(reserveSize);60pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid,61"VM.native_memory", "detail" });6263output = new OutputAnalyzer(pb.start());64output.shouldContain("Test (reserved=4096KB, committed=0KB)");65if (has_nmt_detail) {66output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"67+ Long.toHexString(addr + reserveSize)68+ "\\] reserved 4096KB for Test");69}7071long addrA = addr;72long addrB = addr + commitSize;73long addrC = addr + (2 * commitSize);74long addrD = addr + (3 * commitSize);75long addrE = addr + (4 * commitSize);76long addrF = addr + (5 * commitSize);7778// commit ABCD79wb.NMTCommitMemory(addrA, commitSize);80wb.NMTCommitMemory(addrB, commitSize);81wb.NMTCommitMemory(addrC, commitSize);82wb.NMTCommitMemory(addrD, commitSize);8384output = new OutputAnalyzer(pb.start());85output.shouldContain("Test (reserved=4096KB, committed=512KB)");8687if (has_nmt_detail) {88output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"89+ Long.toHexString(addr + reserveSize)90+ "\\] reserved 4096KB for Test");91}92// uncommit BC93wb.NMTUncommitMemory(addrB, commitSize);94wb.NMTUncommitMemory(addrC, commitSize);9596output = new OutputAnalyzer(pb.start());97output.shouldContain("Test (reserved=4096KB, committed=256KB)");9899if (has_nmt_detail) {100output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"101+ Long.toHexString(addr + reserveSize)102+ "\\] reserved 4096KB for Test");103}104105// commit EF106wb.NMTCommitMemory(addrE, commitSize);107wb.NMTCommitMemory(addrF, commitSize);108109output = new OutputAnalyzer(pb.start());110output.shouldContain("Test (reserved=4096KB, committed=512KB)");111if (has_nmt_detail) {112output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"113+ Long.toHexString(addr + reserveSize)114+ "\\] reserved 4096KB for Test");115}116117// uncommit A118wb.NMTUncommitMemory(addrA, commitSize);119120output = new OutputAnalyzer(pb.start());121output.shouldContain("Test (reserved=4096KB, committed=384KB)");122if (has_nmt_detail) {123output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"124+ Long.toHexString(addr + reserveSize)125+ "\\] reserved 4096KB for Test");126}127128// commit ABC129wb.NMTCommitMemory(addrA, commitSize);130wb.NMTCommitMemory(addrB, commitSize);131wb.NMTCommitMemory(addrC, commitSize);132133output = new OutputAnalyzer(pb.start());134output.shouldContain("Test (reserved=4096KB, committed=768KB)");135if (has_nmt_detail) {136output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"137+ Long.toHexString(addr + reserveSize)138+ "\\] reserved 4096KB for Test");139}140141// uncommit ABCDEF142wb.NMTUncommitMemory(addrA, commitSize);143wb.NMTUncommitMemory(addrB, commitSize);144wb.NMTUncommitMemory(addrC, commitSize);145wb.NMTUncommitMemory(addrD, commitSize);146wb.NMTUncommitMemory(addrE, commitSize);147wb.NMTUncommitMemory(addrF, commitSize);148149output = new OutputAnalyzer(pb.start());150output.shouldContain("Test (reserved=4096KB, committed=0KB)");151if (has_nmt_detail) {152output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"153+ Long.toHexString(addr + reserveSize)154+ "\\] reserved 4096KB for Test");155}156157// release158wb.NMTReleaseMemory(addr, reserveSize);159output = new OutputAnalyzer(pb.start());160output.shouldNotContain("Test (reserved=");161output.shouldNotMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*"162+ Long.toHexString(addr + reserveSize) + "\\] reserved 4096KB for Test");163}164}165166167