1 /*
   2  * Copyright (c) 2011, 2022, 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 #include "precompiled.hpp"
  25 #include "classfile/classLoaderData.inline.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "classfile/vmClasses.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #include "compiler/compileBroker.hpp"
  33 #include "compiler/compilerEvent.hpp"
  34 #include "compiler/disassembler.hpp"
  35 #include "compiler/oopMap.hpp"
  36 #include "interpreter/linkResolver.hpp"
  37 #include "interpreter/bytecodeStream.hpp"
  38 #include "jfr/jfrEvents.hpp"
  39 #include "jvmci/jvmciCompilerToVM.hpp"
  40 #include "jvmci/jvmciCodeInstaller.hpp"
  41 #include "jvmci/jvmciRuntime.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logTag.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/universe.hpp"
  46 #include "oops/constantPool.inline.hpp"
  47 #include "oops/instanceMirrorKlass.hpp"
  48 #include "oops/instanceKlass.inline.hpp"
  49 #include "oops/method.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"
  51 #include "prims/jvmtiExport.hpp"
  52 #include "prims/methodHandles.hpp"
  53 #include "prims/nativeLookup.hpp"
  54 #include "runtime/atomic.hpp"
  55 #include "runtime/deoptimization.hpp"
  56 #include "runtime/fieldDescriptor.inline.hpp"
  57 #include "runtime/frame.inline.hpp"
  58 #include "runtime/globals_extension.hpp"
  59 #include "runtime/interfaceSupport.inline.hpp"
  60 #include "runtime/jniHandles.inline.hpp"
  61 #include "runtime/reflectionUtils.hpp"
  62 #include "runtime/stackFrameStream.inline.hpp"
  63 #include "runtime/timerTrace.hpp"
  64 #include "runtime/vframe_hp.hpp"
  65 #include "runtime/vframe.inline.hpp"
  66 
  67 JVMCIKlassHandle::JVMCIKlassHandle(Thread* thread, Klass* klass) {
  68   _thread = thread;
  69   _klass = klass;
  70   if (klass != NULL) {
  71     _holder = Handle(_thread, klass->klass_holder());
  72   }
  73 }
  74 
  75 JVMCIKlassHandle& JVMCIKlassHandle::operator=(Klass* klass) {
  76   _klass = klass;
  77   if (klass != NULL) {
  78     _holder = Handle(_thread, klass->klass_holder());
  79   }
  80   return *this;
  81 }
  82 
  83 static void requireInHotSpot(const char* caller, JVMCI_TRAPS) {
  84   if (!JVMCIENV->is_hotspot()) {
  85     JVMCI_THROW_MSG(IllegalStateException, err_msg("Cannot call %s from JVMCI shared library", caller));
  86   }
  87 }
  88 
  89 class JVMCITraceMark : public StackObj {
  90   const char* _msg;
  91  public:
  92   JVMCITraceMark(const char* msg) {
  93     _msg = msg;
  94     JVMCI_event_2("Enter %s", _msg);
  95   }
  96   ~JVMCITraceMark() {
  97     JVMCI_event_2(" Exit %s", _msg);
  98   }
  99 };
 100 
 101 
 102 Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
 103   assert(_index < _args->length(), "out of bounds");
 104   oop arg=((objArrayOop) (_args))->obj_at(_index++);
 105   assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch");
 106   return Handle(Thread::current(), arg);
 107 }
 108 
 109 // Bring the JVMCI compiler thread into the VM state.
 110 #define JVMCI_VM_ENTRY_MARK                                       \
 111   MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread));       \
 112   ThreadInVMfromNative __tiv(thread);                             \
 113   HandleMarkCleaner __hm(thread);                                 \
 114   JavaThread* THREAD = thread;                                        \
 115   debug_only(VMNativeEntryWrapper __vew;)
 116 
 117 // Native method block that transitions current thread to '_thread_in_vm'.
 118 #define C2V_BLOCK(result_type, name, signature)      \
 119   JVMCI_VM_ENTRY_MARK;                               \
 120   ResourceMark rm;                                   \
 121   JNI_JVMCIENV(JVMCI::compilation_tick(thread), env);
 122 
 123 static JavaThread* get_current_thread(bool allow_null=true) {
 124   Thread* thread = Thread::current_or_null_safe();
 125   if (thread == NULL) {
 126     assert(allow_null, "npe");
 127     return NULL;
 128   }
 129   return JavaThread::cast(thread);
 130 }
 131 
 132 // Entry to native method implementation that transitions
 133 // current thread to '_thread_in_vm'.
 134 #define C2V_VMENTRY(result_type, name, signature)        \
 135   JNIEXPORT result_type JNICALL c2v_ ## name signature { \
 136   JavaThread* thread = get_current_thread();             \
 137   if (thread == NULL) {                                  \
 138     env->ThrowNew(JNIJVMCI::InternalError::clazz(),      \
 139         err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
 140     return;                                              \
 141   }                                                      \
 142   JVMCITraceMark jtm("CompilerToVM::" #name);            \
 143   C2V_BLOCK(result_type, name, signature)
 144 
 145 #define C2V_VMENTRY_(result_type, name, signature, result) \
 146   JNIEXPORT result_type JNICALL c2v_ ## name signature { \
 147   JavaThread* thread = get_current_thread();             \
 148   if (thread == NULL) {                                  \
 149     env->ThrowNew(JNIJVMCI::InternalError::clazz(),      \
 150         err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
 151     return result;                                       \
 152   }                                                      \
 153   JVMCITraceMark jtm("CompilerToVM::" #name);            \
 154   C2V_BLOCK(result_type, name, signature)
 155 
 156 #define C2V_VMENTRY_NULL(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, NULL)
 157 #define C2V_VMENTRY_0(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, 0)
 158 
 159 // Entry to native method implementation that does not transition
 160 // current thread to '_thread_in_vm'.
 161 #define C2V_VMENTRY_PREFIX(result_type, name, signature) \
 162   JNIEXPORT result_type JNICALL c2v_ ## name signature { \
 163   JavaThread* thread = get_current_thread();
 164 
 165 #define C2V_END }
 166 
 167 #define JNI_THROW(caller, name, msg) do {                                         \
 168     jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg);               \
 169     if (__throw_res != JNI_OK) {                                                  \
 170       tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \
 171     }                                                                             \
 172     return;                                                                       \
 173   } while (0);
 174 
 175 #define JNI_THROW_(caller, name, msg, result) do {                                \
 176     jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg);               \
 177     if (__throw_res != JNI_OK) {                                                  \
 178       tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \
 179     }                                                                             \
 180     return result;                                                                \
 181   } while (0)
 182 
 183 jobjectArray readConfiguration0(JNIEnv *env, JVMCI_TRAPS);
 184 
 185 C2V_VMENTRY_NULL(jobjectArray, readConfiguration, (JNIEnv* env))
 186   jobjectArray config = readConfiguration0(env, JVMCI_CHECK_NULL);
 187   return config;
 188 }
 189 
 190 C2V_VMENTRY_NULL(jobject, getFlagValue, (JNIEnv* env, jobject c2vm, jobject name_handle))
 191 #define RETURN_BOXED_LONG(value) jvalue p; p.j = (jlong) (value); JVMCIObject box = JVMCIENV->create_box(T_LONG, &p, JVMCI_CHECK_NULL); return box.as_jobject();
 192 #define RETURN_BOXED_DOUBLE(value) jvalue p; p.d = (jdouble) (value); JVMCIObject box = JVMCIENV->create_box(T_DOUBLE, &p, JVMCI_CHECK_NULL); return box.as_jobject();
 193   JVMCIObject name = JVMCIENV->wrap(name_handle);
 194   if (name.is_null()) {
 195     JVMCI_THROW_NULL(NullPointerException);
 196   }
 197   const char* cstring = JVMCIENV->as_utf8_string(name);
 198   const JVMFlag* flag = JVMFlag::find_declared_flag(cstring);
 199   if (flag == NULL) {
 200     return c2vm;
 201   }
 202   if (flag->is_bool()) {
 203     jvalue prim;
 204     prim.z = flag->get_bool();
 205     JVMCIObject box = JVMCIENV->create_box(T_BOOLEAN, &prim, JVMCI_CHECK_NULL);
 206     return JVMCIENV->get_jobject(box);
 207   } else if (flag->is_ccstr()) {
 208     JVMCIObject value = JVMCIENV->create_string(flag->get_ccstr(), JVMCI_CHECK_NULL);
 209     return JVMCIENV->get_jobject(value);
 210   } else if (flag->is_intx()) {
 211     RETURN_BOXED_LONG(flag->get_intx());
 212   } else if (flag->is_int()) {
 213     RETURN_BOXED_LONG(flag->get_int());
 214   } else if (flag->is_uint()) {
 215     RETURN_BOXED_LONG(flag->get_uint());
 216   } else if (flag->is_uint64_t()) {
 217     RETURN_BOXED_LONG(flag->get_uint64_t());
 218   } else if (flag->is_size_t()) {
 219     RETURN_BOXED_LONG(flag->get_size_t());
 220   } else if (flag->is_uintx()) {
 221     RETURN_BOXED_LONG(flag->get_uintx());
 222   } else if (flag->is_double()) {
 223     RETURN_BOXED_DOUBLE(flag->get_double());
 224   } else {
 225     JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->name(), flag->type_string());
 226   }
 227 #undef RETURN_BOXED_LONG
 228 #undef RETURN_BOXED_DOUBLE
 229 C2V_END
 230 
 231 C2V_VMENTRY_NULL(jbyteArray, getBytecode, (JNIEnv* env, jobject, jobject jvmci_method))
 232   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
 233 
 234   int code_size = method->code_size();
 235   jbyte* reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size);
 236 
 237   guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten");
 238   // iterate over all bytecodes and replace non-Java bytecodes
 239 
 240   for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) {
 241     Bytecodes::Code code = s.code();
 242     Bytecodes::Code raw_code = s.raw_code();
 243     int bci = s.bci();
 244     int len = s.instruction_size();
 245 
 246     // Restore original byte code.
 247     reconstituted_code[bci] =  (jbyte) (s.is_wide()? Bytecodes::_wide : code);
 248     if (len > 1) {
 249       memcpy(reconstituted_code + (bci + 1), s.bcp()+1, len-1);
 250     }
 251 
 252     if (len > 1) {
 253       // Restore the big-endian constant pool indexes.
 254       // Cf. Rewriter::scan_method
 255       switch (code) {
 256         case Bytecodes::_getstatic:
 257         case Bytecodes::_putstatic:
 258         case Bytecodes::_getfield:
 259         case Bytecodes::_putfield:
 260         case Bytecodes::_invokevirtual:
 261         case Bytecodes::_invokespecial:
 262         case Bytecodes::_invokestatic:
 263         case Bytecodes::_invokeinterface:
 264         case Bytecodes::_invokehandle: {
 265           int cp_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1));
 266           Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index);
 267           break;
 268         }
 269 
 270         case Bytecodes::_invokedynamic: {
 271           int cp_index = Bytes::get_native_u4((address) reconstituted_code + (bci + 1));
 272           Bytes::put_Java_u4((address) reconstituted_code + (bci + 1), (u4) cp_index);
 273           break;
 274         }
 275 
 276         default:
 277           break;
 278       }
 279 
 280       // Not all ldc byte code are rewritten.
 281       switch (raw_code) {
 282         case Bytecodes::_fast_aldc: {
 283           int cpc_index = reconstituted_code[bci + 1] & 0xff;
 284           int cp_index = method->constants()->object_to_cp_index(cpc_index);
 285           assert(cp_index < method->constants()->length(), "sanity check");
 286           reconstituted_code[bci + 1] = (jbyte) cp_index;
 287           break;
 288         }
 289 
 290         case Bytecodes::_fast_aldc_w: {
 291           int cpc_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1));
 292           int cp_index = method->constants()->object_to_cp_index(cpc_index);
 293           assert(cp_index < method->constants()->length(), "sanity check");
 294           Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index);
 295           break;
 296         }
 297 
 298         default:
 299           break;
 300       }
 301     }
 302   }
 303 
 304   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
 305   JVMCIENV->copy_bytes_from(reconstituted_code, result, 0, code_size);
 306   return JVMCIENV->get_jbyteArray(result);
 307 C2V_END
 308 
 309 C2V_VMENTRY_0(jint, getExceptionTableLength, (JNIEnv* env, jobject, jobject jvmci_method))
 310   Method* method = JVMCIENV->asMethod(jvmci_method);
 311   return method->exception_table_length();
 312 C2V_END
 313 
 314 C2V_VMENTRY_0(jlong, getExceptionTableStart, (JNIEnv* env, jobject, jobject jvmci_method))
 315   Method* method = JVMCIENV->asMethod(jvmci_method);
 316   if (method->exception_table_length() == 0) {
 317     return 0L;
 318   }
 319   return (jlong) (address) method->exception_table_start();
 320 C2V_END
 321 
 322 C2V_VMENTRY_NULL(jobject, asResolvedJavaMethod, (JNIEnv* env, jobject, jobject executable_handle))
 323   requireInHotSpot("asResolvedJavaMethod", JVMCI_CHECK_NULL);
 324   oop executable = JNIHandles::resolve(executable_handle);
 325   oop mirror = NULL;
 326   int slot = 0;
 327 
 328   if (executable->klass() == vmClasses::reflect_Constructor_klass()) {
 329     mirror = java_lang_reflect_Constructor::clazz(executable);
 330     slot = java_lang_reflect_Constructor::slot(executable);
 331   } else {
 332     assert(executable->klass() == vmClasses::reflect_Method_klass(), "wrong type");
 333     mirror = java_lang_reflect_Method::clazz(executable);
 334     slot = java_lang_reflect_Method::slot(executable);
 335   }
 336   Klass* holder = java_lang_Class::as_Klass(mirror);
 337   methodHandle method (THREAD, InstanceKlass::cast(holder)->method_with_idnum(slot));
 338   JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
 339   return JVMCIENV->get_jobject(result);
 340 }
 341 
 342 C2V_VMENTRY_NULL(jobject, getResolvedJavaMethod, (JNIEnv* env, jobject, jobject base, jlong offset))
 343   Method* method = NULL;
 344   JVMCIObject base_object = JVMCIENV->wrap(base);
 345   if (base_object.is_null()) {
 346     method = *((Method**)(offset));
 347   } else if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
 348     Handle obj = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
 349     if (obj->is_a(vmClasses::ResolvedMethodName_klass())) {
 350       method = (Method*) (intptr_t) obj->long_field(offset);
 351     } else {
 352       JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", obj->klass()->external_name()));
 353     }
 354   } else if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(base_object)) {
 355     method = JVMCIENV->asMethod(base_object);
 356   }
 357   if (method == NULL) {
 358     JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", JVMCIENV->klass_name(base_object)));
 359   }
 360   assert (method->is_method(), "invalid read");
 361   JVMCIObject result = JVMCIENV->get_jvmci_method(methodHandle(THREAD, method), JVMCI_CHECK_NULL);
 362   return JVMCIENV->get_jobject(result);
 363 }
 364 
 365 C2V_VMENTRY_NULL(jobject, getConstantPool, (JNIEnv* env, jobject, jobject object_handle))
 366   ConstantPool* cp = NULL;
 367   JVMCIObject object = JVMCIENV->wrap(object_handle);
 368   if (object.is_null()) {
 369     JVMCI_THROW_NULL(NullPointerException);
 370   }
 371   if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(object)) {
 372     cp = JVMCIENV->asMethod(object)->constMethod()->constants();
 373   } else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(object)) {
 374     cp = InstanceKlass::cast(JVMCIENV->asKlass(object))->constants();
 375   } else {
 376     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
 377                 err_msg("Unexpected type: %s", JVMCIENV->klass_name(object)));
 378   }
 379   assert(cp != NULL, "npe");
 380 
 381   JVMCIObject result = JVMCIENV->get_jvmci_constant_pool(constantPoolHandle(THREAD, cp), JVMCI_CHECK_NULL);
 382   return JVMCIENV->get_jobject(result);
 383 }
 384 
 385 C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject base, jlong offset, jboolean compressed))
 386   JVMCIKlassHandle klass(THREAD);
 387   JVMCIObject base_object = JVMCIENV->wrap(base);
 388   jlong base_address = 0;
 389   if (base_object.is_non_null() && offset == oopDesc::klass_offset_in_bytes()) {
 390     // klass = JVMCIENV->unhandle(base_object)->klass();
 391     if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
 392       Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
 393       klass = base_oop->klass();
 394     } else {
 395       assert(false, "What types are we actually expecting here?");
 396     }
 397   } else if (!compressed) {
 398     if (base_object.is_non_null()) {
 399       if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(base_object)) {
 400         base_address = (intptr_t) JVMCIENV->asMethod(base_object);
 401       } else if (JVMCIENV->isa_HotSpotConstantPool(base_object)) {
 402         base_address = (intptr_t) JVMCIENV->asConstantPool(base_object);
 403       } else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base_object)) {
 404         base_address = (intptr_t) JVMCIENV->asKlass(base_object);
 405       } else if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
 406         Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
 407         if (base_oop->is_a(vmClasses::Class_klass())) {
 408           base_address = cast_from_oop<jlong>(base_oop());
 409         }
 410       }
 411       if (base_address == 0) {
 412         JVMCI_THROW_MSG_NULL(IllegalArgumentException,
 413                     err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", JVMCIENV->klass_name(base_object), offset, compressed ? "true" : "false"));
 414       }
 415     }
 416     klass = *((Klass**) (intptr_t) (base_address + offset));
 417   } else {
 418     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
 419                 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s",
 420                         base_object.is_non_null() ? JVMCIENV->klass_name(base_object) : "null",
 421                         offset, compressed ? "true" : "false"));
 422   }
 423   assert (klass == NULL || klass->is_klass(), "invalid read");
 424   JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
 425   return JVMCIENV->get_jobject(result);
 426 }
 427 
 428 C2V_VMENTRY_NULL(jobject, findUniqueConcreteMethod, (JNIEnv* env, jobject, jobject jvmci_type, jobject jvmci_method))
 429   methodHandle method (THREAD, JVMCIENV->asMethod(jvmci_method));
 430   InstanceKlass* holder = InstanceKlass::cast(JVMCIENV->asKlass(jvmci_type));
 431   if (holder->is_interface()) {
 432     JVMCI_THROW_MSG_NULL(InternalError, err_msg("Interface %s should be handled in Java code", holder->external_name()));
 433   }
 434   if (method->can_be_statically_bound()) {
 435     JVMCI_THROW_MSG_NULL(InternalError, err_msg("Effectively static method %s.%s should be handled in Java code", method->method_holder()->external_name(), method->external_name()));
 436   }
 437 
 438   methodHandle ucm;
 439   {
 440     MutexLocker locker(Compile_lock);
 441     ucm = methodHandle(THREAD, Dependencies::find_unique_concrete_method(holder, method()));
 442   }
 443   JVMCIObject result = JVMCIENV->get_jvmci_method(ucm, JVMCI_CHECK_NULL);
 444   return JVMCIENV->get_jobject(result);
 445 C2V_END
 446 
 447 C2V_VMENTRY_NULL(jobject, getImplementor, (JNIEnv* env, jobject, jobject jvmci_type))
 448   Klass* klass = JVMCIENV->asKlass(jvmci_type);
 449   if (!klass->is_interface()) {
 450     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 451         err_msg("Expected interface type, got %s", klass->external_name()));
 452   }
 453   InstanceKlass* iklass = InstanceKlass::cast(klass);
 454   JVMCIKlassHandle handle(THREAD);
 455   {
 456     // Need Compile_lock around implementor()
 457     MutexLocker locker(Compile_lock);
 458     handle = iklass->implementor();
 459   }
 460   JVMCIObject implementor = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL);
 461   return JVMCIENV->get_jobject(implementor);
 462 C2V_END
 463 
 464 C2V_VMENTRY_0(jboolean, methodIsIgnoredBySecurityStackWalk,(JNIEnv* env, jobject, jobject jvmci_method))
 465   Method* method = JVMCIENV->asMethod(jvmci_method);
 466   return method->is_ignored_by_security_stack_walk();
 467 C2V_END
 468 
 469 C2V_VMENTRY_0(jboolean, isCompilable,(JNIEnv* env, jobject, jobject jvmci_method))
 470   Method* method = JVMCIENV->asMethod(jvmci_method);
 471   // Skip redefined methods
 472   if (method->is_old()) {
 473     return false;
 474   }
 475   return !method->is_not_compilable(CompLevel_full_optimization);
 476 C2V_END
 477 
 478 C2V_VMENTRY_0(jboolean, hasNeverInlineDirective,(JNIEnv* env, jobject, jobject jvmci_method))
 479   methodHandle method (THREAD, JVMCIENV->asMethod(jvmci_method));
 480   return !Inline || CompilerOracle::should_not_inline(method) || method->dont_inline();
 481 C2V_END
 482 
 483 C2V_VMENTRY_0(jboolean, shouldInlineMethod,(JNIEnv* env, jobject, jobject jvmci_method))
 484   methodHandle method (THREAD, JVMCIENV->asMethod(jvmci_method));
 485   return CompilerOracle::should_inline(method) || method->force_inline();
 486 C2V_END
 487 
 488 C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, jclass accessing_class, jboolean resolve))
 489   JVMCIObject name = JVMCIENV->wrap(jname);
 490   const char* str = JVMCIENV->as_utf8_string(name);
 491   TempNewSymbol class_name = SymbolTable::new_symbol(str);
 492 
 493   if (class_name->utf8_length() <= 1) {
 494     JVMCI_THROW_MSG_0(InternalError, err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string()));
 495   }
 496 
 497   JVMCIKlassHandle resolved_klass(THREAD);
 498   Klass* accessing_klass = NULL;
 499   Handle class_loader;
 500   Handle protection_domain;
 501   if (accessing_class != NULL) {
 502     accessing_klass = JVMCIENV->asKlass(accessing_class);
 503     class_loader = Handle(THREAD, accessing_klass->class_loader());
 504     protection_domain = Handle(THREAD, accessing_klass->protection_domain());
 505   } else {
 506     // Use the System class loader
 507     class_loader = Handle(THREAD, SystemDictionary::java_system_loader());
 508     JVMCIENV->runtime()->initialize(JVMCIENV);
 509   }
 510 
 511   if (resolve) {
 512     resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
 513     if (resolved_klass == NULL) {
 514       JVMCI_THROW_MSG_NULL(ClassNotFoundException, str);
 515     }
 516   } else {
 517     if (Signature::has_envelope(class_name)) {
 518       // This is a name from a signature.  Strip off the trimmings.
 519       // Call recursive to keep scope of strippedsym.
 520       TempNewSymbol strippedsym = Signature::strip_envelope(class_name);
 521       resolved_klass = SystemDictionary::find_instance_klass(strippedsym,
 522                                                              class_loader,
 523                                                              protection_domain);
 524     } else if (Signature::is_array(class_name)) {
 525       SignatureStream ss(class_name, false);
 526       int ndim = ss.skip_array_prefix();
 527       if (ss.type() == T_OBJECT) {
 528         Symbol* strippedsym = ss.as_symbol();
 529         resolved_klass = SystemDictionary::find_instance_klass(strippedsym,
 530                                                                class_loader,
 531                                                                protection_domain);
 532         if (!resolved_klass.is_null()) {
 533           resolved_klass = resolved_klass->array_klass(ndim, CHECK_NULL);
 534         }
 535       } else {
 536         resolved_klass = TypeArrayKlass::cast(Universe::typeArrayKlassObj(ss.type()))->array_klass(ndim, CHECK_NULL);
 537       }
 538     } else {
 539       resolved_klass = SystemDictionary::find_instance_klass(class_name,
 540                                                              class_loader,
 541                                                              protection_domain);
 542     }
 543   }
 544   JVMCIObject result = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL);
 545   return JVMCIENV->get_jobject(result);
 546 C2V_END
 547 
 548 C2V_VMENTRY_NULL(jobject, getArrayType, (JNIEnv* env, jobject, jobject jvmci_type))
 549   if (jvmci_type == NULL) {
 550     JVMCI_THROW_0(NullPointerException);
 551   }
 552 
 553   JVMCIObject jvmci_type_object = JVMCIENV->wrap(jvmci_type);
 554   JVMCIKlassHandle array_klass(THREAD);
 555   if (JVMCIENV->isa_HotSpotResolvedPrimitiveType(jvmci_type_object)) {
 556     BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->get_HotSpotResolvedPrimitiveType_kind(jvmci_type_object), JVMCI_CHECK_0);
 557     if (type == T_VOID) {
 558       return NULL;
 559     }
 560     array_klass = Universe::typeArrayKlassObj(type);
 561     if (array_klass == NULL) {
 562       JVMCI_THROW_MSG_NULL(InternalError, err_msg("No array klass for primitive type %s", type2name(type)));
 563     }
 564   } else {
 565     Klass* klass = JVMCIENV->asKlass(jvmci_type);
 566     if (klass == NULL) {
 567       JVMCI_THROW_0(NullPointerException);
 568     }
 569     array_klass = klass->array_klass(CHECK_NULL);
 570   }
 571   JVMCIObject result = JVMCIENV->get_jvmci_type(array_klass, JVMCI_CHECK_NULL);
 572   return JVMCIENV->get_jobject(result);
 573 C2V_END
 574 
 575 C2V_VMENTRY_NULL(jobject, lookupClass, (JNIEnv* env, jobject, jclass mirror))
 576   requireInHotSpot("lookupClass", JVMCI_CHECK_NULL);
 577   if (mirror == NULL) {
 578     return NULL;
 579   }
 580   JVMCIKlassHandle klass(THREAD);
 581   klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror));
 582   if (klass == NULL) {
 583     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Primitive classes are unsupported");
 584   }
 585   JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
 586   return JVMCIENV->get_jobject(result);
 587 C2V_END
 588 
 589 C2V_VMENTRY_NULL(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
 590   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 591   oop obj = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
 592   constantTag tag = cp->tag_at(index);
 593   if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
 594     if (obj == Universe::the_null_sentinel()) {
 595       return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
 596     }
 597     BasicType bt = Signature::basic_type(cp->uncached_signature_ref_at(index));
 598     if (!is_reference_type(bt)) {
 599       if (!is_java_primitive(bt)) {
 600         return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL());
 601       }
 602 
 603       // Convert standard box (e.g. java.lang.Integer) to JVMCI box (e.g. jdk.vm.ci.meta.PrimitiveConstant)
 604       jvalue value;
 605       jlong raw_value;
 606       JVMCIObject kind;
 607       BasicType bt2 = java_lang_boxing_object::get_value(obj, &value);
 608       assert(bt2 == bt, "");
 609       switch (bt2) {
 610         case T_LONG:    kind = JVMCIENV->get_JavaKind_Long();    raw_value = value.j; break;
 611         case T_DOUBLE:  kind = JVMCIENV->get_JavaKind_Double();  raw_value = value.j; break;
 612         case T_FLOAT:   kind = JVMCIENV->get_JavaKind_Float();   raw_value = value.i; break;
 613         case T_INT:     kind = JVMCIENV->get_JavaKind_Int();     raw_value = value.i; break;
 614         case T_SHORT:   kind = JVMCIENV->get_JavaKind_Short();   raw_value = value.s; break;
 615         case T_BYTE:    kind = JVMCIENV->get_JavaKind_Byte();    raw_value = value.b; break;
 616         case T_CHAR:    kind = JVMCIENV->get_JavaKind_Char();    raw_value = value.c; break;
 617         case T_BOOLEAN: kind = JVMCIENV->get_JavaKind_Boolean(); raw_value = value.z; break;
 618         default:        return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL());
 619       }
 620 
 621       JVMCIObject result = JVMCIENV->call_JavaConstant_forPrimitive(kind, raw_value, JVMCI_CHECK_NULL);
 622       return JVMCIENV->get_jobject(result);
 623     }
 624   }
 625   return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(obj));
 626 C2V_END
 627 
 628 C2V_VMENTRY_NULL(jobjectArray, resolveBootstrapMethod, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
 629   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 630   constantTag tag = cp->tag_at(index);
 631   bool is_indy = tag.is_invoke_dynamic();
 632   bool is_condy = tag.is_dynamic_constant();
 633   if (!(is_condy || is_indy)) {
 634     JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Unexpected constant pool tag at index %d: %d", index, tag.value()));
 635   }
 636   // Resolve the bootstrap specifier, its name, type, and static arguments
 637   BootstrapInfo bootstrap_specifier(cp, index);
 638   Handle bsm = bootstrap_specifier.resolve_bsm(CHECK_NULL);
 639 
 640   // call java.lang.invoke.MethodHandle::asFixedArity() -> MethodHandle
 641   // to get a DirectMethodHandle from which we can then extract a Method*
 642   JavaValue result(T_OBJECT);
 643   JavaCalls::call_virtual(&result,
 644                          bsm,
 645                          vmClasses::MethodHandle_klass(),
 646                          vmSymbols::asFixedArity_name(),
 647                          vmSymbols::asFixedArity_signature(),
 648                          CHECK_NULL);
 649   bsm = Handle(THREAD, result.get_oop());
 650 
 651   // Check assumption about getting a DirectMethodHandle
 652   if (!java_lang_invoke_DirectMethodHandle::is_instance(bsm())) {
 653     JVMCI_THROW_MSG_NULL(InternalError, err_msg("Unexpected MethodHandle subclass: %s", bsm->klass()->external_name()));
 654   }
 655   // Create return array describing the bootstrap method invocation (BSMI)
 656   JVMCIObjectArray bsmi = JVMCIENV->new_Object_array(4, JVMCI_CHECK_NULL);
 657 
 658   // Extract Method* and wrap it in a ResolvedJavaMethod
 659   Handle member = Handle(THREAD, java_lang_invoke_DirectMethodHandle::member(bsm()));
 660   JVMCIObject bsmi_method = JVMCIENV->get_jvmci_method(methodHandle(THREAD, java_lang_invoke_MemberName::vmtarget(member())), JVMCI_CHECK_NULL);
 661   JVMCIENV->put_object_at(bsmi, 0, bsmi_method);
 662 
 663   JVMCIObject bsmi_name = JVMCIENV->create_string(bootstrap_specifier.name(), JVMCI_CHECK_NULL);
 664   JVMCIENV->put_object_at(bsmi, 1, bsmi_name);
 665 
 666   Handle type_arg = bootstrap_specifier.type_arg();
 667   JVMCIObject bsmi_type = JVMCIENV->get_object_constant(type_arg());
 668   JVMCIENV->put_object_at(bsmi, 2, bsmi_type);
 669 
 670   Handle arg_values = bootstrap_specifier.arg_values();
 671   if (arg_values.not_null()) {
 672     if (!arg_values->is_array()) {
 673       JVMCIENV->put_object_at(bsmi, 3, JVMCIENV->get_object_constant(arg_values()));
 674     } else if (arg_values->is_objArray()) {
 675       objArrayHandle args_array = objArrayHandle(THREAD, (objArrayOop) arg_values());
 676       int len = args_array->length();
 677       JVMCIObjectArray arguments = JVMCIENV->new_JavaConstant_array(len, JVMCI_CHECK_NULL);
 678       JVMCIENV->put_object_at(bsmi, 3, arguments);
 679       for (int i = 0; i < len; i++) {
 680         oop x = args_array->obj_at(i);
 681         if (x != nullptr) {
 682           JVMCIENV->put_object_at(arguments, i, JVMCIENV->get_object_constant(x));
 683         } else {
 684           JVMCIENV->put_object_at(arguments, i, JVMCIENV->get_JavaConstant_NULL_POINTER());
 685         }
 686       }
 687     } else if (arg_values->is_typeArray()) {
 688       typeArrayHandle bsci = typeArrayHandle(THREAD, (typeArrayOop) arg_values());
 689       JVMCIPrimitiveArray arguments = JVMCIENV->new_intArray(bsci->length(), JVMCI_CHECK_NULL);
 690       JVMCIENV->put_object_at(bsmi, 3, arguments);
 691       for (int i = 0; i < bsci->length(); i++) {
 692         JVMCIENV->put_int_at(arguments, i, bsci->int_at(i));
 693       }
 694     }
 695   }
 696   return JVMCIENV->get_jobjectArray(bsmi);
 697 C2V_END
 698 
 699 C2V_VMENTRY_0(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
 700   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 701   return cp->name_and_type_ref_index_at(index);
 702 C2V_END
 703 
 704 C2V_VMENTRY_NULL(jobject, lookupNameInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint which))
 705   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 706   JVMCIObject sym = JVMCIENV->create_string(cp->name_ref_at(which), JVMCI_CHECK_NULL);
 707   return JVMCIENV->get_jobject(sym);
 708 C2V_END
 709 
 710 C2V_VMENTRY_NULL(jobject, lookupSignatureInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint which))
 711   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 712   JVMCIObject sym = JVMCIENV->create_string(cp->signature_ref_at(which), JVMCI_CHECK_NULL);
 713   return JVMCIENV->get_jobject(sym);
 714 C2V_END
 715 
 716 C2V_VMENTRY_0(jint, lookupKlassRefIndexInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
 717   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 718   return cp->klass_ref_index_at(index);
 719 C2V_END
 720 
 721 C2V_VMENTRY_NULL(jobject, resolveTypeInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
 722   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 723   Klass* klass = cp->klass_at(index, CHECK_NULL);
 724   JVMCIKlassHandle resolved_klass(THREAD, klass);
 725   if (resolved_klass->is_instance_klass()) {
 726     InstanceKlass::cast(resolved_klass())->link_class(CHECK_NULL);
 727     if (!InstanceKlass::cast(resolved_klass())->is_linked()) {
 728       // link_class() should not return here if there is an issue.
 729       JVMCI_THROW_MSG_NULL(InternalError, err_msg("Class %s must be linked", resolved_klass()->external_name()));
 730     }
 731   }
 732   JVMCIObject klassObject = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL);
 733   return JVMCIENV->get_jobject(klassObject);
 734 C2V_END
 735 
 736 C2V_VMENTRY_NULL(jobject, lookupKlassInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
 737   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 738   Klass* loading_klass = cp->pool_holder();
 739   bool is_accessible = false;
 740   JVMCIKlassHandle klass(THREAD, JVMCIRuntime::get_klass_by_index(cp, index, is_accessible, loading_klass));
 741   Symbol* symbol = NULL;
 742   if (klass.is_null()) {
 743     constantTag tag = cp->tag_at(index);
 744     if (tag.is_klass()) {
 745       // The klass has been inserted into the constant pool
 746       // very recently.
 747       klass = cp->resolved_klass_at(index);
 748     } else if (tag.is_symbol()) {
 749       symbol = cp->symbol_at(index);
 750     } else {
 751       assert(cp->tag_at(index).is_unresolved_klass(), "wrong tag");
 752       symbol = cp->klass_name_at(index);
 753     }
 754   }
 755   JVMCIObject result;
 756   if (!klass.is_null()) {
 757     result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
 758   } else {
 759     result = JVMCIENV->create_string(symbol, JVMCI_CHECK_NULL);
 760   }
 761   return JVMCIENV->get_jobject(result);
 762 C2V_END
 763 
 764 C2V_VMENTRY_NULL(jobject, lookupAppendixInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
 765   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 766   oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index);
 767   return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(appendix_oop));
 768 C2V_END
 769 
 770 C2V_VMENTRY_NULL(jobject, lookupMethodInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
 771   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 772   InstanceKlass* pool_holder = cp->pool_holder();
 773   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
 774   methodHandle method(THREAD, JVMCIRuntime::get_method_by_index(cp, index, bc, pool_holder));
 775   JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
 776   return JVMCIENV->get_jobject(result);
 777 C2V_END
 778 
 779 C2V_VMENTRY_0(jint, constantPoolRemapInstructionOperandFromCache, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
 780   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 781   return cp->remap_instruction_operand_from_cache(index);
 782 C2V_END
 783 
 784 C2V_VMENTRY_NULL(jobject, resolveFieldInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jobject jvmci_method, jbyte opcode, jintArray info_handle))
 785   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
 786   Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
 787   fieldDescriptor fd;
 788   methodHandle mh(THREAD, (jvmci_method != NULL) ? JVMCIENV->asMethod(jvmci_method) : NULL);
 789   LinkInfo link_info(cp, index, mh, CHECK_NULL);
 790   LinkResolver::resolve_field(fd, link_info, Bytecodes::java_code(code), false, CHECK_NULL);
 791   JVMCIPrimitiveArray info = JVMCIENV->wrap(info_handle);
 792   if (info.is_null() || JVMCIENV->get_length(info) != 3) {
 793     JVMCI_ERROR_NULL("info must not be null and have a length of 3");
 794   }
 795   JVMCIENV->put_int_at(info, 0, fd.access_flags().as_int());
 796   JVMCIENV->put_int_at(info, 1, fd.offset());
 797   JVMCIENV->put_int_at(info, 2, fd.index());
 798   JVMCIKlassHandle handle(THREAD, fd.field_holder());
 799   JVMCIObject field_holder = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL);
 800   return JVMCIENV->get_jobject(field_holder);
 801 C2V_END
 802 
 803 C2V_VMENTRY_0(jint, getVtableIndexForInterfaceMethod, (JNIEnv* env, jobject, jobject jvmci_type, jobject jvmci_method))
 804   Klass* klass = JVMCIENV->asKlass(jvmci_type);
 805   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
 806   InstanceKlass* holder = method->method_holder();
 807   if (klass->is_interface()) {
 808     JVMCI_THROW_MSG_0(InternalError, err_msg("Interface %s should be handled in Java code", klass->external_name()));
 809   }
 810   if (!holder->is_interface()) {
 811     JVMCI_THROW_MSG_0(InternalError, err_msg("Method %s is not held by an interface, this case should be handled in Java code", method->name_and_sig_as_C_string()));
 812   }
 813   if (!klass->is_instance_klass()) {
 814     JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be instance klass", klass->external_name()));
 815   }
 816   if (!InstanceKlass::cast(klass)->is_linked()) {
 817     JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be linked", klass->external_name()));
 818   }
 819   if (!klass->is_subtype_of(holder)) {
 820     JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s does not implement interface %s", klass->external_name(), holder->external_name()));
 821   }
 822   return LinkResolver::vtable_index_of_interface_method(klass, method);
 823 C2V_END
 824 
 825 C2V_VMENTRY_NULL(jobject, resolveMethod, (JNIEnv* env, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type))
 826   Klass* recv_klass = JVMCIENV->asKlass(receiver_jvmci_type);
 827   Klass* caller_klass = JVMCIENV->asKlass(caller_jvmci_type);
 828   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
 829 
 830   Klass* resolved     = method->method_holder();
 831   Symbol* h_name      = method->name();
 832   Symbol* h_signature = method->signature();
 833 
 834   if (MethodHandles::is_signature_polymorphic_method(method())) {
 835       // Signature polymorphic methods are already resolved, JVMCI just returns NULL in this case.
 836       return NULL;
 837   }
 838 
 839   if (method->name() == vmSymbols::clone_name() &&
 840       resolved == vmClasses::Object_klass() &&
 841       recv_klass->is_array_klass()) {
 842     // Resolution of the clone method on arrays always returns Object.clone even though that method
 843     // has protected access.  There's some trickery in the access checking to make this all work out
 844     // so it's necessary to pass in the array class as the resolved class to properly trigger this.
 845     // Otherwise it's impossible to resolve the array clone methods through JVMCI.  See
 846     // LinkResolver::check_method_accessability for the matching logic.
 847     resolved = recv_klass;
 848   }
 849 
 850   LinkInfo link_info(resolved, h_name, h_signature, caller_klass);
 851   Method* m = NULL;
 852   // Only do exact lookup if receiver klass has been linked.  Otherwise,
 853   // the vtable has not been setup, and the LinkResolver will fail.
 854   if (recv_klass->is_array_klass() ||
 855       (InstanceKlass::cast(recv_klass)->is_linked() && !recv_klass->is_interface())) {
 856     if (resolved->is_interface()) {
 857       m = LinkResolver::resolve_interface_call_or_null(recv_klass, link_info);
 858     } else {
 859       m = LinkResolver::resolve_virtual_call_or_null(recv_klass, link_info);
 860     }
 861   }
 862 
 863   if (m == NULL) {
 864     // Return NULL if there was a problem with lookup (uninitialized class, etc.)
 865     return NULL;
 866   }
 867 
 868   JVMCIObject result = JVMCIENV->get_jvmci_method(methodHandle(THREAD, m), JVMCI_CHECK_NULL);
 869   return JVMCIENV->get_jobject(result);
 870 C2V_END
 871 
 872 C2V_VMENTRY_0(jboolean, hasFinalizableSubclass,(JNIEnv* env, jobject, jobject jvmci_type))
 873   Klass* klass = JVMCIENV->asKlass(jvmci_type);
 874   assert(klass != NULL, "method must not be called for primitive types");
 875   if (!klass->is_instance_klass()) {
 876     return false;
 877   }
 878   InstanceKlass* iklass = InstanceKlass::cast(klass);
 879   return Dependencies::find_finalizable_subclass(iklass) != NULL;
 880 C2V_END
 881 
 882 C2V_VMENTRY_NULL(jobject, getClassInitializer, (JNIEnv* env, jobject, jobject jvmci_type))
 883   Klass* klass = JVMCIENV->asKlass(jvmci_type);
 884   if (!klass->is_instance_klass()) {
 885     return NULL;
 886   }
 887   InstanceKlass* iklass = InstanceKlass::cast(klass);
 888   methodHandle clinit(THREAD, iklass->class_initializer());
 889   JVMCIObject result = JVMCIENV->get_jvmci_method(clinit, JVMCI_CHECK_NULL);
 890   return JVMCIENV->get_jobject(result);
 891 C2V_END
 892 
 893 C2V_VMENTRY_0(jlong, getMaxCallTargetOffset, (JNIEnv* env, jobject, jlong addr))
 894   address target_addr = (address) addr;
 895   if (target_addr != 0x0) {
 896     int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
 897     int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
 898     return MAX2(ABS(off_low), ABS(off_high));
 899   }
 900   return -1;
 901 C2V_END
 902 
 903 C2V_VMENTRY(void, setNotInlinableOrCompilable,(JNIEnv* env, jobject,  jobject jvmci_method))
 904   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
 905   method->set_not_c1_compilable();
 906   method->set_not_c2_compilable();
 907   method->set_dont_inline(true);
 908 C2V_END
 909 
 910 C2V_VMENTRY_0(jint, installCode, (JNIEnv *env, jobject, jobject target, jobject compiled_code,
 911             jobject installed_code, jlong failed_speculations_address, jbyteArray speculations_obj))
 912   HandleMark hm(THREAD);
 913   JNIHandleMark jni_hm(thread);
 914 
 915   JVMCIObject target_handle = JVMCIENV->wrap(target);
 916   JVMCIObject compiled_code_handle = JVMCIENV->wrap(compiled_code);
 917   CodeBlob* cb = NULL;
 918   JVMCIObject installed_code_handle = JVMCIENV->wrap(installed_code);
 919   JVMCIPrimitiveArray speculations_handle = JVMCIENV->wrap(speculations_obj);
 920 
 921   int speculations_len = JVMCIENV->get_length(speculations_handle);
 922   char* speculations = NEW_RESOURCE_ARRAY(char, speculations_len);
 923   JVMCIENV->copy_bytes_to(speculations_handle, (jbyte*) speculations, 0, speculations_len);
 924 
 925   JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK_JNI_ERR);
 926 
 927   TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer(!thread->is_Compiler_thread()));
 928 
 929   nmethodLocker nmethod_handle;
 930   CodeInstaller installer(JVMCIENV);
 931   JVMCI::CodeInstallResult result = installer.install(compiler,
 932       target_handle,
 933       compiled_code_handle,
 934       cb,
 935       nmethod_handle,
 936       installed_code_handle,
 937       (FailedSpeculation**)(address) failed_speculations_address,
 938       speculations,
 939       speculations_len,
 940       JVMCI_CHECK_0);
 941 
 942   if (PrintCodeCacheOnCompilation) {
 943     stringStream s;
 944     // Dump code cache into a buffer before locking the tty,
 945     {
 946       MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 947       CodeCache::print_summary(&s, false);
 948     }
 949     ttyLocker ttyl;
 950     tty->print_raw_cr(s.as_string());
 951   }
 952 
 953   if (result != JVMCI::ok) {
 954     assert(cb == NULL, "should be");
 955   } else {
 956     if (installed_code_handle.is_non_null()) {
 957       if (cb->is_nmethod()) {
 958         assert(JVMCIENV->isa_HotSpotNmethod(installed_code_handle), "wrong type");
 959         // Clear the link to an old nmethod first
 960         JVMCIObject nmethod_mirror = installed_code_handle;
 961         JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, JVMCI_CHECK_0);
 962       } else {
 963         assert(JVMCIENV->isa_InstalledCode(installed_code_handle), "wrong type");
 964       }
 965       // Initialize the link to the new code blob
 966       JVMCIENV->initialize_installed_code(installed_code_handle, cb, JVMCI_CHECK_0);
 967     }
 968   }
 969   return result;
 970 C2V_END
 971 
 972 C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv* env, jobject))
 973   JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK);
 974   CompilerStatistics* stats = compiler->stats();
 975   stats->_standard.reset();
 976   stats->_osr.reset();
 977 C2V_END
 978 
 979 C2V_VMENTRY_NULL(jobject, disassembleCodeBlob, (JNIEnv* env, jobject, jobject installedCode))
 980   HandleMark hm(THREAD);
 981 
 982   if (installedCode == NULL) {
 983     JVMCI_THROW_MSG_NULL(NullPointerException, "installedCode is null");
 984   }
 985 
 986   JVMCIObject installedCodeObject = JVMCIENV->wrap(installedCode);
 987   nmethodLocker locker;
 988   CodeBlob* cb = JVMCIENV->get_code_blob(installedCodeObject, locker);
 989   if (cb == NULL) {
 990     return NULL;
 991   }
 992 
 993   // We don't want the stringStream buffer to resize during disassembly as it
 994   // uses scoped resource memory. If a nested function called during disassembly uses
 995   // a ResourceMark and the buffer expands within the scope of the mark,
 996   // the buffer becomes garbage when that scope is exited. Experience shows that
 997   // the disassembled code is typically about 10x the code size so a fixed buffer
 998   // sized to 20x code size plus a fixed amount for header info should be sufficient.
 999   int bufferSize = cb->code_size() * 20 + 1024;
1000   char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize);
1001   stringStream st(buffer, bufferSize);
1002   if (cb->is_nmethod()) {
1003     nmethod* nm = (nmethod*) cb;
1004     if (!nm->is_alive()) {
1005       return NULL;
1006     }
1007   }
1008   Disassembler::decode(cb, &st);
1009   if (st.size() <= 0) {
1010     return NULL;
1011   }
1012 
1013   JVMCIObject result = JVMCIENV->create_string(st.as_string(), JVMCI_CHECK_NULL);
1014   return JVMCIENV->get_jobject(result);
1015 C2V_END
1016 
1017 C2V_VMENTRY_NULL(jobject, getStackTraceElement, (JNIEnv* env, jobject, jobject jvmci_method, int bci))
1018   HandleMark hm(THREAD);
1019 
1020   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
1021   JVMCIObject element = JVMCIENV->new_StackTraceElement(method, bci, JVMCI_CHECK_NULL);
1022   return JVMCIENV->get_jobject(element);
1023 C2V_END
1024 
1025 C2V_VMENTRY_NULL(jobject, executeHotSpotNmethod, (JNIEnv* env, jobject, jobject args, jobject hs_nmethod))
1026   // The incoming arguments array would have to contain JavaConstants instead of regular objects
1027   // and the return value would have to be wrapped as a JavaConstant.
1028   requireInHotSpot("executeHotSpotNmethod", JVMCI_CHECK_NULL);
1029 
1030   HandleMark hm(THREAD);
1031 
1032   JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod);
1033   nmethodLocker locker;
1034   nmethod* nm = JVMCIENV->get_nmethod(nmethod_mirror, locker);
1035   if (nm == NULL || !nm->is_in_use()) {
1036     JVMCI_THROW_NULL(InvalidInstalledCodeException);
1037   }
1038   methodHandle mh(THREAD, nm->method());
1039   Symbol* signature = mh->signature();
1040   JavaCallArguments jca(mh->size_of_parameters());
1041 
1042   JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
1043   JavaValue result(jap.return_type());
1044   jca.set_alternative_target(Handle(THREAD, JNIHandles::resolve(nmethod_mirror.as_jobject())));
1045   JavaCalls::call(&result, mh, &jca, CHECK_NULL);
1046 
1047   if (jap.return_type() == T_VOID) {
1048     return NULL;
1049   } else if (is_reference_type(jap.return_type())) {
1050     return JNIHandles::make_local(THREAD, result.get_oop());
1051   } else {
1052     jvalue *value = (jvalue *) result.get_value_addr();
1053     // Narrow the value down if required (Important on big endian machines)
1054     switch (jap.return_type()) {
1055       case T_BOOLEAN:
1056        value->z = (jboolean) value->i;
1057        break;
1058       case T_BYTE:
1059        value->b = (jbyte) value->i;
1060        break;
1061       case T_CHAR:
1062        value->c = (jchar) value->i;
1063        break;
1064       case T_SHORT:
1065        value->s = (jshort) value->i;
1066        break;
1067       default:
1068         break;
1069     }
1070     JVMCIObject o = JVMCIENV->create_box(jap.return_type(), value, JVMCI_CHECK_NULL);
1071     return JVMCIENV->get_jobject(o);
1072   }
1073 C2V_END
1074 
1075 C2V_VMENTRY_NULL(jlongArray, getLineNumberTable, (JNIEnv* env, jobject, jobject jvmci_method))
1076   Method* method = JVMCIENV->asMethod(jvmci_method);
1077   if (!method->has_linenumber_table()) {
1078     return NULL;
1079   }
1080   u2 num_entries = 0;
1081   CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table());
1082   while (streamForSize.read_pair()) {
1083     num_entries++;
1084   }
1085 
1086   CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
1087   JVMCIPrimitiveArray result = JVMCIENV->new_longArray(2 * num_entries, JVMCI_CHECK_NULL);
1088 
1089   int i = 0;
1090   jlong value;
1091   while (stream.read_pair()) {
1092     value = ((jlong) stream.bci());
1093     JVMCIENV->put_long_at(result, i, value);
1094     value = ((jlong) stream.line());
1095     JVMCIENV->put_long_at(result, i + 1, value);
1096     i += 2;
1097   }
1098 
1099   return (jlongArray) JVMCIENV->get_jobject(result);
1100 C2V_END
1101 
1102 C2V_VMENTRY_0(jlong, getLocalVariableTableStart, (JNIEnv* env, jobject, jobject jvmci_method))
1103   Method* method = JVMCIENV->asMethod(jvmci_method);
1104   if (!method->has_localvariable_table()) {
1105     return 0;
1106   }
1107   return (jlong) (address) method->localvariable_table_start();
1108 C2V_END
1109 
1110 C2V_VMENTRY_0(jint, getLocalVariableTableLength, (JNIEnv* env, jobject, jobject jvmci_method))
1111   Method* method = JVMCIENV->asMethod(jvmci_method);
1112   return method->localvariable_table_length();
1113 C2V_END
1114 
1115 C2V_VMENTRY(void, reprofile, (JNIEnv* env, jobject, jobject jvmci_method))
1116   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
1117   MethodCounters* mcs = method->method_counters();
1118   if (mcs != NULL) {
1119     mcs->clear_counters();
1120   }
1121   NOT_PRODUCT(method->set_compiled_invocation_count(0));
1122 
1123   CompiledMethod* code = method->code();
1124   if (code != NULL) {
1125     code->make_not_entrant();
1126   }
1127 
1128   MethodData* method_data = method->method_data();
1129   if (method_data == NULL) {
1130     ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
1131     method_data = MethodData::allocate(loader_data, method, CHECK);
1132     method->set_method_data(method_data);
1133   } else {
1134     method_data->initialize();
1135   }
1136 C2V_END
1137 
1138 
1139 C2V_VMENTRY(void, invalidateHotSpotNmethod, (JNIEnv* env, jobject, jobject hs_nmethod))
1140   JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod);
1141   JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, JVMCI_CHECK);
1142 C2V_END
1143 
1144 C2V_VMENTRY_NULL(jlongArray, collectCounters, (JNIEnv* env, jobject))
1145   // Returns a zero length array if counters aren't enabled
1146   JVMCIPrimitiveArray array = JVMCIENV->new_longArray(JVMCICounterSize, JVMCI_CHECK_NULL);
1147   if (JVMCICounterSize > 0) {
1148     jlong* temp_array = NEW_RESOURCE_ARRAY(jlong, JVMCICounterSize);
1149     JavaThread::collect_counters(temp_array, JVMCICounterSize);
1150     JVMCIENV->copy_longs_from(temp_array, array, 0, JVMCICounterSize);
1151   }
1152   return (jlongArray) JVMCIENV->get_jobject(array);
1153 C2V_END
1154 
1155 C2V_VMENTRY_0(jint, getCountersSize, (JNIEnv* env, jobject))
1156   return (jint) JVMCICounterSize;
1157 C2V_END
1158 
1159 C2V_VMENTRY_0(jboolean, setCountersSize, (JNIEnv* env, jobject, jint new_size))
1160   return JavaThread::resize_all_jvmci_counters(new_size);
1161 C2V_END
1162 
1163 C2V_VMENTRY_0(jint, allocateCompileId, (JNIEnv* env, jobject, jobject jvmci_method, int entry_bci))
1164   HandleMark hm(THREAD);
1165   if (jvmci_method == NULL) {
1166     JVMCI_THROW_0(NullPointerException);
1167   }
1168   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
1169   if (entry_bci >= method->code_size() || entry_bci < -1) {
1170     JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Unexpected bci %d", entry_bci));
1171   }
1172   return CompileBroker::assign_compile_id_unlocked(THREAD, method, entry_bci);
1173 C2V_END
1174 
1175 
1176 C2V_VMENTRY_0(jboolean, isMature, (JNIEnv* env, jobject, jlong metaspace_method_data))
1177   MethodData* mdo = JVMCIENV->asMethodData(metaspace_method_data);
1178   return mdo != NULL && mdo->is_mature();
1179 C2V_END
1180 
1181 C2V_VMENTRY_0(jboolean, hasCompiledCodeForOSR, (JNIEnv* env, jobject, jobject jvmci_method, int entry_bci, int comp_level))
1182   Method* method = JVMCIENV->asMethod(jvmci_method);
1183   return method->lookup_osr_nmethod_for(entry_bci, comp_level, true) != NULL;
1184 C2V_END
1185 
1186 C2V_VMENTRY_NULL(jobject, getSymbol, (JNIEnv* env, jobject, jlong symbol))
1187   JVMCIObject sym = JVMCIENV->create_string((Symbol*)(address)symbol, JVMCI_CHECK_NULL);
1188   return JVMCIENV->get_jobject(sym);
1189 C2V_END
1190 
1191 /*
1192  * Used by matches() to convert a ResolvedJavaMethod[] to an array of Method*.
1193  */
1194 GrowableArray<Method*>* init_resolved_methods(jobjectArray methods, JVMCIEnv* JVMCIENV) {
1195   objArrayOop methods_oop = (objArrayOop) JNIHandles::resolve(methods);
1196   GrowableArray<Method*>* resolved_methods = new GrowableArray<Method*>(methods_oop->length());
1197   for (int i = 0; i < methods_oop->length(); i++) {
1198     oop resolved = methods_oop->obj_at(i);
1199     Method* resolved_method = NULL;
1200     if (resolved->klass() == HotSpotJVMCI::HotSpotResolvedJavaMethodImpl::klass()) {
1201       resolved_method = HotSpotJVMCI::asMethod(JVMCIENV, resolved);
1202     }
1203     resolved_methods->append(resolved_method);
1204   }
1205   return resolved_methods;
1206 }
1207 
1208 /*
1209  * Used by c2v_iterateFrames to check if `method` matches one of the ResolvedJavaMethods in the `methods` array.
1210  * The ResolvedJavaMethod[] array is converted to a Method* array that is then cached in the resolved_methods_ref in/out parameter.
1211  * In case of a match, the matching ResolvedJavaMethod is returned in matched_jvmci_method_ref.
1212  */
1213 bool matches(jobjectArray methods, Method* method, GrowableArray<Method*>** resolved_methods_ref, Handle* matched_jvmci_method_ref, Thread* THREAD, JVMCIEnv* JVMCIENV) {
1214   GrowableArray<Method*>* resolved_methods = *resolved_methods_ref;
1215   if (resolved_methods == NULL) {
1216     resolved_methods = init_resolved_methods(methods, JVMCIENV);
1217     *resolved_methods_ref = resolved_methods;
1218   }
1219   assert(method != NULL, "method should not be NULL");
1220   assert(resolved_methods->length() == ((objArrayOop) JNIHandles::resolve(methods))->length(), "arrays must have the same length");
1221   for (int i = 0; i < resolved_methods->length(); i++) {
1222     Method* m = resolved_methods->at(i);
1223     if (m == method) {
1224       *matched_jvmci_method_ref = Handle(THREAD, ((objArrayOop) JNIHandles::resolve(methods))->obj_at(i));
1225       return true;
1226     }
1227   }
1228   return false;
1229 }
1230 
1231 /*
1232  * Resolves an interface call to a concrete method handle.
1233  */
1234 methodHandle resolve_interface_call(Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
1235   CallInfo callinfo;
1236   Handle receiver = args->receiver();
1237   Klass* recvrKlass = receiver.is_null() ? (Klass*)NULL : receiver->klass();
1238   LinkInfo link_info(spec_klass, name, signature);
1239   LinkResolver::resolve_interface_call(
1240           callinfo, receiver, recvrKlass, link_info, true, CHECK_(methodHandle()));
1241   methodHandle method(THREAD, callinfo.selected_method());
1242   assert(method.not_null(), "should have thrown exception");
1243   return method;
1244 }
1245 
1246 /*
1247  * Used by c2v_iterateFrames to make a new vframeStream at the given compiled frame id (stack pointer) and vframe id.
1248  */
1249 void resync_vframestream_to_compiled_frame(vframeStream& vfst, intptr_t* stack_pointer, int vframe_id, JavaThread* thread, TRAPS) {
1250   vfst = vframeStream(thread);
1251   while (vfst.frame_id() != stack_pointer && !vfst.at_end()) {
1252     vfst.next();
1253   }
1254   if (vfst.frame_id() != stack_pointer) {
1255     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found after deopt")
1256   }
1257   if (vfst.is_interpreted_frame()) {
1258     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected")
1259   }
1260   while (vfst.vframe_id() != vframe_id) {
1261     if (vfst.at_end()) {
1262       THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "vframe not found after deopt")
1263     }
1264     vfst.next();
1265     assert(!vfst.is_interpreted_frame(), "Wrong frame type");
1266   }
1267 }
1268 
1269 /*
1270  * Used by c2v_iterateFrames. Returns an array of any unallocated scope objects or NULL if none.
1271  */
1272 GrowableArray<ScopeValue*>* get_unallocated_objects_or_null(GrowableArray<ScopeValue*>* scope_objects) {
1273   GrowableArray<ScopeValue*>* unallocated = NULL;
1274   for (int i = 0; i < scope_objects->length(); i++) {
1275     ObjectValue* sv = (ObjectValue*) scope_objects->at(i);
1276     if (sv->value().is_null()) {
1277       if (unallocated == NULL) {
1278         unallocated = new GrowableArray<ScopeValue*>(scope_objects->length());
1279       }
1280       unallocated->append(sv);
1281     }
1282   }
1283   return unallocated;
1284 }
1285 
1286 C2V_VMENTRY_NULL(jobject, iterateFrames, (JNIEnv* env, jobject compilerToVM, jobjectArray initial_methods, jobjectArray match_methods, jint initialSkip, jobject visitor_handle))
1287 
1288   if (!thread->has_last_Java_frame()) {
1289     return NULL;
1290   }
1291   Handle visitor(THREAD, JNIHandles::resolve_non_null(visitor_handle));
1292 
1293   requireInHotSpot("iterateFrames", JVMCI_CHECK_NULL);
1294 
1295   HotSpotJVMCI::HotSpotStackFrameReference::klass()->initialize(CHECK_NULL);
1296 
1297   vframeStream vfst(thread);
1298   jobjectArray methods = initial_methods;
1299   methodHandle visitor_method;
1300   GrowableArray<Method*>* resolved_methods = NULL;
1301 
1302   while (!vfst.at_end()) { // frame loop
1303     bool realloc_called = false;
1304     intptr_t* frame_id = vfst.frame_id();
1305 
1306     // Previous compiledVFrame of this frame; use with at_scope() to reuse scope object pool.
1307     compiledVFrame* prev_cvf = NULL;
1308 
1309     for (; !vfst.at_end() && vfst.frame_id() == frame_id; vfst.next()) { // vframe loop
1310       int frame_number = 0;
1311       Method *method = vfst.method();
1312       int bci = vfst.bci();
1313 
1314       Handle matched_jvmci_method;
1315       if (methods == NULL || matches(methods, method, &resolved_methods, &matched_jvmci_method, THREAD, JVMCIENV)) {
1316         if (initialSkip > 0) {
1317           initialSkip--;
1318           continue;
1319         }
1320         javaVFrame* vf;
1321         if (prev_cvf != NULL && prev_cvf->frame_pointer()->id() == frame_id) {
1322           assert(prev_cvf->is_compiled_frame(), "expected compiled Java frame");
1323           vf = prev_cvf->at_scope(vfst.decode_offset(), vfst.vframe_id());
1324         } else {
1325           vf = vfst.asJavaVFrame();
1326         }
1327 
1328         StackValueCollection* locals = NULL;
1329         typeArrayHandle localIsVirtual_h;
1330         if (vf->is_compiled_frame()) {
1331           // compiled method frame
1332           compiledVFrame* cvf = compiledVFrame::cast(vf);
1333 
1334           ScopeDesc* scope = cvf->scope();
1335           // native wrappers do not have a scope
1336           if (scope != NULL && scope->objects() != NULL) {
1337             prev_cvf = cvf;
1338 
1339             GrowableArray<ScopeValue*>* objects = NULL;
1340             if (!realloc_called) {
1341               objects = scope->objects();
1342             } else {
1343               // some object might already have been re-allocated, only reallocate the non-allocated ones
1344               objects = get_unallocated_objects_or_null(scope->objects());
1345             }
1346 
1347             if (objects != NULL) {
1348               RegisterMap reg_map(vf->register_map());
1349               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1350               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false);
1351               realloc_called = true;
1352             }
1353 
1354             GrowableArray<ScopeValue*>* local_values = scope->locals();
1355             for (int i = 0; i < local_values->length(); i++) {
1356               ScopeValue* value = local_values->at(i);
1357               if (value->is_object()) {
1358                 if (localIsVirtual_h.is_null()) {
1359                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1360                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1361                 }
1362                 localIsVirtual_h->bool_at_put(i, true);
1363               }
1364             }
1365           }
1366 
1367           locals = cvf->locals();
1368           frame_number = cvf->vframe_id();
1369         } else {
1370           // interpreted method frame
1371           interpretedVFrame* ivf = interpretedVFrame::cast(vf);
1372 
1373           locals = ivf->locals();
1374         }
1375         assert(bci == vf->bci(), "wrong bci");
1376         assert(method == vf->method(), "wrong method");
1377 
1378         Handle frame_reference = HotSpotJVMCI::HotSpotStackFrameReference::klass()->allocate_instance_handle(CHECK_NULL);
1379         HotSpotJVMCI::HotSpotStackFrameReference::set_bci(JVMCIENV, frame_reference(), bci);
1380         if (matched_jvmci_method.is_null()) {
1381           methodHandle mh(THREAD, method);
1382           JVMCIObject jvmci_method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1383           matched_jvmci_method = Handle(THREAD, JNIHandles::resolve(jvmci_method.as_jobject()));
1384         }
1385         HotSpotJVMCI::HotSpotStackFrameReference::set_method(JVMCIENV, frame_reference(), matched_jvmci_method());
1386         HotSpotJVMCI::HotSpotStackFrameReference::set_localIsVirtual(JVMCIENV, frame_reference(), localIsVirtual_h());
1387 
1388         HotSpotJVMCI::HotSpotStackFrameReference::set_compilerToVM(JVMCIENV, frame_reference(), JNIHandles::resolve(compilerToVM));
1389         HotSpotJVMCI::HotSpotStackFrameReference::set_stackPointer(JVMCIENV, frame_reference(), (jlong) frame_id);
1390         HotSpotJVMCI::HotSpotStackFrameReference::set_frameNumber(JVMCIENV, frame_reference(), frame_number);
1391 
1392         // initialize the locals array
1393         objArrayOop array_oop = oopFactory::new_objectArray(locals->size(), CHECK_NULL);
1394         objArrayHandle array(THREAD, array_oop);
1395         for (int i = 0; i < locals->size(); i++) {
1396           StackValue* var = locals->at(i);
1397           if (var->type() == T_OBJECT) {
1398             array->obj_at_put(i, locals->at(i)->get_obj()());
1399           }
1400         }
1401         HotSpotJVMCI::HotSpotStackFrameReference::set_locals(JVMCIENV, frame_reference(), array());
1402         HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, frame_reference(), JNI_FALSE);
1403 
1404         JavaValue result(T_OBJECT);
1405         JavaCallArguments args(visitor);
1406         if (visitor_method.is_null()) {
1407           visitor_method = resolve_interface_call(HotSpotJVMCI::InspectedFrameVisitor::klass(), vmSymbols::visitFrame_name(), vmSymbols::visitFrame_signature(), &args, CHECK_NULL);
1408         }
1409 
1410         args.push_oop(frame_reference);
1411         JavaCalls::call(&result, visitor_method, &args, CHECK_NULL);
1412         if (result.get_oop() != NULL) {
1413           return JNIHandles::make_local(thread, result.get_oop());
1414         }
1415         if (methods == initial_methods) {
1416           methods = match_methods;
1417           if (resolved_methods != NULL && JNIHandles::resolve(match_methods) != JNIHandles::resolve(initial_methods)) {
1418             resolved_methods = NULL;
1419           }
1420         }
1421         assert(initialSkip == 0, "There should be no match before initialSkip == 0");
1422         if (HotSpotJVMCI::HotSpotStackFrameReference::objectsMaterialized(JVMCIENV, frame_reference()) == JNI_TRUE) {
1423           // the frame has been deoptimized, we need to re-synchronize the frame and vframe
1424           prev_cvf = NULL;
1425           intptr_t* stack_pointer = (intptr_t*) HotSpotJVMCI::HotSpotStackFrameReference::stackPointer(JVMCIENV, frame_reference());
1426           resync_vframestream_to_compiled_frame(vfst, stack_pointer, frame_number, thread, CHECK_NULL);
1427         }
1428       }
1429     } // end of vframe loop
1430   } // end of frame loop
1431 
1432   // the end was reached without finding a matching method
1433   return NULL;
1434 C2V_END
1435 
1436 C2V_VMENTRY(void, resolveInvokeDynamicInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
1437   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
1438   CallInfo callInfo;
1439   LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokedynamic, CHECK);
1440   ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(index);
1441   cp_cache_entry->set_dynamic_call(cp, callInfo);
1442 C2V_END
1443 
1444 C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
1445   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
1446   Klass* holder = cp->klass_ref_at(index, CHECK);
1447   Symbol* name = cp->name_ref_at(index);
1448   if (MethodHandles::is_signature_polymorphic_name(holder, name)) {
1449     CallInfo callInfo;
1450     LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokehandle, CHECK);
1451     ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1452     cp_cache_entry->set_method_handle(cp, callInfo);
1453   }
1454 C2V_END
1455 
1456 C2V_VMENTRY_0(jint, isResolvedInvokeHandleInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
1457   constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
1458   ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1459   if (cp_cache_entry->is_resolved(Bytecodes::_invokehandle)) {
1460     // MethodHandle.invoke* --> LambdaForm?
1461     ResourceMark rm;
1462 
1463     LinkInfo link_info(cp, index, CATCH);
1464 
1465     Klass* resolved_klass = link_info.resolved_klass();
1466 
1467     Symbol* name_sym = cp->name_ref_at(index);
1468 
1469     vmassert(MethodHandles::is_method_handle_invoke_name(resolved_klass, name_sym), "!");
1470     vmassert(MethodHandles::is_signature_polymorphic_name(resolved_klass, name_sym), "!");
1471 
1472     methodHandle adapter_method(THREAD, cp_cache_entry->f1_as_method());
1473 
1474     methodHandle resolved_method(adapter_method);
1475 
1476     // Can we treat it as a regular invokevirtual?
1477     if (resolved_method->method_holder() == resolved_klass && resolved_method->name() == name_sym) {
1478       vmassert(!resolved_method->is_static(),"!");
1479       vmassert(MethodHandles::is_signature_polymorphic_method(resolved_method()),"!");
1480       vmassert(!MethodHandles::is_signature_polymorphic_static(resolved_method->intrinsic_id()), "!");
1481       vmassert(cp_cache_entry->appendix_if_resolved(cp) == NULL, "!");
1482 
1483       methodHandle m(THREAD, LinkResolver::linktime_resolve_virtual_method_or_null(link_info));
1484       vmassert(m == resolved_method, "!!");
1485       return -1;
1486     }
1487 
1488     return Bytecodes::_invokevirtual;
1489   }
1490   if (cp_cache_entry->is_resolved(Bytecodes::_invokedynamic)) {
1491     return Bytecodes::_invokedynamic;
1492   }
1493   return -1;
1494 C2V_END
1495 
1496 
1497 C2V_VMENTRY_NULL(jobject, getSignaturePolymorphicHolders, (JNIEnv* env, jobject))
1498   JVMCIObjectArray holders = JVMCIENV->new_String_array(2, JVMCI_CHECK_NULL);
1499   JVMCIObject mh = JVMCIENV->create_string("Ljava/lang/invoke/MethodHandle;", JVMCI_CHECK_NULL);
1500   JVMCIObject vh = JVMCIENV->create_string("Ljava/lang/invoke/VarHandle;", JVMCI_CHECK_NULL);
1501   JVMCIENV->put_object_at(holders, 0, mh);
1502   JVMCIENV->put_object_at(holders, 1, vh);
1503   return JVMCIENV->get_jobject(holders);
1504 C2V_END
1505 
1506 C2V_VMENTRY_0(jboolean, shouldDebugNonSafepoints, (JNIEnv* env, jobject))
1507   //see compute_recording_non_safepoints in debugInfroRec.cpp
1508   if (JvmtiExport::should_post_compiled_method_load() && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
1509     return true;
1510   }
1511   return DebugNonSafepoints;
1512 C2V_END
1513 
1514 // public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
1515 C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv* env, jobject, jobject _hs_frame, bool invalidate))
1516   JVMCIObject hs_frame = JVMCIENV->wrap(_hs_frame);
1517   if (hs_frame.is_null()) {
1518     JVMCI_THROW_MSG(NullPointerException, "stack frame is null");
1519   }
1520 
1521   requireInHotSpot("materializeVirtualObjects", JVMCI_CHECK);
1522 
1523   JVMCIENV->HotSpotStackFrameReference_initialize(JVMCI_CHECK);
1524 
1525   // look for the given stack frame
1526   StackFrameStream fst(thread, false /* update */, true /* process_frames */);
1527   intptr_t* stack_pointer = (intptr_t*) JVMCIENV->get_HotSpotStackFrameReference_stackPointer(hs_frame);
1528   while (fst.current()->id() != stack_pointer && !fst.is_done()) {
1529     fst.next();
1530   }
1531   if (fst.current()->id() != stack_pointer) {
1532     JVMCI_THROW_MSG(IllegalStateException, "stack frame not found");
1533   }
1534 
1535   if (invalidate) {
1536     if (!fst.current()->is_compiled_frame()) {
1537       JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected");
1538     }
1539     assert(fst.current()->cb()->is_nmethod(), "nmethod expected");
1540     ((nmethod*) fst.current()->cb())->make_not_entrant();
1541   }
1542   Deoptimization::deoptimize(thread, *fst.current(), Deoptimization::Reason_none);
1543   // look for the frame again as it has been updated by deopt (pc, deopt state...)
1544   StackFrameStream fstAfterDeopt(thread, true /* update */, true /* process_frames */);
1545   while (fstAfterDeopt.current()->id() != stack_pointer && !fstAfterDeopt.is_done()) {
1546     fstAfterDeopt.next();
1547   }
1548   if (fstAfterDeopt.current()->id() != stack_pointer) {
1549     JVMCI_THROW_MSG(IllegalStateException, "stack frame not found after deopt");
1550   }
1551 
1552   vframe* vf = vframe::new_vframe(fstAfterDeopt.current(), fstAfterDeopt.register_map(), thread);
1553   if (!vf->is_compiled_frame()) {
1554     JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected");
1555   }
1556 
1557   GrowableArray<compiledVFrame*>* virtualFrames = new GrowableArray<compiledVFrame*>(10);
1558   while (true) {
1559     assert(vf->is_compiled_frame(), "Wrong frame type");
1560     virtualFrames->push(compiledVFrame::cast(vf));
1561     if (vf->is_top()) {
1562       break;
1563     }
1564     vf = vf->sender();
1565   }
1566 
1567   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1568   if (last_frame_number >= virtualFrames->length()) {
1569     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1570   }
1571 
1572   // Reallocate the non-escaping objects and restore their fields.
1573   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1574   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1575 
1576   if (objects == NULL) {
1577     // no objects to materialize
1578     return;
1579   }
1580 
1581   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1582   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1583 
1584   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1585     compiledVFrame* cvf = virtualFrames->at(frame_index);
1586 
1587     GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1588     StackValueCollection* locals = cvf->locals();
1589     if (locals != NULL) {
1590       for (int i2 = 0; i2 < locals->size(); i2++) {
1591         StackValue* var = locals->at(i2);
1592         if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1593           jvalue val;
1594           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1595           cvf->update_local(T_OBJECT, i2, val);
1596         }
1597       }
1598     }
1599 
1600     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1601     StackValueCollection* expressions = cvf->expressions();
1602     if (expressions != NULL) {
1603       for (int i2 = 0; i2 < expressions->size(); i2++) {
1604         StackValue* var = expressions->at(i2);
1605         if (var->type() == T_OBJECT && scopeExpressions->at(i2)->is_object()) {
1606           jvalue val;
1607           val.l = cast_from_oop<jobject>(expressions->at(i2)->get_obj()());
1608           cvf->update_stack(T_OBJECT, i2, val);
1609         }
1610       }
1611     }
1612 
1613     GrowableArray<MonitorValue*>* scopeMonitors = cvf->scope()->monitors();
1614     GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1615     if (monitors != NULL) {
1616       for (int i2 = 0; i2 < monitors->length(); i2++) {
1617         cvf->update_monitor(i2, monitors->at(i2));
1618       }
1619     }
1620   }
1621 
1622   // all locals are materialized by now
1623   JVMCIENV->set_HotSpotStackFrameReference_localIsVirtual(hs_frame, NULL);
1624   // update the locals array
1625   JVMCIObjectArray array = JVMCIENV->get_HotSpotStackFrameReference_locals(hs_frame);
1626   StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals();
1627   for (int i = 0; i < locals->size(); i++) {
1628     StackValue* var = locals->at(i);
1629     if (var->type() == T_OBJECT) {
1630       JVMCIENV->put_object_at(array, i, HotSpotJVMCI::wrap(locals->at(i)->get_obj()()));
1631     }
1632   }
1633   HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, hs_frame, JNI_TRUE);
1634 C2V_END
1635 
1636 // Use of tty does not require the current thread to be attached to the VM
1637 // so no need for a full C2V_VMENTRY transition.
1638 C2V_VMENTRY_PREFIX(void, writeDebugOutput, (JNIEnv* env, jobject, jlong buffer, jint length, bool flush))
1639   if (length <= 8) {
1640     tty->write((char*) &buffer, length);
1641   } else {
1642     tty->write((char*) buffer, length);
1643   }
1644   if (flush) {
1645     tty->flush();
1646   }
1647 C2V_END
1648 
1649 // Use of tty does not require the current thread to be attached to the VM
1650 // so no need for a full C2V_VMENTRY transition.
1651 C2V_VMENTRY_PREFIX(void, flushDebugOutput, (JNIEnv* env, jobject))
1652   tty->flush();
1653 C2V_END
1654 
1655 C2V_VMENTRY_0(jint, methodDataProfileDataSize, (JNIEnv* env, jobject, jlong metaspace_method_data, jint position))
1656   MethodData* mdo = JVMCIENV->asMethodData(metaspace_method_data);
1657   ProfileData* profile_data = mdo->data_at(position);
1658   if (mdo->is_valid(profile_data)) {
1659     return profile_data->size_in_bytes();
1660   }
1661   DataLayout* data    = mdo->extra_data_base();
1662   DataLayout* end   = mdo->extra_data_limit();
1663   for (;; data = mdo->next_extra(data)) {
1664     assert(data < end, "moved past end of extra data");
1665     profile_data = data->data_in();
1666     if (mdo->dp_to_di(profile_data->dp()) == position) {
1667       return profile_data->size_in_bytes();
1668     }
1669   }
1670   JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Invalid profile data position %d", position));
1671 C2V_END
1672 
1673 C2V_VMENTRY_NULL(jobject, getInterfaces, (JNIEnv* env, jobject, jobject jvmci_type))
1674   if (jvmci_type == NULL) {
1675     JVMCI_THROW_0(NullPointerException);
1676   }
1677 
1678   Klass* klass = JVMCIENV->asKlass(jvmci_type);
1679   if (klass == NULL) {
1680     JVMCI_THROW_0(NullPointerException);
1681   }
1682   if (!klass->is_instance_klass()) {
1683     JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be instance klass", klass->external_name()));
1684   }
1685   InstanceKlass* iklass = InstanceKlass::cast(klass);
1686 
1687   // Regular instance klass, fill in all local interfaces
1688   int size = iklass->local_interfaces()->length();
1689   JVMCIObjectArray interfaces = JVMCIENV->new_HotSpotResolvedObjectTypeImpl_array(size, JVMCI_CHECK_NULL);
1690   for (int index = 0; index < size; index++) {
1691     JVMCIKlassHandle klass(THREAD);
1692     Klass* k = iklass->local_interfaces()->at(index);
1693     klass = k;
1694     JVMCIObject type = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
1695     JVMCIENV->put_object_at(interfaces, index, type);
1696   }
1697   return JVMCIENV->get_jobject(interfaces);
1698 C2V_END
1699 
1700 C2V_VMENTRY_NULL(jobject, getComponentType, (JNIEnv* env, jobject, jobject jvmci_type))
1701   if (jvmci_type == NULL) {
1702     JVMCI_THROW_0(NullPointerException);
1703   }
1704 
1705   Klass* klass = JVMCIENV->asKlass(jvmci_type);
1706   oop mirror = klass->java_mirror();
1707   if (java_lang_Class::is_primitive(mirror) ||
1708       !java_lang_Class::as_Klass(mirror)->is_array_klass()) {
1709     return NULL;
1710   }
1711 
1712   oop component_mirror = java_lang_Class::component_mirror(mirror);
1713   if (component_mirror == NULL) {
1714     return NULL;
1715   }
1716   Klass* component_klass = java_lang_Class::as_Klass(component_mirror);
1717   if (component_klass != NULL) {
1718     JVMCIKlassHandle klass_handle(THREAD);
1719     klass_handle = component_klass;
1720     JVMCIObject result = JVMCIENV->get_jvmci_type(klass_handle, JVMCI_CHECK_NULL);
1721     return JVMCIENV->get_jobject(result);
1722   }
1723   BasicType type = java_lang_Class::primitive_type(component_mirror);
1724   JVMCIObject result = JVMCIENV->get_jvmci_primitive_type(type);
1725   return JVMCIENV->get_jobject(result);
1726 C2V_END
1727 
1728 C2V_VMENTRY(void, ensureInitialized, (JNIEnv* env, jobject, jobject jvmci_type))
1729   if (jvmci_type == NULL) {
1730     JVMCI_THROW(NullPointerException);
1731   }
1732 
1733   Klass* klass = JVMCIENV->asKlass(jvmci_type);
1734   if (klass != NULL && klass->should_be_initialized()) {
1735     InstanceKlass* k = InstanceKlass::cast(klass);
1736     k->initialize(CHECK);
1737   }
1738 C2V_END
1739 
1740 C2V_VMENTRY(void, ensureLinked, (JNIEnv* env, jobject, jobject jvmci_type))
1741   if (jvmci_type == NULL) {
1742     JVMCI_THROW(NullPointerException);
1743   }
1744 
1745   Klass* klass = JVMCIENV->asKlass(jvmci_type);
1746   if (klass != NULL && klass->is_instance_klass()) {
1747     InstanceKlass* k = InstanceKlass::cast(klass);
1748     k->link_class(CHECK);
1749   }
1750 C2V_END
1751 
1752 C2V_VMENTRY_0(jint, interpreterFrameSize, (JNIEnv* env, jobject, jobject bytecode_frame_handle))
1753   if (bytecode_frame_handle == NULL) {
1754     JVMCI_THROW_0(NullPointerException);
1755   }
1756 
1757   JVMCIObject top_bytecode_frame = JVMCIENV->wrap(bytecode_frame_handle);
1758   JVMCIObject bytecode_frame = top_bytecode_frame;
1759   int size = 0;
1760   int callee_parameters = 0;
1761   int callee_locals = 0;
1762   Method* method = JVMCIENV->asMethod(JVMCIENV->get_BytecodePosition_method(bytecode_frame));
1763   int extra_args = method->max_stack() - JVMCIENV->get_BytecodeFrame_numStack(bytecode_frame);
1764 
1765   while (bytecode_frame.is_non_null()) {
1766     int locks = JVMCIENV->get_BytecodeFrame_numLocks(bytecode_frame);
1767     int temps = JVMCIENV->get_BytecodeFrame_numStack(bytecode_frame);
1768     bool is_top_frame = (JVMCIENV->equals(bytecode_frame, top_bytecode_frame));
1769     Method* method = JVMCIENV->asMethod(JVMCIENV->get_BytecodePosition_method(bytecode_frame));
1770 
1771     int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
1772                                                                  temps + callee_parameters,
1773                                                                  extra_args,
1774                                                                  locks,
1775                                                                  callee_parameters,
1776                                                                  callee_locals,
1777                                                                  is_top_frame);
1778     size += frame_size;
1779 
1780     callee_parameters = method->size_of_parameters();
1781     callee_locals = method->max_locals();
1782     extra_args = 0;
1783     bytecode_frame = JVMCIENV->get_BytecodePosition_caller(bytecode_frame);
1784   }
1785   return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
1786 C2V_END
1787 
1788 C2V_VMENTRY(void, compileToBytecode, (JNIEnv* env, jobject, jobject lambda_form_handle))
1789   Handle lambda_form = JVMCIENV->asConstant(JVMCIENV->wrap(lambda_form_handle), JVMCI_CHECK);
1790   if (lambda_form->is_a(vmClasses::LambdaForm_klass())) {
1791     TempNewSymbol compileToBytecode = SymbolTable::new_symbol("compileToBytecode");
1792     JavaValue result(T_VOID);
1793     JavaCalls::call_special(&result, lambda_form, vmClasses::LambdaForm_klass(), compileToBytecode, vmSymbols::void_method_signature(), CHECK);
1794   } else {
1795     JVMCI_THROW_MSG(IllegalArgumentException,
1796                     err_msg("Unexpected type: %s", lambda_form->klass()->external_name()))
1797   }
1798 C2V_END
1799 
1800 C2V_VMENTRY_0(jint, getIdentityHashCode, (JNIEnv* env, jobject, jobject object))
1801   Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0);
1802   return obj->identity_hash();
1803 C2V_END
1804 
1805 C2V_VMENTRY_0(jboolean, isInternedString, (JNIEnv* env, jobject, jobject object))
1806   Handle str = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0);
1807   if (!java_lang_String::is_instance(str())) {
1808     return false;
1809   }
1810   int len;
1811   jchar* name = java_lang_String::as_unicode_string(str(), len, CHECK_false);
1812   return (StringTable::lookup(name, len) != NULL);
1813 C2V_END
1814 
1815 
1816 C2V_VMENTRY_NULL(jobject, unboxPrimitive, (JNIEnv* env, jobject, jobject object))
1817   if (object == NULL) {
1818     JVMCI_THROW_0(NullPointerException);
1819   }
1820   Handle box = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL);
1821   BasicType type = java_lang_boxing_object::basic_type(box());
1822   jvalue result;
1823   if (java_lang_boxing_object::get_value(box(), &result) == T_ILLEGAL) {
1824     return NULL;
1825   }
1826   JVMCIObject boxResult = JVMCIENV->create_box(type, &result, JVMCI_CHECK_NULL);
1827   return JVMCIENV->get_jobject(boxResult);
1828 C2V_END
1829 
1830 C2V_VMENTRY_NULL(jobject, boxPrimitive, (JNIEnv* env, jobject, jobject object))
1831   if (object == NULL) {
1832     JVMCI_THROW_0(NullPointerException);
1833   }
1834   JVMCIObject box = JVMCIENV->wrap(object);
1835   BasicType type = JVMCIENV->get_box_type(box);
1836   if (type == T_ILLEGAL) {
1837     return NULL;
1838   }
1839   jvalue value = JVMCIENV->get_boxed_value(type, box);
1840   JavaValue box_result(T_OBJECT);
1841   JavaCallArguments jargs;
1842   Klass* box_klass = NULL;
1843   Symbol* box_signature = NULL;
1844 #define BOX_CASE(bt, v, argtype, name)           \
1845   case bt: \
1846     jargs.push_##argtype(value.v); \
1847     box_klass = vmClasses::name##_klass(); \
1848     box_signature = vmSymbols::name##_valueOf_signature(); \
1849     break
1850 
1851   switch (type) {
1852     BOX_CASE(T_BOOLEAN, z, int, Boolean);
1853     BOX_CASE(T_BYTE, b, int, Byte);
1854     BOX_CASE(T_CHAR, c, int, Character);
1855     BOX_CASE(T_SHORT, s, int, Short);
1856     BOX_CASE(T_INT, i, int, Integer);
1857     BOX_CASE(T_LONG, j, long, Long);
1858     BOX_CASE(T_FLOAT, f, float, Float);
1859     BOX_CASE(T_DOUBLE, d, double, Double);
1860     default:
1861       ShouldNotReachHere();
1862   }
1863 #undef BOX_CASE
1864 
1865   JavaCalls::call_static(&box_result,
1866                          box_klass,
1867                          vmSymbols::valueOf_name(),
1868                          box_signature, &jargs, CHECK_NULL);
1869   oop hotspot_box = box_result.get_oop();
1870   JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
1871   return JVMCIENV->get_jobject(result);
1872 C2V_END
1873 
1874 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, jobject holder))
1875   if (holder == NULL) {
1876     JVMCI_THROW_0(NullPointerException);
1877   }
1878   Klass* klass = JVMCIENV->asKlass(holder);
1879   if (!klass->is_instance_klass()) {
1880     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1881     return JVMCIENV->get_jobjectArray(methods);
1882   }
1883 
1884   InstanceKlass* iklass = InstanceKlass::cast(klass);
1885   // Ensure class is linked
1886   iklass->link_class(CHECK_NULL);
1887 
1888   GrowableArray<Method*> constructors_array;
1889   for (int i = 0; i < iklass->methods()->length(); i++) {
1890     Method* m = iklass->methods()->at(i);
1891     if (m->is_initializer() && !m->is_static()) {
1892       constructors_array.append(m);
1893     }
1894   }
1895   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1896   for (int i = 0; i < constructors_array.length(); i++) {
1897     methodHandle ctor(THREAD, constructors_array.at(i));
1898     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
1899     JVMCIENV->put_object_at(methods, i, method);
1900   }
1901   return JVMCIENV->get_jobjectArray(methods);
1902 C2V_END
1903 
1904 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, jobject holder))
1905   if (holder == NULL) {
1906     JVMCI_THROW_0(NullPointerException);
1907   }
1908   Klass* klass = JVMCIENV->asKlass(holder);
1909   if (!klass->is_instance_klass()) {
1910     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1911     return JVMCIENV->get_jobjectArray(methods);
1912   }
1913 
1914   InstanceKlass* iklass = InstanceKlass::cast(klass);
1915   // Ensure class is linked
1916   iklass->link_class(CHECK_NULL);
1917 
1918   GrowableArray<Method*> methods_array;
1919   for (int i = 0; i < iklass->methods()->length(); i++) {
1920     Method* m = iklass->methods()->at(i);
1921     if (!m->is_initializer() && !m->is_overpass()) {
1922       methods_array.append(m);
1923     }
1924   }
1925   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1926   for (int i = 0; i < methods_array.length(); i++) {
1927     methodHandle mh(THREAD, methods_array.at(i));
1928     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1929     JVMCIENV->put_object_at(methods, i, method);
1930   }
1931   return JVMCIENV->get_jobjectArray(methods);
1932 C2V_END
1933 
1934 C2V_VMENTRY_NULL(jobject, readFieldValue, (JNIEnv* env, jobject, jobject object, jobject expected_type, jlong displacement, jobject kind_object))
1935   if (object == NULL || kind_object == NULL) {
1936     JVMCI_THROW_0(NullPointerException);
1937   }
1938 
1939   JVMCIObject kind = JVMCIENV->wrap(kind_object);
1940   BasicType basic_type = JVMCIENV->kindToBasicType(kind, JVMCI_CHECK_NULL);
1941 
1942   InstanceKlass* holder = NULL;
1943   if (expected_type != NULL) {
1944     holder = InstanceKlass::cast(JVMCIENV->asKlass(JVMCIENV->wrap(expected_type)));
1945   }
1946 
1947   bool is_static = false;
1948   Handle obj;
1949   JVMCIObject base = JVMCIENV->wrap(object);
1950   if (JVMCIENV->isa_HotSpotObjectConstantImpl(base)) {
1951     obj = JVMCIENV->asConstant(base, JVMCI_CHECK_NULL);
1952     // asConstant will throw an NPE if a constant contains NULL
1953 
1954     if (holder != NULL && !obj->is_a(holder)) {
1955       // Not a subtype of field holder
1956       return NULL;
1957     }
1958     is_static = false;
1959     if (holder == NULL && java_lang_Class::is_instance(obj()) && displacement >= InstanceMirrorKlass::offset_of_static_fields()) {
1960       is_static = true;
1961     }
1962   } else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base)) {
1963     is_static = true;
1964     Klass* klass = JVMCIENV->asKlass(base);
1965     if (holder != NULL && holder != klass) {
1966       return NULL;
1967     }
1968     obj = Handle(THREAD, klass->java_mirror());
1969   } else {
1970     // The Java code is expected to guard against this path
1971     ShouldNotReachHere();
1972   }
1973 
1974   int basic_type_elemsize = type2aelembytes(basic_type);
1975   if (displacement < 0 || ((size_t) displacement + basic_type_elemsize > HeapWordSize * obj->size())) {
1976     // Reading outside of the object bounds
1977     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading outside object bounds");
1978   }
1979 
1980   // Perform basic sanity checks on the read.  Primitive reads are permitted to read outside the
1981   // bounds of their fields but object reads must map exactly onto the underlying oop slot.
1982   bool aligned = (displacement % basic_type_elemsize) == 0;
1983   if (!aligned) {
1984     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "read is unaligned");
1985   }
1986   if (basic_type == T_OBJECT) {
1987     if (obj->is_objArray()) {
1988       if (displacement < arrayOopDesc::base_offset_in_bytes(T_OBJECT)) {
1989         JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading from array header");
1990       }
1991       if (displacement + heapOopSize > arrayOopDesc::base_offset_in_bytes(T_OBJECT) + arrayOop(obj())->length() * heapOopSize) {
1992         JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading after last array element");
1993       }
1994       if (((displacement - arrayOopDesc::base_offset_in_bytes(T_OBJECT)) % heapOopSize) != 0) {
1995         JVMCI_THROW_MSG_NULL(IllegalArgumentException, "misaligned object read from array");
1996       }
1997     } else if (obj->is_instance()) {
1998       InstanceKlass* klass = InstanceKlass::cast(is_static ? java_lang_Class::as_Klass(obj()) : obj->klass());
1999       fieldDescriptor fd;
2000       if (!klass->find_field_from_offset(displacement, is_static, &fd)) {
2001         JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Can't find field at displacement %d in object of type %s", (int) displacement, klass->external_name()));
2002       }
2003       if (fd.field_type() != T_OBJECT && fd.field_type() != T_ARRAY) {
2004         JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Field at displacement %d in object of type %s is %s but expected %s", (int) displacement,
2005                                                                klass->external_name(), type2name(fd.field_type()), type2name(basic_type)));
2006       }
2007     } else if (obj->is_typeArray()) {
2008       JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Can't read objects from primitive array");
2009     } else {
2010       ShouldNotReachHere();
2011     }
2012   } else {
2013     if (obj->is_objArray()) {
2014       JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Reading primitive from object array");
2015     } else if (obj->is_typeArray()) {
2016       if (displacement < arrayOopDesc::base_offset_in_bytes(ArrayKlass::cast(obj->klass())->element_type())) {
2017         JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading from array header");
2018       }
2019     }
2020   }
2021 
2022   jlong value = 0;
2023 
2024   // Treat all reads as volatile for simplicity as this function can be used
2025   // both for reading Java fields declared as volatile as well as for constant
2026   // folding Unsafe.get* methods with volatile semantics.
2027 
2028   switch (basic_type) {
2029     case T_BOOLEAN: value = obj->bool_field_acquire(displacement);  break;
2030     case T_BYTE:    value = obj->byte_field_acquire(displacement);  break;
2031     case T_SHORT:   value = obj->short_field_acquire(displacement); break;
2032     case T_CHAR:    value = obj->char_field_acquire(displacement);  break;
2033     case T_FLOAT:
2034     case T_INT:     value = obj->int_field_acquire(displacement);   break;
2035     case T_DOUBLE:
2036     case T_LONG:    value = obj->long_field_acquire(displacement);  break;
2037 
2038     case T_OBJECT: {
2039       if (displacement == java_lang_Class::component_mirror_offset() && java_lang_Class::is_instance(obj()) &&
2040           (java_lang_Class::as_Klass(obj()) == NULL || !java_lang_Class::as_Klass(obj())->is_array_klass())) {
2041         // Class.componentType for non-array classes can transiently contain an int[] that's
2042         // used for locking so always return null to mimic Class.getComponentType()
2043         return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
2044       }
2045 
2046       oop value = obj->obj_field_acquire(displacement);
2047 
2048       if (value == NULL) {
2049         return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
2050       } else {
2051         if (value != NULL && !oopDesc::is_oop(value)) {
2052           // Throw an exception to improve debuggability.  This check isn't totally reliable because
2053           // is_oop doesn't try to be completety safe but for most invalid values it provides a good
2054           // enough answer.  It possible to crash in the is_oop call but that just means the crash happens
2055           // closer to where things went wrong.
2056           JVMCI_THROW_MSG_NULL(InternalError, err_msg("Read bad oop " INTPTR_FORMAT " at offset " JLONG_FORMAT " in object " INTPTR_FORMAT " of type %s",
2057                                                       p2i(value), displacement, p2i(obj()), obj->klass()->external_name()));
2058         }
2059 
2060         JVMCIObject result = JVMCIENV->get_object_constant(value);
2061         return JVMCIENV->get_jobject(result);
2062       }
2063     }
2064 
2065     default:
2066       ShouldNotReachHere();
2067   }
2068   JVMCIObject result = JVMCIENV->call_JavaConstant_forPrimitive(kind, value, JVMCI_CHECK_NULL);
2069   return JVMCIENV->get_jobject(result);
2070 C2V_END
2071 
2072 C2V_VMENTRY_0(jboolean, isInstance, (JNIEnv* env, jobject, jobject holder, jobject object))
2073   if (object == NULL || holder == NULL) {
2074     JVMCI_THROW_0(NullPointerException);
2075   }
2076   Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0);
2077   Klass* klass = JVMCIENV->asKlass(JVMCIENV->wrap(holder));
2078   return obj->is_a(klass);
2079 C2V_END
2080 
2081 C2V_VMENTRY_0(jboolean, isAssignableFrom, (JNIEnv* env, jobject, jobject holder, jobject otherHolder))
2082   if (holder == NULL || otherHolder == NULL) {
2083     JVMCI_THROW_0(NullPointerException);
2084   }
2085   Klass* klass = JVMCIENV->asKlass(JVMCIENV->wrap(holder));
2086   Klass* otherKlass = JVMCIENV->asKlass(JVMCIENV->wrap(otherHolder));
2087   return otherKlass->is_subtype_of(klass);
2088 C2V_END
2089 
2090 C2V_VMENTRY_0(jboolean, isTrustedForIntrinsics, (JNIEnv* env, jobject, jobject holder))
2091   if (holder == NULL) {
2092     JVMCI_THROW_0(NullPointerException);
2093   }
2094   InstanceKlass* ik = InstanceKlass::cast(JVMCIENV->asKlass(JVMCIENV->wrap(holder)));
2095   if (ik->class_loader_data()->is_boot_class_loader_data() || ik->class_loader_data()->is_platform_class_loader_data()) {
2096     return true;
2097   }
2098   return false;
2099 C2V_END
2100 
2101 C2V_VMENTRY_NULL(jobject, asJavaType, (JNIEnv* env, jobject, jobject object))
2102   if (object == NULL) {
2103     JVMCI_THROW_0(NullPointerException);
2104   }
2105   Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL);
2106   if (java_lang_Class::is_instance(obj())) {
2107     if (java_lang_Class::is_primitive(obj())) {
2108       JVMCIObject type = JVMCIENV->get_jvmci_primitive_type(java_lang_Class::primitive_type(obj()));
2109       return JVMCIENV->get_jobject(type);
2110     }
2111     Klass* klass = java_lang_Class::as_Klass(obj());
2112     JVMCIKlassHandle klass_handle(THREAD);
2113     klass_handle = klass;
2114     JVMCIObject type = JVMCIENV->get_jvmci_type(klass_handle, JVMCI_CHECK_NULL);
2115     return JVMCIENV->get_jobject(type);
2116   }
2117   return NULL;
2118 C2V_END
2119 
2120 
2121 C2V_VMENTRY_NULL(jobject, asString, (JNIEnv* env, jobject, jobject object))
2122   if (object == NULL) {
2123     JVMCI_THROW_0(NullPointerException);
2124   }
2125   Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL);
2126   const char* str = java_lang_String::as_utf8_string(obj());
2127   JVMCIObject result = JVMCIENV->create_string(str, JVMCI_CHECK_NULL);
2128   return JVMCIENV->get_jobject(result);
2129 C2V_END
2130 
2131 
2132 C2V_VMENTRY_0(jboolean, equals, (JNIEnv* env, jobject, jobject x, jlong xHandle, jobject y, jlong yHandle))
2133   if (x == NULL || y == NULL) {
2134     JVMCI_THROW_0(NullPointerException);
2135   }
2136   return JVMCIENV->resolve_oop_handle(xHandle) == JVMCIENV->resolve_oop_handle(yHandle);
2137 C2V_END
2138 
2139 C2V_VMENTRY_NULL(jobject, getJavaMirror, (JNIEnv* env, jobject, jobject object))
2140   if (object == NULL) {
2141     JVMCI_THROW_0(NullPointerException);
2142   }
2143   JVMCIObject base_object = JVMCIENV->wrap(object);
2144   Handle mirror;
2145   if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base_object)) {
2146     mirror = Handle(THREAD, JVMCIENV->asKlass(base_object)->java_mirror());
2147   } else if (JVMCIENV->isa_HotSpotResolvedPrimitiveType(base_object)) {
2148     mirror = JVMCIENV->asConstant(JVMCIENV->get_HotSpotResolvedPrimitiveType_mirror(base_object), JVMCI_CHECK_NULL);
2149   } else {
2150     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2151                          err_msg("Unexpected type: %s", JVMCIENV->klass_name(base_object)));
2152  }
2153   JVMCIObject result = JVMCIENV->get_object_constant(mirror());
2154   return JVMCIENV->get_jobject(result);
2155 C2V_END
2156 
2157 
2158 C2V_VMENTRY_0(jint, getArrayLength, (JNIEnv* env, jobject, jobject x))
2159   if (x == NULL) {
2160     JVMCI_THROW_0(NullPointerException);
2161   }
2162   Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0);
2163   if (xobj->klass()->is_array_klass()) {
2164     return arrayOop(xobj())->length();
2165   }
2166   return -1;
2167  C2V_END
2168 
2169 
2170 C2V_VMENTRY_NULL(jobject, readArrayElement, (JNIEnv* env, jobject, jobject x, int index))
2171   if (x == NULL) {
2172     JVMCI_THROW_0(NullPointerException);
2173   }
2174   Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_NULL);
2175   if (xobj->klass()->is_array_klass()) {
2176     arrayOop array = arrayOop(xobj());
2177     BasicType element_type = ArrayKlass::cast(array->klass())->element_type();
2178     if (index < 0 || index >= array->length()) {
2179       return NULL;
2180     }
2181     JVMCIObject result;
2182 
2183     if (element_type == T_OBJECT) {
2184       result = JVMCIENV->get_object_constant(objArrayOop(xobj())->obj_at(index));
2185       if (result.is_null()) {
2186         result = JVMCIENV->get_JavaConstant_NULL_POINTER();
2187       }
2188     } else {
2189       jvalue value;
2190       switch (element_type) {
2191         case T_DOUBLE:        value.d = typeArrayOop(xobj())->double_at(index);        break;
2192         case T_FLOAT:         value.f = typeArrayOop(xobj())->float_at(index);         break;
2193         case T_LONG:          value.j = typeArrayOop(xobj())->long_at(index);          break;
2194         case T_INT:           value.i = typeArrayOop(xobj())->int_at(index);            break;
2195         case T_SHORT:         value.s = typeArrayOop(xobj())->short_at(index);          break;
2196         case T_CHAR:          value.c = typeArrayOop(xobj())->char_at(index);           break;
2197         case T_BYTE:          value.b = typeArrayOop(xobj())->byte_at(index);           break;
2198         case T_BOOLEAN:       value.z = typeArrayOop(xobj())->byte_at(index) & 1;       break;
2199         default:              ShouldNotReachHere();
2200       }
2201       result = JVMCIENV->create_box(element_type, &value, JVMCI_CHECK_NULL);
2202     }
2203     assert(!result.is_null(), "must have a value");
2204     return JVMCIENV->get_jobject(result);
2205   }
2206   return NULL;;
2207 C2V_END
2208 
2209 
2210 C2V_VMENTRY_0(jint, arrayBaseOffset, (JNIEnv* env, jobject, jobject kind))
2211   if (kind == NULL) {
2212     JVMCI_THROW_0(NullPointerException);
2213   }
2214   BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->wrap(kind), JVMCI_CHECK_0);
2215   return arrayOopDesc::base_offset_in_bytes(type);
2216 C2V_END
2217 
2218 C2V_VMENTRY_0(jint, arrayIndexScale, (JNIEnv* env, jobject, jobject kind))
2219   if (kind == NULL) {
2220     JVMCI_THROW_0(NullPointerException);
2221   }
2222   BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->wrap(kind), JVMCI_CHECK_0);
2223   return type2aelembytes(type);
2224 C2V_END
2225 
2226 C2V_VMENTRY(void, deleteGlobalHandle, (JNIEnv* env, jobject, jlong handle))
2227   if (handle != 0) {
2228     JVMCIENV->runtime()->destroy_oop_handle(handle);
2229   }
2230 }
2231 
2232 static void requireJVMCINativeLibrary(JVMCI_TRAPS) {
2233   if (!UseJVMCINativeLibrary) {
2234     JVMCI_THROW_MSG(UnsupportedOperationException, "JVMCI shared library is not enabled (requires -XX:+UseJVMCINativeLibrary)");
2235   }
2236 }
2237 
2238 C2V_VMENTRY_NULL(jlongArray, registerNativeMethods, (JNIEnv* env, jobject, jclass mirror))
2239   requireJVMCINativeLibrary(JVMCI_CHECK_NULL);
2240   requireInHotSpot("registerNativeMethods", JVMCI_CHECK_NULL);
2241   char* sl_path;
2242   void* sl_handle;
2243   JVMCIRuntime* runtime;
2244   {
2245     // Ensure the JVMCI shared library runtime is initialized.
2246     JVMCIEnv __peer_jvmci_env__(thread, false, __FILE__, __LINE__);
2247     JVMCIEnv* peerEnv = &__peer_jvmci_env__;
2248     HandleMark hm(THREAD);
2249     runtime = JVMCI::compiler_runtime(thread);
2250     if (peerEnv->has_pending_exception()) {
2251       peerEnv->describe_pending_exception(true);
2252     }
2253     sl_handle = JVMCI::get_shared_library(sl_path, false);
2254     if (sl_handle == NULL) {
2255       JVMCI_THROW_MSG_0(InternalError, err_msg("Error initializing JVMCI runtime %d", runtime->id()));
2256     }
2257   }
2258 
2259   if (mirror == NULL) {
2260     JVMCI_THROW_0(NullPointerException);
2261   }
2262   Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror));
2263   if (klass == NULL || !klass->is_instance_klass()) {
2264     JVMCI_THROW_MSG_0(IllegalArgumentException, "clazz is for primitive type");
2265   }
2266 
2267   InstanceKlass* iklass = InstanceKlass::cast(klass);
2268   for (int i = 0; i < iklass->methods()->length(); i++) {
2269     methodHandle method(THREAD, iklass->methods()->at(i));
2270     if (method->is_native()) {
2271 
2272       // Compute argument size
2273       int args_size = 1                             // JNIEnv
2274                     + (method->is_static() ? 1 : 0) // class for static methods
2275                     + method->size_of_parameters(); // actual parameters
2276 
2277       // 1) Try JNI short style
2278       stringStream st;
2279       char* pure_name = NativeLookup::pure_jni_name(method);
2280       guarantee(pure_name != NULL, "Illegal native method name encountered");
2281       os::print_jni_name_prefix_on(&st, args_size);
2282       st.print_raw(pure_name);
2283       os::print_jni_name_suffix_on(&st, args_size);
2284       char* jni_name = st.as_string();
2285 
2286       address entry = (address) os::dll_lookup(sl_handle, jni_name);
2287       if (entry == NULL) {
2288         // 2) Try JNI long style
2289         st.reset();
2290         char* long_name = NativeLookup::long_jni_name(method);
2291         guarantee(long_name != NULL, "Illegal native method name encountered");
2292         os::print_jni_name_prefix_on(&st, args_size);
2293         st.print_raw(pure_name);
2294         st.print_raw(long_name);
2295         os::print_jni_name_suffix_on(&st, args_size);
2296         char* jni_long_name = st.as_string();
2297         entry = (address) os::dll_lookup(sl_handle, jni_long_name);
2298         if (entry == NULL) {
2299           JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("%s [neither %s nor %s exist in %s]",
2300               method->name_and_sig_as_C_string(),
2301               jni_name, jni_long_name, sl_path));
2302         }
2303       }
2304 
2305       if (method->has_native_function() && entry != method->native_function()) {
2306         JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("%s [cannot re-link from " PTR_FORMAT " to " PTR_FORMAT "]",
2307             method->name_and_sig_as_C_string(), p2i(method->native_function()), p2i(entry)));
2308       }
2309       method->set_native_function(entry, Method::native_bind_event_is_interesting);
2310       log_debug(jni, resolve)("[Dynamic-linking native method %s.%s ... JNI] @ " PTR_FORMAT,
2311                               method->method_holder()->external_name(),
2312                               method->name()->as_C_string(),
2313                               p2i((void*) entry));
2314     }
2315   }
2316 
2317   typeArrayOop info_oop = oopFactory::new_longArray(4, CHECK_0);
2318   jlongArray info = (jlongArray) JNIHandles::make_local(THREAD, info_oop);
2319   runtime->init_JavaVM_info(info, JVMCI_CHECK_0);
2320   return info;
2321 }
2322 
2323 C2V_VMENTRY_PREFIX(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject c2vm))
2324   if (thread == nullptr || thread->libjvmci_runtime() == nullptr) {
2325     // Called from unattached JVMCI shared library thread
2326     return false;
2327   }
2328   JVMCITraceMark jtm("isCurrentThreadAttached");
2329   if (thread->jni_environment() == env) {
2330     C2V_BLOCK(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject))
2331     requireJVMCINativeLibrary(JVMCI_CHECK_0);
2332     JVMCIRuntime* runtime = thread->libjvmci_runtime();
2333     if (runtime == nullptr || !runtime->has_shared_library_javavm()) {
2334       JVMCI_THROW_MSG_0(IllegalStateException, "Require JVMCI shared library JavaVM to be initialized in isCurrentThreadAttached");
2335     }
2336     JNIEnv* peerEnv;
2337     return runtime->GetEnv(thread, (void**) &peerEnv, JNI_VERSION_1_2) == JNI_OK;
2338   }
2339   return true;
2340 C2V_END
2341 
2342 C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm))
2343   if (thread == NULL) {
2344     // Called from unattached JVMCI shared library thread
2345     return 0L;
2346   }
2347   JVMCITraceMark jtm("getCurrentJavaThread");
2348   return (jlong) p2i(thread);
2349 C2V_END
2350 
2351 // Attaches a thread started in a JVMCI shared library to a JavaThread and JVMCI runtime.
2352 static void attachSharedLibraryThread(JNIEnv* env, jbyteArray name, jboolean as_daemon) {
2353   JavaVM* javaVM = nullptr;
2354   jint res = env->GetJavaVM(&javaVM);
2355   if (res != JNI_OK) {
2356     JNI_THROW("attachSharedLibraryThread", InternalError, err_msg("Error getting shared library JavaVM from shared library JNIEnv: %d", res));
2357   }
2358   extern struct JavaVM_ main_vm;
2359   JNIEnv* hotspotEnv;
2360 
2361   int name_len = env->GetArrayLength(name);
2362   char name_buf[64]; // Cannot use Resource heap as it requires a current thread
2363   int to_copy = MIN2(name_len, (int) sizeof(name_buf) - 1);
2364   env->GetByteArrayRegion(name, 0, to_copy, (jbyte*) name_buf);
2365   name_buf[to_copy] = '\0';
2366   JavaVMAttachArgs attach_args;
2367   attach_args.version = JNI_VERSION_1_2;
2368   attach_args.name = name_buf;
2369   attach_args.group = nullptr;
2370   res = as_daemon ? main_vm.AttachCurrentThreadAsDaemon((void**)&hotspotEnv, &attach_args) :
2371                     main_vm.AttachCurrentThread((void**)&hotspotEnv, &attach_args);
2372   if (res != JNI_OK) {
2373     JNI_THROW("attachSharedLibraryThread", InternalError, err_msg("Trying to attach thread returned %d", res));
2374   }
2375   JavaThread* thread = get_current_thread(false);
2376   const char* attach_error;
2377   {
2378     // Transition to VM
2379     JVMCI_VM_ENTRY_MARK
2380     attach_error = JVMCIRuntime::attach_shared_library_thread(thread, javaVM);
2381     // Transition back to Native
2382   }
2383   if (attach_error != nullptr) {
2384     JNI_THROW("attachCurrentThread", InternalError, attach_error);
2385   }
2386 }
2387 
2388 C2V_VMENTRY_PREFIX(jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jbyteArray name, jboolean as_daemon, jlongArray javaVM_info))
2389   if (thread == nullptr) {
2390     attachSharedLibraryThread(env, name, as_daemon);
2391     return true;
2392   }
2393   JVMCITraceMark jtm("attachCurrentThread");
2394   if (thread->jni_environment() == env) {
2395     // Called from HotSpot
2396     C2V_BLOCK(jboolean, attachCurrentThread, (JNIEnv* env, jobject, jboolean))
2397     requireJVMCINativeLibrary(JVMCI_CHECK_0);
2398 
2399     JVMCIRuntime* runtime = JVMCI::compiler_runtime(thread);
2400     JNIEnv* peerJNIEnv;
2401     if (runtime->has_shared_library_javavm()) {
2402       if (runtime->GetEnv(thread, (void**)&peerJNIEnv, JNI_VERSION_1_2) == JNI_OK) {
2403         // Already attached
2404         runtime->init_JavaVM_info(javaVM_info, JVMCI_CHECK_0);
2405         return false;
2406       }
2407     }
2408 
2409     {
2410       // Ensure the JVMCI shared library runtime is initialized.
2411       JVMCIEnv __peer_jvmci_env__(thread, false, __FILE__, __LINE__);
2412       JVMCIEnv* peerJVMCIEnv = &__peer_jvmci_env__;
2413       HandleMark hm(thread);
2414       JVMCIObject receiver = runtime->get_HotSpotJVMCIRuntime(peerJVMCIEnv);
2415       if (peerJVMCIEnv->has_pending_exception()) {
2416         peerJVMCIEnv->describe_pending_exception(true);
2417       }
2418       char* sl_path;
2419       if (JVMCI::get_shared_library(sl_path, false) == nullptr) {
2420         JVMCI_THROW_MSG_0(InternalError, "Error initializing JVMCI runtime");
2421       }
2422     }
2423 
2424     JavaVMAttachArgs attach_args;
2425     attach_args.version = JNI_VERSION_1_2;
2426     attach_args.name = const_cast<char*>(thread->name());
2427     attach_args.group = nullptr;
2428     jint res = as_daemon ? runtime->AttachCurrentThreadAsDaemon(thread, (void**) &peerJNIEnv, &attach_args) :
2429                            runtime->AttachCurrentThread(thread, (void**) &peerJNIEnv, &attach_args);
2430 
2431     if (res == JNI_OK) {
2432       guarantee(peerJNIEnv != nullptr, "must be");
2433       runtime->init_JavaVM_info(javaVM_info, JVMCI_CHECK_0);
2434       JVMCI_event_1("attached to JavaVM[%d] for JVMCI runtime %d", runtime->get_shared_library_javavm_id(), runtime->id());
2435       return true;
2436     }
2437     JVMCI_THROW_MSG_0(InternalError, err_msg("Error %d while attaching %s", res, attach_args.name));
2438   }
2439   // Called from JVMCI shared library
2440   return false;
2441 C2V_END
2442 
2443 C2V_VMENTRY_PREFIX(jboolean, detachCurrentThread, (JNIEnv* env, jobject c2vm, jboolean release))
2444   if (thread == nullptr) {
2445     // Called from unattached JVMCI shared library thread
2446     JNI_THROW_("detachCurrentThread", IllegalStateException, "Cannot detach non-attached thread", false);
2447   }
2448   JVMCITraceMark jtm("detachCurrentThread");
2449   if (thread->jni_environment() == env) {
2450     // Called from HotSpot
2451     C2V_BLOCK(void, detachCurrentThread, (JNIEnv* env, jobject))
2452     requireJVMCINativeLibrary(JVMCI_CHECK_0);
2453     requireInHotSpot("detachCurrentThread", JVMCI_CHECK_0);
2454     JVMCIRuntime* runtime = thread->libjvmci_runtime();
2455     if (runtime == nullptr || !runtime->has_shared_library_javavm()) {
2456       JVMCI_THROW_MSG_0(IllegalStateException, "Require JVMCI shared library JavaVM to be initialized in detachCurrentThread");
2457     }
2458     JNIEnv* peerEnv;
2459 
2460     if (runtime->GetEnv(thread, (void**) &peerEnv, JNI_VERSION_1_2) != JNI_OK) {
2461       JVMCI_THROW_MSG_0(IllegalStateException, err_msg("Cannot detach non-attached thread: %s", thread->name()));
2462     }
2463     jint res = runtime->DetachCurrentThread(thread);
2464     if (res != JNI_OK) {
2465       JVMCI_THROW_MSG_0(InternalError, err_msg("Error %d while attaching %s", res, thread->name()));
2466     }
2467     JVMCI_event_1("detached from JavaVM[%d] for JVMCI runtime %d",
2468         runtime->get_shared_library_javavm_id(), runtime->id());
2469     if (release) {
2470       return runtime->detach_thread(thread, "user thread detach");
2471     }
2472   } else {
2473     // Called from attached JVMCI shared library thread
2474     if (release) {
2475       JNI_THROW_("detachCurrentThread", InternalError, "JVMCI shared library thread cannot release JVMCI shared library JavaVM", false);
2476     }
2477     JVMCIRuntime* runtime = thread->libjvmci_runtime();
2478     if (runtime == nullptr) {
2479       JNI_THROW_("detachCurrentThread", InternalError, "JVMCI shared library thread should have a JVMCI runtime", false);
2480     }
2481     {
2482       // Transition to VM
2483       C2V_BLOCK(jboolean, detachCurrentThread, (JNIEnv* env, jobject))
2484       // Cannot destroy shared library JavaVM as we're about to return to it.
2485       runtime->detach_thread(thread, "shared library thread detach", false);
2486       JVMCI_event_1("detaching JVMCI shared library thread from HotSpot JavaVM");
2487       // Transition back to Native
2488     }
2489     extern struct JavaVM_ main_vm;
2490     jint res = main_vm.DetachCurrentThread();
2491     if (res != JNI_OK) {
2492       JNI_THROW_("detachCurrentThread", InternalError, "Cannot detach non-attached thread", false);
2493     }
2494   }
2495   return false;
2496 C2V_END
2497 
2498 C2V_VMENTRY_0(jlong, translate, (JNIEnv* env, jobject, jobject obj_handle, jboolean callPostTranslation))
2499   requireJVMCINativeLibrary(JVMCI_CHECK_0);
2500   if (obj_handle == NULL) {
2501     return 0L;
2502   }
2503   JVMCIEnv __peer_jvmci_env__(thread, !JVMCIENV->is_hotspot(), __FILE__, __LINE__);
2504   JVMCIEnv* peerEnv = &__peer_jvmci_env__;
2505   JVMCIEnv* thisEnv = JVMCIENV;
2506 
2507   JVMCIObject obj = thisEnv->wrap(obj_handle);
2508   JVMCIObject result;
2509   if (thisEnv->isa_HotSpotResolvedJavaMethodImpl(obj)) {
2510     methodHandle method(THREAD, thisEnv->asMethod(obj));
2511     result = peerEnv->get_jvmci_method(method, JVMCI_CHECK_0);
2512   } else if (thisEnv->isa_HotSpotResolvedObjectTypeImpl(obj)) {
2513     Klass* klass = thisEnv->asKlass(obj);
2514     JVMCIKlassHandle klass_handle(THREAD);
2515     klass_handle = klass;
2516     result = peerEnv->get_jvmci_type(klass_handle, JVMCI_CHECK_0);
2517   } else if (thisEnv->isa_HotSpotResolvedPrimitiveType(obj)) {
2518     BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->get_HotSpotResolvedPrimitiveType_kind(obj), JVMCI_CHECK_0);
2519     result = peerEnv->get_jvmci_primitive_type(type);
2520   } else if (thisEnv->isa_IndirectHotSpotObjectConstantImpl(obj) ||
2521              thisEnv->isa_DirectHotSpotObjectConstantImpl(obj)) {
2522     Handle constant = thisEnv->asConstant(obj, JVMCI_CHECK_0);
2523     result = peerEnv->get_object_constant(constant());
2524   } else if (thisEnv->isa_HotSpotNmethod(obj)) {
2525     nmethodLocker locker;
2526     nmethod* nm = JVMCIENV->get_nmethod(obj, locker);
2527     if (nm != NULL) {
2528       JVMCINMethodData* data = nm->jvmci_nmethod_data();
2529       if (data != NULL) {
2530         if (peerEnv->is_hotspot()) {
2531           // Only the mirror in the HotSpot heap is accessible
2532           // through JVMCINMethodData
2533           oop nmethod_mirror = data->get_nmethod_mirror(nm, /* phantom_ref */ true);
2534           if (nmethod_mirror != NULL) {
2535             result = HotSpotJVMCI::wrap(nmethod_mirror);
2536           }
2537         }
2538       }
2539     }
2540     if (result.is_null()) {
2541       JVMCIObject methodObject = thisEnv->get_HotSpotNmethod_method(obj);
2542       methodHandle mh(THREAD, thisEnv->asMethod(methodObject));
2543       jboolean isDefault = thisEnv->get_HotSpotNmethod_isDefault(obj);
2544       jlong compileIdSnapshot = thisEnv->get_HotSpotNmethod_compileIdSnapshot(obj);
2545       JVMCIObject name_string = thisEnv->get_InstalledCode_name(obj);
2546       const char* cstring = name_string.is_null() ? NULL : thisEnv->as_utf8_string(name_string);
2547       // Create a new HotSpotNmethod instance in the peer runtime
2548       result = peerEnv->new_HotSpotNmethod(mh, cstring, isDefault, compileIdSnapshot, JVMCI_CHECK_0);
2549       if (result.is_null()) {
2550         // exception occurred (e.g. OOME) creating a new HotSpotNmethod
2551       } else if (nm == NULL) {
2552         // nmethod must have been unloaded
2553       } else {
2554         // Link the new HotSpotNmethod to the nmethod
2555         peerEnv->initialize_installed_code(result, nm, JVMCI_CHECK_0);
2556         // Only HotSpotNmethod instances in the HotSpot heap are tracked directly by the runtime.
2557         if (peerEnv->is_hotspot()) {
2558           JVMCINMethodData* data = nm->jvmci_nmethod_data();
2559           if (data == NULL) {
2560             JVMCI_THROW_MSG_0(IllegalArgumentException, "Cannot set HotSpotNmethod mirror for default nmethod");
2561           }
2562           if (data->get_nmethod_mirror(nm, /* phantom_ref */ false) != NULL) {
2563             JVMCI_THROW_MSG_0(IllegalArgumentException, "Cannot overwrite existing HotSpotNmethod mirror for nmethod");
2564           }
2565           oop nmethod_mirror = HotSpotJVMCI::resolve(result);
2566           data->set_nmethod_mirror(nm, nmethod_mirror);
2567         }
2568       }
2569     }
2570   } else {
2571     JVMCI_THROW_MSG_0(IllegalArgumentException,
2572                 err_msg("Cannot translate object of type: %s", thisEnv->klass_name(obj)));
2573   }
2574   if (callPostTranslation) {
2575     peerEnv->call_HotSpotJVMCIRuntime_postTranslation(result, JVMCI_CHECK_0);
2576   }
2577   // Propagate any exception that occurred while creating the translated object
2578   if (peerEnv->transfer_pending_exception(thread, thisEnv)) {
2579     return 0L;
2580   }
2581   return (jlong) peerEnv->make_global(result).as_jobject();
2582 }
2583 
2584 C2V_VMENTRY_NULL(jobject, unhand, (JNIEnv* env, jobject, jlong obj_handle))
2585   requireJVMCINativeLibrary(JVMCI_CHECK_NULL);
2586   if (obj_handle == 0L) {
2587     return NULL;
2588   }
2589   jobject global_handle = (jobject) obj_handle;
2590   JVMCIObject global_handle_obj = JVMCIENV->wrap(global_handle);
2591   jobject result = JVMCIENV->make_local(global_handle_obj).as_jobject();
2592 
2593   JVMCIENV->destroy_global(global_handle_obj);
2594   return result;
2595 }
2596 
2597 C2V_VMENTRY(void, updateHotSpotNmethod, (JNIEnv* env, jobject, jobject code_handle))
2598   JVMCIObject code = JVMCIENV->wrap(code_handle);
2599   // Execute this operation for the side effect of updating the InstalledCode state
2600   nmethodLocker locker;
2601   JVMCIENV->get_nmethod(code, locker);
2602 }
2603 
2604 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2605   JVMCIObject code = JVMCIENV->wrap(code_handle);
2606   nmethodLocker locker;
2607   CodeBlob* cb = JVMCIENV->get_code_blob(code, locker);
2608   if (cb == NULL) {
2609     return NULL;
2610   }
2611   int code_size = cb->code_size();
2612   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2613   JVMCIENV->copy_bytes_from((jbyte*) cb->code_begin(), result, 0, code_size);
2614   return JVMCIENV->get_jbyteArray(result);
2615 }
2616 
2617 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, jobject jvmci_method))
2618   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2619   methodHandle m(THREAD, JVMCIENV->asMethod(jvmci_method));
2620   oop executable;
2621   if (m->is_initializer()) {
2622     if (m->is_static_initializer()) {
2623       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2624           "Cannot create java.lang.reflect.Method for class initializer");
2625     }
2626     executable = Reflection::new_constructor(m, CHECK_NULL);
2627   } else {
2628     executable = Reflection::new_method(m, false, CHECK_NULL);
2629   }
2630   return JNIHandles::make_local(THREAD, executable);
2631 }
2632 
2633 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, jobject jvmci_type, jint index))
2634   requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL);
2635   Klass* klass = JVMCIENV->asKlass(jvmci_type);
2636   if (!klass->is_instance_klass()) {
2637     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2638         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2639   }
2640   InstanceKlass* iklass = InstanceKlass::cast(klass);
2641   Array<u2>* fields = iklass->fields();
2642   if (index < 0 ||index > fields->length()) {
2643     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2644         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2645   }
2646   fieldDescriptor fd(iklass, index);
2647   oop reflected = Reflection::new_field(&fd, CHECK_NULL);
2648   return JNIHandles::make_local(THREAD, reflected);
2649 }
2650 
2651 C2V_VMENTRY_NULL(jobjectArray, getFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address, jobjectArray current))
2652   FailedSpeculation* head = *((FailedSpeculation**)(address) failed_speculations_address);
2653   int result_length = 0;
2654   for (FailedSpeculation* fs = head; fs != NULL; fs = fs->next()) {
2655     result_length++;
2656   }
2657   int current_length = 0;
2658   JVMCIObjectArray current_array = NULL;
2659   if (current != NULL) {
2660     current_array = JVMCIENV->wrap(current);
2661     current_length = JVMCIENV->get_length(current_array);
2662     if (current_length == result_length) {
2663       // No new failures
2664       return current;
2665     }
2666   }
2667   JVMCIObjectArray result = JVMCIENV->new_byte_array_array(result_length, JVMCI_CHECK_NULL);
2668   int result_index = 0;
2669   for (FailedSpeculation* fs = head; result_index < result_length; fs = fs->next()) {
2670     assert(fs != NULL, "npe");
2671     JVMCIPrimitiveArray entry;
2672     if (result_index < current_length) {
2673       entry = (JVMCIPrimitiveArray) JVMCIENV->get_object_at(current_array, result_index);
2674     } else {
2675       entry = JVMCIENV->new_byteArray(fs->data_len(), JVMCI_CHECK_NULL);
2676       JVMCIENV->copy_bytes_from((jbyte*) fs->data(), entry, 0, fs->data_len());
2677     }
2678     JVMCIENV->put_object_at(result, result_index++, entry);
2679   }
2680   return JVMCIENV->get_jobjectArray(result);
2681 }
2682 
2683 C2V_VMENTRY_0(jlong, getFailedSpeculationsAddress, (JNIEnv* env, jobject, jobject jvmci_method))
2684   methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
2685   MethodData* method_data = method->method_data();
2686   if (method_data == NULL) {
2687     ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
2688     method_data = MethodData::allocate(loader_data, method, CHECK_0);
2689     method->set_method_data(method_data);
2690   }
2691   return (jlong) method_data->get_failed_speculations_address();
2692 }
2693 
2694 C2V_VMENTRY(void, releaseFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address))
2695   FailedSpeculation::free_failed_speculations((FailedSpeculation**)(address) failed_speculations_address);
2696 }
2697 
2698 C2V_VMENTRY_0(jboolean, addFailedSpeculation, (JNIEnv* env, jobject, jlong failed_speculations_address, jbyteArray speculation_obj))
2699   JVMCIPrimitiveArray speculation_handle = JVMCIENV->wrap(speculation_obj);
2700   int speculation_len = JVMCIENV->get_length(speculation_handle);
2701   char* speculation = NEW_RESOURCE_ARRAY(char, speculation_len);
2702   JVMCIENV->copy_bytes_to(speculation_handle, (jbyte*) speculation, 0, speculation_len);
2703   return FailedSpeculation::add_failed_speculation(NULL, (FailedSpeculation**)(address) failed_speculations_address, (address) speculation, speculation_len);
2704 }
2705 
2706 C2V_VMENTRY(void, callSystemExit, (JNIEnv* env, jobject, jint status))
2707   JavaValue result(T_VOID);
2708   JavaCallArguments jargs(1);
2709   jargs.push_int(status);
2710   JavaCalls::call_static(&result,
2711                        vmClasses::System_klass(),
2712                        vmSymbols::exit_method_name(),
2713                        vmSymbols::int_void_signature(),
2714                        &jargs,
2715                        CHECK);
2716 }
2717 
2718 C2V_VMENTRY_0(jlong, ticksNow, (JNIEnv* env, jobject))
2719   return CompilerEvent::ticksNow();
2720 }
2721 
2722 C2V_VMENTRY_0(jint, registerCompilerPhase, (JNIEnv* env, jobject, jstring jphase_name))
2723 #if INCLUDE_JFR
2724   JVMCIObject phase_name = JVMCIENV->wrap(jphase_name);
2725   const char *name = JVMCIENV->as_utf8_string(phase_name);
2726   return CompilerEvent::PhaseEvent::get_phase_id(name, true, true, true);
2727 #else
2728   return -1;
2729 #endif // !INCLUDE_JFR
2730 }
2731 
2732 C2V_VMENTRY(void, notifyCompilerPhaseEvent, (JNIEnv* env, jobject, jlong startTime, jint phase, jint compileId, jint level))
2733   EventCompilerPhase event;
2734   if (event.should_commit()) {
2735     CompilerEvent::PhaseEvent::post(event, startTime, phase, compileId, level);
2736   }
2737 }
2738 
2739 C2V_VMENTRY(void, notifyCompilerInliningEvent, (JNIEnv* env, jobject, jint compileId, jobject caller, jobject callee, jboolean succeeded, jstring jmessage, jint bci))
2740   EventCompilerInlining event;
2741   if (event.should_commit()) {
2742     Method* caller_method = JVMCIENV->asMethod(caller);
2743     Method* callee_method = JVMCIENV->asMethod(callee);
2744     JVMCIObject message = JVMCIENV->wrap(jmessage);
2745     CompilerEvent::InlineEvent::post(event, compileId, caller_method, callee_method, succeeded, JVMCIENV->as_utf8_string(message), bci);
2746   }
2747 }
2748 
2749 C2V_VMENTRY(void, setThreadLocalObject, (JNIEnv* env, jobject, jint id, jobject value))
2750   requireInHotSpot("setThreadLocalObject", JVMCI_CHECK);
2751   if (id == 0) {
2752     thread->set_jvmci_reserved_oop0(JNIHandles::resolve(value));
2753     return;
2754   }
2755   THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2756             err_msg("%d is not a valid thread local id", id));
2757 }
2758 
2759 C2V_VMENTRY_NULL(jobject, getThreadLocalObject, (JNIEnv* env, jobject, jint id))
2760   requireInHotSpot("getThreadLocalObject", JVMCI_CHECK_NULL);
2761   if (id == 0) {
2762     return JNIHandles::make_local(thread->get_jvmci_reserved_oop0());
2763   }
2764   THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
2765               err_msg("%d is not a valid thread local id", id));
2766 }
2767 
2768 C2V_VMENTRY(void, setThreadLocalLong, (JNIEnv* env, jobject, jint id, jlong value))
2769   requireInHotSpot("setThreadLocalLong", JVMCI_CHECK);
2770   if (id == 0) {
2771     thread->set_jvmci_reserved0(value);
2772   } else if (id == 1) {
2773     thread->set_jvmci_reserved1(value);
2774   } else {
2775     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2776               err_msg("%d is not a valid thread local id", id));
2777   }
2778 }
2779 
2780 C2V_VMENTRY_0(jlong, getThreadLocalLong, (JNIEnv* env, jobject, jint id))
2781   requireInHotSpot("getThreadLocalLong", JVMCI_CHECK_0);
2782   if (id == 0) {
2783     return thread->get_jvmci_reserved0();
2784   } else if (id == 1) {
2785     return thread->get_jvmci_reserved1();
2786   } else {
2787     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
2788                 err_msg("%d is not a valid thread local id", id));
2789   }
2790 }
2791 
2792 #define CC (char*)  /*cast a literal from (const char*)*/
2793 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
2794 
2795 #define STRING                  "Ljava/lang/String;"
2796 #define OBJECT                  "Ljava/lang/Object;"
2797 #define CLASS                   "Ljava/lang/Class;"
2798 #define OBJECTCONSTANT          "Ljdk/vm/ci/hotspot/HotSpotObjectConstantImpl;"
2799 #define HANDLECONSTANT          "Ljdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl;"
2800 #define EXECUTABLE              "Ljava/lang/reflect/Executable;"
2801 #define STACK_TRACE_ELEMENT     "Ljava/lang/StackTraceElement;"
2802 #define INSTALLED_CODE          "Ljdk/vm/ci/code/InstalledCode;"
2803 #define TARGET_DESCRIPTION      "Ljdk/vm/ci/code/TargetDescription;"
2804 #define BYTECODE_FRAME          "Ljdk/vm/ci/code/BytecodeFrame;"
2805 #define JAVACONSTANT            "Ljdk/vm/ci/meta/JavaConstant;"
2806 #define INSPECTED_FRAME_VISITOR "Ljdk/vm/ci/code/stack/InspectedFrameVisitor;"
2807 #define RESOLVED_METHOD         "Ljdk/vm/ci/meta/ResolvedJavaMethod;"
2808 #define HS_RESOLVED_METHOD      "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;"
2809 #define HS_RESOLVED_KLASS       "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;"
2810 #define HS_RESOLVED_TYPE        "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaType;"
2811 #define HS_RESOLVED_FIELD       "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaField;"
2812 #define HS_INSTALLED_CODE       "Ljdk/vm/ci/hotspot/HotSpotInstalledCode;"
2813 #define HS_NMETHOD              "Ljdk/vm/ci/hotspot/HotSpotNmethod;"
2814 #define HS_CONSTANT_POOL        "Ljdk/vm/ci/hotspot/HotSpotConstantPool;"
2815 #define HS_COMPILED_CODE        "Ljdk/vm/ci/hotspot/HotSpotCompiledCode;"
2816 #define HS_CONFIG               "Ljdk/vm/ci/hotspot/HotSpotVMConfig;"
2817 #define HS_STACK_FRAME_REF      "Ljdk/vm/ci/hotspot/HotSpotStackFrameReference;"
2818 #define HS_SPECULATION_LOG      "Ljdk/vm/ci/hotspot/HotSpotSpeculationLog;"
2819 #define METASPACE_OBJECT        "Ljdk/vm/ci/hotspot/MetaspaceObject;"
2820 #define REFLECTION_EXECUTABLE   "Ljava/lang/reflect/Executable;"
2821 #define REFLECTION_FIELD        "Ljava/lang/reflect/Field;"
2822 #define METASPACE_METHOD_DATA   "J"
2823 
2824 JNINativeMethod CompilerToVM::methods[] = {
2825   {CC "getBytecode",                                  CC "(" HS_RESOLVED_METHOD ")[B",                                                      FN_PTR(getBytecode)},
2826   {CC "getExceptionTableStart",                       CC "(" HS_RESOLVED_METHOD ")J",                                                       FN_PTR(getExceptionTableStart)},
2827   {CC "getExceptionTableLength",                      CC "(" HS_RESOLVED_METHOD ")I",                                                       FN_PTR(getExceptionTableLength)},
2828   {CC "findUniqueConcreteMethod",                     CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")" HS_RESOLVED_METHOD,                   FN_PTR(findUniqueConcreteMethod)},
2829   {CC "getImplementor",                               CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_KLASS,                                       FN_PTR(getImplementor)},
2830   {CC "getStackTraceElement",                         CC "(" HS_RESOLVED_METHOD "I)" STACK_TRACE_ELEMENT,                                   FN_PTR(getStackTraceElement)},
2831   {CC "methodIsIgnoredBySecurityStackWalk",           CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(methodIsIgnoredBySecurityStackWalk)},
2832   {CC "setNotInlinableOrCompilable",                  CC "(" HS_RESOLVED_METHOD ")V",                                                       FN_PTR(setNotInlinableOrCompilable)},
2833   {CC "isCompilable",                                 CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(isCompilable)},
2834   {CC "hasNeverInlineDirective",                      CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(hasNeverInlineDirective)},
2835   {CC "shouldInlineMethod",                           CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(shouldInlineMethod)},
2836   {CC "lookupType",                                   CC "(" STRING HS_RESOLVED_KLASS "Z)" HS_RESOLVED_TYPE,                                FN_PTR(lookupType)},
2837   {CC "getArrayType",                                 CC "(" HS_RESOLVED_TYPE ")" HS_RESOLVED_KLASS,                                        FN_PTR(getArrayType)},
2838   {CC "lookupClass",                                  CC "(" CLASS ")" HS_RESOLVED_TYPE,                                                    FN_PTR(lookupClass)},
2839   {CC "lookupNameInPool",                             CC "(" HS_CONSTANT_POOL "I)" STRING,                                                  FN_PTR(lookupNameInPool)},
2840   {CC "lookupNameAndTypeRefIndexInPool",              CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(lookupNameAndTypeRefIndexInPool)},
2841   {CC "lookupSignatureInPool",                        CC "(" HS_CONSTANT_POOL "I)" STRING,                                                  FN_PTR(lookupSignatureInPool)},
2842   {CC "lookupKlassRefIndexInPool",                    CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(lookupKlassRefIndexInPool)},
2843   {CC "lookupKlassInPool",                            CC "(" HS_CONSTANT_POOL "I)Ljava/lang/Object;",                                       FN_PTR(lookupKlassInPool)},
2844   {CC "lookupAppendixInPool",                         CC "(" HS_CONSTANT_POOL "I)" OBJECTCONSTANT,                                          FN_PTR(lookupAppendixInPool)},
2845   {CC "lookupMethodInPool",                           CC "(" HS_CONSTANT_POOL "IB)" HS_RESOLVED_METHOD,                                     FN_PTR(lookupMethodInPool)},
2846   {CC "constantPoolRemapInstructionOperandFromCache", CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(constantPoolRemapInstructionOperandFromCache)},
2847   {CC "resolveBootstrapMethod",                       CC "(" HS_CONSTANT_POOL "I)[" OBJECT,                                                 FN_PTR(resolveBootstrapMethod)},
2848   {CC "resolvePossiblyCachedConstantInPool",          CC "(" HS_CONSTANT_POOL "I)" JAVACONSTANT,                                            FN_PTR(resolvePossiblyCachedConstantInPool)},
2849   {CC "resolveTypeInPool",                            CC "(" HS_CONSTANT_POOL "I)" HS_RESOLVED_KLASS,                                       FN_PTR(resolveTypeInPool)},
2850   {CC "resolveFieldInPool",                           CC "(" HS_CONSTANT_POOL "I" HS_RESOLVED_METHOD "B[I)" HS_RESOLVED_KLASS,              FN_PTR(resolveFieldInPool)},
2851   {CC "resolveInvokeDynamicInPool",                   CC "(" HS_CONSTANT_POOL "I)V",                                                        FN_PTR(resolveInvokeDynamicInPool)},
2852   {CC "resolveInvokeHandleInPool",                    CC "(" HS_CONSTANT_POOL "I)V",                                                        FN_PTR(resolveInvokeHandleInPool)},
2853   {CC "isResolvedInvokeHandleInPool",                 CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(isResolvedInvokeHandleInPool)},
2854   {CC "resolveMethod",                                CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD, FN_PTR(resolveMethod)},
2855   {CC "getSignaturePolymorphicHolders",               CC "()[" STRING,                                                                      FN_PTR(getSignaturePolymorphicHolders)},
2856   {CC "getVtableIndexForInterfaceMethod",             CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")I",                                     FN_PTR(getVtableIndexForInterfaceMethod)},
2857   {CC "getClassInitializer",                          CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD,                                      FN_PTR(getClassInitializer)},
2858   {CC "hasFinalizableSubclass",                       CC "(" HS_RESOLVED_KLASS ")Z",                                                        FN_PTR(hasFinalizableSubclass)},
2859   {CC "getMaxCallTargetOffset",                       CC "(J)J",                                                                            FN_PTR(getMaxCallTargetOffset)},
2860   {CC "asResolvedJavaMethod",                         CC "(" EXECUTABLE ")" HS_RESOLVED_METHOD,                                             FN_PTR(asResolvedJavaMethod)},
2861   {CC "getResolvedJavaMethod",                        CC "(" OBJECTCONSTANT "J)" HS_RESOLVED_METHOD,                                        FN_PTR(getResolvedJavaMethod)},
2862   {CC "getConstantPool",                              CC "(" METASPACE_OBJECT ")" HS_CONSTANT_POOL,                                         FN_PTR(getConstantPool)},
2863   {CC "getResolvedJavaType0",                         CC "(Ljava/lang/Object;JZ)" HS_RESOLVED_KLASS,                                        FN_PTR(getResolvedJavaType0)},
2864   {CC "readConfiguration",                            CC "()[" OBJECT,                                                                      FN_PTR(readConfiguration)},
2865   {CC "installCode",                                  CC "(" TARGET_DESCRIPTION HS_COMPILED_CODE INSTALLED_CODE "J[B)I",                    FN_PTR(installCode)},
2866   {CC "resetCompilationStatistics",                   CC "()V",                                                                             FN_PTR(resetCompilationStatistics)},
2867   {CC "disassembleCodeBlob",                          CC "(" INSTALLED_CODE ")" STRING,                                                     FN_PTR(disassembleCodeBlob)},
2868   {CC "executeHotSpotNmethod",                        CC "([" OBJECT HS_NMETHOD ")" OBJECT,                                                 FN_PTR(executeHotSpotNmethod)},
2869   {CC "getLineNumberTable",                           CC "(" HS_RESOLVED_METHOD ")[J",                                                      FN_PTR(getLineNumberTable)},
2870   {CC "getLocalVariableTableStart",                   CC "(" HS_RESOLVED_METHOD ")J",                                                       FN_PTR(getLocalVariableTableStart)},
2871   {CC "getLocalVariableTableLength",                  CC "(" HS_RESOLVED_METHOD ")I",                                                       FN_PTR(getLocalVariableTableLength)},
2872   {CC "reprofile",                                    CC "(" HS_RESOLVED_METHOD ")V",                                                       FN_PTR(reprofile)},
2873   {CC "invalidateHotSpotNmethod",                     CC "(" HS_NMETHOD ")V",                                                               FN_PTR(invalidateHotSpotNmethod)},
2874   {CC "collectCounters",                              CC "()[J",                                                                            FN_PTR(collectCounters)},
2875   {CC "getCountersSize",                              CC "()I",                                                                             FN_PTR(getCountersSize)},
2876   {CC "setCountersSize",                              CC "(I)Z",                                                                            FN_PTR(setCountersSize)},
2877   {CC "allocateCompileId",                            CC "(" HS_RESOLVED_METHOD "I)I",                                                      FN_PTR(allocateCompileId)},
2878   {CC "isMature",                                     CC "(" METASPACE_METHOD_DATA ")Z",                                                    FN_PTR(isMature)},
2879   {CC "hasCompiledCodeForOSR",                        CC "(" HS_RESOLVED_METHOD "II)Z",                                                     FN_PTR(hasCompiledCodeForOSR)},
2880   {CC "getSymbol",                                    CC "(J)" STRING,                                                                      FN_PTR(getSymbol)},
2881   {CC "iterateFrames",                                CC "([" RESOLVED_METHOD "[" RESOLVED_METHOD "I" INSPECTED_FRAME_VISITOR ")" OBJECT,   FN_PTR(iterateFrames)},
2882   {CC "materializeVirtualObjects",                    CC "(" HS_STACK_FRAME_REF "Z)V",                                                      FN_PTR(materializeVirtualObjects)},
2883   {CC "shouldDebugNonSafepoints",                     CC "()Z",                                                                             FN_PTR(shouldDebugNonSafepoints)},
2884   {CC "writeDebugOutput",                             CC "(JIZ)V",                                                                          FN_PTR(writeDebugOutput)},
2885   {CC "flushDebugOutput",                             CC "()V",                                                                             FN_PTR(flushDebugOutput)},
2886   {CC "methodDataProfileDataSize",                    CC "(JI)I",                                                                           FN_PTR(methodDataProfileDataSize)},
2887   {CC "interpreterFrameSize",                         CC "(" BYTECODE_FRAME ")I",                                                           FN_PTR(interpreterFrameSize)},
2888   {CC "compileToBytecode",                            CC "(" OBJECTCONSTANT ")V",                                                           FN_PTR(compileToBytecode)},
2889   {CC "getFlagValue",                                 CC "(" STRING ")" OBJECT,                                                             FN_PTR(getFlagValue)},
2890   {CC "getInterfaces",                                CC "(" HS_RESOLVED_KLASS ")[" HS_RESOLVED_KLASS,                                      FN_PTR(getInterfaces)},
2891   {CC "getComponentType",                             CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_TYPE,                                        FN_PTR(getComponentType)},
2892   {CC "ensureInitialized",                            CC "(" HS_RESOLVED_KLASS ")V",                                                        FN_PTR(ensureInitialized)},
2893   {CC "ensureLinked",                                 CC "(" HS_RESOLVED_KLASS ")V",                                                        FN_PTR(ensureLinked)},
2894   {CC "getIdentityHashCode",                          CC "(" OBJECTCONSTANT ")I",                                                           FN_PTR(getIdentityHashCode)},
2895   {CC "isInternedString",                             CC "(" OBJECTCONSTANT ")Z",                                                           FN_PTR(isInternedString)},
2896   {CC "unboxPrimitive",                               CC "(" OBJECTCONSTANT ")" OBJECT,                                                     FN_PTR(unboxPrimitive)},
2897   {CC "boxPrimitive",                                 CC "(" OBJECT ")" OBJECTCONSTANT,                                                     FN_PTR(boxPrimitive)},
2898   {CC "getDeclaredConstructors",                      CC "(" HS_RESOLVED_KLASS ")[" RESOLVED_METHOD,                                        FN_PTR(getDeclaredConstructors)},
2899   {CC "getDeclaredMethods",                           CC "(" HS_RESOLVED_KLASS ")[" RESOLVED_METHOD,                                        FN_PTR(getDeclaredMethods)},
2900   {CC "readFieldValue",                               CC "(" HS_RESOLVED_KLASS HS_RESOLVED_KLASS "JLjdk/vm/ci/meta/JavaKind;)" JAVACONSTANT, FN_PTR(readFieldValue)},
2901   {CC "readFieldValue",                               CC "(" OBJECTCONSTANT HS_RESOLVED_KLASS "JLjdk/vm/ci/meta/JavaKind;)" JAVACONSTANT,   FN_PTR(readFieldValue)},
2902   {CC "isInstance",                                   CC "(" HS_RESOLVED_KLASS OBJECTCONSTANT ")Z",                                         FN_PTR(isInstance)},
2903   {CC "isAssignableFrom",                             CC "(" HS_RESOLVED_KLASS HS_RESOLVED_KLASS ")Z",                                      FN_PTR(isAssignableFrom)},
2904   {CC "isTrustedForIntrinsics",                       CC "(" HS_RESOLVED_KLASS ")Z",                                                        FN_PTR(isTrustedForIntrinsics)},
2905   {CC "asJavaType",                                   CC "(" OBJECTCONSTANT ")" HS_RESOLVED_TYPE,                                           FN_PTR(asJavaType)},
2906   {CC "asString",                                     CC "(" OBJECTCONSTANT ")" STRING,                                                     FN_PTR(asString)},
2907   {CC "equals",                                       CC "(" OBJECTCONSTANT "J" OBJECTCONSTANT "J)Z",                                       FN_PTR(equals)},
2908   {CC "getJavaMirror",                                CC "(" HS_RESOLVED_TYPE ")" OBJECTCONSTANT,                                           FN_PTR(getJavaMirror)},
2909   {CC "getArrayLength",                               CC "(" OBJECTCONSTANT ")I",                                                           FN_PTR(getArrayLength)},
2910   {CC "readArrayElement",                             CC "(" OBJECTCONSTANT "I)Ljava/lang/Object;",                                         FN_PTR(readArrayElement)},
2911   {CC "arrayBaseOffset",                              CC "(Ljdk/vm/ci/meta/JavaKind;)I",                                                    FN_PTR(arrayBaseOffset)},
2912   {CC "arrayIndexScale",                              CC "(Ljdk/vm/ci/meta/JavaKind;)I",                                                    FN_PTR(arrayIndexScale)},
2913   {CC "deleteGlobalHandle",                           CC "(J)V",                                                                            FN_PTR(deleteGlobalHandle)},
2914   {CC "registerNativeMethods",                        CC "(" CLASS ")[J",                                                                   FN_PTR(registerNativeMethods)},
2915   {CC "isCurrentThreadAttached",                      CC "()Z",                                                                             FN_PTR(isCurrentThreadAttached)},
2916   {CC "getCurrentJavaThread",                         CC "()J",                                                                             FN_PTR(getCurrentJavaThread)},
2917   {CC "attachCurrentThread",                          CC "([BZ[J)Z",                                                                        FN_PTR(attachCurrentThread)},
2918   {CC "detachCurrentThread",                          CC "(Z)Z",                                                                            FN_PTR(detachCurrentThread)},
2919   {CC "translate",                                    CC "(" OBJECT "Z)J",                                                                  FN_PTR(translate)},
2920   {CC "unhand",                                       CC "(J)" OBJECT,                                                                      FN_PTR(unhand)},
2921   {CC "updateHotSpotNmethod",                         CC "(" HS_NMETHOD ")V",                                                               FN_PTR(updateHotSpotNmethod)},
2922   {CC "getCode",                                      CC "(" HS_INSTALLED_CODE ")[B",                                                       FN_PTR(getCode)},
2923   {CC "asReflectionExecutable",                       CC "(" HS_RESOLVED_METHOD ")" REFLECTION_EXECUTABLE,                                  FN_PTR(asReflectionExecutable)},
2924   {CC "asReflectionField",                            CC "(" HS_RESOLVED_KLASS "I)" REFLECTION_FIELD,                                       FN_PTR(asReflectionField)},
2925   {CC "getFailedSpeculations",                        CC "(J[[B)[[B",                                                                       FN_PTR(getFailedSpeculations)},
2926   {CC "getFailedSpeculationsAddress",                 CC "(" HS_RESOLVED_METHOD ")J",                                                       FN_PTR(getFailedSpeculationsAddress)},
2927   {CC "releaseFailedSpeculations",                    CC "(J)V",                                                                            FN_PTR(releaseFailedSpeculations)},
2928   {CC "addFailedSpeculation",                         CC "(J[B)Z",                                                                          FN_PTR(addFailedSpeculation)},
2929   {CC "callSystemExit",                               CC "(I)V",                                                                            FN_PTR(callSystemExit)},
2930   {CC "ticksNow",                                     CC "()J",                                                                             FN_PTR(ticksNow)},
2931   {CC "getThreadLocalObject",                         CC "(I)" OBJECT,                                                                      FN_PTR(getThreadLocalObject)},
2932   {CC "setThreadLocalObject",                         CC "(I" OBJECT ")V",                                                                  FN_PTR(setThreadLocalObject)},
2933   {CC "getThreadLocalLong",                           CC "(I)J",                                                                            FN_PTR(getThreadLocalLong)},
2934   {CC "setThreadLocalLong",                           CC "(IJ)V",                                                                           FN_PTR(setThreadLocalLong)},
2935   {CC "registerCompilerPhase",                        CC "(" STRING ")I",                                                                   FN_PTR(registerCompilerPhase)},
2936   {CC "notifyCompilerPhaseEvent",                     CC "(JIII)V",                                                                         FN_PTR(notifyCompilerPhaseEvent)},
2937   {CC "notifyCompilerInliningEvent",                  CC "(I" HS_RESOLVED_METHOD HS_RESOLVED_METHOD "ZLjava/lang/String;I)V",               FN_PTR(notifyCompilerInliningEvent)},
2938 };
2939 
2940 int CompilerToVM::methods_count() {
2941   return sizeof(methods) / sizeof(JNINativeMethod);
2942 }