예제 #1
0
 private void test() {
   for (TestCaseData testCase : TestCaseData.values()) {
     System.out.println(testCase);
     OutputAnalyzer oa;
     try {
       oa =
           ProcessTools.executeTestJvmAllArgs(
               "-XX:+UnlockExperimentalVMOptions",
               "-XX:+EnableJVMCI",
               "-Xbootclasspath/a:.",
               DebugOutputTest.Worker.class.getName(),
               testCase.name());
     } catch (Throwable e) {
       e.printStackTrace();
       throw new Error("Problems running child process", e);
     }
     if (testCase.expectedException != null) {
       oa.shouldHaveExitValue(1);
       oa.shouldContain(testCase.expectedException.getName());
     } else {
       oa.shouldHaveExitValue(0);
       oa.shouldContain(new String(testCase.getExpected()));
     }
   }
 }
예제 #2
0
  /** Compile two module definitions used by the test, jdk.test and jdk.translet. */
  public static void main(String[] args) throws Exception {

    boolean compiled;
    // Compile module jdk.test declaration
    compiled = CompilerUtils.compile(SRC_DIR.resolve("jdk.test"), MODS_DIR.resolve("jdk.test"));
    if (!compiled) {
      throw new RuntimeException("Test failed to compile module jdk.test");
    }

    // Compile module jdk.translet declaration
    compiled =
        CompilerUtils.compile(
            SRC_DIR.resolve("jdk.translet"),
            MODS_DIR.resolve("jdk.translet"),
            "--add-exports=jdk.test/test=jdk.translet",
            "-p",
            MODS_DIR.toString());
    if (!compiled) {
      throw new RuntimeException("Test failed to compile module jdk.translet");
    }

    // Sanity check that the test, jdk.test/test/MainGC.java,
    // correctly walks module jdk.test's reads list and package
    // test's, defined to module jdk.translet, export list at
    // GC safepoints.
    ProcessBuilder pb =
        ProcessTools.createJavaProcessBuilder(
            "-Xlog:modules=trace", "-p", MODS_DIR.toString(), "-m", "jdk.test/test.MainGC");
    OutputAnalyzer oa = new OutputAnalyzer(pb.start());
    oa.shouldContain("package test defined in module jdk.test, exports list being walked")
        .shouldContain("module jdk.test reads list being walked")
        .shouldHaveExitValue(0);
  }
예제 #3
0
 private static void verifyCodeHeapNotExists(ProcessBuilder pb, String... heapNames)
     throws Exception {
   OutputAnalyzer out = new OutputAnalyzer(pb.start());
   out.shouldHaveExitValue(0);
   for (String name : heapNames) {
     out.shouldNotContain(name);
   }
 }
예제 #4
0
 private static void verifySegmentedCodeCache(ProcessBuilder pb, boolean enabled)
     throws Exception {
   OutputAnalyzer out = new OutputAnalyzer(pb.start());
   out.shouldHaveExitValue(0);
   if (enabled) {
     try {
       // Non-nmethod code heap should be always available with the segmented code cache
       out.shouldContain(NON_METHOD);
     } catch (RuntimeException e) {
       // Check if TieredCompilation is disabled (in a client VM)
       if (!out.getOutput().contains("-XX:+TieredCompilation not supported in this VM")) {
         // Code cache is not segmented
         throw new RuntimeException("No code cache segmentation.");
       }
     }
   } else {
     out.shouldNotContain(NON_METHOD);
   }
 }
