test/runtime/NMT/AllocTestType.java

Sat, 02 Feb 2013 16:34:10 +0100

author
ctornqvi
date
Sat, 02 Feb 2013 16:34:10 +0100
changeset 4518
879c6de913d6
child 4637
1b0dc9f87e75
permissions
-rw-r--r--

8005013: Add NMT tests
Summary: Add tests for the Native Memory Tracking feature, includes regression tests for 8005936 and 8004802
Reviewed-by: zgu, coleenp

ctornqvi@4518 1 /*
ctornqvi@4518 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
ctornqvi@4518 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ctornqvi@4518 4 *
ctornqvi@4518 5 * This code is free software; you can redistribute it and/or modify it
ctornqvi@4518 6 * under the terms of the GNU General Public License version 2 only, as
ctornqvi@4518 7 * published by the Free Software Foundation.
ctornqvi@4518 8 *
ctornqvi@4518 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ctornqvi@4518 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ctornqvi@4518 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ctornqvi@4518 12 * version 2 for more details (a copy is included in the LICENSE file that
ctornqvi@4518 13 * accompanied this code).
ctornqvi@4518 14 *
ctornqvi@4518 15 * You should have received a copy of the GNU General Public License version
ctornqvi@4518 16 * 2 along with this work; if not, write to the Free Software Foundation,
ctornqvi@4518 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ctornqvi@4518 18 *
ctornqvi@4518 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ctornqvi@4518 20 * or visit www.oracle.com if you need additional information or have any
ctornqvi@4518 21 * questions.
ctornqvi@4518 22 */
ctornqvi@4518 23
ctornqvi@4518 24 /*
ctornqvi@4518 25 * @test
ctornqvi@4518 26 * @summary Test consistency of NMT by leaking a few select allocations of the Test type and then verify visibility with jcmd
ctornqvi@4518 27 * @key nmt jcmd
ctornqvi@4518 28 * @library /testlibrary
ctornqvi@4518 29 * @run compile -J-XX:+UnlockDiagnosticVMOptions -J-XX:+WhiteBoxAPI AllocTestType.java
ctornqvi@4518 30 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail AllocTestType
ctornqvi@4518 31 */
ctornqvi@4518 32
ctornqvi@4518 33 import com.oracle.java.testlibrary.*;
ctornqvi@4518 34 import sun.hotspot.WhiteBox;
ctornqvi@4518 35
ctornqvi@4518 36 public class AllocTestType {
ctornqvi@4518 37
ctornqvi@4518 38 public static void main(String args[]) throws Exception {
ctornqvi@4518 39 OutputAnalyzer output;
ctornqvi@4518 40
ctornqvi@4518 41 // Grab my own PID
ctornqvi@4518 42 String pid = Integer.toString(ProcessTools.getProcessId());
ctornqvi@4518 43 ProcessBuilder pb = new ProcessBuilder();
ctornqvi@4518 44
ctornqvi@4518 45 // Use WB API to alloc with the mtTest type
ctornqvi@4518 46 if (!WhiteBox.getWhiteBox().NMTAllocTest()) {
ctornqvi@4518 47 throw new Exception("Call to WB API NMTAllocTest() failed");
ctornqvi@4518 48 }
ctornqvi@4518 49
ctornqvi@4518 50 // Use WB API to ensure that all data has been merged before we continue
ctornqvi@4518 51 if (!WhiteBox.getWhiteBox().NMTWaitForDataMerge()) {
ctornqvi@4518 52 throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
ctornqvi@4518 53 }
ctornqvi@4518 54
ctornqvi@4518 55 // Run 'jcmd <pid> VM.native_memory summary'
ctornqvi@4518 56 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
ctornqvi@4518 57 output = new OutputAnalyzer(pb.start());
ctornqvi@4518 58 output.shouldContain("Test (reserved=512KB, committed=512KB)");
ctornqvi@4518 59
ctornqvi@4518 60 // Free the memory allocated by NMTAllocTest
ctornqvi@4518 61 if (!WhiteBox.getWhiteBox().NMTFreeTestMemory()) {
ctornqvi@4518 62 throw new Exception("Call to WB API NMTFreeTestMemory() failed");
ctornqvi@4518 63 }
ctornqvi@4518 64
ctornqvi@4518 65 // Use WB API to ensure that all data has been merged before we continue
ctornqvi@4518 66 if (!WhiteBox.getWhiteBox().NMTWaitForDataMerge()) {
ctornqvi@4518 67 throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
ctornqvi@4518 68 }
ctornqvi@4518 69 output = new OutputAnalyzer(pb.start());
ctornqvi@4518 70 output.shouldNotContain("Test (reserved=");
ctornqvi@4518 71 }
ctornqvi@4518 72 }

mercurial