27 28 #include "classfile/javaClasses.hpp" 29 #include "jvmci/jvmciJavaClasses.hpp" 30 #include "runtime/thread.hpp" 31 32 class CompileTask; 33 class JVMCIObject; 34 class JVMCIObjectArray; 35 class JVMCIPrimitiveArray; 36 class JVMCICompiler; 37 class JVMCIRuntime; 38 39 #define JVMCI_EXCEPTION_CONTEXT \ 40 JavaThread* thread=JavaThread::current(); \ 41 Thread* THREAD = thread; 42 43 // Helper to log more context on a JNI exception 44 #define JVMCI_EXCEPTION_CHECK(env, ...) \ 45 do { \ 46 if (env->ExceptionCheck()) { \ 47 if (env != JavaThread::current()->jni_environment() && JVMCIEnv::get_shared_library_path() != NULL) { \ 48 tty->print_cr("In JVMCI shared library (%s):", JVMCIEnv::get_shared_library_path()); \ 49 } \ 50 tty->print_cr(__VA_ARGS__); \ 51 return; \ 52 } \ 53 } while(0) 54 55 // Helper class to ensure that references to Klass* are kept alive for G1 56 class JVMCIKlassHandle : public StackObj { 57 private: 58 Klass* _klass; 59 Handle _holder; 60 Thread* _thread; 61 62 Klass* klass() const { return _klass; } 63 Klass* non_null_klass() const { assert(_klass != NULL, "resolving NULL _klass"); return _klass; } 64 65 public: 66 /* Constructors */ 67 JVMCIKlassHandle (Thread* thread) : _klass(NULL), _thread(thread) {} 68 JVMCIKlassHandle (Thread* thread, Klass* klass); 124 bool failure_reason_on_C_heap() { return _failure_reason_on_C_heap; } 125 bool retryable() { return _retryable; } 126 127 void set_failure(bool retryable, const char* reason, bool reason_on_C_heap = false) { 128 _failure_reason = reason; 129 _failure_reason_on_C_heap = reason_on_C_heap; 130 _retryable = retryable; 131 } 132 }; 133 134 135 // This class is a top level wrapper around interactions between HotSpot 136 // and the JVMCI Java code. It supports both a HotSpot heap based 137 // runtime with HotSpot oop based accessors as well as a shared library 138 // based runtime that is accessed through JNI. It abstracts away all 139 // interactions with JVMCI objects so that a single version of the 140 // HotSpot C++ code can can work with either runtime. 141 class JVMCIEnv : public ResourceObj { 142 friend class JNIAccessMark; 143 144 static char* _shared_library_path; // argument to os:dll_load 145 static void* _shared_library_handle; // result of os::dll_load 146 static JavaVM* _shared_library_javavm; // result of calling JNI_CreateJavaVM in shared library 147 148 // Initializes the shared library JavaVM if not already initialized. 149 // Returns the JNI interface pointer for the current thread 150 // if initialization was performed by this call, NULL if 151 // initialization was performed by a previous call. 152 static JNIEnv* init_shared_library(JavaThread* thread); 153 154 // Initializes the _env, _mode and _runtime fields. 155 void init_env_mode_runtime(JavaThread* thread, JNIEnv* parent_env); 156 157 void init(JavaThread* thread, bool is_hotspot, const char* file, int line); 158 159 JNIEnv* _env; // JNI env for calling into shared library 160 bool _pop_frame_on_close; // Must pop frame on close? 161 bool _detach_on_close; // Must detach on close? 162 JVMCIRuntime* _runtime; // Access to a HotSpotJVMCIRuntime 163 bool _is_hotspot; // Which heap is the HotSpotJVMCIRuntime in 164 bool _throw_to_caller; // Propagate an exception raised in this env to the caller? 165 const char* _file; // The file and ... 166 int _line; // ... line where this JNIEnv was created 167 168 // Translates an exception on the HotSpot heap to an exception on 169 // the shared library heap. The translation includes the stack and 170 // causes of `throwable`. The translated exception is pending in the 171 // shared library thread upon returning. 172 void translate_hotspot_exception_to_jni_exception(JavaThread* THREAD, const Handle& throwable); 173 365 JVMCIPrimitiveArray new_byteArray(int length, JVMCI_TRAPS); 366 JVMCIPrimitiveArray new_intArray(int length, JVMCI_TRAPS); 367 JVMCIPrimitiveArray new_longArray(int length, JVMCI_TRAPS); 368 369 JVMCIObjectArray new_byte_array_array(int length, JVMCI_TRAPS); 370 371 JVMCIObject new_StackTraceElement(const methodHandle& method, int bci, JVMCI_TRAPS); 372 JVMCIObject new_HotSpotNmethod(const methodHandle& method, const char* name, jboolean isDefault, jlong compileId, JVMCI_TRAPS); 373 JVMCIObject new_VMField(JVMCIObject name, JVMCIObject type, jlong offset, jlong address, JVMCIObject value, JVMCI_TRAPS); 374 JVMCIObject new_VMFlag(JVMCIObject name, JVMCIObject type, JVMCIObject value, JVMCI_TRAPS); 375 JVMCIObject new_VMIntrinsicMethod(JVMCIObject declaringClass, JVMCIObject name, JVMCIObject descriptor, int id, JVMCI_TRAPS); 376 JVMCIObject new_HotSpotStackFrameReference(JVMCI_TRAPS); 377 JVMCIObject new_JVMCIError(JVMCI_TRAPS); 378 379 jlong make_handle(const Handle& obj); 380 oop resolve_handle(jlong objectHandle); 381 382 // These are analagous to the JNI routines 383 JVMCIObject make_local(JVMCIObject object); 384 JVMCIObject make_global(JVMCIObject object); 385 JVMCIObject make_weak(JVMCIObject object); 386 void destroy_local(JVMCIObject object); 387 void destroy_global(JVMCIObject object); 388 void destroy_weak(JVMCIObject object); 389 390 // Deoptimizes the nmethod (if any) in the HotSpotNmethod.address 391 // field of mirror. The field is subsequently zeroed. 392 void invalidate_nmethod_mirror(JVMCIObject mirror, JVMCI_TRAPS); 393 394 void initialize_installed_code(JVMCIObject installed_code, CodeBlob* cb, JVMCI_TRAPS); 395 396 private: 397 JVMCICompileState* _compile_state; 398 399 public: 400 static JavaVM* get_shared_library_javavm() { return _shared_library_javavm; } 401 static void* get_shared_library_handle() { return _shared_library_handle; } 402 static char* get_shared_library_path() { return _shared_library_path; } 403 404 // Determines if this is for the JVMCI runtime in the HotSpot 405 // heap (true) or the shared library heap (false). 406 bool is_hotspot() { return _is_hotspot; } 407 408 JVMCICompileState* compile_state() { return _compile_state; } 409 void set_compile_state(JVMCICompileState* compile_state) { 410 assert(_compile_state == NULL, "set only once"); 411 _compile_state = compile_state; 412 } 413 // Generate declarations for the initialize, new, isa, get and set methods for all the types and 414 // fields declared in the JVMCI_CLASSES_DO macro. 415 416 #define START_CLASS(className, fullClassName) \ 417 void className##_initialize(JVMCI_TRAPS); \ 418 JVMCIObjectArray new_##className##_array(int length, JVMCI_TRAPS); \ 419 bool isa_##className(JVMCIObject object); 420 421 #define END_CLASS 422 | 27 28 #include "classfile/javaClasses.hpp" 29 #include "jvmci/jvmciJavaClasses.hpp" 30 #include "runtime/thread.hpp" 31 32 class CompileTask; 33 class JVMCIObject; 34 class JVMCIObjectArray; 35 class JVMCIPrimitiveArray; 36 class JVMCICompiler; 37 class JVMCIRuntime; 38 39 #define JVMCI_EXCEPTION_CONTEXT \ 40 JavaThread* thread=JavaThread::current(); \ 41 Thread* THREAD = thread; 42 43 // Helper to log more context on a JNI exception 44 #define JVMCI_EXCEPTION_CHECK(env, ...) \ 45 do { \ 46 if (env->ExceptionCheck()) { \ 47 if (env != JavaThread::current()->jni_environment()) { \ 48 char* sl_path; \ 49 if (::JVMCI::get_shared_library(sl_path, false) != NULL) { \ 50 tty->print_cr("In JVMCI shared library (%s):", sl_path); \ 51 } \ 52 } \ 53 tty->print_cr(__VA_ARGS__); \ 54 return; \ 55 } \ 56 } while(0) 57 58 // Helper class to ensure that references to Klass* are kept alive for G1 59 class JVMCIKlassHandle : public StackObj { 60 private: 61 Klass* _klass; 62 Handle _holder; 63 Thread* _thread; 64 65 Klass* klass() const { return _klass; } 66 Klass* non_null_klass() const { assert(_klass != NULL, "resolving NULL _klass"); return _klass; } 67 68 public: 69 /* Constructors */ 70 JVMCIKlassHandle (Thread* thread) : _klass(NULL), _thread(thread) {} 71 JVMCIKlassHandle (Thread* thread, Klass* klass); 127 bool failure_reason_on_C_heap() { return _failure_reason_on_C_heap; } 128 bool retryable() { return _retryable; } 129 130 void set_failure(bool retryable, const char* reason, bool reason_on_C_heap = false) { 131 _failure_reason = reason; 132 _failure_reason_on_C_heap = reason_on_C_heap; 133 _retryable = retryable; 134 } 135 }; 136 137 138 // This class is a top level wrapper around interactions between HotSpot 139 // and the JVMCI Java code. It supports both a HotSpot heap based 140 // runtime with HotSpot oop based accessors as well as a shared library 141 // based runtime that is accessed through JNI. It abstracts away all 142 // interactions with JVMCI objects so that a single version of the 143 // HotSpot C++ code can can work with either runtime. 144 class JVMCIEnv : public ResourceObj { 145 friend class JNIAccessMark; 146 147 // Initializes the _env, _mode and _runtime fields. 148 void init_env_mode_runtime(JavaThread* thread, JNIEnv* parent_env); 149 150 void init(JavaThread* thread, bool is_hotspot, const char* file, int line); 151 152 JNIEnv* _env; // JNI env for calling into shared library 153 bool _pop_frame_on_close; // Must pop frame on close? 154 bool _detach_on_close; // Must detach on close? 155 JVMCIRuntime* _runtime; // Access to a HotSpotJVMCIRuntime 156 bool _is_hotspot; // Which heap is the HotSpotJVMCIRuntime in 157 bool _throw_to_caller; // Propagate an exception raised in this env to the caller? 158 const char* _file; // The file and ... 159 int _line; // ... line where this JNIEnv was created 160 161 // Translates an exception on the HotSpot heap to an exception on 162 // the shared library heap. The translation includes the stack and 163 // causes of `throwable`. The translated exception is pending in the 164 // shared library thread upon returning. 165 void translate_hotspot_exception_to_jni_exception(JavaThread* THREAD, const Handle& throwable); 166 358 JVMCIPrimitiveArray new_byteArray(int length, JVMCI_TRAPS); 359 JVMCIPrimitiveArray new_intArray(int length, JVMCI_TRAPS); 360 JVMCIPrimitiveArray new_longArray(int length, JVMCI_TRAPS); 361 362 JVMCIObjectArray new_byte_array_array(int length, JVMCI_TRAPS); 363 364 JVMCIObject new_StackTraceElement(const methodHandle& method, int bci, JVMCI_TRAPS); 365 JVMCIObject new_HotSpotNmethod(const methodHandle& method, const char* name, jboolean isDefault, jlong compileId, JVMCI_TRAPS); 366 JVMCIObject new_VMField(JVMCIObject name, JVMCIObject type, jlong offset, jlong address, JVMCIObject value, JVMCI_TRAPS); 367 JVMCIObject new_VMFlag(JVMCIObject name, JVMCIObject type, JVMCIObject value, JVMCI_TRAPS); 368 JVMCIObject new_VMIntrinsicMethod(JVMCIObject declaringClass, JVMCIObject name, JVMCIObject descriptor, int id, JVMCI_TRAPS); 369 JVMCIObject new_HotSpotStackFrameReference(JVMCI_TRAPS); 370 JVMCIObject new_JVMCIError(JVMCI_TRAPS); 371 372 jlong make_handle(const Handle& obj); 373 oop resolve_handle(jlong objectHandle); 374 375 // These are analagous to the JNI routines 376 JVMCIObject make_local(JVMCIObject object); 377 JVMCIObject make_global(JVMCIObject object); 378 void destroy_local(JVMCIObject object); 379 void destroy_global(JVMCIObject object); 380 381 // Deoptimizes the nmethod (if any) in the HotSpotNmethod.address 382 // field of mirror. The field is subsequently zeroed. 383 void invalidate_nmethod_mirror(JVMCIObject mirror, JVMCI_TRAPS); 384 385 void initialize_installed_code(JVMCIObject installed_code, CodeBlob* cb, JVMCI_TRAPS); 386 387 private: 388 JVMCICompileState* _compile_state; 389 390 public: 391 392 // Determines if this is for the JVMCI runtime in the HotSpot 393 // heap (true) or the shared library heap (false). 394 bool is_hotspot() { return _is_hotspot; } 395 396 JVMCICompileState* compile_state() { return _compile_state; } 397 void set_compile_state(JVMCICompileState* compile_state) { 398 assert(_compile_state == NULL, "set only once"); 399 _compile_state = compile_state; 400 } 401 // Generate declarations for the initialize, new, isa, get and set methods for all the types and 402 // fields declared in the JVMCI_CLASSES_DO macro. 403 404 #define START_CLASS(className, fullClassName) \ 405 void className##_initialize(JVMCI_TRAPS); \ 406 JVMCIObjectArray new_##className##_array(int length, JVMCI_TRAPS); \ 407 bool isa_##className(JVMCIObject object); 408 409 #define END_CLASS 410 |