src/hotspot/share/jvmci/jvmciEnv.hpp
changeset 54669 ad45b3802d4e
parent 53430 ccfd4e614bb8
child 54732 2d012a75d35c
equal deleted inserted replaced
54668:0bda2308eded 54669:ad45b3802d4e
    23  */
    23  */
    24 
    24 
    25 #ifndef SHARE_JVMCI_JVMCIENV_HPP
    25 #ifndef SHARE_JVMCI_JVMCIENV_HPP
    26 #define SHARE_JVMCI_JVMCIENV_HPP
    26 #define SHARE_JVMCI_JVMCIENV_HPP
    27 
    27 
    28 #include "classfile/systemDictionary.hpp"
    28 #include "classfile/javaClasses.hpp"
    29 #include "code/debugInfoRec.hpp"
    29 #include "jvmci/jvmciJavaClasses.hpp"
    30 #include "code/dependencies.hpp"
       
    31 #include "code/exceptionHandlerTable.hpp"
       
    32 #include "compiler/oopMap.hpp"
       
    33 #include "runtime/thread.hpp"
    30 #include "runtime/thread.hpp"
    34 
    31 
    35 class CompileTask;
    32 class CompileTask;
       
    33 class JVMCIObject;
       
    34 class JVMCIObjectArray;
       
    35 class JVMCIPrimitiveArray;
       
    36 class JVMCICompiler;
       
    37 class JVMCIRuntime;
    36 
    38 
    37 // Bring the JVMCI compiler thread into the VM state.
    39 // Bring the JVMCI compiler thread into the VM state.
    38 #define JVMCI_VM_ENTRY_MARK                       \
    40 #define JVMCI_VM_ENTRY_MARK                       \
    39   JavaThread* thread = JavaThread::current(); \
    41   JavaThread* thread = JavaThread::current(); \
    40   ThreadInVMfromNative __tiv(thread);       \
    42   ThreadInVMfromNative __tiv(thread);       \
    45 
    47 
    46 #define JVMCI_EXCEPTION_CONTEXT \
    48 #define JVMCI_EXCEPTION_CONTEXT \
    47   JavaThread* thread=JavaThread::current(); \
    49   JavaThread* thread=JavaThread::current(); \
    48   Thread* THREAD = thread;
    50   Thread* THREAD = thread;
    49 
    51 
    50 //
    52 // Helper to log more context on a JNI exception
    51 // This class is the top level broker for requests from the compiler
    53 #define JVMCI_EXCEPTION_CHECK(env, ...) \
    52 // to the VM.
    54   do { \
    53 class JVMCIEnv : StackObj {
    55     if (env->ExceptionCheck()) { \
    54   CI_PACKAGE_ACCESS_TO
    56       if (env != JavaThread::current()->jni_environment() && JVMCIEnv::get_shared_library_path() != NULL) { \
    55 
    57         tty->print_cr("In JVMCI shared library (%s):", JVMCIEnv::get_shared_library_path()); \
    56   friend class JVMCIVMStructs;
    58       } \
    57   friend class CompileBroker;
    59       tty->print_cr(__VA_ARGS__); \
    58   friend class Dependencies;  // for get_object, during logging
    60       return; \
    59 
    61     } \
    60 public:
    62   } while(0)
    61 
    63 
    62   enum CodeInstallResult {
    64 // Helper class to ensure that references to Klass* are kept alive for G1
    63      ok,
    65 class JVMCIKlassHandle : public StackObj {
    64      dependencies_failed,
    66  private:
    65      dependencies_invalid,
    67   Klass*     _klass;
    66      cache_full,
    68   Handle     _holder;
    67      code_too_large
    69   Thread*    _thread;
    68   };
    70 
    69 
    71   Klass*        klass() const                     { return _klass; }
    70   // Look up a klass by name from a particular class loader (the accessor's).
    72   Klass*        non_null_klass() const            { assert(_klass != NULL, "resolving NULL _klass"); return _klass; }
    71   // If require_local, result must be defined in that class loader, or NULL.
    73 
    72   // If !require_local, a result from remote class loader may be reported,
    74  public:
    73   // if sufficient class loader constraints exist such that initiating
    75   /* Constructors */
    74   // a class loading request from the given loader is bound to return
    76   JVMCIKlassHandle (Thread* thread) : _klass(NULL), _thread(thread) {}
    75   // the class defined in the remote loader (or throw an error).
    77   JVMCIKlassHandle (Thread* thread, Klass* klass);
    76   //
    78 
    77   // Return an unloaded klass if !require_local and no class at all is found.
    79   JVMCIKlassHandle (const JVMCIKlassHandle &h): _klass(h._klass), _holder(h._holder), _thread(h._thread) {}
    78   //
    80   JVMCIKlassHandle& operator=(const JVMCIKlassHandle &s);
    79   // The CI treats a klass as loaded if it is consistently defined in
    81   JVMCIKlassHandle& operator=(Klass* klass);
    80   // another loader, even if it hasn't yet been loaded in all loaders
    82 
    81   // that could potentially see it via delegation.
    83   /* Operators for ease of use */
    82   static Klass* get_klass_by_name(Klass* accessing_klass, Symbol* klass_name, bool require_local);
    84   Klass*        operator () () const            { return klass(); }
    83 
    85   Klass*        operator -> () const            { return non_null_klass(); }
    84   // Constant pool access.
    86 
    85   static Klass* get_klass_by_index(const constantPoolHandle& cpool,
    87   bool    operator == (Klass* o) const          { return klass() == o; }
    86                                    int klass_index,
    88   bool    operator == (const JVMCIKlassHandle& h) const  { return klass() == h.klass(); }
    87                                    bool& is_accessible,
    89 
    88                                    Klass* loading_klass);
    90   /* Null checks */
    89   static void   get_field_by_index(InstanceKlass* loading_klass, fieldDescriptor& fd,
    91   bool    is_null() const                      { return _klass == NULL; }
    90                                    int field_index);
    92   bool    not_null() const                     { return _klass != NULL; }
    91   static methodHandle  get_method_by_index(const constantPoolHandle& cpool,
    93 };
    92                                     int method_index, Bytecodes::Code bc,
    94 
    93                                     InstanceKlass* loading_klass);
    95 // A class that maintains the state needed for compilations requested
    94 
    96 // by the CompileBroker.  It is created in the broker and passed through
    95   JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter);
    97 // into the code installation step.
    96 
    98 class JVMCICompileState : public ResourceObj {
    97 private:
    99   friend class VMStructs;
       
   100  private:
    98   CompileTask*     _task;
   101   CompileTask*     _task;
    99   int              _system_dictionary_modification_counter;
   102   int              _system_dictionary_modification_counter;
   100 
       
   101   // Compilation result values
       
   102   bool             _retryable;
       
   103   const char*      _failure_reason;
       
   104 
       
   105   // Specifies if _failure_reason is on the C heap.
       
   106   bool             _failure_reason_on_C_heap;
       
   107 
   103 
   108   // Cache JVMTI state. Defined as bytes so that reading them from Java
   104   // Cache JVMTI state. Defined as bytes so that reading them from Java
   109   // via Unsafe is well defined (the C++ type for bool is implementation
   105   // via Unsafe is well defined (the C++ type for bool is implementation
   110   // defined and may not be the same as a Java boolean).
   106   // defined and may not be the same as a Java boolean).
   111   jbyte  _jvmti_can_hotswap_or_post_breakpoint;
   107   jbyte  _jvmti_can_hotswap_or_post_breakpoint;
   112   jbyte  _jvmti_can_access_local_variables;
   108   jbyte  _jvmti_can_access_local_variables;
   113   jbyte  _jvmti_can_post_on_exceptions;
   109   jbyte  _jvmti_can_post_on_exceptions;
   114   jbyte  _jvmti_can_pop_frame;
   110   jbyte  _jvmti_can_pop_frame;
   115 
   111 
   116   // Implementation methods for loading and constant pool access.
   112   // Compilation result values.
   117   static Klass* get_klass_by_name_impl(Klass* accessing_klass,
   113   bool             _retryable;
   118                                   const constantPoolHandle& cpool,
   114   const char*      _failure_reason;
   119                                   Symbol* klass_name,
   115 
   120                                   bool require_local);
   116   // Specifies if _failure_reason is on the C heap. If so, it is allocated
   121   static Klass* get_klass_by_index_impl(const constantPoolHandle& cpool,
   117   // with the mtJVMCI NMT flag.
   122                                      int klass_index,
   118   bool             _failure_reason_on_C_heap;
   123                                      bool& is_accessible,
   119 
   124                                      Klass* loading_klass);
   120  public:
   125   static void   get_field_by_index_impl(InstanceKlass* loading_klass, fieldDescriptor& fd,
   121   JVMCICompileState(CompileTask* task, int system_dictionary_modification_counter);
   126                                      int field_index);
   122 
   127   static methodHandle  get_method_by_index_impl(const constantPoolHandle& cpool,
       
   128                                       int method_index, Bytecodes::Code bc,
       
   129                                       InstanceKlass* loading_klass);
       
   130 
       
   131   // Helper methods
       
   132   static bool       check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass);
       
   133   static methodHandle  lookup_method(InstanceKlass*  accessor,
       
   134                            Klass*         holder,
       
   135                            Symbol*        name,
       
   136                            Symbol*        sig,
       
   137                            Bytecodes::Code bc,
       
   138                            constantTag     tag);
       
   139 
       
   140   private:
       
   141 
       
   142   // Is this thread currently in the VM state?
       
   143   static bool is_in_vm();
       
   144 
       
   145   // Helper routine for determining the validity of a compilation
       
   146   // with respect to concurrent class loading.
       
   147   static JVMCIEnv::CodeInstallResult validate_compile_task_dependencies(Dependencies* target, Handle compiled_code,
       
   148                                                                         JVMCIEnv* env, char** failure_detail);
       
   149 
       
   150 public:
       
   151   CompileTask* task() { return _task; }
   123   CompileTask* task() { return _task; }
   152 
   124 
       
   125   int system_dictionary_modification_counter() { return _system_dictionary_modification_counter; }
   153   bool  jvmti_state_changed() const;
   126   bool  jvmti_state_changed() const;
   154   bool  jvmti_can_hotswap_or_post_breakpoint() const { return  _jvmti_can_hotswap_or_post_breakpoint != 0; }
   127   bool  jvmti_can_hotswap_or_post_breakpoint() const { return  _jvmti_can_hotswap_or_post_breakpoint != 0; }
   155   bool  jvmti_can_access_local_variables() const     { return  _jvmti_can_access_local_variables != 0; }
   128   bool  jvmti_can_access_local_variables() const     { return  _jvmti_can_access_local_variables != 0; }
   156   bool  jvmti_can_post_on_exceptions() const         { return  _jvmti_can_post_on_exceptions != 0; }
   129   bool  jvmti_can_post_on_exceptions() const         { return  _jvmti_can_post_on_exceptions != 0; }
   157   bool  jvmti_can_pop_frame() const                  { return  _jvmti_can_pop_frame != 0; }
   130   bool  jvmti_can_pop_frame() const                  { return  _jvmti_can_pop_frame != 0; }
   163   void set_failure(bool retryable, const char* reason, bool reason_on_C_heap = false) {
   136   void set_failure(bool retryable, const char* reason, bool reason_on_C_heap = false) {
   164     _failure_reason = reason;
   137     _failure_reason = reason;
   165     _failure_reason_on_C_heap = reason_on_C_heap;
   138     _failure_reason_on_C_heap = reason_on_C_heap;
   166     _retryable = retryable;
   139     _retryable = retryable;
   167   }
   140   }
   168 
       
   169   // Register the result of a compilation.
       
   170   static JVMCIEnv::CodeInstallResult register_method(
       
   171                        const methodHandle&       target,
       
   172                        nmethod*&                 nm,
       
   173                        int                       entry_bci,
       
   174                        CodeOffsets*              offsets,
       
   175                        int                       orig_pc_offset,
       
   176                        CodeBuffer*               code_buffer,
       
   177                        int                       frame_words,
       
   178                        OopMapSet*                oop_map_set,
       
   179                        ExceptionHandlerTable*    handler_table,
       
   180                        AbstractCompiler*         compiler,
       
   181                        DebugInformationRecorder* debug_info,
       
   182                        Dependencies*             dependencies,
       
   183                        JVMCIEnv*                 env,
       
   184                        int                       compile_id,
       
   185                        bool                      has_unsafe_access,
       
   186                        bool                      has_wide_vector,
       
   187                        Handle                    installed_code,
       
   188                        Handle                    compiled_code,
       
   189                        Handle                    speculation_log);
       
   190 
       
   191   // converts the Klass* representing the holder of a method into a
       
   192   // InstanceKlass*.  This is needed since the holder of a method in
       
   193   // the bytecodes could be an array type.  Basically this converts
       
   194   // array types into java/lang/Object and other types stay as they are.
       
   195   static InstanceKlass* get_instance_klass_for_declared_method_holder(Klass* klass);
       
   196 };
   141 };
   197 
   142 
       
   143 
       
   144 // This class is a top level wrapper around interactions between HotSpot
       
   145 // and the JVMCI Java code.  It supports both a HotSpot heap based
       
   146 // runtime with HotSpot oop based accessors as well as a shared library
       
   147 // based runtime that is accessed through JNI. It abstracts away all
       
   148 // interactions with JVMCI objects so that a single version of the
       
   149 // HotSpot C++ code can can work with either runtime.
       
   150 class JVMCIEnv : public ResourceObj {
       
   151   friend class JNIAccessMark;
       
   152 
       
   153   static char*   _shared_library_path;   // argument to os:dll_load
       
   154   static void*   _shared_library_handle; // result of os::dll_load
       
   155   static JavaVM* _shared_library_javavm; // result of calling JNI_CreateJavaVM in shared library
       
   156 
       
   157   // Attaches the current thread to the JavaVM in the shared library,
       
   158   // initializing the shared library VM first if necessary.
       
   159   // Returns the JNI interface pointer of the current thread.
       
   160   // The _shared_library_* fields are initialized by the first
       
   161   // call to this method.
       
   162   static JNIEnv* attach_shared_library();
       
   163 
       
   164   // Initializes the _env, _mode and _runtime fields.
       
   165   void init_env_mode_runtime(JNIEnv* parent_env);
       
   166 
       
   167   void init(bool is_hotspot, const char* file, int line);
       
   168 
       
   169   JNIEnv*                _env;     // JNI env for calling into shared library
       
   170   JVMCIRuntime*          _runtime; // Access to a HotSpotJVMCIRuntime
       
   171   bool             _is_hotspot;    // Which heap is the HotSpotJVMCIRuntime in
       
   172   bool        _throw_to_caller;    // Propagate an exception raised in this env to the caller?
       
   173   const char*            _file;    // The file and ...
       
   174   int                    _line;    // ... line where this JNIEnv was created
       
   175 
       
   176   // Translates an exception on the HotSpot heap to an exception on
       
   177   // the shared library heap. The translation includes the stack and
       
   178   // causes of `throwable`. The translated exception is pending in the
       
   179   // shared library thread upon returning.
       
   180   void translate_hotspot_exception_to_jni_exception(JavaThread* THREAD, const Handle& throwable);
       
   181 
       
   182 public:
       
   183   // 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
       
   185   // scope closes so that it will be propagated back to Java.
       
   186   // The JVMCIEnv destructor translates the exception object for the
       
   187   // Java runtime if necessary.
       
   188   JVMCIEnv(JNIEnv* env, const char* file, int line);
       
   189 
       
   190   // Opens a JVMCIEnv scope for a compilation scheduled by the CompileBroker.
       
   191   // An exception occurring within the scope must not be propagated back to
       
   192   // the CompileBroker.
       
   193   JVMCIEnv(JVMCICompileState* compile_state, const char* file, int line);
       
   194 
       
   195   // 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.
       
   197   JVMCIEnv(JavaThread* env, const char* file, int line);
       
   198 
       
   199   // Opens a JNIEnv scope for accessing `for_object`. An exception occurring
       
   200   // within the scope must not be propagated back to the caller.
       
   201   JVMCIEnv(JVMCIObject for_object, const char* file, int line) {
       
   202     // 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
       
   204     // on the VM thread.
       
   205     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");
       
   207     init(for_object.is_hotspot(), file, line);
       
   208   }
       
   209 
       
   210   // Opens a JNIEnv scope for the HotSpot runtime if `is_hotspot` is true
       
   211   // otherwise for the shared library runtime. An exception occurring
       
   212   // within the scope must not be propagated back to the caller.
       
   213   JVMCIEnv(bool is_hotspot, const char* file, int line) {
       
   214     init(is_hotspot, file, line);
       
   215   }
       
   216 
       
   217   ~JVMCIEnv();
       
   218 
       
   219   JVMCIRuntime* runtime() {
       
   220     return _runtime;
       
   221   }
       
   222 
       
   223   // Initializes Services.savedProperties in the shared library by copying
       
   224   // the values from the same field in the HotSpot heap.
       
   225   void copy_saved_properties();
       
   226 
       
   227   jboolean has_pending_exception();
       
   228   void clear_pending_exception();
       
   229 
       
   230   // Prints an exception and stack trace of a pending exception.
       
   231   void describe_pending_exception(bool clear);
       
   232 
       
   233   int get_length(JVMCIArray array);
       
   234 
       
   235   JVMCIObject get_object_at(JVMCIObjectArray array, int index);
       
   236   void put_object_at(JVMCIObjectArray array, int index, JVMCIObject value);
       
   237 
       
   238   jboolean get_bool_at(JVMCIPrimitiveArray array, int index);
       
   239   void put_bool_at(JVMCIPrimitiveArray array, int index, jboolean value);
       
   240 
       
   241   jbyte get_byte_at(JVMCIPrimitiveArray array, int index);
       
   242   void put_byte_at(JVMCIPrimitiveArray array, int index, jbyte value);
       
   243 
       
   244   jint get_int_at(JVMCIPrimitiveArray array, int index);
       
   245   void put_int_at(JVMCIPrimitiveArray array, int index, jint value);
       
   246 
       
   247   long get_long_at(JVMCIPrimitiveArray array, int index);
       
   248   void put_long_at(JVMCIPrimitiveArray array, int index, jlong value);
       
   249 
       
   250   void copy_bytes_to(JVMCIPrimitiveArray src, jbyte* dest, int offset, int size_in_bytes);
       
   251   void copy_bytes_from(jbyte* src, JVMCIPrimitiveArray dest, int offset, int size_in_bytes);
       
   252 
       
   253   JVMCIObjectArray initialize_intrinsics(JVMCI_TRAPS);
       
   254 
       
   255   jboolean is_boxing_object(BasicType type, JVMCIObject object);
       
   256 
       
   257   // Get the primitive value from a Java boxing object.  It's hard error to
       
   258   // pass a non-primitive BasicType.
       
   259   jvalue get_boxed_value(BasicType type, JVMCIObject object);
       
   260 
       
   261   // Return the BasicType of the object if it's a boxing object, otherwise return T_ILLEGAL.
       
   262   BasicType get_box_type(JVMCIObject object);
       
   263 
       
   264   // Create a boxing object of the appropriate primitive type.
       
   265   JVMCIObject create_box(BasicType type, jvalue* value, JVMCI_TRAPS);
       
   266 
       
   267   const char* as_utf8_string(JVMCIObject str);
       
   268   char* as_utf8_string(JVMCIObject str, char* buf, int buflen);
       
   269 
       
   270   JVMCIObject create_string(Symbol* str, JVMCI_TRAPS) {
       
   271     return create_string(str->as_C_string(), JVMCI_CHECK_(JVMCIObject()));
       
   272   }
       
   273 
       
   274   JVMCIObject create_string(const char* str, JVMCI_TRAPS);
       
   275 
       
   276   bool equals(JVMCIObject a, JVMCIObject b);
       
   277 
       
   278   // Convert into a JNI handle for the appropriate runtime
       
   279   jobject get_jobject(JVMCIObject object)                       { assert(object.as_jobject() == NULL || is_hotspot() == object.is_hotspot(), "mismatch"); return object.as_jobject(); }
       
   280   jarray get_jarray(JVMCIArray array)                           { assert(array.as_jobject() == NULL || is_hotspot() == array.is_hotspot(), "mismatch"); return array.as_jobject(); }
       
   281   jobjectArray get_jobjectArray(JVMCIObjectArray objectArray)   { assert(objectArray.as_jobject() == NULL || is_hotspot() == objectArray.is_hotspot(), "mismatch"); return objectArray.as_jobject(); }
       
   282   jbyteArray get_jbyteArray(JVMCIPrimitiveArray primitiveArray) { assert(primitiveArray.as_jobject() == NULL || is_hotspot() == primitiveArray.is_hotspot(), "mismatch"); return primitiveArray.as_jbyteArray(); }
       
   283 
       
   284   JVMCIObject         wrap(jobject obj);
       
   285   JVMCIObjectArray    wrap(jobjectArray obj)  { return (JVMCIObjectArray)    wrap((jobject) obj); }
       
   286   JVMCIPrimitiveArray wrap(jintArray obj)     { return (JVMCIPrimitiveArray) wrap((jobject) obj); }
       
   287   JVMCIPrimitiveArray wrap(jbooleanArray obj) { return (JVMCIPrimitiveArray) wrap((jobject) obj); }
       
   288   JVMCIPrimitiveArray wrap(jbyteArray obj)    { return (JVMCIPrimitiveArray) wrap((jobject) obj); }
       
   289   JVMCIPrimitiveArray wrap(jlongArray obj)    { return (JVMCIPrimitiveArray) wrap((jobject) obj); }
       
   290 
       
   291  private:
       
   292   JVMCIObject wrap(oop obj)                  { assert(is_hotspot(), "must be"); return wrap(JNIHandles::make_local(obj)); }
       
   293   JVMCIObjectArray wrap(objArrayOop obj)     { assert(is_hotspot(), "must be"); return (JVMCIObjectArray) wrap(JNIHandles::make_local(obj)); }
       
   294   JVMCIPrimitiveArray wrap(typeArrayOop obj) { assert(is_hotspot(), "must be"); return (JVMCIPrimitiveArray) wrap(JNIHandles::make_local(obj)); }
       
   295 
       
   296  public:
       
   297   // Compiles a method with the JVMIC compiler.
       
   298   // Caller must handle pending exception.
       
   299   JVMCIObject call_HotSpotJVMCIRuntime_compileMethod(JVMCIObject runtime, JVMCIObject method, int entry_bci,
       
   300                                                      jlong compile_state, int id);
       
   301 
       
   302   void call_HotSpotJVMCIRuntime_bootstrapFinished(JVMCIObject runtime, JVMCI_TRAPS);
       
   303   void call_HotSpotJVMCIRuntime_shutdown(JVMCIObject runtime);
       
   304   JVMCIObject call_HotSpotJVMCIRuntime_runtime(JVMCI_TRAPS);
       
   305   JVMCIObject call_JVMCI_getRuntime(JVMCI_TRAPS);
       
   306   JVMCIObject call_HotSpotJVMCIRuntime_getCompiler(JVMCIObject runtime, JVMCI_TRAPS);
       
   307 
       
   308   JVMCIObject call_HotSpotJVMCIRuntime_callToString(JVMCIObject object, JVMCI_TRAPS);
       
   309 
       
   310   JVMCIObject call_PrimitiveConstant_forTypeChar(jchar kind, jlong value, JVMCI_TRAPS);
       
   311   JVMCIObject call_JavaConstant_forFloat(float value, JVMCI_TRAPS);
       
   312   JVMCIObject call_JavaConstant_forDouble(double value, JVMCI_TRAPS);
       
   313 
       
   314   BasicType kindToBasicType(JVMCIObject kind, JVMCI_TRAPS);
       
   315 
       
   316 #define DO_THROW(name) \
       
   317   void throw_##name(const char* msg = NULL);
       
   318 
       
   319   DO_THROW(InternalError)
       
   320   DO_THROW(ArrayIndexOutOfBoundsException)
       
   321   DO_THROW(IllegalStateException)
       
   322   DO_THROW(NullPointerException)
       
   323   DO_THROW(IllegalArgumentException)
       
   324   DO_THROW(InvalidInstalledCodeException)
       
   325   DO_THROW(UnsatisfiedLinkError)
       
   326 
       
   327 #undef DO_THROW
       
   328 
       
   329   void fthrow_error(const char* file, int line, const char* format, ...) ATTRIBUTE_PRINTF(4, 5);
       
   330 
       
   331   // Given an instance of HotSpotInstalledCode return the corresponding CodeBlob*
       
   332   CodeBlob* asCodeBlob(JVMCIObject code);
       
   333 
       
   334   nmethod* asNmethod(JVMCIObject code) {
       
   335     CodeBlob* cb = asCodeBlob(code);
       
   336     if (cb == NULL) {
       
   337       return NULL;
       
   338     }
       
   339     nmethod* nm = cb->as_nmethod_or_null();
       
   340     guarantee(nm != NULL, "not an nmethod");
       
   341     return nm;
       
   342   }
       
   343 
       
   344   MethodData* asMethodData(jlong metaspaceMethodData) {
       
   345     return (MethodData*) (address) metaspaceMethodData;
       
   346   }
       
   347 
       
   348   const char* klass_name(JVMCIObject object);
       
   349 
       
   350   // Unpack an instance of HotSpotResolvedJavaMethodImpl into the original Method*
       
   351   Method* asMethod(JVMCIObject jvmci_method);
       
   352   Method* asMethod(jobject jvmci_method) { return asMethod(wrap(jvmci_method)); }
       
   353 
       
   354   // Unpack an instance of HotSpotResolvedObjectTypeImpl into the original Klass*
       
   355   Klass* asKlass(JVMCIObject jvmci_type);
       
   356   Klass* asKlass(jobject jvmci_type)  { return asKlass(wrap(jvmci_type)); }
       
   357 
       
   358   JVMCIObject get_jvmci_method(const methodHandle& method, JVMCI_TRAPS);
       
   359 
       
   360   JVMCIObject get_jvmci_type(const JVMCIKlassHandle& klass, JVMCI_TRAPS);
       
   361 
       
   362   // Unpack an instance of HotSpotConstantPool into the original ConstantPool*
       
   363   ConstantPool* asConstantPool(JVMCIObject constant_pool);
       
   364   ConstantPool* asConstantPool(jobject constant_pool)  { return asConstantPool(wrap(constant_pool)); }
       
   365 
       
   366   JVMCIObject get_jvmci_constant_pool(const constantPoolHandle& cp, JVMCI_TRAPS);
       
   367   JVMCIObject get_jvmci_primitive_type(BasicType type);
       
   368 
       
   369   Handle asConstant(JVMCIObject object, JVMCI_TRAPS);
       
   370   JVMCIObject get_object_constant(oop objOop, bool compressed = false, bool dont_register = false);
       
   371 
       
   372   JVMCIPrimitiveArray new_booleanArray(int length, JVMCI_TRAPS);
       
   373   JVMCIPrimitiveArray new_byteArray(int length, JVMCI_TRAPS);
       
   374   JVMCIPrimitiveArray new_intArray(int length, JVMCI_TRAPS);
       
   375   JVMCIPrimitiveArray new_longArray(int length, JVMCI_TRAPS);
       
   376 
       
   377   JVMCIObjectArray new_byte_array_array(int length, JVMCI_TRAPS);
       
   378 
       
   379   JVMCIObject new_StackTraceElement(const methodHandle& method, int bci, JVMCI_TRAPS);
       
   380   JVMCIObject new_HotSpotNmethod(const methodHandle& method, const char* name, jboolean isDefault, jlong compileId, JVMCI_TRAPS);
       
   381   JVMCIObject new_VMField(JVMCIObject name, JVMCIObject type, jlong offset, jlong address, JVMCIObject value, JVMCI_TRAPS);
       
   382   JVMCIObject new_VMFlag(JVMCIObject name, JVMCIObject type, JVMCIObject value, JVMCI_TRAPS);
       
   383   JVMCIObject new_VMIntrinsicMethod(JVMCIObject declaringClass, JVMCIObject name, JVMCIObject descriptor, int id, JVMCI_TRAPS);
       
   384   JVMCIObject new_HotSpotStackFrameReference(JVMCI_TRAPS);
       
   385   JVMCIObject new_JVMCIError(JVMCI_TRAPS);
       
   386 
       
   387   jlong make_handle(const Handle& obj);
       
   388   oop resolve_handle(jlong objectHandle);
       
   389 
       
   390   // These are analagous to the JNI routines
       
   391   JVMCIObject make_local(JVMCIObject object);
       
   392   JVMCIObject make_global(JVMCIObject object);
       
   393   JVMCIObject make_weak(JVMCIObject object);
       
   394   void destroy_local(JVMCIObject object);
       
   395   void destroy_global(JVMCIObject object);
       
   396   void destroy_weak(JVMCIObject object);
       
   397 
       
   398   // Deoptimizes the nmethod (if any) in the HotSpotNmethod.address
       
   399   // field of mirror. The field is subsequently zeroed.
       
   400   void invalidate_nmethod_mirror(JVMCIObject mirror, JVMCI_TRAPS);
       
   401 
       
   402   void initialize_installed_code(JVMCIObject installed_code, CodeBlob* cb, JVMCI_TRAPS);
       
   403 
       
   404  private:
       
   405   JVMCICompileState* _compile_state;
       
   406 
       
   407  public:
       
   408   static JavaVM* get_shared_library_javavm() { return _shared_library_javavm; }
       
   409   static void* get_shared_library_handle()   { return _shared_library_handle; }
       
   410   static char* get_shared_library_path()     { return _shared_library_path; }
       
   411 
       
   412   // Determines if this is for the JVMCI runtime in the HotSpot
       
   413   // heap (true) or the shared library heap (false).
       
   414   bool is_hotspot() { return _is_hotspot; }
       
   415 
       
   416   JVMCICompileState* compile_state() { return _compile_state; }
       
   417   void set_compile_state(JVMCICompileState* compile_state) {
       
   418     assert(_compile_state == NULL, "set only once");
       
   419     _compile_state = compile_state;
       
   420   }
       
   421   // Generate declarations for the initialize, new, isa, get and set methods for all the types and
       
   422   // fields declared in the JVMCI_CLASSES_DO macro.
       
   423 
       
   424 #define START_CLASS(className, fullClassName)                           \
       
   425   void className##_initialize(JVMCI_TRAPS); \
       
   426   JVMCIObjectArray new_##className##_array(int length, JVMCI_TRAPS); \
       
   427   bool isa_##className(JVMCIObject object);
       
   428 
       
   429 #define END_CLASS
       
   430 
       
   431 #define FIELD(className, name, type, accessor)                                                                                                                         \
       
   432   type get_ ## className ## _ ## name(JVMCIObject obj); \
       
   433   void set_ ## className ## _ ## name(JVMCIObject obj, type x);
       
   434 
       
   435 #define OOPISH_FIELD(className, name, type, hstype, accessor) \
       
   436   FIELD(className, name, type, accessor)
       
   437 
       
   438 #define STATIC_FIELD(className, name, type) \
       
   439   type get_ ## className ## _ ## name(); \
       
   440   void set_ ## className ## _ ## name(type x);
       
   441 
       
   442 #define STATIC_OOPISH_FIELD(className, name, type, hstype) \
       
   443   STATIC_FIELD(className, name, type)
       
   444 
       
   445 #define EMPTY_CAST
       
   446 #define CHAR_FIELD(className,  name) FIELD(className, name, jchar, char_field)
       
   447 #define INT_FIELD(className,  name) FIELD(className, name, jint, int_field)
       
   448 #define BOOLEAN_FIELD(className,  name) FIELD(className, name, jboolean, bool_field)
       
   449 #define LONG_FIELD(className,  name) FIELD(className, name, jlong, long_field)
       
   450 #define FLOAT_FIELD(className,  name) FIELD(className, name, jfloat, float_field)
       
   451 #define OBJECT_FIELD(className,  name, signature) OOPISH_FIELD(className, name, JVMCIObject, oop, obj_field)
       
   452 #define OBJECTARRAY_FIELD(className,  name, signature) OOPISH_FIELD(className, name, JVMCIObjectArray, objArrayOop, obj_field)
       
   453 #define PRIMARRAY_FIELD(className,  name, signature) OOPISH_FIELD(className, name, JVMCIPrimitiveArray, typeArrayOop, obj_field)
       
   454 
       
   455 #define STATIC_INT_FIELD(className, name) STATIC_FIELD(className, name, jint)
       
   456 #define STATIC_BOOLEAN_FIELD(className, name) STATIC_FIELD(className, name, jboolean)
       
   457 #define STATIC_OBJECT_FIELD(className, name, signature) STATIC_OOPISH_FIELD(className, name, JVMCIObject, oop)
       
   458 #define STATIC_OBJECTARRAY_FIELD(className, name, signature) STATIC_OOPISH_FIELD(className, name, JVMCIObjectArray, objArrayOop)
       
   459 #define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args)
       
   460 #define CONSTRUCTOR(className, signature)
       
   461 
       
   462   JVMCI_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OBJECT_FIELD, PRIMARRAY_FIELD, OBJECTARRAY_FIELD, STATIC_OBJECT_FIELD, STATIC_OBJECTARRAY_FIELD, STATIC_INT_FIELD, STATIC_BOOLEAN_FIELD, METHOD, CONSTRUCTOR)
       
   463 
       
   464 #undef JNI_START_CLASS
       
   465 #undef START_CLASS
       
   466 #undef END_CLASS
       
   467 #undef METHOD
       
   468 #undef CONSTRUCTOR
       
   469 #undef FIELD
       
   470 #undef CHAR_FIELD
       
   471 #undef INT_FIELD
       
   472 #undef BOOLEAN_FIELD
       
   473 #undef LONG_FIELD
       
   474 #undef FLOAT_FIELD
       
   475 #undef OBJECT_FIELD
       
   476 #undef PRIMARRAY_FIELD
       
   477 #undef OBJECTARRAY_FIELD
       
   478 #undef FIELD
       
   479 #undef OOPISH_FIELD
       
   480 #undef STATIC_FIELD
       
   481 #undef STATIC_OOPISH_FIELD
       
   482 #undef STATIC_FIELD
       
   483 #undef STATIC_OBJECT_FIELD
       
   484 #undef STATIC_OBJECTARRAY_FIELD
       
   485 #undef STATIC_INT_FIELD
       
   486 #undef STATIC_BOOLEAN_FIELD
       
   487 #undef EMPTY_CAST
       
   488 
       
   489   // End of JVMCIEnv
       
   490 };
       
   491 
   198 #endif // SHARE_JVMCI_JVMCIENV_HPP
   492 #endif // SHARE_JVMCI_JVMCIENV_HPP