1 /*
   2  * Copyright (c) 2017, 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 #ifndef SHARE_JVMCI_JVMCI_HPP
  25 #define SHARE_JVMCI_JVMCI_HPP
  26 
  27 #include "compiler/compilerDefinitions.hpp"
  28 #include "utilities/exceptions.hpp"
  29 
  30 class BoolObjectClosure;
  31 class constantPoolHandle;
  32 class JavaThread;
  33 class JVMCIEnv;
  34 class JVMCIRuntime;
  35 class Metadata;
  36 class MetadataHandleBlock;
  37 class OopClosure;
  38 class OopStorage;
  39 
  40 struct _jmetadata;
  41 typedef struct _jmetadata *jmetadata;
  42 
  43 class JVMCI : public AllStatic {
  44   friend class JVMCIRuntime;
  45   friend class JVMCIEnv;
  46 
  47  private:
  48   // Access to the HotSpotJVMCIRuntime used by the CompileBroker.
  49   static JVMCIRuntime* _compiler_runtime;
  50 
  51   // True when at least one JVMCIRuntime::initialize_HotSpotJVMCIRuntime()
  52   // execution has completed successfully.
  53   static volatile bool _is_initialized;
  54 
  55   // Handle created when loading the JVMCI shared library with os::dll_load.
  56   // Must hold JVMCI_lock when initializing.
  57   static void* _shared_library_handle;
  58 
  59   // Argument to os::dll_load when loading JVMCI shared library
  60   static char* _shared_library_path;
  61 
  62   // Records whether JVMCI::shutdown has been called.
  63   static volatile bool _in_shutdown;
  64 
  65   // Access to the HotSpot heap based JVMCIRuntime
  66   static JVMCIRuntime* _java_runtime;
  67 
  68  public:
  69   enum CodeInstallResult {
  70      ok,
  71      dependencies_failed,
  72      dependencies_invalid,
  73      cache_full,
  74      code_too_large
  75   };
  76 
  77   // Gets the handle to the loaded JVMCI shared library, loading it
  78   // first if not yet loaded and `load` is true. The path from
  79   // which the library is loaded is returned in `path`. If
  80   // `load` is true then JVMCI_lock must be locked.
  81   static void* get_shared_library(char*& path, bool load);
  82 
  83   static void do_unloading(bool unloading_occurred);
  84 
  85   static void metadata_do(void f(Metadata*));
  86 
  87   static void oops_do(OopClosure* f);
  88 
  89   static void shutdown();
  90 
  91   // Returns whether JVMCI::shutdown has been called.
  92   static bool in_shutdown();
  93 
  94   static bool is_compiler_initialized();
  95 
  96   /**
  97    * Determines if the VM is sufficiently booted to initialize JVMCI.
  98    */
  99   static bool can_initialize_JVMCI();
 100 
 101   static void initialize_globals();
 102 
 103   static void initialize_compiler(TRAPS);
 104 
 105   static JVMCIRuntime* compiler_runtime() { return _compiler_runtime; }
 106   // Gets the single runtime for JVMCI on the Java heap. This is the only
 107   // JVMCI runtime available when !UseJVMCINativeLibrary.
 108   static JVMCIRuntime* java_runtime()     { return _java_runtime; }
 109 };
 110 
 111 #endif // SHARE_JVMCI_JVMCI_HPP