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