0N/A/*
2014N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_RUNTIME_JAVA_HPP
1879N/A#define SHARE_VM_RUNTIME_JAVA_HPP
1879N/A
1879N/A#include "runtime/os.hpp"
1879N/A
0N/A// Register function to be called by before_exit
0N/Aextern "C" { void register_on_exit_function(void (*func)(void)) ;}
0N/A
0N/A// Execute code before all handles are released and thread is killed; prologue to vm_exit
0N/Aextern void before_exit(JavaThread * thread);
0N/A
0N/A// Forced VM exit (i.e, internal error or JVM_Exit)
0N/Aextern void vm_exit(int code);
0N/A
0N/A// Wrapper for ::exit()
0N/Aextern void vm_direct_exit(int code);
0N/A
0N/A// Shutdown the VM but do not exit the process
0N/Aextern void vm_shutdown();
0N/A// Shutdown the VM and abort the process
227N/Aextern void vm_abort(bool dump_core=true);
0N/A
0N/A// Trigger any necessary notification of the VM being shutdown
0N/Aextern void notify_vm_shutdown();
0N/A
0N/A// VM exit if error occurs during initialization of VM
0N/Aextern void vm_exit_during_initialization(Handle exception);
2062N/Aextern void vm_exit_during_initialization(Symbol* exception_name, const char* message);
0N/Aextern void vm_exit_during_initialization(const char* error, const char* message = NULL);
0N/Aextern void vm_shutdown_during_initialization(const char* error, const char* message = NULL);
0N/A
242N/A/**
242N/A * Discovering the JDK_Version during initialization is tricky when the
242N/A * running JDK is less than JDK6. For JDK6 and greater, a "GetVersion"
242N/A * function exists in libjava.so and we simply call it during the
242N/A * 'initialize()' call to find the version. For JDKs with version < 6, no
242N/A * such call exists and we have to probe the JDK in order to determine
242N/A * the exact version. This probing cannot happen during late in
242N/A * the VM initialization process so there's a period of time during
242N/A * initialization when we don't know anything about the JDK version other than
242N/A * that it less than version 6. This is the "partially initialized" time,
242N/A * when we can answer only certain version queries (such as, is the JDK
242N/A * version greater than 5? Answer: no). Once the JDK probing occurs, we
242N/A * know the version and are considered fully initialized.
242N/A */
242N/Aclass JDK_Version VALUE_OBJ_CLASS_SPEC {
0N/A friend class VMStructs;
242N/A friend class Universe;
242N/A friend void JDK_Version_init();
0N/A private:
242N/A
242N/A static JDK_Version _current;
3847N/A static const char* _runtime_name;
4063N/A static const char* _runtime_version;
242N/A
242N/A // In this class, we promote the minor version of release to be the
242N/A // major version for releases >= 5 in anticipation of the JDK doing the
242N/A // same thing. For example, we represent "1.5.0" as major version 5 (we
242N/A // drop the leading 1 and use 5 as the 'major').
242N/A
242N/A uint8_t _major;
242N/A uint8_t _minor;
242N/A uint8_t _micro;
242N/A uint8_t _update;
242N/A uint8_t _special;
242N/A uint8_t _build;
242N/A
242N/A // If partially initialized, the above fields are invalid and we know
242N/A // that we're less than major version 6.
242N/A bool _partially_initialized;
242N/A
242N/A bool _thread_park_blocker;
2751N/A bool _pending_list_uses_discovered_field;
2014N/A bool _post_vm_init_hook_enabled;
242N/A
242N/A bool is_valid() const {
242N/A return (_major != 0 || _partially_initialized);
242N/A }
242N/A
242N/A // initializes or partially initializes the _current static field
242N/A static void initialize();
242N/A
242N/A // Completes initialization for a pre-JDK6 version.
242N/A static void fully_initialize(uint8_t major, uint8_t minor = 0,
242N/A uint8_t micro = 0, uint8_t update = 0);
0N/A
0N/A public:
242N/A
242N/A // Returns true if the the current version has only been partially initialized
242N/A static bool is_partially_initialized() {
242N/A return _current._partially_initialized;
242N/A }
242N/A
242N/A JDK_Version() : _major(0), _minor(0), _micro(0), _update(0),
242N/A _special(0), _build(0), _partially_initialized(false),
2751N/A _thread_park_blocker(false), _post_vm_init_hook_enabled(false),
2751N/A _pending_list_uses_discovered_field(false) {}
0N/A
242N/A JDK_Version(uint8_t major, uint8_t minor = 0, uint8_t micro = 0,
242N/A uint8_t update = 0, uint8_t special = 0, uint8_t build = 0,
2751N/A bool thread_park_blocker = false, bool post_vm_init_hook_enabled = false,
2751N/A bool pending_list_uses_discovered_field = false) :
242N/A _major(major), _minor(minor), _micro(micro), _update(update),
242N/A _special(special), _build(build), _partially_initialized(false),
2014N/A _thread_park_blocker(thread_park_blocker),
2751N/A _post_vm_init_hook_enabled(post_vm_init_hook_enabled),
2751N/A _pending_list_uses_discovered_field(pending_list_uses_discovered_field) {}
176N/A
242N/A // Returns the current running JDK version
242N/A static JDK_Version current() { return _current; }
242N/A
242N/A // Factory methods for convenience
242N/A static JDK_Version jdk(uint8_t m) {
242N/A return JDK_Version(m);
242N/A }
242N/A
242N/A static JDK_Version jdk_update(uint8_t major, uint8_t update_number) {
242N/A return JDK_Version(major, 0, 0, update_number);
176N/A }
176N/A
242N/A uint8_t major_version() const { return _major; }
242N/A uint8_t minor_version() const { return _minor; }
242N/A uint8_t micro_version() const { return _micro; }
242N/A uint8_t update_version() const { return _update; }
242N/A uint8_t special_update_version() const { return _special; }
242N/A uint8_t build_number() const { return _build; }
242N/A
242N/A bool supports_thread_park_blocker() const {
242N/A return _thread_park_blocker;
242N/A }
2014N/A bool post_vm_init_hook_enabled() const {
2014N/A return _post_vm_init_hook_enabled;
2014N/A }
2751N/A // For compatibility wrt pre-4965777 JDK's
2751N/A bool pending_list_uses_discovered_field() const {
2751N/A return _pending_list_uses_discovered_field;
2751N/A }
242N/A
242N/A // Performs a full ordering comparison using all fields (update, build, etc.)
242N/A int compare(const JDK_Version& other) const;
242N/A
242N/A /**
242N/A * Performs comparison using only the major version, returning negative
242N/A * if the major version of 'this' is less than the parameter, 0 if it is
242N/A * equal, and a positive value if it is greater.
242N/A */
242N/A int compare_major(int version) const {
242N/A if (_partially_initialized) {
242N/A if (version >= 6) {
242N/A return -1;
242N/A } else {
242N/A assert(false, "Can't make this comparison during init time");
242N/A return -1; // conservative
242N/A }
176N/A } else {
242N/A return major_version() - version;
176N/A }
176N/A }
0N/A
242N/A void to_string(char* buffer, size_t buflen) const;
242N/A
3847N/A static const char* runtime_name() {
3847N/A return _runtime_name;
3847N/A }
3847N/A static void set_runtime_name(const char* name) {
3847N/A _runtime_name = name;
3847N/A }
3847N/A
4063N/A static const char* runtime_version() {
4063N/A return _runtime_version;
4063N/A }
4063N/A static void set_runtime_version(const char* version) {
4063N/A _runtime_version = version;
4063N/A }
4063N/A
242N/A // Convenience methods for queries on the current major/minor version
242N/A static bool is_jdk12x_version() {
242N/A return current().compare_major(2) == 0;
242N/A }
242N/A
242N/A static bool is_jdk13x_version() {
242N/A return current().compare_major(3) == 0;
242N/A }
242N/A
242N/A static bool is_jdk14x_version() {
242N/A return current().compare_major(4) == 0;
242N/A }
242N/A
242N/A static bool is_jdk15x_version() {
242N/A return current().compare_major(5) == 0;
242N/A }
242N/A
242N/A static bool is_jdk16x_version() {
242N/A return current().compare_major(6) == 0;
242N/A }
242N/A
242N/A static bool is_jdk17x_version() {
242N/A return current().compare_major(7) == 0;
242N/A }
242N/A
3733N/A static bool is_jdk18x_version() {
3733N/A return current().compare_major(8) == 0;
3733N/A }
3733N/A
242N/A static bool is_gte_jdk13x_version() {
242N/A return current().compare_major(3) >= 0;
242N/A }
0N/A
0N/A static bool is_gte_jdk14x_version() {
242N/A return current().compare_major(4) >= 0;
0N/A }
242N/A
242N/A static bool is_gte_jdk15x_version() {
242N/A return current().compare_major(5) >= 0;
242N/A }
242N/A
0N/A static bool is_gte_jdk16x_version() {
242N/A return current().compare_major(6) >= 0;
0N/A }
0N/A
0N/A static bool is_gte_jdk17x_version() {
242N/A return current().compare_major(7) >= 0;
0N/A }
3733N/A
3733N/A static bool is_gte_jdk18x_version() {
3733N/A return current().compare_major(8) >= 0;
3733N/A }
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_RUNTIME_JAVA_HPP