1 /*
2 * Copyright (c) 1997, 2025, 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 "utilities/globalDefinitions.hpp"
29
30 class Handle;
31 class JavaThread;
32 class Symbol;
33
34 // Execute code before all handles are released and thread is killed; prologue to vm_exit
35 extern void before_exit(JavaThread * thread, bool halt = false);
36
37 // Forced VM exit (i.e, internal error or JVM_Exit)
38 extern void vm_exit(int code);
39
40 // Wrapper for ::exit()
41 extern void vm_direct_exit(int code);
42 extern void vm_direct_exit(int code, const char* message);
43
44 // Shutdown the VM but do not exit the process
45 extern void vm_shutdown();
46 // Shutdown the VM and abort the process
47 extern void vm_abort(bool dump_core=true);
48
49 // Trigger any necessary notification of the VM being shutdown
50 extern void notify_vm_shutdown();
51
52 // VM exit if error occurs during initialization of VM
53 extern void vm_exit_during_initialization();
54 extern void vm_exit_during_initialization(Handle exception);
55 extern void vm_exit_during_initialization(Symbol* exception_name, const char* message);
56 extern void vm_exit_during_initialization(const char* error, const char* message = nullptr);
57 extern void vm_shutdown_during_initialization(const char* error, const char* message = nullptr);
58
59 extern void vm_exit_during_cds_dumping(const char* error, const char* message = nullptr);
60
61 // This is defined in linkType.cpp due to linking restraints
62 extern bool is_vm_statically_linked();
63
64 /**
65 * With the integration of the changes to handle the version string
66 * as defined by JEP-223, most of the code related to handle the version
67 * string prior to JDK 1.6 was removed (partial initialization)
68 */
69 class JDK_Version {
70 friend class Universe;
71 friend void JDK_Version_init();
72 private:
73
74 static JDK_Version _current;
75 static const char* _java_version;
76 static const char* _runtime_name;
77 static const char* _runtime_version;
78 static const char* _runtime_vendor_version;
79 static const char* _runtime_vendor_vm_bug_url;
80
81 int _major;
82 int _minor;
83 int _security;
84 int _patch;
85 int _build;
86
87 bool is_valid() const {
88 return (_major != 0);
89 }
90
91 // initializes or partially initializes the _current static field
92 static void initialize();
93
94 public:
95
96 JDK_Version() :
97 _major(0), _minor(0), _security(0), _patch(0), _build(0)
98 {}
99
100 JDK_Version(int major, int minor = 0, int security = 0,
101 int patch = 0, int build = 0) :
102 _major(major), _minor(minor), _security(security), _patch(patch), _build(build)
103 {}
104
105 // Returns the current running JDK version
106 static JDK_Version current() { return _current; }
107
108 // Factory methods for convenience
109 static JDK_Version jdk(int m) {
110 return JDK_Version(m);
111 }
112
113 static JDK_Version undefined() {
114 return JDK_Version(0);
115 }
116
117 bool is_undefined() const {
118 return _major == 0;
119 }
120
121 int major_version() const { return _major; }
122 int minor_version() const { return _minor; }
123 int security_version() const { return _security; }
124 int patch_version() const { return _patch; }
125 int build_number() const { return _build; }
126
127 // Performs a full ordering comparison using all fields (patch, build, etc.)
128 int compare(const JDK_Version& other) const;
129
130 void to_string(char* buffer, size_t buflen) const;
131
132 static const char* java_version() {
133 return _java_version;
134 }
135 static void set_java_version(const char* version);
136
137 static const char* runtime_name() {
138 return _runtime_name;
139 }
140 static void set_runtime_name(const char* name);
141
142 static const char* runtime_version() {
143 return _runtime_version;
144 }
145 static void set_runtime_version(const char* version);
146
147 static const char* runtime_vendor_version() {
148 return _runtime_vendor_version;
149 }
150 static void set_runtime_vendor_version(const char* vendor_version);
151
152 static const char* runtime_vendor_vm_bug_url() {
153 return _runtime_vendor_vm_bug_url;
154 }
155 static void set_runtime_vendor_vm_bug_url(const char* vendor_vm_bug_url);
156 };
157
158 #endif // SHARE_RUNTIME_JAVA_HPP