Java Code Examples for jdk.test.lib.Platform#isDebugBuild()

The following examples show how to use jdk.test.lib.Platform#isDebugBuild() . 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: RunUnitTestsConcurrently.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
  if (!Platform.isDebugBuild() || !Platform.is64bit()) {
    return;
  }
  wb = WhiteBox.getWhiteBox();
  System.out.println("Starting threads");

  int threads = Integer.valueOf(args[0]);
  timeout = Long.valueOf(args[1]);

  timeStamp = System.currentTimeMillis();

  Thread[] threadsArray = new Thread[threads];
  for (int i = 0; i < threads; i++) {
    threadsArray[i] = new Thread(new Worker());
    threadsArray[i].start();
  }
  for (int i = 0; i < threads; i++) {
    threadsArray[i].join();
  }

  System.out.println("Quitting test.");
}
 
Example 2
Source File: AssertSafepointCheckConsistency2.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(false, false);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
              "-Xbootclasspath/a:.",
              "-XX:+UnlockDiagnosticVMOptions",
              "-XX:+WhiteBoxAPI",
              "-XX:-TransmitErrorReport",
              "-XX:-CreateCoredumpOnCrash",
              "-Xmx32m",
              "AssertSafepointCheckConsistency2",
              "test");

        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldContain("assert").shouldContain("never");
    }
}
 
Example 3
Source File: AssertSafepointCheckConsistency1.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(true, true);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
              "-Xbootclasspath/a:.",
              "-XX:+UnlockDiagnosticVMOptions",
              "-XX:+WhiteBoxAPI",
              "-XX:-TransmitErrorReport",
              "-XX:-CreateCoredumpOnCrash",
              "-Xmx32m",
              "AssertSafepointCheckConsistency1",
              "test");
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldContain("assert").shouldContain("always");
    }
}
 
Example 4
Source File: AssertSafepointCheckConsistency4.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(true, false);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
           "-Xbootclasspath/a:.",
           "-XX:+UnlockDiagnosticVMOptions",
           "-XX:+WhiteBoxAPI",
           "-XX:-TransmitErrorReport",
           "-XX:-CreateCoredumpOnCrash",
           "-Xmx32m",
           "AssertSafepointCheckConsistency4",
           "test");

        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldNotContain("assert");
        output.shouldNotContain("never");
        output.shouldNotContain("always");
    }
}
 
Example 5
Source File: AssertSafepointCheckConsistency3.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(false, true);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
              "-Xbootclasspath/a:.",
              "-XX:+UnlockDiagnosticVMOptions",
              "-XX:+WhiteBoxAPI",
              "-XX:-TransmitErrorReport",
              "-XX:-CreateCoredumpOnCrash",
              "-Xmx32m",
              "AssertSafepointCheckConsistency3",
              "test");

        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldNotContain("assert");
        output.shouldNotContain("never");
        output.shouldNotContain("always");
    }
}
 
Example 6
Source File: RangeCheck.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    if (!Platform.isDebugBuild()) {
        System.out.println("Testing assert which requires a debug build. Passing silently.");
        return;
    }

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
            true,
            "-Xmx32m",
            "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
            "-XX:-TransmitErrorReport",
            "-XX:-CreateCoredumpOnCrash",
            "-XX:-InlineUnsafeOps", // The compiler intrinsics doesn't have the assert
            DummyClassWithMainRangeCheck.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldMatch("assert\\(byte_offset < p_size\\) failed: Unsafe access: offset \\d+ > object's size \\d+");
}
 
Example 7
Source File: RemovedDevelopFlagsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    if (Platform.isDebugBuild()){
        exec("TraceClassInitialization", "-Xlog:class+init");
        exec("TraceClassLoaderData", "-Xlog:class+loader+data");
        exec("TraceDefaultMethods", "-Xlog:defaultmethods=debug");
        exec("TraceItables", "-Xlog:itables=debug");
        exec("TraceSafepoint", "-Xlog:safepoint=debug");
        exec("TraceStartupTime", "-Xlog:startuptime");
        exec("TraceVMOperation", "-Xlog:vmoperation=debug");
        exec("PrintVtables", "-Xlog:vtables=debug");
        exec("VerboseVerification", "-Xlog:verification");
    }
}
 
