src/hotspot/share/jvmci/jvmciEnv.hpp
changeset 54732 2d012a75d35c
parent 54669 ad45b3802d4e
child 54812 f2d5f44d994e
equal deleted inserted replaced
54731:81de17a33575 54732:2d012a75d35c
    34 class JVMCIObjectArray;
    34 class JVMCIObjectArray;
    35 class JVMCIPrimitiveArray;
    35 class JVMCIPrimitiveArray;
    36 class JVMCICompiler;
    36 class JVMCICompiler;
    37 class JVMCIRuntime;
    37 class JVMCIRuntime;
    38 
    38 
    39 // Bring the JVMCI compiler thread into the VM state.
       
    40 #define JVMCI_VM_ENTRY_MARK                       \
       
    41   JavaThread* thread = JavaThread::current(); \
       
    42   ThreadInVMfromNative __tiv(thread);       \
       
    43   ResetNoHandleMark rnhm;                   \
       
    44   HandleMarkCleaner __hm(thread);           \
       
    45   Thread* THREAD = thread;                  \
       
    46   debug_only(VMNativeEntryWrapper __vew;)
       
    47 
       
    48 #define JVMCI_EXCEPTION_CONTEXT \
    39 #define JVMCI_EXCEPTION_CONTEXT \
    49   JavaThread* thread=JavaThread::current(); \
    40   JavaThread* thread=JavaThread::current(); \
    50   Thread* THREAD = thread;
    41   Thread* THREAD = thread;
    51 
    42 
    52 // Helper to log more context on a JNI exception
    43 // Helper to log more context on a JNI exception
   152 
   143 
   153   static char*   _shared_library_path;   // argument to os:dll_load
   144   static char*   _shared_library_path;   // argument to os:dll_load
   154   static void*   _shared_library_handle; // result of os::dll_load
   145   static void*   _shared_library_handle; // result of os::dll_load
   155   static JavaVM* _shared_library_javavm; // result of calling JNI_CreateJavaVM in shared library
   146   static JavaVM* _shared_library_javavm; // result of calling JNI_CreateJavaVM in shared library
   156 
   147 
   157   // Attaches the current thread to the JavaVM in the shared library,
   148   // Initializes the shared library JavaVM if not already initialized.
   158   // initializing the shared library VM first if necessary.
   149   // Returns the JNI interface pointer for the current thread
   159   // Returns the JNI interface pointer of the current thread.
   150   // if initialization was performed by this call, NULL if
   160   // The _shared_library_* fields are initialized by the first
   151   // initialization was performed by a previous call.
   161   // call to this method.
   152   static JNIEnv* init_shared_library(JavaThread* thread);
   162   static JNIEnv* attach_shared_library();
       
   163 
   153 
   164   // Initializes the _env, _mode and _runtime fields.
   154   // Initializes the _env, _mode and _runtime fields.
   165   void init_env_mode_runtime(JNIEnv* parent_env);
   155   void init_env_mode_runtime(JavaThread* thread, JNIEnv* parent_env);
   166 
   156 
   167   void init(bool is_hotspot, const char* file, int line);
   157   void init(JavaThread* thread, bool is_hotspot, const char* file, int line);
   168 
   158 
   169   JNIEnv*                _env;     // JNI env for calling into shared library
   159   JNIEnv*                 _env;  // JNI env for calling into shared library
   170   JVMCIRuntime*          _runtime; // Access to a HotSpotJVMCIRuntime
   160   bool     _pop_frame_on_close;  // Must pop frame on close?
   171   bool             _is_hotspot;    // Which heap is the HotSpotJVMCIRuntime in
   161   bool        _detach_on_close;  // Must detach on close?
   172   bool        _throw_to_caller;    // Propagate an exception raised in this env to the caller?
   162   JVMCIRuntime*       _runtime;  // Access to a HotSpotJVMCIRuntime
   173   const char*            _file;    // The file and ...
   163   bool             _is_hotspot;  // Which heap is the HotSpotJVMCIRuntime in
   174   int                    _line;    // ... line where this JNIEnv was created
   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
   175 
   167 
   176   // Translates an exception on the HotSpot heap to an exception on
   168   // Translates an exception on the HotSpot heap to an exception on
   177   // the shared library heap. The translation includes the stack and
   169   // the shared library heap. The translation includes the stack and
   178   // causes of `throwable`. The translated exception is pending in the
   170   // causes of `throwable`. The translated exception is pending in the
   179   // shared library thread upon returning.
   171   // shared library thread upon returning.
   183   // Opens a JVMCIEnv scope for a Java to VM call (e.g., via CompilerToVM).
   175   // Opens a JVMCIEnv scope for a Java to VM call (e.g., via CompilerToVM).
   184   // An exception occurring within the scope is left pending when the
   176   // An exception occurring within the scope is left pending when the
   185   // scope closes so that it will be propagated back to Java.
   177   // scope closes so that it will be propagated back to Java.
   186   // The JVMCIEnv destructor translates the exception object for the
   178   // The JVMCIEnv destructor translates the exception object for the
   187   // Java runtime if necessary.
   179   // Java runtime if necessary.
   188   JVMCIEnv(JNIEnv* env, const char* file, int line);
   180   JVMCIEnv(JavaThread* thread, JNIEnv* env, const char* file, int line);
   189 
   181 
   190   // Opens a JVMCIEnv scope for a compilation scheduled by the CompileBroker.
   182   // Opens a JVMCIEnv scope for a compilation scheduled by the CompileBroker.
   191   // An exception occurring within the scope must not be propagated back to
   183   // An exception occurring within the scope must not be propagated back to
   192   // the CompileBroker.
   184   // the CompileBroker.
   193   JVMCIEnv(JVMCICompileState* compile_state, const char* file, int line);
   185   JVMCIEnv(JavaThread* thread, JVMCICompileState* compile_state, const char* file, int line);
   194 
   186 
   195   // Opens a JNIEnv scope for a call from within the VM. An exception occurring
   187   // Opens a JNIEnv scope for a call from within the VM. An exception occurring
   196   // within the scope must not be propagated back to the caller.
   188   // within the scope must not be propagated back to the caller.
   197   JVMCIEnv(JavaThread* env, const char* file, int line);
   189   JVMCIEnv(JavaThread* env, const char* file, int line);
   198 
   190 
   199   // Opens a JNIEnv scope for accessing `for_object`. An exception occurring
   191   // Opens a JNIEnv scope for accessing `for_object`. An exception occurring
   200   // within the scope must not be propagated back to the caller.
   192   // within the scope must not be propagated back to the caller.
   201   JVMCIEnv(JVMCIObject for_object, const char* file, int line) {
   193   JVMCIEnv(JavaThread* thread, JVMCIObject for_object, const char* file, int line) {
   202     // A JNI call to access an object in the shared library heap
   194     // A JNI call to access an object in the shared library heap
   203     // can block or take a long time so do not allow such access
   195     // can block or take a long time so do not allow such access
   204     // on the VM thread.
   196     // on the VM thread.
   205     assert(for_object.is_hotspot() || !Thread::current()->is_VM_thread(),
   197     assert(for_object.is_hotspot() || !Thread::current()->is_VM_thread(),
   206         "cannot open JVMCIEnv scope when in the VM thread for accessing a shared library heap object");
   198         "cannot open JVMCIEnv scope when in the VM thread for accessing a shared library heap object");
   207     init(for_object.is_hotspot(), file, line);
   199     init(thread, for_object.is_hotspot(), file, line);
   208   }
   200   }
   209 
   201 
   210   // Opens a JNIEnv scope for the HotSpot runtime if `is_hotspot` is true
   202   // Opens a JNIEnv scope for the HotSpot runtime if `is_hotspot` is true
   211   // otherwise for the shared library runtime. An exception occurring
   203   // otherwise for the shared library runtime. An exception occurring
   212   // within the scope must not be propagated back to the caller.
   204   // within the scope must not be propagated back to the caller.
   213   JVMCIEnv(bool is_hotspot, const char* file, int line) {
   205   JVMCIEnv(JavaThread* thread, bool is_hotspot, const char* file, int line) {
   214     init(is_hotspot, file, line);
   206     init(thread, is_hotspot, file, line);
   215   }
   207   }
   216 
   208 
   217   ~JVMCIEnv();
   209   ~JVMCIEnv();
   218 
   210 
   219   JVMCIRuntime* runtime() {
   211   JVMCIRuntime* runtime() {
   245   void put_int_at(JVMCIPrimitiveArray array, int index, jint value);
   237   void put_int_at(JVMCIPrimitiveArray array, int index, jint value);
   246 
   238 
   247   long get_long_at(JVMCIPrimitiveArray array, int index);
   239   long get_long_at(JVMCIPrimitiveArray array, int index);
   248   void put_long_at(JVMCIPrimitiveArray array, int index, jlong value);
   240   void put_long_at(JVMCIPrimitiveArray array, int index, jlong value);
   249 
   241 
   250   void copy_bytes_to(JVMCIPrimitiveArray src, jbyte* dest, int offset, int size_in_bytes);
   242   void copy_bytes_to(JVMCIPrimitiveArray src, jbyte* dest, int offset, jsize length);
   251   void copy_bytes_from(jbyte* src, JVMCIPrimitiveArray dest, int offset, int size_in_bytes);
   243   void copy_bytes_from(jbyte* src, JVMCIPrimitiveArray dest, int offset, jsize length);
       
   244 
       
   245   void copy_longs_from(jlong* src, JVMCIPrimitiveArray dest, int offset, jsize length);
   252 
   246 
   253   JVMCIObjectArray initialize_intrinsics(JVMCI_TRAPS);
   247   JVMCIObjectArray initialize_intrinsics(JVMCI_TRAPS);
   254 
   248 
   255   jboolean is_boxing_object(BasicType type, JVMCIObject object);
   249   jboolean is_boxing_object(BasicType type, JVMCIObject object);
   256 
   250 
   321   DO_THROW(IllegalStateException)
   315   DO_THROW(IllegalStateException)
   322   DO_THROW(NullPointerException)
   316   DO_THROW(NullPointerException)
   323   DO_THROW(IllegalArgumentException)
   317   DO_THROW(IllegalArgumentException)
   324   DO_THROW(InvalidInstalledCodeException)
   318   DO_THROW(InvalidInstalledCodeException)
   325   DO_THROW(UnsatisfiedLinkError)
   319   DO_THROW(UnsatisfiedLinkError)
       
   320   DO_THROW(UnsupportedOperationException)
       
   321   DO_THROW(ClassNotFoundException)
   326 
   322 
   327 #undef DO_THROW
   323 #undef DO_THROW
   328 
   324 
   329   void fthrow_error(const char* file, int line, const char* format, ...) ATTRIBUTE_PRINTF(4, 5);
   325   void fthrow_error(const char* file, int line, const char* format, ...) ATTRIBUTE_PRINTF(4, 5);
   330 
   326