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 #include "precompiled.hpp" 25 #include "classfile/systemDictionary.hpp" 26 #include "gc/shared/collectedHeap.hpp" 27 #include "gc/shared/oopStorage.inline.hpp" 28 #include "jvmci/jvmci.hpp" 29 #include "jvmci/jvmci_globals.hpp" 30 #include "jvmci/jvmciJavaClasses.hpp" 31 #include "jvmci/jvmciRuntime.hpp" 32 #include "jvmci/metadataHandleBlock.hpp" 33 34 OopStorage* JVMCI::_object_handles = NULL; 35 MetadataHandleBlock* JVMCI::_metadata_handles = NULL; 36 JVMCIRuntime* JVMCI::_compiler_runtime = NULL; 37 JVMCIRuntime* JVMCI::_java_runtime = NULL; 38 39 bool JVMCI::can_initialize_JVMCI() { 40 // Initializing JVMCI requires the module system to be initialized past phase 3. 41 // The JVMCI API itself isn't available until phase 2 and ServiceLoader (which 42 // JVMCI initialization requires) isn't usable until after phase 3. Testing 43 // whether the system loader is initialized satisfies all these invariants. 44 if (SystemDictionary::java_system_loader() == NULL) { 45 return false; 46 } 47 assert(Universe::is_module_initialized(), "must be"); 48 return true; 49 } 50 51 void JVMCI::initialize_compiler(TRAPS) { 52 if (JVMCILibDumpJNIConfig) { 53 JNIJVMCI::initialize_ids(NULL); 54 ShouldNotReachHere(); 55 } 56 57 JVMCI::compiler_runtime()->call_getCompiler(CHECK); 58 } 59 60 void JVMCI::initialize_globals() { 61 _object_handles = new OopStorage("JVMCI Global Oop Handles", 62 JVMCIGlobalAlloc_lock, 63 JVMCIGlobalActive_lock); 64 _metadata_handles = MetadataHandleBlock::allocate_block(); 65 if (UseJVMCINativeLibrary) { 66 // There are two runtimes. 67 _compiler_runtime = new JVMCIRuntime(); 68 _java_runtime = new JVMCIRuntime(); 69 } else { 70 // There is only a single runtime 71 _java_runtime = _compiler_runtime = new JVMCIRuntime(); 72 } 73 } 74 75 OopStorage* JVMCI::object_handles() { 76 assert(_object_handles != NULL, "Uninitialized"); 77 return _object_handles; 78 } 79 80 jobject JVMCI::make_global(const Handle& obj) { 81 assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC"); 82 assert(oopDesc::is_oop(obj()), "not an oop"); 83 oop* ptr = object_handles()->allocate(); 84 jobject res = NULL; 85 if (ptr != NULL) { 86 assert(*ptr == NULL, "invariant"); 87 NativeAccess<>::oop_store(ptr, obj()); 88 res = reinterpret_cast<jobject>(ptr); 89 } else { 90 vm_exit_out_of_memory(sizeof(oop), OOM_MALLOC_ERROR, 91 "Cannot create JVMCI oop handle"); 92 } 93 return res; 94 } 95 96 void JVMCI::destroy_global(jobject handle) { 97 // Assert before nulling out, for better debugging. 98 assert(is_global_handle(handle), "precondition"); 99 oop* oop_ptr = reinterpret_cast<oop*>(handle); 100 NativeAccess<>::oop_store(oop_ptr, (oop)NULL); 101 object_handles()->release(oop_ptr); 102 } 103 104 bool JVMCI::is_global_handle(jobject handle) { 105 const oop* ptr = reinterpret_cast<oop*>(handle); 106 return object_handles()->allocation_status(ptr) == OopStorage::ALLOCATED_ENTRY; 107 } 108 109 jmetadata JVMCI::allocate_handle(const methodHandle& handle) { 110 assert(_metadata_handles != NULL, "uninitialized"); 111 MutexLocker ml(JVMCI_lock); 112 return _metadata_handles->allocate_handle(handle); 113 } 114 115 jmetadata JVMCI::allocate_handle(const constantPoolHandle& handle) { 116 assert(_metadata_handles != NULL, "uninitialized"); 117 MutexLocker ml(JVMCI_lock); 118 return _metadata_handles->allocate_handle(handle); 119 } 120 121 void JVMCI::release_handle(jmetadata handle) { 122 MutexLocker ml(JVMCI_lock); 123 _metadata_handles->chain_free_list(handle); 124 } 125 126 void JVMCI::oops_do(OopClosure* f) { 127 if (_object_handles != NULL) { 128 _object_handles->oops_do(f); 129 } 130 } 131 132 void JVMCI::metadata_do(void f(Metadata*)) { 133 if (_metadata_handles != NULL) { 134 _metadata_handles->metadata_do(f); 135 } 136 } 137 138 void JVMCI::do_unloading(bool unloading_occurred) { 139 if (_metadata_handles != NULL && unloading_occurred) { 140 _metadata_handles->do_unloading(); 141 } 142 } 143 144 bool JVMCI::is_compiler_initialized() { 145 return compiler_runtime()->is_HotSpotJVMCIRuntime_initialized(); 146 } 147 148 void JVMCI::shutdown() { 149 if (compiler_runtime() != NULL) { 150 compiler_runtime()->shutdown(); 151 } 152 } 153 154 bool JVMCI::shutdown_called() { 155 if (compiler_runtime() != NULL) { 156 return compiler_runtime()->shutdown_called(); 157 } 158 return false; 159 } | 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 #include "precompiled.hpp" 25 #include "classfile/systemDictionary.hpp" 26 #include "gc/shared/collectedHeap.hpp" 27 #include "gc/shared/oopStorage.inline.hpp" 28 #include "jvmci/jvmci.hpp" 29 #include "jvmci/jvmci_globals.hpp" 30 #include "jvmci/jvmciJavaClasses.hpp" 31 #include "jvmci/jvmciRuntime.hpp" 32 #include "jvmci/metadataHandles.hpp" 33 #include "memory/resourceArea.hpp" 34 35 JVMCIRuntime* JVMCI::_compiler_runtime = NULL; 36 JVMCIRuntime* JVMCI::_java_runtime = NULL; 37 volatile bool JVMCI::_is_initialized = false; 38 void* JVMCI::_shared_library_handle = NULL; 39 char* JVMCI::_shared_library_path = NULL; 40 volatile bool JVMCI::_in_shutdown = false; 41 42 bool JVMCI::can_initialize_JVMCI() { 43 // Initializing JVMCI requires the module system to be initialized past phase 3. 44 // The JVMCI API itself isn't available until phase 2 and ServiceLoader (which 45 // JVMCI initialization requires) isn't usable until after phase 3. Testing 46 // whether the system loader is initialized satisfies all these invariants. 47 if (SystemDictionary::java_system_loader() == NULL) { 48 return false; 49 } 50 assert(Universe::is_module_initialized(), "must be"); 51 return true; 52 } 53 54 void* JVMCI::get_shared_library(char*& path, bool load) { 55 void* sl_handle = _shared_library_handle; 56 if (sl_handle != NULL || !load) { 57 path = _shared_library_path; 58 return sl_handle; 59 } 60 assert(JVMCI_lock->owner() == Thread::current(), "must be"); 61 path = NULL; 62 if (_shared_library_handle == NULL) { 63 char path[JVM_MAXPATHLEN]; 64 char ebuf[1024]; 65 if (JVMCILibPath != NULL) { 66 if (!os::dll_locate_lib(path, sizeof(path), JVMCILibPath, JVMCI_SHARED_LIBRARY_NAME)) { 67 vm_exit_during_initialization("Unable to locate JVMCI shared library in path specified by -XX:JVMCILibPath value", JVMCILibPath); 68 } 69 } else { 70 if (!os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), JVMCI_SHARED_LIBRARY_NAME)) { 71 vm_exit_during_initialization("Unable to create path to JVMCI shared library"); 72 } 73 } 74 75 void* handle = os::dll_load(path, ebuf, sizeof ebuf); 76 if (handle == NULL) { 77 vm_exit_during_initialization("Unable to load JVMCI shared library", ebuf); 78 } 79 _shared_library_handle = handle; 80 _shared_library_path = strdup(path); 81 82 TRACE_jvmci_1("loaded JVMCI shared library from %s", path); 83 } 84 path = _shared_library_path; 85 return _shared_library_handle; 86 } 87 88 void JVMCI::initialize_compiler(TRAPS) { 89 if (JVMCILibDumpJNIConfig) { 90 JNIJVMCI::initialize_ids(NULL); 91 ShouldNotReachHere(); 92 } 93 94 JVMCI::compiler_runtime()->call_getCompiler(CHECK); 95 } 96 97 void JVMCI::initialize_globals() { 98 if (UseJVMCINativeLibrary) { 99 // There are two runtimes. 100 _compiler_runtime = new JVMCIRuntime(0); 101 _java_runtime = new JVMCIRuntime(-1); 102 } else { 103 // There is only a single runtime 104 _java_runtime = _compiler_runtime = new JVMCIRuntime(0); 105 } 106 } 107 108 void JVMCI::oops_do(OopClosure* f) { 109 if (_java_runtime != NULL) { 110 _java_runtime->_object_handles->oops_do(f); 111 } 112 if (_compiler_runtime != NULL && _compiler_runtime != _java_runtime) { 113 _compiler_runtime->_object_handles->oops_do(f); 114 } 115 } 116 117 void JVMCI::metadata_do(void f(Metadata*)) { 118 if (_java_runtime != NULL) { 119 _java_runtime->_metadata_handles->metadata_do(f); 120 } 121 if (_compiler_runtime != NULL && _compiler_runtime != _java_runtime) { 122 _compiler_runtime->_metadata_handles->metadata_do(f); 123 } 124 } 125 126 void JVMCI::do_unloading(bool unloading_occurred) { 127 if (unloading_occurred) { 128 if (_java_runtime != NULL) { 129 _java_runtime->_metadata_handles->do_unloading(); 130 } 131 if (_compiler_runtime != NULL && _compiler_runtime != _java_runtime) { 132 _compiler_runtime->_metadata_handles->do_unloading(); 133 } 134 } 135 } 136 137 bool JVMCI::is_compiler_initialized() { 138 return _is_initialized; 139 } 140 141 void JVMCI::shutdown() { 142 ResourceMark rm; 143 { 144 MutexLocker locker(JVMCI_lock); 145 _in_shutdown = true; 146 TRACE_jvmci_1("shutting down JVMCI"); 147 } 148 JVMCIRuntime* java_runtime = _java_runtime; 149 if (java_runtime != compiler_runtime()) { 150 java_runtime->shutdown(); 151 } 152 if (compiler_runtime() != NULL) { 153 compiler_runtime()->shutdown(); 154 } 155 } 156 157 bool JVMCI::in_shutdown() { 158 return _in_shutdown; 159 } |