Java Code Examples for sun.hotspot.WhiteBox#NMTFree

The following examples show how to use sun.hotspot.WhiteBox#NMTFree . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MallocTestType.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  // Use WB API to alloc and free with the mtTest type
  long memAlloc3 = wb.NMTMalloc(128 * 1024);
  long memAlloc2 = wb.NMTMalloc(256 * 1024);
  wb.NMTFree(memAlloc3);
  long memAlloc1 = wb.NMTMalloc(512 * 1024);
  wb.NMTFree(memAlloc2);

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=512KB, committed=512KB)");

  // Free the memory allocated by NMTAllocTest
  wb.NMTFree(memAlloc1);

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 2
Source File: MallocTestType.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  // Use WB API to alloc and free with the mtTest type
  long memAlloc3 = wb.NMTMalloc(128 * 1024);
  long memAlloc2 = wb.NMTMalloc(256 * 1024);
  wb.NMTFree(memAlloc3);
  long memAlloc1 = wb.NMTMalloc(512 * 1024);
  wb.NMTFree(memAlloc2);

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=512KB, committed=512KB)");

  // Free the memory allocated by NMTAllocTest
  wb.NMTFree(memAlloc1);

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 3
Source File: MallocTestType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  // Use WB API to alloc and free with the mtTest type
  long memAlloc3 = wb.NMTMalloc(128 * 1024);
  long memAlloc2 = wb.NMTMalloc(256 * 1024);
  wb.NMTFree(memAlloc3);
  long memAlloc1 = wb.NMTMalloc(512 * 1024);
  wb.NMTFree(memAlloc2);

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=512KB, committed=512KB)");

  // Free the memory allocated by NMTAllocTest
  wb.NMTFree(memAlloc1);

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 4
Source File: MallocTestType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  // Use WB API to alloc and free with the mtTest type
  long memAlloc3 = wb.NMTMalloc(128 * 1024);
  long memAlloc2 = wb.NMTMalloc(256 * 1024);
  wb.NMTFree(memAlloc3);
  long memAlloc1 = wb.NMTMalloc(512 * 1024);
  wb.NMTFree(memAlloc2);

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=512KB, committed=512KB)");

  // Free the memory allocated by NMTAllocTest
  wb.NMTFree(memAlloc1);

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 5
Source File: MallocSiteHashOverflow.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

        // Size of entries based on malloc tracking header defined in mallocTracker.hpp
        // For 32-bit systems, create 257 malloc sites with the same hash bucket to overflow a hash bucket
        long entries = 257;

        OutputAnalyzer output;
        WhiteBox wb = WhiteBox.getWhiteBox();
        int MAX_HASH_SIZE = wb.NMTGetHashSize();

        // Grab my own PID
        String pid = Integer.toString(ProcessTools.getProcessId());
        ProcessBuilder pb = new ProcessBuilder();

        // Verify that current tracking level is "detail"
        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
        output = new OutputAnalyzer(pb.start());
        output.shouldContain("Native Memory Tracking Statistics");

        // Attempt to cause NMT to downgrade tracking level by allocating small amounts
        // of memory with random pseudo call stack
        int pc = 1;
        for (int i = 0; i < entries; i++) {
            long addr = wb.NMTMallocWithPseudoStack(1, pc);
            if (addr == 0) {
                throw new RuntimeException("NMTMallocWithPseudoStack: out of memory");
            }
            // We free memory here since it doesn't affect pseudo malloc alloc site hash table entries
            wb.NMTFree(addr);
            pc += MAX_HASH_SIZE;
            if (i == entries) {
                // Verify that tracking has been downgraded
                pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
                output = new OutputAnalyzer(pb.start());
                output.shouldContain("Tracking level has been downgraded due to lack of resources");
            }
        }
    }
 