Example 8
Source File: ErrorHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Test is only applicable for debug builds
    if (!Platform.isDebugBuild()) {
        return;
    }
    // Keep this in sync with hotspot/src/share/vm/utilities/debug.cpp
    int i = 1;
    String[] strings = {
        "assert(str == NULL) failed: expected null",
        "assert(num == 1023 && *str == 'X') failed: num=",
        "guarantee(str == NULL) failed: expected null",
        "guarantee(num == 1023 && *str == 'X') failed: num=",
        "fatal error: expected null",
        "fatal error: num=",
        "fatal error: this message should be truncated during formatting",
        "ChunkPool::allocate",
        "Error: ShouldNotCall()",
        "Error: ShouldNotReachHere()",
        "Error: Unimplemented()"
    };

    String[] patterns = {
        "(SIGILL|SIGSEGV|EXCEPTION_ACCESS_VIOLATION).* at pc=",
        "(SIGBUS|SIGSEGV|SIGILL|EXCEPTION_ACCESS_VIOLATION).* at pc="
    };

    for (String s : strings) {
        runTest(i++).shouldContain(s);
    }

    for (String p : patterns) {
        runTest(i++).shouldMatch(p);
    }
}
 
Example 9
Source File: TestOnError.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (!Platform.isDebugBuild()) {
        System.out.println("Test requires a non-product build - skipping");
        return;
    }

    String msg = "Test Succeeded";

    // Execute the VM so that a
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
       "-XX:-TransmitErrorReport",
       "-XX:-CreateCoredumpOnCrash",
       "-XX:ErrorHandlerTest=12", // trigger potential SEGV
       "-XX:OnError=echo " + msg,
       TestOnError.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    /* Actual output will include:
       #
       # -XX:OnError="echo Test Succeeded"
       #   Executing /bin/sh -c "echo Test Succeeded"...
       Test Succeeded

       So we don't want to match on the "# Executing ..." line, and they
       both get written to stdout.
    */
    output.stdoutShouldMatch("^" + msg); // match start of line only
    System.out.println("PASSED");
}
 
Example 10
Source File: SafeFetchInErrorHandlingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

    if (!Platform.isDebugBuild() || Platform.isZero()) {
      return;
    }

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-XX:+UnlockDiagnosticVMOptions",
        "-Xmx100M",
        "-XX:ErrorHandlerTest=14",
        "-XX:+TestSafeFetchInErrorHandler",
        "-XX:-CreateCoredumpOnCrash",
        "-version");

    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());

    // we should have crashed with a SIGSEGV
    output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
    output_detail.shouldMatch("# +(?:SIGSEGV|EXCEPTION_ACCESS_VIOLATION).*");

    // extract hs-err file
    String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
    if (hs_err_file == null) {
      throw new RuntimeException("Did not find hs-err file in output.\n");
    }

    File f = new File(hs_err_file);
    if (!f.exists()) {
      throw new RuntimeException("hs-err file missing at "
          + f.getAbsolutePath() + ".\n");
    }

    System.out.println("Found hs_err file. Scanning...");

    FileInputStream fis = new FileInputStream(f);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String line = null;

    Pattern [] pattern = new Pattern[] {
        Pattern.compile("Will test SafeFetch..."),
        Pattern.compile("SafeFetch OK."),
    };
    int currentPattern = 0;

    String lastLine = null;
    while ((line = br.readLine()) != null) {
      if (currentPattern < pattern.length) {
        if (pattern[currentPattern].matcher(line).matches()) {
          System.out.println("Found: " + line + ".");
          currentPattern ++;
        }
      }
      lastLine = line;
    }
    br.close();

    if (currentPattern < pattern.length) {
      throw new RuntimeException("hs-err file incomplete (first missing pattern: " +  currentPattern + ")");
    }

    if (!lastLine.equals("END.")) {
      throw new RuntimeException("hs-err file incomplete (missing END marker.)");
    } else {
      System.out.println("End marker found.");
    }

    System.out.println("OK.");

  }
 
