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