예제 #5
0
  public void run(CommandExecutor executor) throws ClassNotFoundException {

    // create a classloader and load our special class
    dummyloader = new DummyClassLoader();
    Class<?> c = Class.forName("TestClass", true, dummyloader);
    if (c.getClassLoader() != dummyloader) {
      Assert.fail("TestClass defined by wrong classloader: " + c.getClassLoader());
    }

    OutputAnalyzer output = executor.execute("VM.classloader_stats");
    Iterator<String> lines = output.asLines().iterator();
    while (lines.hasNext()) {
      String line = lines.next();
      Matcher m = clLine.matcher(line);
      if (m.matches()) {
        // verify that DummyClassLoader has loaded 1 class and 1 anonymous class
        if (m.group(4).equals("ClassLoaderStatsTest$DummyClassLoader")) {
          System.out.println("line: " + line);
          if (!m.group(1).equals("1")) {
            Assert.fail("Should have loaded 1 class: " + line);
          }
          checkPositiveInt(m.group(2));
          checkPositiveInt(m.group(3));

          String next = lines.next();
          System.out.println("next: " + next);
          Matcher m1 = anonLine.matcher(next);
          m1.matches();
          if (!m1.group(1).equals("1")) {
            Assert.fail("Should have loaded 1 anonymous class, but found : " + m1.group(1));
          }
          checkPositiveInt(m1.group(2));
          checkPositiveInt(m1.group(3));
        }
      }
    }
  }
 private static void verifyDynamicNumberOfGCThreads(OutputAnalyzer output) {
   output.shouldHaveExitValue(0); // test should run succesfully
   output.shouldContain("new_active_workers");
 }
예제 #7
0
 private static void failsWith(ProcessBuilder pb, String message) throws Exception {
   OutputAnalyzer out = new OutputAnalyzer(pb.start());
   out.shouldContain(message);
   out.shouldHaveExitValue(1);
 }
예제 #8
0
 public static void runTest(String test, String result) throws Throwable {
   ProcessBuilder pb =
       ProcessTools.createJavaProcessBuilder("-cp", testsrc + File.separator + "test.jar", test);
   OutputAnalyzer output = new OutputAnalyzer(pb.start());
   output.shouldContain("java.lang.ClassFormatError: Multiple " + result);
 }
예제 #9
0
  public static void main(String args[]) throws Exception {
    is_64_bit_system = (Platform.is64bit());

    OutputAnalyzer output;
    whiteBox = WhiteBox.getWhiteBox();

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

    AllocThread[] alloc_threads = new AllocThread[256];
    ReleaseThread[] release_threads = new ReleaseThread[64];

    int index;
    // Create many allocation threads
    for (index = 0; index < alloc_threads.length; index++) {
      alloc_threads[index] = new AllocThread();
    }

    // Fewer release threads
    for (index = 0; index < release_threads.length; index++) {
      release_threads[index] = new ReleaseThread();
    }

    if (is_64_bit_system()) {
      sleep_wait(2 * 60 * 1000);
    } else {
      sleep_wait(60 * 1000);
    }
    // pause the stress test
    phase = TestPhase.pause;
    while (pause_count.intValue() < alloc_threads.length + release_threads.length) {
      sleep_wait(10);
    }

    long mallocd_total_in_KB = (mallocd_total + K / 2) / K;

    // Now check if the result from NMT matches the total memory allocated.
    String expected_test_summary =
        "Test (reserved=" + mallocd_total_in_KB + "KB, committed=" + mallocd_total_in_KB + "KB)";
    // 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(expected_test_summary);

    // Release all allocated memory
    phase = TestPhase.release;
    synchronized (mallocd_memory) {
      mallocd_memory.notifyAll();
    }

    // Join all threads
    for (index = 0; index < alloc_threads.length; index++) {
      try {
        alloc_threads[index].join();
      } catch (InterruptedException e) {
      }
    }

    for (index = 0; index < release_threads.length; index++) {
      try {
        release_threads[index].join();
      } catch (InterruptedException e) {
      }
    }

    // All test memory allocated should be released
    output = new OutputAnalyzer(pb.start());
    output.shouldNotContain("Test (reserved=");

    // Verify that tracking level has not been downgraded
    pb.command(
        new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
    output = new OutputAnalyzer(pb.start());
    output.shouldNotContain("Tracking level has been downgraded due to lack of resources");
  }