Example 6
Source File: MallocTestType.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  // Use WB API to alloc and free with the mtTest type
  long memAlloc3 = wb.NMTMalloc(128 * 1024);
  long memAlloc2 = wb.NMTMalloc(256 * 1024);
  wb.NMTFree(memAlloc3);
  long memAlloc1 = wb.NMTMalloc(512 * 1024);
  wb.NMTFree(memAlloc2);

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=512KB, committed=512KB)");

  // Free the memory allocated by NMTAllocTest
  wb.NMTFree(memAlloc1);

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }
  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 7
Source File: MallocTestType.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  // Use WB API to alloc and free with the mtTest type
  long memAlloc3 = wb.NMTMalloc(128 * 1024);
  long memAlloc2 = wb.NMTMalloc(256 * 1024);
  wb.NMTFree(memAlloc3);
  long memAlloc1 = wb.NMTMalloc(512 * 1024);
  wb.NMTFree(memAlloc2);

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=512KB, committed=512KB)");

  // Free the memory allocated by NMTAllocTest
  wb.NMTFree(memAlloc1);

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }
  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 8
Source File: MallocSiteHashOverflow.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

        // Size of entries based on malloc tracking header defined in mallocTracker.hpp
        // For 32-bit systems, create 257 malloc sites with the same hash bucket to overflow a hash bucket
        long entries = 257;

        OutputAnalyzer output;
        WhiteBox wb = WhiteBox.getWhiteBox();
        int MAX_HASH_SIZE = wb.NMTGetHashSize();

        // Grab my own PID
        String pid = Integer.toString(ProcessTools.getProcessId());
        ProcessBuilder pb = new ProcessBuilder();

        // Verify that current tracking level is "detail"
        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
        output = new OutputAnalyzer(pb.start());
        output.shouldContain("Native Memory Tracking Statistics");

        // Attempt to cause NMT to downgrade tracking level by allocating small amounts
        // of memory with random pseudo call stack
        int pc = 1;
        for (int i = 0; i < entries; i++) {
            long addr = wb.NMTMallocWithPseudoStack(1, pc);
            if (addr == 0) {
                throw new RuntimeException("NMTMallocWithPseudoStack: out of memory");
            }
            // We free memory here since it doesn't affect pseudo malloc alloc site hash table entries
            wb.NMTFree(addr);
            pc += MAX_HASH_SIZE;
            if (i == entries) {
                // Verify that tracking has been downgraded
                pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
                output = new OutputAnalyzer(pb.start());
                output.shouldContain("Tracking level has been downgraded due to lack of resources");
            }
        }
    }
 
Example 9
Source File: MallocSiteHashOverflow.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

        // Size of entries based on malloc tracking header defined in mallocTracker.hpp
        // For 32-bit systems, create 257 malloc sites with the same hash bucket to overflow a hash bucket
        long entries = 257;

        OutputAnalyzer output;
        WhiteBox wb = WhiteBox.getWhiteBox();
        int MAX_HASH_SIZE = wb.NMTGetHashSize();

        // Grab my own PID
        String pid = Integer.toString(ProcessTools.getProcessId());
        ProcessBuilder pb = new ProcessBuilder();

        // Verify that current tracking level is "detail"
        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
        output = new OutputAnalyzer(pb.start());
        output.shouldContain("Native Memory Tracking Statistics");

        // Attempt to cause NMT to downgrade tracking level by allocating small amounts
        // of memory with random pseudo call stack
        int pc = 1;
        for (int i = 0; i < entries; i++) {
            long addr = wb.NMTMallocWithPseudoStack(1, pc);
            if (addr == 0) {
                throw new RuntimeException("NMTMallocWithPseudoStack: out of memory");
            }
            // We free memory here since it doesn't affect pseudo malloc alloc site hash table entries
            wb.NMTFree(addr);
            pc += MAX_HASH_SIZE;
            if (i == entries) {
                // Verify that tracking has been downgraded
                pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
                output = new OutputAnalyzer(pb.start());
                output.shouldContain("Tracking level has been downgraded due to lack of resources");
            }
        }
    }
 
