changeset 13142:c95bba55626c

8139986: Store debug level in java.vm.debug and conditionally print in "java -version" Reviewed-by: ihse, dcubed, ksrini, dholmes Contributed-by: alejandro.murillo@oracle.com, kumar.x.srinivasan@oracle.com
author amurillo
date Wed, 04 Nov 2015 16:02:53 -0800
parents 1c369f2fc224
children a56eb2b071a4
files src/java.base/share/classes/sun/misc/Version.java.template test/lib/testlibrary/jdk/testlibrary/Platform.java test/tools/launcher/VersionCheck.java
diffstat 3 files changed, 48 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/sun/misc/Version.java.template	Sun Nov 01 09:49:05 2015 -0800
+++ b/src/java.base/share/classes/sun/misc/Version.java.template	Wed Nov 04 16:02:53 2015 -0800
@@ -98,7 +98,15 @@
 
         /* Second line: runtime version (ie, libraries). */
 
-        ps.print(java_runtime_name + " (build " + java_runtime_version);
+        String jdk_debug_level = System.getProperty("jdk.debug", "release");
+        /* Debug level is not printed for "release" builds */
+        if ("release".equals(jdk_debug_level)) {
+            jdk_debug_level = "";
+        } else {
+            jdk_debug_level = jdk_debug_level + " ";
+        }
+
+        ps.print(java_runtime_name + " (" + jdk_debug_level + "build " + java_runtime_version);
 
         if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
             // embedded builds report headless state
@@ -110,7 +118,7 @@
         String java_vm_name    = System.getProperty("java.vm.name");
         String java_vm_version = System.getProperty("java.vm.version");
         String java_vm_info    = System.getProperty("java.vm.info");
-        ps.println(java_vm_name + " (build " + java_vm_version + ", " +
+        ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " +
                    java_vm_info + ")");
     }
 
--- a/test/lib/testlibrary/jdk/testlibrary/Platform.java	Sun Nov 01 09:49:05 2015 -0800
+++ b/test/lib/testlibrary/jdk/testlibrary/Platform.java	Wed Nov 04 16:02:53 2015 -0800
@@ -31,7 +31,7 @@
     private static final String osName      = System.getProperty("os.name");
     private static final String dataModel   = System.getProperty("sun.arch.data.model");
     private static final String vmVersion   = System.getProperty("java.vm.version");
-    private static final String javaVersion = System.getProperty("java.version");
+    private static final String jdkDebug    = System.getProperty("jdk.debug");
     private static final String osArch      = System.getProperty("os.arch");
     private static final String vmName      = System.getProperty("java.vm.name");
     private static final String userName    = System.getProperty("user.name");
@@ -99,8 +99,7 @@
     }
 
     public static boolean isDebugBuild() {
-        return (vmVersion.toLowerCase().contains("debug") ||
-                javaVersion.toLowerCase().contains("debug"));
+        return (jdkDebug.toLowerCase().contains("debug"));
     }
 
     public static String getVMVersion() {
--- a/test/tools/launcher/VersionCheck.java	Sun Nov 01 09:49:05 2015 -0800
+++ b/test/tools/launcher/VersionCheck.java	Wed Nov 04 16:02:53 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 6545058 6611182 8016209
+ * @bug 6545058 6611182 8016209 8139986
  * @summary validate and test -version, -fullversion, and internal, as well as
  *          sanity checks if a tool can be launched.
  * @compile VersionCheck.java
@@ -115,12 +115,20 @@
     static String refVersion;
     static String refFullVersion;
 
+    static String getAllVersionLines(String... argv) {
+        return getVersion0(true, argv);
+    }
+
     static String getVersion(String... argv) {
+        return getVersion0(false, argv);
+    }
+
+    static String getVersion0(boolean allLines, String... argv) {
         TestHelper.TestResult tr = doExec(argv);
         StringBuilder out = new StringBuilder();
         // remove the HotSpot line
         for (String x : tr.testOutput) {
-            if (!x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
+            if (allLines || !x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
                 out = out.append(x + "\n");
             }
         }
@@ -202,6 +210,28 @@
         return failcount == 0;
     }
 
+    static boolean testDebugVersion() {
+        String jdkType = System.getProperty("jdk.debug", "release");
+        String versionLines = getAllVersionLines(javaCmd, "-version");
+        if ("release".equals(jdkType)) {
+            jdkType = "";
+        } else {
+            jdkType = jdkType + " ";
+        }
+        String tofind = "(" + jdkType + "build";
+        int idx = versionLines.indexOf(tofind);
+        if (idx < 0) {
+            System.out.println("Did not find first instance of " + tofind);
+            return false;
+        }
+        idx =  versionLines.indexOf(tofind, idx + 1);
+        if (idx < 0) {
+            System.out.println("Did not find first instance of " + tofind);
+            return false;
+        }
+        return true;
+    }
+
     // Initialize
     static void init() {
         refVersion = getVersion(javaCmd, "-version");
@@ -212,7 +242,8 @@
         init();
         if (compareJVersionStrings() &&
                 compareInternalStrings() &&
-                testToolVersion()) {
+                testToolVersion() &&
+                testDebugVersion()) {
             System.out.println("All Version string comparisons: PASS");
         } else {
             throw new AssertionError("Some tests failed");
@@ -220,7 +251,7 @@
     }
 
     static class ToolFilter implements FileFilter {
-        final Iterable<String> exclude ;
+        final Iterable<String> exclude;
         protected ToolFilter(String... exclude) {
             List<String> tlist = new ArrayList<>();
             this.exclude = tlist;