java.hpp revision 1472:c18cbe5936b8
1151497Sru/*
2151497Sru * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
375584Sru * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
475584Sru *
575584Sru * This code is free software; you can redistribute it and/or modify it
675584Sru * under the terms of the GNU General Public License version 2 only, as
775584Sru * published by the Free Software Foundation.
875584Sru *
975584Sru * This code is distributed in the hope that it will be useful, but WITHOUT
1075584Sru * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1175584Sru * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1275584Sru * version 2 for more details (a copy is included in the LICENSE file that
1375584Sru * accompanied this code).
1475584Sru *
1575584Sru * You should have received a copy of the GNU General Public License version
1675584Sru * 2 along with this work; if not, write to the Free Software Foundation,
1775584Sru * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1875584Sru *
19151497Sru * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2075584Sru * or visit www.oracle.com if you need additional information or have any
2175584Sru * questions.
2275584Sru *
23151497Sru */
24151497Sru
25151497Sru// Register function to be called by before_exit
26151497Sruextern "C" { void register_on_exit_function(void (*func)(void)) ;}
27151497Sru
2875584Sru// Execute code before all handles are released and thread is killed; prologue to vm_exit
2975584Sruextern void before_exit(JavaThread * thread);
3075584Sru
3175584Sru// Forced VM exit (i.e, internal error or JVM_Exit)
3275584Sruextern void vm_exit(int code);
3375584Sru
3475584Sru// Wrapper for ::exit()
3575584Sruextern void vm_direct_exit(int code);
3675584Sru
3775584Sru// Shutdown the VM but do not exit the process
3875584Sruextern void vm_shutdown();
3975584Sru// Shutdown the VM and abort the process
4075584Sruextern void vm_abort(bool dump_core=true);
4175584Sru
4275584Sru// Trigger any necessary notification of the VM being shutdown
4375584Sruextern void notify_vm_shutdown();
4475584Sru
4575584Sru// VM exit if error occurs during initialization of VM
4675584Sruextern void vm_exit_during_initialization(Handle exception);
4775584Sruextern void vm_exit_during_initialization(symbolHandle exception_name, const char* message);
4875584Sruextern void vm_exit_during_initialization(const char* error, const char* message = NULL);
4975584Sruextern void vm_shutdown_during_initialization(const char* error, const char* message = NULL);
5075584Sru
5175584Sru/**
5275584Sru * Discovering the JDK_Version during initialization is tricky when the
5375584Sru * running JDK is less than JDK6.  For JDK6 and greater, a "GetVersion"
5475584Sru * function exists in libjava.so and we simply call it during the
5575584Sru * 'initialize()' call to find the version.  For JDKs with version < 6, no
5675584Sru * such call exists and we have to probe the JDK in order to determine
5775584Sru * the exact version.  This probing cannot happen during late in
5875584Sru * the VM initialization process so there's a period of time during
5975584Sru * initialization when we don't know anything about the JDK version other than
6075584Sru * that it less than version 6.  This is the "partially initialized" time,
6175584Sru * when we can answer only certain version queries (such as, is the JDK
6275584Sru * version greater than 5?  Answer: no).  Once the JDK probing occurs, we
6375584Sru * know the version and are considered fully initialized.
6475584Sru */
6575584Sruclass JDK_Version VALUE_OBJ_CLASS_SPEC {
6675584Sru  friend class VMStructs;
6775584Sru  friend class Universe;
6875584Sru  friend void JDK_Version_init();
6975584Sru private:
70151497Sru
71151497Sru  static JDK_Version _current;
72151497Sru
73151497Sru  // In this class, we promote the minor version of release to be the
74  // major version for releases >= 5 in anticipation of the JDK doing the
75  // same thing.  For example, we represent "1.5.0" as major version 5 (we
76  // drop the leading 1 and use 5 as the 'major').
77
78  uint8_t _major;
79  uint8_t _minor;
80  uint8_t _micro;
81  uint8_t _update;
82  uint8_t _special;
83  uint8_t _build;
84
85  // If partially initialized, the above fields are invalid and we know
86  // that we're less than major version 6.
87  bool _partially_initialized;
88
89  bool _thread_park_blocker;
90
91  bool is_valid() const {
92    return (_major != 0 || _partially_initialized);
93  }
94
95  // initializes or partially initializes the _current static field
96  static void initialize();
97
98  // Completes initialization for a pre-JDK6 version.
99  static void fully_initialize(uint8_t major, uint8_t minor = 0,
100                               uint8_t micro = 0, uint8_t update = 0);
101
102 public:
103
104  // Returns true if the the current version has only been partially initialized
105  static bool is_partially_initialized() {
106    return _current._partially_initialized;
107  }
108
109  JDK_Version() : _major(0), _minor(0), _micro(0), _update(0),
110                  _special(0), _build(0), _partially_initialized(false),
111                  _thread_park_blocker(false) {}
112
113  JDK_Version(uint8_t major, uint8_t minor = 0, uint8_t micro = 0,
114              uint8_t update = 0, uint8_t special = 0, uint8_t build = 0,
115              bool thread_park_blocker = false) :
116      _major(major), _minor(minor), _micro(micro), _update(update),
117      _special(special), _build(build), _partially_initialized(false),
118      _thread_park_blocker(thread_park_blocker) {}
119
120  // Returns the current running JDK version
121  static JDK_Version current() { return _current; }
122
123  // Factory methods for convenience
124  static JDK_Version jdk(uint8_t m) {
125    return JDK_Version(m);
126  }
127
128  static JDK_Version jdk_update(uint8_t major, uint8_t update_number) {
129    return JDK_Version(major, 0, 0, update_number);
130  }
131
132  uint8_t major_version() const          { return _major; }
133  uint8_t minor_version() const          { return _minor; }
134  uint8_t micro_version() const          { return _micro; }
135  uint8_t update_version() const         { return _update; }
136  uint8_t special_update_version() const { return _special; }
137  uint8_t build_number() const           { return _build; }
138
139  bool supports_thread_park_blocker() const {
140    return _thread_park_blocker;
141  }
142
143  // Performs a full ordering comparison using all fields (update, build, etc.)
144  int compare(const JDK_Version& other) const;
145
146  /**
147   * Performs comparison using only the major version, returning negative
148   * if the major version of 'this' is less than the parameter, 0 if it is
149   * equal, and a positive value if it is greater.
150   */
151  int compare_major(int version) const {
152    if (_partially_initialized) {
153      if (version >= 6) {
154        return -1;
155      } else {
156        assert(false, "Can't make this comparison during init time");
157        return -1; // conservative
158      }
159    } else {
160      return major_version() - version;
161    }
162  }
163
164  void to_string(char* buffer, size_t buflen) const;
165
166  // Convenience methods for queries on the current major/minor version
167  static bool is_jdk12x_version() {
168    return current().compare_major(2) == 0;
169  }
170
171  static bool is_jdk13x_version() {
172    return current().compare_major(3) == 0;
173  }
174
175  static bool is_jdk14x_version() {
176    return current().compare_major(4) == 0;
177  }
178
179  static bool is_jdk15x_version() {
180    return current().compare_major(5) == 0;
181  }
182
183  static bool is_jdk16x_version() {
184    return current().compare_major(6) == 0;
185  }
186
187  static bool is_jdk17x_version() {
188    return current().compare_major(7) == 0;
189  }
190
191  static bool is_gte_jdk13x_version() {
192    return current().compare_major(3) >= 0;
193  }
194
195  static bool is_gte_jdk14x_version() {
196    return current().compare_major(4) >= 0;
197  }
198
199  static bool is_gte_jdk15x_version() {
200    return current().compare_major(5) >= 0;
201  }
202
203  static bool is_gte_jdk16x_version() {
204    return current().compare_major(6) >= 0;
205  }
206
207  static bool is_gte_jdk17x_version() {
208    return current().compare_major(7) >= 0;
209  }
210};
211