Example 10
Source File: ThreadedMallocTestType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  final WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  Thread allocThread = new Thread() {
    public void run() {
      // Alloc memory using the WB api
      memAlloc1 = wb.NMTMalloc(128 * 1024);
      memAlloc2 = wb.NMTMalloc(256 * 1024);
      memAlloc3 = wb.NMTMalloc(512 * 1024);
    }
  };

  allocThread.start();
  allocThread.join();

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=896KB, committed=896KB)");

  Thread freeThread = new Thread() {
    public void run() {
      // Free the memory allocated by NMTMalloc
      wb.NMTFree(memAlloc1);
      wb.NMTFree(memAlloc2);
      wb.NMTFree(memAlloc3);
    }
  };

  freeThread.start();
  freeThread.join();

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 11
Source File: MallocRoundingReportTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    OutputAnalyzer output;
    WhiteBox wb = WhiteBox.getWhiteBox();

    // Grab my own PID
    String pid = Integer.toString(ProcessTools.getProcessId());
    ProcessBuilder pb = new ProcessBuilder();

    long[] additionalBytes = {0, 1, 512, 650};
    long[] kByteSize = {1024, 2048};
    long mallocd_total = 0;
    for ( int i = 0; i < kByteSize.length; i++)
    {
        for (int j = 0; j < (additionalBytes.length); j++) {
            long curKB = kByteSize[i] + additionalBytes[j];
            // round up/down to the nearest KB to match NMT reporting
            long numKB = (curKB % kByteSize[i] >= 512) ? ((curKB / K) + 1) : curKB / K;
            // Use WB API to alloc and free with the mtTest type
            mallocd_total = wb.NMTMalloc(curKB);
            // Run 'jcmd <pid> VM.native_memory summary', check for expected output
            // NMT does not track memory allocations less than 1KB, and rounds to the nearest KB
            String expectedOut = ("Test (reserved=" + numKB + "KB, committed=" + numKB + "KB)");

            pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" });
            output = new OutputAnalyzer(pb.start());
            output.shouldContain(expectedOut);

            wb.NMTFree(mallocd_total);
            // Run 'jcmd <pid> VM.native_memory summary', check for expected output
            pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" });
            output = new OutputAnalyzer(pb.start());
            output.shouldNotContain("Test (reserved=");
        }
    }
}
 
Example 12
Source File: MallocSiteTypeChange.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
      OutputAnalyzer output;
      WhiteBox wb = WhiteBox.getWhiteBox();

      // Grab my own PID
      String pid = Long.toString(ProcessTools.getProcessId());
      ProcessBuilder pb = new ProcessBuilder();

      int pc = 1;
      long addr = wb.NMTMallocWithPseudoStack(4 * 1024, pc);

      // Verify that current tracking level is "detail"
      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("Test (reserved=4KB, committed=4KB)");

      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("Baseline succeeded");

      wb.NMTFree(addr);
      addr = wb.NMTMallocWithPseudoStackAndType(2 * 1024, pc, 7 /* mtInternal */ );
      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("(malloc=0KB type=Test -4KB)");
      output.shouldContain("(malloc=2KB type=Internal +2KB #1 +1)");
      output.shouldHaveExitValue(0);
}
 
Example 13
Source File: MallocSiteTypeChange.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
      OutputAnalyzer output;
      WhiteBox wb = WhiteBox.getWhiteBox();

      // Grab my own PID
      String pid = Long.toString(ProcessTools.getProcessId());
      ProcessBuilder pb = new ProcessBuilder();

      int pc = 1;
      long addr = wb.NMTMallocWithPseudoStack(4 * 1024, pc);

      // Verify that current tracking level is "detail"
      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("Test (reserved=4KB, committed=4KB)");

      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("Baseline succeeded");

      wb.NMTFree(addr);
      addr = wb.NMTMallocWithPseudoStackAndType(2 * 1024, pc, 7 /* mtInternal */ );
      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("(malloc=0KB type=Test -4KB)");
      output.shouldContain("(malloc=2KB type=Internal +2KB #1 +1)");
      output.shouldHaveExitValue(0);
}
 
