1 /*
2  * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #ifndef SHARE_RUNTIME_JAVA_HPP
26 #define SHARE_RUNTIME_JAVA_HPP
27 
28 #include "runtime/os.hpp"
29 
30 // Execute code before all handles are released and thread is killed; prologue to vm_exit
31 extern void before_exit(JavaThread * thread);
32 
33 // Forced VM exit (i.e, internal error or JVM_Exit)
34 extern void vm_exit(int code);
35 
36 // Wrapper for ::exit()
37 extern void vm_direct_exit(int code);
38 extern void vm_direct_exit(int code, const char* message);
39 
40 // Shutdown the VM but do not exit the process
41 extern void vm_shutdown();
42 // Shutdown the VM and abort the process
43 extern void vm_abort(bool dump_core=true);
44 
45 // Trigger any necessary notification of the VM being shutdown
46 extern void notify_vm_shutdown();
47 
48 // VM exit if error occurs during initialization of VM
49 extern void vm_exit_during_initialization();
50 extern void vm_exit_during_initialization(Handle exception);
51 extern void vm_exit_during_initialization(Symbol* exception_name, const char* message);
52 extern void vm_exit_during_initialization(const char* error, const char* message = NULL);
53 extern void vm_shutdown_during_initialization(const char* error, const char* message = NULL);
54 
55 extern void vm_exit_during_cds_dumping(const char* error, const char* message = NULL);
56 
57 /**
58  * With the integration of the changes to handle the version string
59  * as defined by JEP-223, most of the code related to handle the version
60  * string prior to JDK 1.6 was removed (partial initialization)
61  */
62 class JDK_Version {
63   friend class VMStructs;
64   friend class Universe;
65   friend void JDK_Version_init();
66  private:
67 
68   static JDK_Version _current;
69   static const char* _java_version;
70   static const char* _runtime_name;
71   static const char* _runtime_version;
72   static const char* _runtime_vendor_version;
73   static const char* _runtime_vendor_vm_bug_url;
74 
75   uint8_t _major;
76   uint8_t _minor;
77   uint8_t _security;
78   uint8_t _patch;
79   uint8_t _build;
80 
is_valid() const81   bool is_valid() const {
82     return (_major != 0);
83   }
84 
85   // initializes or partially initializes the _current static field
86   static void initialize();
87 
88  public:
89 
JDK_Version()90   JDK_Version() :
91       _major(0), _minor(0), _security(0), _patch(0), _build(0)
92       {}
93 
JDK_Version(uint8_t major,uint8_t minor=0,uint8_t security=0,uint8_t patch=0,uint8_t build=0)94   JDK_Version(uint8_t major, uint8_t minor = 0, uint8_t security = 0,
95               uint8_t patch = 0, uint8_t build = 0) :
96       _major(major), _minor(minor), _security(security), _patch(patch), _build(build)
97       {}
98 
99   // Returns the current running JDK version
current()100   static JDK_Version current() { return _current; }
101 
102   // Factory methods for convenience
jdk(uint8_t m)103   static JDK_Version jdk(uint8_t m) {
104     return JDK_Version(m);
105   }
106 
undefined()107   static JDK_Version undefined() {
108     return JDK_Version(0);
109   }
110 
is_undefined() const111   bool is_undefined() const {
112     return _major == 0;
113   }
114 
major_version() const115   uint8_t major_version() const          { return _major; }
minor_version() const116   uint8_t minor_version() const          { return _minor; }
security_version() const117   uint8_t security_version() const       { return _security; }
patch_version() const118   uint8_t patch_version() const          { return _patch; }
build_number() const119   uint8_t build_number() const           { return _build; }
120 
121   // Performs a full ordering comparison using all fields (patch, build, etc.)
122   int compare(const JDK_Version& other) const;
123 
124   /**
125    * Performs comparison using only the major version, returning negative
126    * if the major version of 'this' is less than the parameter, 0 if it is
127    * equal, and a positive value if it is greater.
128    */
compare_major(int version) const129   int compare_major(int version) const {
130       return major_version() - version;
131   }
132 
133   void to_string(char* buffer, size_t buflen) const;
134 
java_version()135   static const char* java_version() {
136     return _java_version;
137   }
set_java_version(const char * version)138   static void set_java_version(const char* version) {
139     _java_version = version;
140   }
141 
runtime_name()142   static const char* runtime_name() {
143     return _runtime_name;
144   }
set_runtime_name(const char * name)145   static void set_runtime_name(const char* name) {
146     _runtime_name = name;
147   }
148 
runtime_version()149   static const char* runtime_version() {
150     return _runtime_version;
151   }
set_runtime_version(const char * version)152   static void set_runtime_version(const char* version) {
153     _runtime_version = version;
154   }
155 
runtime_vendor_version()156   static const char* runtime_vendor_version() {
157     return _runtime_vendor_version;
158   }
set_runtime_vendor_version(const char * vendor_version)159   static void set_runtime_vendor_version(const char* vendor_version) {
160     _runtime_vendor_version = vendor_version;
161   }
162 
runtime_vendor_vm_bug_url()163   static const char* runtime_vendor_vm_bug_url() {
164     return _runtime_vendor_vm_bug_url;
165   }
set_runtime_vendor_vm_bug_url(const char * vendor_vm_bug_url)166   static void set_runtime_vendor_vm_bug_url(const char* vendor_vm_bug_url) {
167     _runtime_vendor_vm_bug_url = vendor_vm_bug_url;
168   }
169 
170 };
171 
172 #endif // SHARE_RUNTIME_JAVA_HPP
173