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