test/runtime/NMT/AllocTestType.java

changeset 4518
879c6de913d6
child 4637
1b0dc9f87e75
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/runtime/NMT/AllocTestType.java	Sat Feb 02 16:34:10 2013 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +/*
     1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @summary Test consistency of NMT by leaking a few select allocations of the Test type and then verify visibility with jcmd
    1.30 + * @key nmt jcmd
    1.31 + * @library /testlibrary
    1.32 + * @run compile -J-XX:+UnlockDiagnosticVMOptions -J-XX:+WhiteBoxAPI AllocTestType.java
    1.33 + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail AllocTestType
    1.34 + */
    1.35 +
    1.36 +import com.oracle.java.testlibrary.*;
    1.37 +import sun.hotspot.WhiteBox;
    1.38 +
    1.39 +public class AllocTestType {
    1.40 +
    1.41 +  public static void main(String args[]) throws Exception {
    1.42 +    OutputAnalyzer output;
    1.43 +
    1.44 +    // Grab my own PID
    1.45 +    String pid = Integer.toString(ProcessTools.getProcessId());
    1.46 +    ProcessBuilder pb = new ProcessBuilder();
    1.47 +
    1.48 +    // Use WB API to alloc with the mtTest type
    1.49 +    if (!WhiteBox.getWhiteBox().NMTAllocTest()) {
    1.50 +      throw new Exception("Call to WB API NMTAllocTest() failed");
    1.51 +    }
    1.52 +
    1.53 +    // Use WB API to ensure that all data has been merged before we continue
    1.54 +    if (!WhiteBox.getWhiteBox().NMTWaitForDataMerge()) {
    1.55 +      throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
    1.56 +    }
    1.57 +
    1.58 +    // Run 'jcmd <pid> VM.native_memory summary'
    1.59 +    pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
    1.60 +    output = new OutputAnalyzer(pb.start());
    1.61 +    output.shouldContain("Test (reserved=512KB, committed=512KB)");
    1.62 +
    1.63 +    // Free the memory allocated by NMTAllocTest
    1.64 +    if (!WhiteBox.getWhiteBox().NMTFreeTestMemory()) {
    1.65 +      throw new Exception("Call to WB API NMTFreeTestMemory() failed");
    1.66 +    }
    1.67 +
    1.68 +    // Use WB API to ensure that all data has been merged before we continue
    1.69 +    if (!WhiteBox.getWhiteBox().NMTWaitForDataMerge()) {
    1.70 +      throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
    1.71 +    }
    1.72 +    output = new OutputAnalyzer(pb.start());
    1.73 +    output.shouldNotContain("Test (reserved=");
    1.74 +  }
    1.75 +}

mercurial