Example 14
Source File: ThreadedMallocTestType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  final WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  Thread allocThread = new Thread() {
    public void run() {
      // Alloc memory using the WB api
      memAlloc1 = wb.NMTMalloc(128 * 1024);
      memAlloc2 = wb.NMTMalloc(256 * 1024);
      memAlloc3 = wb.NMTMalloc(512 * 1024);
    }
  };

  allocThread.start();
  allocThread.join();

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=896KB, committed=896KB)");

  Thread freeThread = new Thread() {
    public void run() {
      // Free the memory allocated by NMTMalloc
      wb.NMTFree(memAlloc1);
      wb.NMTFree(memAlloc2);
      wb.NMTFree(memAlloc3);
    }
  };

  freeThread.start();
  freeThread.join();

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 15
Source File: ThreadedMallocTestType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  final WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  Thread allocThread = new Thread() {
    public void run() {
      // Alloc memory using the WB api
      memAlloc1 = wb.NMTMalloc(128 * 1024);
      memAlloc2 = wb.NMTMalloc(256 * 1024);
      memAlloc3 = wb.NMTMalloc(512 * 1024);
    }
  };

  allocThread.start();
  allocThread.join();

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=896KB, committed=896KB)");

  Thread freeThread = new Thread() {
    public void run() {
      // Free the memory allocated by NMTMalloc
      wb.NMTFree(memAlloc1);
      wb.NMTFree(memAlloc2);
      wb.NMTFree(memAlloc3);
    }
  };

  freeThread.start();
  freeThread.join();

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 16
Source File: MallocRoundingReportTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    OutputAnalyzer output;
    WhiteBox wb = WhiteBox.getWhiteBox();

    // Grab my own PID
    String pid = Integer.toString(ProcessTools.getProcessId());
    ProcessBuilder pb = new ProcessBuilder();

    long[] additionalBytes = {0, 1, 512, 650};
    long[] kByteSize = {1024, 2048};
    long mallocd_total = 0;
    for ( int i = 0; i < kByteSize.length; i++)
    {
        for (int j = 0; j < (additionalBytes.length); j++) {
            long curKB = kByteSize[i] + additionalBytes[j];
            // round up/down to the nearest KB to match NMT reporting
            long numKB = (curKB % kByteSize[i] >= 512) ? ((curKB / K) + 1) : curKB / K;
            // Use WB API to alloc and free with the mtTest type
            mallocd_total = wb.NMTMalloc(curKB);
            // Run 'jcmd <pid> VM.native_memory summary', check for expected output
            // NMT does not track memory allocations less than 1KB, and rounds to the nearest KB
            String expectedOut = ("Test (reserved=" + numKB + "KB, committed=" + numKB + "KB)");

            pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" });
            output = new OutputAnalyzer(pb.start());
            output.shouldContain(expectedOut);

            wb.NMTFree(mallocd_total);
            // Run 'jcmd <pid> VM.native_memory summary', check for expected output
            pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" });
            output = new OutputAnalyzer(pb.start());
            output.shouldNotContain("Test (reserved=");
        }
    }
}
 
Example 17
Source File: MallocSiteHashOverflow.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

        // Size of entries based on malloc tracking header defined in mallocTracker.hpp
        // For 32-bit systems, create 257 malloc sites with the same hash bucket to overflow a hash bucket
        long entries = 257;

        OutputAnalyzer output;
        WhiteBox wb = WhiteBox.getWhiteBox();
        int MAX_HASH_SIZE = wb.NMTGetHashSize();

        // Grab my own PID
        String pid = Integer.toString(ProcessTools.getProcessId());
        ProcessBuilder pb = new ProcessBuilder();

        // Verify that current tracking level is "detail"
        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
        output = new OutputAnalyzer(pb.start());
        output.shouldContain("Native Memory Tracking Statistics");

        // Attempt to cause NMT to downgrade tracking level by allocating small amounts
        // of memory with random pseudo call stack
        int pc = 1;
        for (int i = 0; i < entries; i++) {
            long addr = wb.NMTMallocWithPseudoStack(1, pc);
            if (addr == 0) {
                throw new RuntimeException("NMTMallocWithPseudoStack: out of memory");
            }
            // We free memory here since it doesn't affect pseudo malloc alloc site hash table entries
            wb.NMTFree(addr);
            pc += MAX_HASH_SIZE;
            if (i == entries) {
                // Verify that tracking has been downgraded
                pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
                output = new OutputAnalyzer(pb.start());
                output.shouldContain("Tracking level has been downgraded due to lack of resources");
            }
        }
    }
 
