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