Example 11
Source File: SecondaryErrorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

    // Do not execute for windows, nor for non-debug builds
    if (Platform.isWindows()) {
      return;
    }

    if (!Platform.isDebugBuild()) {
      return;
    }

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-XX:+UnlockDiagnosticVMOptions",
        "-Xmx100M",
        "-XX:-CreateCoredumpOnCrash",
        "-XX:ErrorHandlerTest=15",
        "-XX:TestCrashInErrorHandler=14",
        "-version");

    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());

    // we should have crashed with a SIGFPE
    output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
    output_detail.shouldMatch("# +SIGFPE.*");

    // extract hs-err file
    String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
    if (hs_err_file == null) {
      throw new RuntimeException("Did not find hs-err file in output.\n");
    }

    // scan hs-err file: File should contain the "[error occurred during error reporting..]"
    // markers which show that the secondary error handling kicked in and handled the
    // error successfully. As an added test, we check that the last line contains "END.",
    // which is an end marker written in the last step and proves that hs-err file was
    // completely written.
    File f = new File(hs_err_file);
    if (!f.exists()) {
      throw new RuntimeException("hs-err file missing at "
          + f.getAbsolutePath() + ".\n");
    }

    System.out.println("Found hs_err file. Scanning...");

    FileInputStream fis = new FileInputStream(f);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String line = null;

    Pattern [] pattern = new Pattern[] {
        Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),
        Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 1\\).*\\]"),
        Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),
        Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 2\\).*\\]"),
    };
    int currentPattern = 0;

    String lastLine = null;
    while ((line = br.readLine()) != null) {
      if (currentPattern < pattern.length) {
        if (pattern[currentPattern].matcher(line).matches()) {
          System.out.println("Found: " + line + ".");
          currentPattern ++;
        }
      }
      lastLine = line;
    }
    br.close();

    if (currentPattern < pattern.length) {
      throw new RuntimeException("hs-err file incomplete (first missing pattern: " +  currentPattern + ")");
    }

    if (!lastLine.equals("END.")) {
      throw new RuntimeException("hs-err file incomplete (missing END marker.)");
    } else {
      System.out.println("End marker found.");
    }

    System.out.println("OK.");

  }
 
Example 12
Source File: CheckSegmentedCodeCache.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
* Check the result of segmented code cache related VM options.
*/
public static void main(String[] args) throws Exception {
    ProcessBuilder pb;

    // Disabled with ReservedCodeCacheSize < 240MB
    pb = ProcessTools.createJavaProcessBuilder("-XX:ReservedCodeCacheSize=239m",
                                               "-XX:+PrintCodeCache", "-version");
    verifySegmentedCodeCache(pb, false);

    // Disabled without TieredCompilation
    pb = ProcessTools.createJavaProcessBuilder("-XX:-TieredCompilation",
                                               "-XX:+PrintCodeCache", "-version");
    verifySegmentedCodeCache(pb, false);

    // Enabled with TieredCompilation and ReservedCodeCacheSize >= 240MB
    pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",
                                               "-XX:ReservedCodeCacheSize=240m",
                                               "-XX:+PrintCodeCache", "-version");
    verifySegmentedCodeCache(pb, true);
    pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",
                                               "-XX:ReservedCodeCacheSize=400m",
                                               "-XX:+PrintCodeCache", "-version");
    verifySegmentedCodeCache(pb, true);

    // Always enabled if SegmentedCodeCache is set
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
                                               "-XX:-TieredCompilation",
                                               "-XX:ReservedCodeCacheSize=239m",
                                               "-XX:+PrintCodeCache", "-version");
    verifySegmentedCodeCache(pb, true);

    // The profiled and non-profiled code heaps should not be available in
    // interpreter-only mode
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
                                               "-Xint",
                                               "-XX:+PrintCodeCache", "-version");
    verifyCodeHeapNotExists(pb, PROFILED, NON_PROFILED);

    // If we stop compilation at CompLevel_none or CompLevel_simple we
    // don't need a profiled code heap.
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
                                               "-XX:TieredStopAtLevel=0",
                                               "-XX:+PrintCodeCache", "-version");
    verifyCodeHeapNotExists(pb, PROFILED);
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
                                               "-XX:TieredStopAtLevel=1",
                                               "-XX:+PrintCodeCache", "-version");
    verifyCodeHeapNotExists(pb, PROFILED);

    // Fails with too small non-nmethod code heap size
    pb = ProcessTools.createJavaProcessBuilder("-XX:NonNMethodCodeHeapSize=100K");
    failsWith(pb, "Invalid NonNMethodCodeHeapSize");

    // Fails if code heap sizes do not add up
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
                                               "-XX:ReservedCodeCacheSize=10M",
                                               "-XX:NonNMethodCodeHeapSize=5M",
                                               "-XX:ProfiledCodeHeapSize=5M",
                                               "-XX:NonProfiledCodeHeapSize=5M");
    failsWith(pb, "Invalid code heap sizes");

    // Fails if not enough space for VM internal code
    long minUseSpace = WHITE_BOX.getUintxVMFlag("CodeCacheMinimumUseSpace");
    // minimum size: CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)
    long minSize = (Platform.isDebugBuild() ? 3 : 1) * minUseSpace;
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
                                               "-XX:ReservedCodeCacheSize=" + minSize,
                                               "-XX:InitialCodeCacheSize=100K");
    failsWith(pb, "Not enough space in non-nmethod code heap to run VM");
}