Example 18
Source File: ThreadedMallocTestType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  final WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  Thread allocThread = new Thread() {
    public void run() {
      // Alloc memory using the WB api
      memAlloc1 = wb.NMTMalloc(128 * 1024);
      memAlloc2 = wb.NMTMalloc(256 * 1024);
      memAlloc3 = wb.NMTMalloc(512 * 1024);
    }
  };

  allocThread.start();
  allocThread.join();

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=896KB, committed=896KB)");

  Thread freeThread = new Thread() {
    public void run() {
      // Free the memory allocated by NMTMalloc
      wb.NMTFree(memAlloc1);
      wb.NMTFree(memAlloc2);
      wb.NMTFree(memAlloc3);
    }
  };

  freeThread.start();
  freeThread.join();

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 19
Source File: MallocRoundingReportTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    OutputAnalyzer output;
    WhiteBox wb = WhiteBox.getWhiteBox();

    // Grab my own PID
    String pid = Integer.toString(ProcessTools.getProcessId());
    ProcessBuilder pb = new ProcessBuilder();

    long[] additionalBytes = {0, 1, 512, 650};
    long[] kByteSize = {1024, 2048};
    long mallocd_total = 0;
    for ( int i = 0; i < kByteSize.length; i++)
    {
        for (int j = 0; j < (additionalBytes.length); j++) {
            long curKB = kByteSize[i] + additionalBytes[j];
            // round up/down to the nearest KB to match NMT reporting
            long numKB = (curKB % kByteSize[i] >= 512) ? ((curKB / K) + 1) : curKB / K;
            // Use WB API to alloc and free with the mtTest type
            mallocd_total = wb.NMTMalloc(curKB);
            // Run 'jcmd <pid> VM.native_memory summary', check for expected output
            // NMT does not track memory allocations less than 1KB, and rounds to the nearest KB
            String expectedOut = ("Test (reserved=" + numKB + "KB, committed=" + numKB + "KB)");

            pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" });
            output = new OutputAnalyzer(pb.start());
            output.shouldContain(expectedOut);

            wb.NMTFree(mallocd_total);
            // Run 'jcmd <pid> VM.native_memory summary', check for expected output
            pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" });
            output = new OutputAnalyzer(pb.start());
            output.shouldNotContain("Test (reserved=");
        }
    }
}
 
Example 20
Source File: ThreadedMallocTestType.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
  OutputAnalyzer output;
  final WhiteBox wb = WhiteBox.getWhiteBox();

  // Grab my own PID
  String pid = Integer.toString(ProcessTools.getProcessId());
  ProcessBuilder pb = new ProcessBuilder();

  Thread allocThread = new Thread() {
    public void run() {
      // Alloc memory using the WB api
      memAlloc1 = wb.NMTMalloc(128 * 1024);
      memAlloc2 = wb.NMTMalloc(256 * 1024);
      memAlloc3 = wb.NMTMalloc(512 * 1024);
    }
  };

  allocThread.start();
  allocThread.join();

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }

  // Run 'jcmd <pid> VM.native_memory summary'
  pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
  output = new OutputAnalyzer(pb.start());
  output.shouldContain("Test (reserved=896KB, committed=896KB)");

  Thread freeThread = new Thread() {
    public void run() {
      // Free the memory allocated by NMTMalloc
      wb.NMTFree(memAlloc1);
      wb.NMTFree(memAlloc2);
      wb.NMTFree(memAlloc3);
    }
  };

  freeThread.start();
  freeThread.join();

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }

  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}