< prev index next >

src/java.base/share/classes/java/lang/VersionProps.java.template

Print this page
rev 52426 : 8185496: Improve performance of system properties initialization in initPhase1
8213424: VersionProps duplicate and skipped initialization


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.io.PrintStream;
  29 import java.util.Arrays;
  30 import java.util.List;
  31 import java.util.Optional;

  32 
  33 class VersionProps {
  34 
  35     private static final String launcher_name =
  36         "@@LAUNCHER_NAME@@";
  37 
  38     private static final String java_version =
  39         "@@VERSION_SHORT@@";
  40 
  41     private static final String java_version_date =
  42         "@@VERSION_DATE@@";
  43 
  44     private static final String java_runtime_name =
  45         "@@RUNTIME_NAME@@";
  46 
  47     private static final String java_runtime_version =
  48         "@@VERSION_STRING@@";
  49 
  50     private static final String VERSION_NUMBER =
  51         "@@VERSION_NUMBER@@";
  52 
  53     private static final String VERSION_BUILD =
  54         "@@VERSION_BUILD@@";
  55 
  56     private static final String VERSION_PRE =
  57         "@@VERSION_PRE@@";
  58 
  59     private static final String VERSION_OPT =
  60         "@@VERSION_OPT@@";
  61 
  62     private static final boolean isLTS =
  63         "@@VERSION_OPT@@".startsWith("LTS");
  64 
  65     private static final String VENDOR_VERSION_STRING =
  66         "@@VENDOR_VERSION_STRING@@";
  67 
  68     private static final String vendor_version =
  69         (VENDOR_VERSION_STRING.length() > 0
  70          ? " " + VENDOR_VERSION_STRING : "");
  71 
  72     static {
  73         init();
  74     }
  75 
  76     public static void init() {
  77         System.setProperty("java.version", java_version);
  78         System.setProperty("java.version.date", java_version_date);
  79         System.setProperty("java.runtime.version", java_runtime_version);
  80         System.setProperty("java.runtime.name", java_runtime_name);
  81         if (VENDOR_VERSION_STRING.length() > 0)
  82             System.setProperty("java.vendor.version", VENDOR_VERSION_STRING);
  83     }
  84 
  85     private static int parseVersionNumber(String version, int prevIndex, int index) {
  86         if (index - prevIndex > 1 &&
  87             Character.digit(version.charAt(prevIndex), 10) <= 0)
  88             throw new IllegalArgumentException("Leading zeros not supported (" +
  89                     version.substring(prevIndex, index) + ")");
  90         return Integer.parseInt(version, prevIndex, index, 10);
  91     }
  92 
  93     // This method is reflectively used by regression tests.
  94     static List<Integer> parseVersionNumbers(String version) {
  95         // Let's find the size of an array required to hold $VNUM components
  96         int size = 0;
  97         int prevIndex = 0;
  98         do {
  99             prevIndex = version.indexOf('.', prevIndex) + 1;
 100             size++;
 101         } while (prevIndex > 0);
 102         Integer[] verNumbers = new Integer[size];




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.io.PrintStream;
  29 import java.util.Arrays;
  30 import java.util.List;
  31 import java.util.Optional;
  32 import java.util.Properties;
  33 
  34 class VersionProps {
  35 
  36     private static final String launcher_name =
  37         "@@LAUNCHER_NAME@@";
  38 
  39     private static final String java_version =
  40         "@@VERSION_SHORT@@";
  41 
  42     private static final String java_version_date =
  43         "@@VERSION_DATE@@";
  44 
  45     private static final String java_runtime_name =
  46         "@@RUNTIME_NAME@@";
  47 
  48     private static final String java_runtime_version =
  49         "@@VERSION_STRING@@";
  50 
  51     private static final String VERSION_NUMBER =
  52         "@@VERSION_NUMBER@@";
  53 
  54     private static final String VERSION_BUILD =
  55         "@@VERSION_BUILD@@";
  56 
  57     private static final String VERSION_PRE =
  58         "@@VERSION_PRE@@";
  59 
  60     private static final String VERSION_OPT =
  61         "@@VERSION_OPT@@";
  62 
  63     private static final boolean isLTS =
  64         "@@VERSION_OPT@@".startsWith("LTS");
  65 
  66     private static final String VENDOR_VERSION_STRING =
  67         "@@VENDOR_VERSION_STRING@@";
  68 
  69     private static final String vendor_version =
  70         (VENDOR_VERSION_STRING.length() > 0
  71          ? " " + VENDOR_VERSION_STRING : "");
  72 
  73     public static void init(Properties props) {
  74         props.setProperty("java.version", java_version);
  75         props.setProperty("java.version.date", java_version_date);
  76         props.setProperty("java.runtime.version", java_runtime_version);
  77         props.setProperty("java.runtime.name", java_runtime_name);




  78         if (VENDOR_VERSION_STRING.length() > 0)
  79             props.setProperty("java.vendor.version", VENDOR_VERSION_STRING);
  80     }
  81 
  82     private static int parseVersionNumber(String version, int prevIndex, int index) {
  83         if (index - prevIndex > 1 &&
  84             Character.digit(version.charAt(prevIndex), 10) <= 0)
  85             throw new IllegalArgumentException("Leading zeros not supported (" +
  86                     version.substring(prevIndex, index) + ")");
  87         return Integer.parseInt(version, prevIndex, index, 10);
  88     }
  89 
  90     // This method is reflectively used by regression tests.
  91     static List<Integer> parseVersionNumbers(String version) {
  92         // Let's find the size of an array required to hold $VNUM components
  93         int size = 0;
  94         int prevIndex = 0;
  95         do {
  96             prevIndex = version.indexOf('.', prevIndex) + 1;
  97             size++;
  98         } while (prevIndex > 0);
  99         Integer[] verNumbers = new Integer[size];


< prev index next >