1 /*
   2  * Copyright (c) 2011, 2017, 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/javaClasses.inline.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "code/scopeDesc.hpp"
  28 #include "interpreter/linkResolver.hpp"
  29 #include "memory/oopFactory.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/generateOopMap.hpp"
  32 #include "oops/fieldStreams.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "oops/objArrayOop.inline.hpp"
  35 #include "runtime/fieldDescriptor.hpp"
  36 #include "runtime/javaCalls.hpp"
  37 #include "jvmci/jvmciRuntime.hpp"
  38 #include "compiler/abstractCompiler.hpp"
  39 #include "compiler/compileBroker.hpp"
  40 #include "compiler/compilerOracle.hpp"
  41 #include "compiler/disassembler.hpp"
  42 #include "compiler/oopMap.hpp"
  43 #include "jvmci/jvmciCompilerToVM.hpp"
  44 #include "jvmci/jvmciCompiler.hpp"
  45 #include "jvmci/jvmciEnv.hpp"
  46 #include "jvmci/jvmciJavaClasses.hpp"
  47 #include "jvmci/jvmciCodeInstaller.hpp"
  48 #include "jvmci/vmStructs_jvmci.hpp"
  49 #include "gc/g1/heapRegion.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "runtime/deoptimization.hpp"
  52 #include "runtime/timerTrace.hpp"
  53 #include "runtime/vframe.hpp"
  54 #include "runtime/vframe_hp.hpp"
  55 #include "runtime/vmStructs.hpp"
  56 #include "utilities/resourceHash.hpp"
  57 
  58 
  59 void JNIHandleMark::push_jni_handle_block() {
  60   JavaThread* thread = JavaThread::current();
  61   if (thread != NULL) {
  62     // Allocate a new block for JNI handles.
  63     // Inlined code from jni_PushLocalFrame()
  64     JNIHandleBlock* java_handles = ((JavaThread*)thread)->active_handles();
  65     JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread);
  66     assert(compile_handles != NULL && java_handles != NULL, "should not be NULL");
  67     compile_handles->set_pop_frame_link(java_handles);
  68     thread->set_active_handles(compile_handles);
  69   }
  70 }
  71 
  72 void JNIHandleMark::pop_jni_handle_block() {
  73   JavaThread* thread = JavaThread::current();
  74   if (thread != NULL) {
  75     // Release our JNI handle block
  76     JNIHandleBlock* compile_handles = thread->active_handles();
  77     JNIHandleBlock* java_handles = compile_handles->pop_frame_link();
  78     thread->set_active_handles(java_handles);
  79     compile_handles->set_pop_frame_link(NULL);
  80     JNIHandleBlock::release_block(compile_handles, thread); // may block
  81   }
  82 }
  83 
  84 // Entry to native method implementation that transitions current thread to '_thread_in_vm'.
  85 #define C2V_VMENTRY(result_type, name, signature) \
  86   JNIEXPORT result_type JNICALL c2v_ ## name signature { \
  87   TRACE_jvmci_1("CompilerToVM::" #name); \
  88   TRACE_CALL(result_type, jvmci_ ## name signature) \
  89   JVMCI_VM_ENTRY_MARK; \
  90 
  91 #define C2V_END }
  92 
  93 oop CompilerToVM::get_jvmci_method(const methodHandle& method, TRAPS) {
  94   if (method() != NULL) {
  95     JavaValue result(T_OBJECT);
  96     JavaCallArguments args;
  97     args.push_long((jlong) (address) method());
  98     JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, CHECK_NULL);
  99 
 100     return (oop)result.get_jobject();
 101   }
 102   return NULL;
 103 }
 104 
 105 oop CompilerToVM::get_jvmci_type(Klass* klass, TRAPS) {
 106   if (klass != NULL) {
 107     JavaValue result(T_OBJECT);
 108     JavaCallArguments args;
 109     args.push_oop(Handle(THREAD, klass->java_mirror()));
 110     JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedObjectTypeImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::klass_fromMetaspace_signature(), &args, CHECK_NULL);
 111 
 112     return (oop)result.get_jobject();
 113   }
 114   return NULL;
 115 }
 116 
 117 
 118 int CompilerToVM::Data::Klass_vtable_start_offset;
 119 int CompilerToVM::Data::Klass_vtable_length_offset;
 120 
 121 int CompilerToVM::Data::Method_extra_stack_entries;
 122 
 123 address CompilerToVM::Data::SharedRuntime_ic_miss_stub;
 124 address CompilerToVM::Data::SharedRuntime_handle_wrong_method_stub;
 125 address CompilerToVM::Data::SharedRuntime_deopt_blob_unpack;
 126 address CompilerToVM::Data::SharedRuntime_deopt_blob_uncommon_trap;
 127 
 128 size_t CompilerToVM::Data::ThreadLocalAllocBuffer_alignment_reserve;
 129 
 130 CollectedHeap* CompilerToVM::Data::Universe_collectedHeap;
 131 int CompilerToVM::Data::Universe_base_vtable_size;
 132 address CompilerToVM::Data::Universe_narrow_oop_base;
 133 int CompilerToVM::Data::Universe_narrow_oop_shift;
 134 address CompilerToVM::Data::Universe_narrow_klass_base;
 135 int CompilerToVM::Data::Universe_narrow_klass_shift;
 136 void* CompilerToVM::Data::Universe_non_oop_bits;
 137 uintptr_t CompilerToVM::Data::Universe_verify_oop_mask;
 138 uintptr_t CompilerToVM::Data::Universe_verify_oop_bits;
 139 
 140 bool       CompilerToVM::Data::_supports_inline_contig_alloc;
 141 HeapWord** CompilerToVM::Data::_heap_end_addr;
 142 HeapWord* volatile* CompilerToVM::Data::_heap_top_addr;
 143 int CompilerToVM::Data::_max_oop_map_stack_offset;
 144 
 145 jbyte* CompilerToVM::Data::cardtable_start_address;
 146 int CompilerToVM::Data::cardtable_shift;
 147 
 148 int CompilerToVM::Data::vm_page_size;
 149 
 150 int CompilerToVM::Data::sizeof_vtableEntry = sizeof(vtableEntry);
 151 int CompilerToVM::Data::sizeof_ExceptionTableElement = sizeof(ExceptionTableElement);
 152 int CompilerToVM::Data::sizeof_LocalVariableTableElement = sizeof(LocalVariableTableElement);
 153 int CompilerToVM::Data::sizeof_ConstantPool = sizeof(ConstantPool);
 154 int CompilerToVM::Data::sizeof_SymbolPointer = sizeof(Symbol*);
 155 int CompilerToVM::Data::sizeof_narrowKlass = sizeof(narrowKlass);
 156 int CompilerToVM::Data::sizeof_arrayOopDesc = sizeof(arrayOopDesc);
 157 int CompilerToVM::Data::sizeof_BasicLock = sizeof(BasicLock);
 158 
 159 address CompilerToVM::Data::dsin;
 160 address CompilerToVM::Data::dcos;
 161 address CompilerToVM::Data::dtan;
 162 address CompilerToVM::Data::dexp;
 163 address CompilerToVM::Data::dlog;
 164 address CompilerToVM::Data::dlog10;
 165 address CompilerToVM::Data::dpow;
 166 
 167 address CompilerToVM::Data::symbol_init;
 168 address CompilerToVM::Data::symbol_clinit;
 169 
 170 void CompilerToVM::Data::initialize(TRAPS) {
 171   Klass_vtable_start_offset = in_bytes(Klass::vtable_start_offset());
 172   Klass_vtable_length_offset = in_bytes(Klass::vtable_length_offset());
 173 
 174   Method_extra_stack_entries = Method::extra_stack_entries();
 175 
 176   SharedRuntime_ic_miss_stub = SharedRuntime::get_ic_miss_stub();
 177   SharedRuntime_handle_wrong_method_stub = SharedRuntime::get_handle_wrong_method_stub();
 178   SharedRuntime_deopt_blob_unpack = SharedRuntime::deopt_blob()->unpack();
 179   SharedRuntime_deopt_blob_uncommon_trap = SharedRuntime::deopt_blob()->uncommon_trap();
 180 
 181   ThreadLocalAllocBuffer_alignment_reserve = ThreadLocalAllocBuffer::alignment_reserve();
 182 
 183   Universe_collectedHeap = Universe::heap();
 184   Universe_base_vtable_size = Universe::base_vtable_size();
 185   Universe_narrow_oop_base = Universe::narrow_oop_base();
 186   Universe_narrow_oop_shift = Universe::narrow_oop_shift();
 187   Universe_narrow_klass_base = Universe::narrow_klass_base();
 188   Universe_narrow_klass_shift = Universe::narrow_klass_shift();
 189   Universe_non_oop_bits = Universe::non_oop_word();
 190   Universe_verify_oop_mask = Universe::verify_oop_mask();
 191   Universe_verify_oop_bits = Universe::verify_oop_bits();
 192 
 193   _supports_inline_contig_alloc = Universe::heap()->supports_inline_contig_alloc();
 194   _heap_end_addr = _supports_inline_contig_alloc ? Universe::heap()->end_addr() : (HeapWord**) -1;
 195   _heap_top_addr = _supports_inline_contig_alloc ? Universe::heap()->top_addr() : (HeapWord* volatile*) -1;
 196 
 197   _max_oop_map_stack_offset = (OopMapValue::register_mask - VMRegImpl::stack2reg(0)->value()) * VMRegImpl::stack_slot_size;
 198   int max_oop_map_stack_index = _max_oop_map_stack_offset / VMRegImpl::stack_slot_size;
 199   assert(OopMapValue::legal_vm_reg_name(VMRegImpl::stack2reg(max_oop_map_stack_index)), "should be valid");
 200   assert(!OopMapValue::legal_vm_reg_name(VMRegImpl::stack2reg(max_oop_map_stack_index + 1)), "should be invalid");
 201 
 202   symbol_init = (address) vmSymbols::object_initializer_name();
 203   symbol_clinit = (address) vmSymbols::class_initializer_name();
 204 
 205   BarrierSet* bs = Universe::heap()->barrier_set();
 206   switch (bs->kind()) {
 207   case BarrierSet::CardTableModRef:
 208   case BarrierSet::CardTableForRS:
 209   case BarrierSet::CardTableExtension:
 210   case BarrierSet::G1SATBCT:
 211   case BarrierSet::G1SATBCTLogging: {
 212     jbyte* base = barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base;
 213     assert(base != 0, "unexpected byte_map_base");
 214     cardtable_start_address = base;
 215     cardtable_shift = CardTableModRefBS::card_shift;
 216     break;
 217   }
 218   case BarrierSet::ModRef:
 219     cardtable_start_address = 0;
 220     cardtable_shift = 0;
 221     // No post barriers
 222     break;
 223   default:
 224     JVMCI_ERROR("Unsupported BarrierSet kind %d", bs->kind());
 225     break;
 226   }
 227 
 228   vm_page_size = os::vm_page_size();
 229 
 230 #define SET_TRIGFUNC(name)                                      \
 231   if (StubRoutines::name() != NULL) {                           \
 232     name = StubRoutines::name();                                \
 233   } else {                                                      \
 234     name = CAST_FROM_FN_PTR(address, SharedRuntime::name);      \
 235   }
 236 
 237   SET_TRIGFUNC(dsin);
 238   SET_TRIGFUNC(dcos);
 239   SET_TRIGFUNC(dtan);
 240   SET_TRIGFUNC(dexp);
 241   SET_TRIGFUNC(dlog10);
 242   SET_TRIGFUNC(dlog);
 243   SET_TRIGFUNC(dpow);
 244 
 245 #undef SET_TRIGFUNC
 246 }
 247 
 248 objArrayHandle CompilerToVM::initialize_intrinsics(TRAPS) {
 249   objArrayHandle vmIntrinsics = oopFactory::new_objArray_handle(VMIntrinsicMethod::klass(), (vmIntrinsics::ID_LIMIT - 1), CHECK_(objArrayHandle()));
 250   int index = 0;
 251   // The intrinsics for a class are usually adjacent to each other.
 252   // When they are, the string for the class name can be reused.
 253   vmSymbols::SID kls_sid = vmSymbols::NO_SID;
 254   Handle kls_str;
 255 #define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n)
 256 #define VM_SYMBOL_TO_STRING(s) \
 257   java_lang_String::create_from_symbol(vmSymbols::symbol_at(SID_ENUM(s)), CHECK_(objArrayHandle()))
 258 #define VM_INTRINSIC_INFO(id, kls, name, sig, ignore_fcode) {             \
 259     instanceHandle vmIntrinsicMethod = InstanceKlass::cast(VMIntrinsicMethod::klass())->allocate_instance_handle(CHECK_(objArrayHandle())); \
 260     if (kls_sid != SID_ENUM(kls)) {                                       \
 261       kls_str = VM_SYMBOL_TO_STRING(kls);                                 \
 262       kls_sid = SID_ENUM(kls);                                            \
 263     }                                                                     \
 264     Handle name_str = VM_SYMBOL_TO_STRING(name);                          \
 265     Handle sig_str = VM_SYMBOL_TO_STRING(sig);                            \
 266     VMIntrinsicMethod::set_declaringClass(vmIntrinsicMethod, kls_str());  \
 267     VMIntrinsicMethod::set_name(vmIntrinsicMethod, name_str());           \
 268     VMIntrinsicMethod::set_descriptor(vmIntrinsicMethod, sig_str());      \
 269     VMIntrinsicMethod::set_id(vmIntrinsicMethod, vmIntrinsics::id);       \
 270       vmIntrinsics->obj_at_put(index++, vmIntrinsicMethod());             \
 271   }
 272 
 273   VM_INTRINSICS_DO(VM_INTRINSIC_INFO, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE)
 274 #undef SID_ENUM
 275 #undef VM_SYMBOL_TO_STRING
 276 #undef VM_INTRINSIC_INFO
 277   assert(index == vmIntrinsics::ID_LIMIT - 1, "must be");
 278 
 279   return vmIntrinsics;
 280 }
 281 
 282 /**
 283  * The set of VM flags known to be used.
 284  */
 285 #define PREDEFINED_CONFIG_FLAGS(do_bool_flag, do_intx_flag, do_uintx_flag) \
 286   do_intx_flag(AllocateInstancePrefetchLines)                              \
 287   do_intx_flag(AllocatePrefetchDistance)                                   \
 288   do_intx_flag(AllocatePrefetchInstr)                                      \
 289   do_intx_flag(AllocatePrefetchLines)                                      \
 290   do_intx_flag(AllocatePrefetchStepSize)                                   \
 291   do_intx_flag(AllocatePrefetchStyle)                                      \
 292   do_intx_flag(BciProfileWidth)                                            \
 293   do_bool_flag(BootstrapJVMCI)                                             \
 294   do_bool_flag(CITime)                                                     \
 295   do_bool_flag(CITimeEach)                                                 \
 296   do_uintx_flag(CodeCacheSegmentSize)                                      \
 297   do_intx_flag(CodeEntryAlignment)                                         \
 298   do_bool_flag(CompactFields)                                              \
 299   NOT_PRODUCT(do_intx_flag(CompileTheWorldStartAt))                        \
 300   NOT_PRODUCT(do_intx_flag(CompileTheWorldStopAt))                         \
 301   do_intx_flag(ContendedPaddingWidth)                                      \
 302   do_bool_flag(DontCompileHugeMethods)                                     \
 303   do_bool_flag(EnableContended)                                            \
 304   do_intx_flag(FieldsAllocationStyle)                                      \
 305   do_bool_flag(FoldStableValues)                                           \
 306   do_bool_flag(ForceUnreachable)                                           \
 307   do_intx_flag(HugeMethodLimit)                                            \
 308   do_bool_flag(Inline)                                                     \
 309   do_intx_flag(JVMCICounterSize)                                           \
 310   do_bool_flag(JVMCIPrintProperties)                                       \
 311   do_bool_flag(JVMCIUseFastLocking)                                        \
 312   do_intx_flag(MethodProfileWidth)                                         \
 313   do_intx_flag(ObjectAlignmentInBytes)                                     \
 314   do_bool_flag(PrintInlining)                                              \
 315   do_bool_flag(ReduceInitialCardMarks)                                     \
 316   do_bool_flag(RestrictContended)                                          \
 317   do_intx_flag(StackReservedPages)                                         \
 318   do_intx_flag(StackShadowPages)                                           \
 319   do_bool_flag(TLABStats)                                                  \
 320   do_uintx_flag(TLABWasteIncrement)                                        \
 321   do_intx_flag(TypeProfileWidth)                                           \
 322   do_bool_flag(UseAESIntrinsics)                                           \
 323   X86_ONLY(do_intx_flag(UseAVX))                                           \
 324   do_bool_flag(UseBiasedLocking)                                           \
 325   do_bool_flag(UseCRC32Intrinsics)                                         \
 326   do_bool_flag(UseCompressedClassPointers)                                 \
 327   do_bool_flag(UseCompressedOops)                                          \
 328   do_bool_flag(UseConcMarkSweepGC)                                         \
 329   X86_ONLY(do_bool_flag(UseCountLeadingZerosInstruction))                  \
 330   X86_ONLY(do_bool_flag(UseCountTrailingZerosInstruction))                 \
 331   do_bool_flag(UseG1GC)                                                    \
 332   COMPILER2_PRESENT(do_bool_flag(UseMontgomeryMultiplyIntrinsic))          \
 333   COMPILER2_PRESENT(do_bool_flag(UseMontgomerySquareIntrinsic))            \
 334   COMPILER2_PRESENT(do_bool_flag(UseMulAddIntrinsic))                      \
 335   COMPILER2_PRESENT(do_bool_flag(UseMultiplyToLenIntrinsic))               \
 336   do_bool_flag(UsePopCountInstruction)                                     \
 337   do_bool_flag(UseSHA1Intrinsics)                                          \
 338   do_bool_flag(UseSHA256Intrinsics)                                        \
 339   do_bool_flag(UseSHA512Intrinsics)                                        \
 340   do_intx_flag(UseSSE)                                                     \
 341   COMPILER2_PRESENT(do_bool_flag(UseSquareToLenIntrinsic))                 \
 342   do_bool_flag(UseStackBanging)                                            \
 343   do_bool_flag(UseTLAB)                                                    \
 344   do_bool_flag(VerifyOops)                                                 \
 345 
 346 #define BOXED_BOOLEAN(name, value) oop name = ((jboolean)(value) ? boxedTrue() : boxedFalse())
 347 #define BOXED_DOUBLE(name, value) oop name; do { jvalue p; p.d = (jdouble) (value); name = java_lang_boxing_object::create(T_DOUBLE, &p, CHECK_NULL);} while(0)
 348 #define BOXED_LONG(name, value) \
 349   oop name; \
 350   do { \
 351     jvalue p; p.j = (jlong) (value); \
 352     Handle* e = longs.get(p.j); \
 353     if (e == NULL) { \
 354       oop o = java_lang_boxing_object::create(T_LONG, &p, CHECK_NULL); \
 355       Handle h(THREAD, o); \
 356       longs.put(p.j, h); \
 357       name = h(); \
 358     } else { \
 359       name = (*e)(); \
 360     } \
 361   } while (0)
 362 
 363 #define CSTRING_TO_JSTRING(name, value) \
 364   Handle name; \
 365   do { \
 366     if (value != NULL) { \
 367       Handle* e = strings.get(value); \
 368       if (e == NULL) { \
 369         Handle h = java_lang_String::create_from_str(value, CHECK_NULL); \
 370         strings.put(value, h); \
 371         name = h; \
 372       } else { \
 373         name = (*e); \
 374       } \
 375     } \
 376   } while (0)
 377 
 378 C2V_VMENTRY(jobjectArray, readConfiguration, (JNIEnv *env))
 379   ResourceMark rm;
 380   HandleMark hm;
 381 
 382   // Used to canonicalize Long and String values.
 383   ResourceHashtable<jlong, Handle> longs;
 384   ResourceHashtable<const char*, Handle, &CompilerToVM::cstring_hash, &CompilerToVM::cstring_equals> strings;
 385 
 386   jvalue prim;
 387   prim.z = true;  oop boxedTrueOop =  java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL);
 388   Handle boxedTrue(THREAD, boxedTrueOop);
 389   prim.z = false; oop boxedFalseOop = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL);
 390   Handle boxedFalse(THREAD, boxedFalseOop);
 391 
 392   CompilerToVM::Data::initialize(CHECK_NULL);
 393 
 394   VMField::klass()->initialize(CHECK_NULL);
 395   VMFlag::klass()->initialize(CHECK_NULL);
 396   VMIntrinsicMethod::klass()->initialize(CHECK_NULL);
 397 
 398   int len = JVMCIVMStructs::localHotSpotVMStructs_count();
 399   objArrayHandle vmFields = oopFactory::new_objArray_handle(VMField::klass(), len, CHECK_NULL);
 400   for (int i = 0; i < len ; i++) {
 401     VMStructEntry vmField = JVMCIVMStructs::localHotSpotVMStructs[i];
 402     instanceHandle vmFieldObj = InstanceKlass::cast(VMField::klass())->allocate_instance_handle(CHECK_NULL);
 403     size_t name_buf_len = strlen(vmField.typeName) + strlen(vmField.fieldName) + 2 /* "::" */;
 404     char* name_buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, name_buf_len + 1);
 405     sprintf(name_buf, "%s::%s", vmField.typeName, vmField.fieldName);
 406     CSTRING_TO_JSTRING(name, name_buf);
 407     CSTRING_TO_JSTRING(type, vmField.typeString);
 408     VMField::set_name(vmFieldObj, name());
 409     VMField::set_type(vmFieldObj, type());
 410     VMField::set_offset(vmFieldObj, vmField.offset);
 411     VMField::set_address(vmFieldObj, (jlong) vmField.address);
 412     if (vmField.isStatic && vmField.typeString != NULL) {
 413       if (strcmp(vmField.typeString, "bool") == 0) {
 414         BOXED_BOOLEAN(box, *(jbyte*) vmField.address);
 415         VMField::set_value(vmFieldObj, box);
 416       } else if (strcmp(vmField.typeString, "int") == 0 ||
 417                  strcmp(vmField.typeString, "jint") == 0) {
 418         BOXED_LONG(box, *(jint*) vmField.address);
 419         VMField::set_value(vmFieldObj, box);
 420       } else if (strcmp(vmField.typeString, "uint64_t") == 0) {
 421         BOXED_LONG(box, *(uint64_t*) vmField.address);
 422         VMField::set_value(vmFieldObj, box);
 423       } else if (strcmp(vmField.typeString, "address") == 0 ||
 424                  strcmp(vmField.typeString, "intptr_t") == 0 ||
 425                  strcmp(vmField.typeString, "uintptr_t") == 0 ||
 426                  strcmp(vmField.typeString, "size_t") == 0 ||
 427                  // All foo* types are addresses.
 428                  vmField.typeString[strlen(vmField.typeString) - 1] == '*') {
 429         BOXED_LONG(box, *((address*) vmField.address));
 430         VMField::set_value(vmFieldObj, box);
 431       } else {
 432         JVMCI_ERROR_NULL("VM field %s has unsupported type %s", name_buf, vmField.typeString);
 433       }
 434     }
 435     vmFields->obj_at_put(i, vmFieldObj());
 436   }
 437 
 438   int ints_len = JVMCIVMStructs::localHotSpotVMIntConstants_count();
 439   int longs_len = JVMCIVMStructs::localHotSpotVMLongConstants_count();
 440   len = ints_len + longs_len;
 441   objArrayHandle vmConstants = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
 442   int insert = 0;
 443   for (int i = 0; i < ints_len ; i++) {
 444     VMIntConstantEntry c = JVMCIVMStructs::localHotSpotVMIntConstants[i];
 445     CSTRING_TO_JSTRING(name, c.name);
 446     BOXED_LONG(value, c.value);
 447     vmConstants->obj_at_put(insert++, name());
 448     vmConstants->obj_at_put(insert++, value);
 449   }
 450   for (int i = 0; i < longs_len ; i++) {
 451     VMLongConstantEntry c = JVMCIVMStructs::localHotSpotVMLongConstants[i];
 452     CSTRING_TO_JSTRING(name, c.name);
 453     BOXED_LONG(value, c.value);
 454     vmConstants->obj_at_put(insert++, name());
 455     vmConstants->obj_at_put(insert++, value);
 456   }
 457   assert(insert == len * 2, "must be");
 458 
 459   len = JVMCIVMStructs::localHotSpotVMAddresses_count();
 460   objArrayHandle vmAddresses = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
 461   for (int i = 0; i < len ; i++) {
 462     VMAddressEntry a = JVMCIVMStructs::localHotSpotVMAddresses[i];
 463     CSTRING_TO_JSTRING(name, a.name);
 464     BOXED_LONG(value, a.value);
 465     vmAddresses->obj_at_put(i * 2, name());
 466     vmAddresses->obj_at_put(i * 2 + 1, value);
 467   }
 468 
 469 #define COUNT_FLAG(ignore) +1
 470 #ifdef ASSERT
 471 #define CHECK_FLAG(type, name) { \
 472   Flag* flag = Flag::find_flag(#name, strlen(#name), /*allow_locked*/ true, /* return_flag */ true); \
 473   assert(flag != NULL, "No such flag named " #name); \
 474   assert(flag->is_##type(), "Flag " #name " is not of type " #type); \
 475 }
 476 #else
 477 #define CHECK_FLAG(type, name)
 478 #endif
 479 
 480 #define ADD_FLAG(type, name, convert) { \
 481   CHECK_FLAG(type, name) \
 482   instanceHandle vmFlagObj = InstanceKlass::cast(VMFlag::klass())->allocate_instance_handle(CHECK_NULL); \
 483   CSTRING_TO_JSTRING(fname, #name); \
 484   CSTRING_TO_JSTRING(ftype, #type); \
 485   VMFlag::set_name(vmFlagObj, fname()); \
 486   VMFlag::set_type(vmFlagObj, ftype()); \
 487   convert(value, name); \
 488   VMFlag::set_value(vmFlagObj, value); \
 489   vmFlags->obj_at_put(i++, vmFlagObj()); \
 490 }
 491 #define ADD_BOOL_FLAG(name)  ADD_FLAG(bool, name, BOXED_BOOLEAN)
 492 #define ADD_INTX_FLAG(name)  ADD_FLAG(intx, name, BOXED_LONG)
 493 #define ADD_UINTX_FLAG(name) ADD_FLAG(uintx, name, BOXED_LONG)
 494 
 495   len = 0 + PREDEFINED_CONFIG_FLAGS(COUNT_FLAG, COUNT_FLAG, COUNT_FLAG);
 496   objArrayHandle vmFlags = oopFactory::new_objArray_handle(VMFlag::klass(), len, CHECK_NULL);
 497   int i = 0;
 498   PREDEFINED_CONFIG_FLAGS(ADD_BOOL_FLAG, ADD_INTX_FLAG, ADD_UINTX_FLAG)
 499 
 500   objArrayHandle vmIntrinsics = CompilerToVM::initialize_intrinsics(CHECK_NULL);
 501 
 502   objArrayOop data = oopFactory::new_objArray(SystemDictionary::Object_klass(), 5, CHECK_NULL);
 503   data->obj_at_put(0, vmFields());
 504   data->obj_at_put(1, vmConstants());
 505   data->obj_at_put(2, vmAddresses());
 506   data->obj_at_put(3, vmFlags());
 507   data->obj_at_put(4, vmIntrinsics());
 508 
 509   return (jobjectArray) JNIHandles::make_local(THREAD, data);
 510 #undef COUNT_FLAG
 511 #undef ADD_FLAG
 512 #undef ADD_BOOL_FLAG
 513 #undef ADD_INTX_FLAG
 514 #undef ADD_UINTX_FLAG
 515 #undef CHECK_FLAG
 516 C2V_END
 517 
 518 C2V_VMENTRY(jobject, getFlagValue, (JNIEnv *, jobject c2vm, jobject name_handle))
 519 #define RETURN_BOXED_LONG(value) oop box; jvalue p; p.j = (jlong) (value); box = java_lang_boxing_object::create(T_LONG, &p, CHECK_NULL); return JNIHandles::make_local(THREAD, box);
 520 #define RETURN_BOXED_DOUBLE(value) oop box; jvalue p; p.d = (jdouble) (value); box = java_lang_boxing_object::create(T_DOUBLE, &p, CHECK_NULL); return JNIHandles::make_local(THREAD, box);
 521   Handle name(THREAD, JNIHandles::resolve(name_handle));
 522   if (name.is_null()) {
 523     THROW_0(vmSymbols::java_lang_NullPointerException());
 524   }
 525   ResourceMark rm;
 526   const char* cstring = java_lang_String::as_utf8_string(name());
 527   Flag* flag = Flag::find_flag(cstring, strlen(cstring), /* allow_locked */ true, /* return_flag */ true);
 528   if (flag == NULL) {
 529     return c2vm;
 530   }
 531   if (flag->is_bool()) {
 532     jvalue prim;
 533     prim.z = flag->get_bool();
 534     oop box = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL);
 535     return JNIHandles::make_local(THREAD, box);
 536   } else if (flag->is_ccstr()) {
 537     Handle value = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_NULL);
 538     return JNIHandles::make_local(THREAD, value());
 539   } else if (flag->is_intx()) {
 540     RETURN_BOXED_LONG(flag->get_intx());
 541   } else if (flag->is_int()) {
 542     RETURN_BOXED_LONG(flag->get_int());
 543   } else if (flag->is_uint()) {
 544     RETURN_BOXED_LONG(flag->get_uint());
 545   } else if (flag->is_uint64_t()) {
 546     RETURN_BOXED_LONG(flag->get_uint64_t());
 547   } else if (flag->is_size_t()) {
 548     RETURN_BOXED_LONG(flag->get_size_t());
 549   } else if (flag->is_uintx()) {
 550     RETURN_BOXED_LONG(flag->get_uintx());
 551   } else if (flag->is_double()) {
 552     RETURN_BOXED_DOUBLE(flag->get_double());
 553   } else {
 554     JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->_name, flag->_type);
 555   }
 556 C2V_END
 557 
 558 #undef BOXED_LONG
 559 #undef BOXED_DOUBLE
 560 #undef CSTRING_TO_JSTRING
 561 
 562 C2V_VMENTRY(jbyteArray, getBytecode, (JNIEnv *, jobject, jobject jvmci_method))
 563   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 564   ResourceMark rm;
 565 
 566   int code_size = method->code_size();
 567   typeArrayOop reconstituted_code = oopFactory::new_byteArray(code_size, CHECK_NULL);
 568 
 569   guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten");
 570   // iterate over all bytecodes and replace non-Java bytecodes
 571 
 572   for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) {
 573     Bytecodes::Code code = s.code();
 574     Bytecodes::Code raw_code = s.raw_code();
 575     int bci = s.bci();
 576     int len = s.instruction_size();
 577 
 578     // Restore original byte code.
 579     reconstituted_code->byte_at_put(bci, (jbyte) (s.is_wide()? Bytecodes::_wide : code));
 580     if (len > 1) {
 581       memcpy(reconstituted_code->byte_at_addr(bci + 1), s.bcp()+1, len-1);
 582     }
 583 
 584     if (len > 1) {
 585       // Restore the big-endian constant pool indexes.
 586       // Cf. Rewriter::scan_method
 587       switch (code) {
 588         case Bytecodes::_getstatic:
 589         case Bytecodes::_putstatic:
 590         case Bytecodes::_getfield:
 591         case Bytecodes::_putfield:
 592         case Bytecodes::_invokevirtual:
 593         case Bytecodes::_invokespecial:
 594         case Bytecodes::_invokestatic:
 595         case Bytecodes::_invokeinterface:
 596         case Bytecodes::_invokehandle: {
 597           int cp_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1));
 598           Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index);
 599           break;
 600         }
 601 
 602         case Bytecodes::_invokedynamic:
 603           int cp_index = Bytes::get_native_u4((address) reconstituted_code->byte_at_addr(bci + 1));
 604           Bytes::put_Java_u4((address) reconstituted_code->byte_at_addr(bci + 1), (u4) cp_index);
 605           break;
 606       }
 607 
 608       // Not all ldc byte code are rewritten.
 609       switch (raw_code) {
 610         case Bytecodes::_fast_aldc: {
 611           int cpc_index = reconstituted_code->byte_at(bci + 1) & 0xff;
 612           int cp_index = method->constants()->object_to_cp_index(cpc_index);
 613           assert(cp_index < method->constants()->length(), "sanity check");
 614           reconstituted_code->byte_at_put(bci + 1, (jbyte) cp_index);
 615           break;
 616         }
 617 
 618         case Bytecodes::_fast_aldc_w: {
 619           int cpc_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1));
 620           int cp_index = method->constants()->object_to_cp_index(cpc_index);
 621           assert(cp_index < method->constants()->length(), "sanity check");
 622           Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index);
 623           break;
 624         }
 625       }
 626     }
 627   }
 628 
 629   return (jbyteArray) JNIHandles::make_local(THREAD, reconstituted_code);
 630 C2V_END
 631 
 632 C2V_VMENTRY(jint, getExceptionTableLength, (JNIEnv *, jobject, jobject jvmci_method))
 633   ResourceMark rm;
 634   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 635   return method->exception_table_length();
 636 C2V_END
 637 
 638 C2V_VMENTRY(jlong, getExceptionTableStart, (JNIEnv *, jobject, jobject jvmci_method))
 639   ResourceMark rm;
 640   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 641   if (method->exception_table_length() == 0) {
 642     return 0L;
 643   }
 644   return (jlong) (address) method->exception_table_start();
 645 C2V_END
 646 
 647 C2V_VMENTRY(jobject, asResolvedJavaMethod, (JNIEnv *, jobject, jobject executable_handle))
 648   oop executable = JNIHandles::resolve(executable_handle);
 649   oop mirror = NULL;
 650   int slot = 0;
 651 
 652   if (executable->klass() == SystemDictionary::reflect_Constructor_klass()) {
 653     mirror = java_lang_reflect_Constructor::clazz(executable);
 654     slot = java_lang_reflect_Constructor::slot(executable);
 655   } else {
 656     assert(executable->klass() == SystemDictionary::reflect_Method_klass(), "wrong type");
 657     mirror = java_lang_reflect_Method::clazz(executable);
 658     slot = java_lang_reflect_Method::slot(executable);
 659   }
 660   Klass* holder = java_lang_Class::as_Klass(mirror);
 661   methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot);
 662   oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL);
 663   return JNIHandles::make_local(THREAD, result);
 664 }
 665 
 666 C2V_VMENTRY(jobject, getResolvedJavaMethod, (JNIEnv *, jobject, jobject base, jlong offset))
 667   methodHandle method;
 668   oop base_object = JNIHandles::resolve(base);
 669   if (base_object == NULL) {
 670     method = *((Method**)(offset));
 671   } else if (base_object->is_a(SystemDictionary::MemberName_klass())) {
 672     method = (Method*) (intptr_t) base_object->long_field(offset);
 673   } else if (base_object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) {
 674     method = *((Method**)(HotSpotResolvedJavaMethodImpl::metaspaceMethod(base_object) + offset));
 675   } else {
 676     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 677                 err_msg("Unexpected type: %s", base_object->klass()->external_name()));
 678   }
 679   assert (method.is_null() || method->is_method(), "invalid read");
 680   oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL);
 681   return JNIHandles::make_local(THREAD, result);
 682 }
 683 
 684 C2V_VMENTRY(jobject, getConstantPool, (JNIEnv *, jobject, jobject object_handle))
 685   constantPoolHandle cp;
 686   oop object = JNIHandles::resolve(object_handle);
 687   if (object == NULL) {
 688     THROW_0(vmSymbols::java_lang_NullPointerException());
 689   }
 690   if (object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) {
 691     cp = CompilerToVM::asMethod(object)->constMethod()->constants();
 692   } else if (object->is_a(SystemDictionary::HotSpotResolvedObjectTypeImpl_klass())) {
 693     cp = InstanceKlass::cast(CompilerToVM::asKlass(object))->constants();
 694   } else {
 695     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 696                 err_msg("Unexpected type: %s", object->klass()->external_name()));
 697   }
 698   assert(!cp.is_null(), "npe");
 699   JavaValue method_result(T_OBJECT);
 700   JavaCallArguments args;
 701   args.push_long((jlong) (address) cp());
 702   JavaCalls::call_static(&method_result, SystemDictionary::HotSpotConstantPool_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::constantPool_fromMetaspace_signature(), &args, CHECK_NULL);
 703   return JNIHandles::make_local(THREAD, (oop)method_result.get_jobject());
 704 }
 705 
 706 C2V_VMENTRY(jobject, getResolvedJavaType, (JNIEnv *, jobject, jobject base, jlong offset, jboolean compressed))
 707   Klass* klass = NULL;
 708   oop base_object = JNIHandles::resolve(base);
 709   jlong base_address = 0;
 710   if (base_object != NULL && offset == oopDesc::klass_offset_in_bytes()) {
 711     klass = base_object->klass();
 712   } else if (!compressed) {
 713     if (base_object != NULL) {
 714       if (base_object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) {
 715         base_address = HotSpotResolvedJavaMethodImpl::metaspaceMethod(base_object);
 716       } else if (base_object->is_a(SystemDictionary::HotSpotConstantPool_klass())) {
 717         base_address = HotSpotConstantPool::metaspaceConstantPool(base_object);
 718       } else if (base_object->is_a(SystemDictionary::HotSpotResolvedObjectTypeImpl_klass())) {
 719         base_address = (jlong) CompilerToVM::asKlass(base_object);
 720       } else if (base_object->is_a(SystemDictionary::Class_klass())) {
 721         base_address = (jlong) (address) base_object;
 722       } else {
 723         THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 724                     err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false"));
 725       }
 726     }
 727     klass = *((Klass**) (intptr_t) (base_address + offset));
 728   } else {
 729     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 730                 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false"));
 731   }
 732   assert (klass == NULL || klass->is_klass(), "invalid read");
 733   oop result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
 734   return JNIHandles::make_local(THREAD, result);
 735 }
 736 
 737 C2V_VMENTRY(jobject, findUniqueConcreteMethod, (JNIEnv *, jobject, jobject jvmci_type, jobject jvmci_method))
 738   ResourceMark rm;
 739   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 740   Klass* holder = CompilerToVM::asKlass(jvmci_type);
 741   if (holder->is_interface()) {
 742     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Interface %s should be handled in Java code", holder->external_name()));
 743   }
 744 
 745   methodHandle ucm;
 746   {
 747     MutexLocker locker(Compile_lock);
 748     ucm = Dependencies::find_unique_concrete_method(holder, method());
 749   }
 750   oop result = CompilerToVM::get_jvmci_method(ucm, CHECK_NULL);
 751   return JNIHandles::make_local(THREAD, result);
 752 C2V_END
 753 
 754 C2V_VMENTRY(jobject, getImplementor, (JNIEnv *, jobject, jobject jvmci_type))
 755   InstanceKlass* klass = (InstanceKlass*) CompilerToVM::asKlass(jvmci_type);
 756   oop implementor = CompilerToVM::get_jvmci_type(klass->implementor(), CHECK_NULL);
 757   return JNIHandles::make_local(THREAD, implementor);
 758 C2V_END
 759 
 760 C2V_VMENTRY(jboolean, methodIsIgnoredBySecurityStackWalk,(JNIEnv *, jobject, jobject jvmci_method))
 761   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 762   return method->is_ignored_by_security_stack_walk();
 763 C2V_END
 764 
 765 C2V_VMENTRY(jboolean, isCompilable,(JNIEnv *, jobject, jobject jvmci_method))
 766   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 767   return !method->is_not_compilable(CompLevel_full_optimization);
 768 C2V_END
 769 
 770 C2V_VMENTRY(jboolean, hasNeverInlineDirective,(JNIEnv *, jobject, jobject jvmci_method))
 771   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 772   return CompilerOracle::should_not_inline(method) || method->dont_inline();
 773 C2V_END
 774 
 775 C2V_VMENTRY(jboolean, shouldInlineMethod,(JNIEnv *, jobject, jobject jvmci_method))
 776   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 777   return CompilerOracle::should_inline(method) || method->force_inline();
 778 C2V_END
 779 
 780 C2V_VMENTRY(jobject, lookupType, (JNIEnv*, jobject, jstring jname, jclass accessing_class, jboolean resolve))
 781   ResourceMark rm;
 782   Handle name(THREAD, JNIHandles::resolve(jname));
 783   Symbol* class_name = java_lang_String::as_symbol(name(), CHECK_0);
 784   if (java_lang_String::length(name()) <= 1) {
 785     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string()));
 786   }
 787 
 788   Klass* resolved_klass = NULL;
 789   if (JNIHandles::resolve(accessing_class) == NULL) {
 790     THROW_0(vmSymbols::java_lang_NullPointerException());
 791   }
 792   Klass* accessing_klass = java_lang_Class::as_Klass(JNIHandles::resolve(accessing_class));
 793   Handle class_loader(THREAD, accessing_klass->class_loader());
 794   Handle protection_domain(THREAD, accessing_klass->protection_domain());
 795 
 796   if (resolve) {
 797     resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_0);
 798   } else {
 799     if (class_name->byte_at(0) == 'L' &&
 800       class_name->byte_at(class_name->utf8_length()-1) == ';') {
 801       // This is a name from a signature.  Strip off the trimmings.
 802       // Call recursive to keep scope of strippedsym.
 803       TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1,
 804                                                           class_name->utf8_length()-2,
 805                                                           CHECK_0);
 806       resolved_klass = SystemDictionary::find(strippedsym, class_loader, protection_domain, CHECK_0);
 807     } else if (FieldType::is_array(class_name)) {
 808       FieldArrayInfo fd;
 809       // dimension and object_key in FieldArrayInfo are assigned as a side-effect
 810       // of this call
 811       BasicType t = FieldType::get_array_info(class_name, fd, CHECK_0);
 812       if (t == T_OBJECT) {
 813         TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1+fd.dimension(),
 814                                                             class_name->utf8_length()-2-fd.dimension(),
 815                                                             CHECK_0);
 816         // naked oop "k" is OK here -- we assign back into it
 817         resolved_klass = SystemDictionary::find(strippedsym,
 818                                                              class_loader,
 819                                                              protection_domain,
 820                                                              CHECK_0);
 821         if (resolved_klass != NULL) {
 822           resolved_klass = resolved_klass->array_klass(fd.dimension(), CHECK_0);
 823         }
 824       } else {
 825         resolved_klass = Universe::typeArrayKlassObj(t);
 826         resolved_klass = TypeArrayKlass::cast(resolved_klass)->array_klass(fd.dimension(), CHECK_0);
 827       }
 828     }
 829   }
 830   oop result = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
 831   return JNIHandles::make_local(THREAD, result);
 832 C2V_END
 833 
 834 C2V_VMENTRY(jobject, resolveConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 835   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 836   oop result = cp->resolve_constant_at(index, CHECK_NULL);
 837   return JNIHandles::make_local(THREAD, result);
 838 C2V_END
 839 
 840 C2V_VMENTRY(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 841   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 842   oop result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
 843   return JNIHandles::make_local(THREAD, result);
 844 C2V_END
 845 
 846 C2V_VMENTRY(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 847   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 848   return cp->name_and_type_ref_index_at(index);
 849 C2V_END
 850 
 851 C2V_VMENTRY(jobject, lookupNameInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint which))
 852   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 853   Handle sym = java_lang_String::create_from_symbol(cp->name_ref_at(which), CHECK_NULL);
 854   return JNIHandles::make_local(THREAD, sym());
 855 C2V_END
 856 
 857 C2V_VMENTRY(jobject, lookupSignatureInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint which))
 858   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 859   Handle sym = java_lang_String::create_from_symbol(cp->signature_ref_at(which), CHECK_NULL);
 860   return JNIHandles::make_local(THREAD, sym());
 861 C2V_END
 862 
 863 C2V_VMENTRY(jint, lookupKlassRefIndexInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 864   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 865   return cp->klass_ref_index_at(index);
 866 C2V_END
 867 
 868 C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 869   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 870   Klass* resolved_klass = cp->klass_at(index, CHECK_NULL);
 871   oop klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
 872   return JNIHandles::make_local(THREAD, klass);
 873 C2V_END
 874 
 875 C2V_VMENTRY(jobject, lookupKlassInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
 876   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 877   Klass* loading_klass = cp->pool_holder();
 878   bool is_accessible = false;
 879   Klass* klass = JVMCIEnv::get_klass_by_index(cp, index, is_accessible, loading_klass);
 880   Symbol* symbol = NULL;
 881   if (klass == NULL) {
 882     symbol = cp->klass_name_at(index);
 883   }
 884   oop result_oop;
 885   if (klass != NULL) {
 886     result_oop = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
 887   } else {
 888     Handle result = java_lang_String::create_from_symbol(symbol, CHECK_NULL);
 889     result_oop = result();
 890   }
 891   return JNIHandles::make_local(THREAD, result_oop);
 892 C2V_END
 893 
 894 C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 895   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 896   oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index);
 897   return JNIHandles::make_local(THREAD, appendix_oop);
 898 C2V_END
 899 
 900 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
 901   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 902   InstanceKlass* pool_holder = cp->pool_holder();
 903   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
 904   methodHandle method = JVMCIEnv::get_method_by_index(cp, index, bc, pool_holder);
 905   oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL);
 906   return JNIHandles::make_local(THREAD, result);
 907 C2V_END
 908 
 909 C2V_VMENTRY(jint, constantPoolRemapInstructionOperandFromCache, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 910   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 911   return cp->remap_instruction_operand_from_cache(index);
 912 C2V_END
 913 
 914 C2V_VMENTRY(jobject, resolveFieldInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jobject jvmci_method, jbyte opcode, jintArray info_handle))
 915   ResourceMark rm;
 916   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 917   Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
 918   fieldDescriptor fd;
 919   LinkInfo link_info(cp, index, (jvmci_method != NULL) ? CompilerToVM::asMethod(jvmci_method) : NULL, CHECK_0);
 920   LinkResolver::resolve_field(fd, link_info, Bytecodes::java_code(code), false, CHECK_0);
 921   typeArrayOop info = (typeArrayOop) JNIHandles::resolve(info_handle);
 922   if (info == NULL || info->length() != 3) {
 923     JVMCI_ERROR_NULL("info must not be null and have a length of 3");
 924   }
 925   info->int_at_put(0, fd.access_flags().as_int());
 926   info->int_at_put(1, fd.offset());
 927   info->int_at_put(2, fd.index());
 928   oop field_holder = CompilerToVM::get_jvmci_type(fd.field_holder(), CHECK_NULL);
 929   return JNIHandles::make_local(THREAD, field_holder);
 930 C2V_END
 931 
 932 C2V_VMENTRY(jint, getVtableIndexForInterfaceMethod, (JNIEnv *, jobject, jobject jvmci_type, jobject jvmci_method))
 933   ResourceMark rm;
 934   Klass* klass = CompilerToVM::asKlass(jvmci_type);
 935   Method* method = CompilerToVM::asMethod(jvmci_method);
 936   if (klass->is_interface()) {
 937     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Interface %s should be handled in Java code", klass->external_name()));
 938   }
 939   if (!method->method_holder()->is_interface()) {
 940     THROW_MSG_0(vmSymbols::java_lang_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()));
 941   }
 942   if (!InstanceKlass::cast(klass)->is_linked()) {
 943     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Class %s must be linked", klass->external_name()));
 944   }
 945   return LinkResolver::vtable_index_of_interface_method(klass, method);
 946 C2V_END
 947 
 948 C2V_VMENTRY(jobject, resolveMethod, (JNIEnv *, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type))
 949   Klass* recv_klass = CompilerToVM::asKlass(receiver_jvmci_type);
 950   Klass* caller_klass = CompilerToVM::asKlass(caller_jvmci_type);
 951   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 952 
 953   Klass* resolved     = method->method_holder();
 954   Symbol* h_name      = method->name();
 955   Symbol* h_signature = method->signature();
 956 
 957   if (MethodHandles::is_signature_polymorphic_method(method())) {
 958       // Signature polymorphic methods are already resolved, JVMCI just returns NULL in this case.
 959       return NULL;
 960   }
 961 
 962   LinkInfo link_info(resolved, h_name, h_signature, caller_klass);
 963   methodHandle m;
 964   // Only do exact lookup if receiver klass has been linked.  Otherwise,
 965   // the vtable has not been setup, and the LinkResolver will fail.
 966   if (recv_klass->is_array_klass() ||
 967       InstanceKlass::cast(recv_klass)->is_linked() && !recv_klass->is_interface()) {
 968     if (resolved->is_interface()) {
 969       m = LinkResolver::resolve_interface_call_or_null(recv_klass, link_info);
 970     } else {
 971       m = LinkResolver::resolve_virtual_call_or_null(recv_klass, link_info);
 972     }
 973   }
 974 
 975   if (m.is_null()) {
 976     // Return NULL if there was a problem with lookup (uninitialized class, etc.)
 977     return NULL;
 978   }
 979 
 980   oop result = CompilerToVM::get_jvmci_method(m, CHECK_NULL);
 981   return JNIHandles::make_local(THREAD, result);
 982 C2V_END
 983 
 984 C2V_VMENTRY(jboolean, hasFinalizableSubclass,(JNIEnv *, jobject, jobject jvmci_type))
 985   Klass* klass = CompilerToVM::asKlass(jvmci_type);
 986   assert(klass != NULL, "method must not be called for primitive types");
 987   return Dependencies::find_finalizable_subclass(klass) != NULL;
 988 C2V_END
 989 
 990 C2V_VMENTRY(jobject, getClassInitializer, (JNIEnv *, jobject, jobject jvmci_type))
 991   InstanceKlass* klass = (InstanceKlass*) CompilerToVM::asKlass(jvmci_type);
 992   oop result = CompilerToVM::get_jvmci_method(klass->class_initializer(), CHECK_NULL);
 993   return JNIHandles::make_local(THREAD, result);
 994 C2V_END
 995 
 996 C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv*, jobject, jlong addr))
 997   address target_addr = (address) addr;
 998   if (target_addr != 0x0) {
 999     int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
1000     int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
1001     return MAX2(ABS(off_low), ABS(off_high));
1002   }
1003   return -1;
1004 C2V_END
1005 
1006 C2V_VMENTRY(void, setNotInlineableOrCompileable,(JNIEnv *, jobject,  jobject jvmci_method))
1007   methodHandle method = CompilerToVM::asMethod(jvmci_method);
1008   method->set_not_c1_compilable();
1009   method->set_not_c2_compilable();
1010   method->set_dont_inline(true);
1011 C2V_END
1012 
1013 C2V_VMENTRY(jint, installCode, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject installed_code, jobject speculation_log))
1014   ResourceMark rm;
1015   HandleMark hm;
1016   JNIHandleMark jni_hm;
1017 
1018   Handle target_handle(THREAD, JNIHandles::resolve(target));
1019   Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
1020   CodeBlob* cb = NULL;
1021   Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code));
1022   Handle speculation_log_handle(THREAD, JNIHandles::resolve(speculation_log));
1023 
1024   JVMCICompiler* compiler = JVMCICompiler::instance(CHECK_JNI_ERR);
1025 
1026   TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer());
1027   bool is_immutable_PIC = HotSpotCompiledCode::isImmutablePIC(compiled_code_handle) > 0;
1028   CodeInstaller installer(is_immutable_PIC);
1029   JVMCIEnv::CodeInstallResult result = installer.install(compiler, target_handle, compiled_code_handle, cb, installed_code_handle, speculation_log_handle, CHECK_0);
1030 
1031   if (PrintCodeCacheOnCompilation) {
1032     stringStream s;
1033     // Dump code cache  into a buffer before locking the tty,
1034     {
1035       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1036       CodeCache::print_summary(&s, false);
1037     }
1038     ttyLocker ttyl;
1039     tty->print_raw_cr(s.as_string());
1040   }
1041 
1042   if (result != JVMCIEnv::ok) {
1043     assert(cb == NULL, "should be");
1044   } else {
1045     if (!installed_code_handle.is_null()) {
1046       assert(installed_code_handle->is_a(InstalledCode::klass()), "wrong type");
1047       nmethod::invalidate_installed_code(installed_code_handle, CHECK_0);
1048       {
1049         // Ensure that all updates to the InstalledCode fields are consistent.
1050         MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1051         InstalledCode::set_address(installed_code_handle, (jlong) cb);
1052         InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1);
1053         if (cb->is_nmethod()) {
1054           InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->as_nmethod_or_null()->verified_entry_point());
1055         } else {
1056           InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->code_begin());
1057         }
1058         if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) {
1059           HotSpotInstalledCode::set_size(installed_code_handle, cb->size());
1060           HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin());
1061           HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size());
1062         }
1063       }
1064       nmethod* nm = cb->as_nmethod_or_null();
1065       if (nm != NULL && installed_code_handle->is_scavengable()) {
1066         assert(nm->detect_scavenge_root_oops(), "nm should be scavengable if installed_code is scavengable");
1067         if (!UseG1GC) {
1068           assert(nm->on_scavenge_root_list(), "nm should be on scavengable list");
1069         }
1070       }
1071     }
1072   }
1073   return result;
1074 C2V_END
1075 
1076 C2V_VMENTRY(jint, getMetadata, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject metadata))
1077   ResourceMark rm;
1078   HandleMark hm;
1079 
1080   Handle target_handle(THREAD, JNIHandles::resolve(target));
1081   Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
1082   Handle metadata_handle(THREAD, JNIHandles::resolve(metadata));
1083 
1084   CodeMetadata code_metadata;
1085   CodeBlob *cb = NULL;
1086   CodeInstaller installer(true /* immutable PIC compilation */);
1087 
1088   JVMCIEnv::CodeInstallResult result = installer.gather_metadata(target_handle, compiled_code_handle, code_metadata, CHECK_0);
1089   if (result != JVMCIEnv::ok) {
1090     return result;
1091   }
1092 
1093   if (code_metadata.get_nr_pc_desc() > 0) {
1094     typeArrayHandle pcArrayOop = oopFactory::new_byteArray_handle(sizeof(PcDesc) * code_metadata.get_nr_pc_desc(), CHECK_(JVMCIEnv::cache_full));
1095     memcpy(pcArrayOop->byte_at_addr(0), code_metadata.get_pc_desc(), sizeof(PcDesc) * code_metadata.get_nr_pc_desc());
1096     HotSpotMetaData::set_pcDescBytes(metadata_handle, pcArrayOop());
1097   }
1098 
1099   if (code_metadata.get_scopes_size() > 0) {
1100     typeArrayHandle scopesArrayOop = oopFactory::new_byteArray_handle(code_metadata.get_scopes_size(), CHECK_(JVMCIEnv::cache_full));
1101     memcpy(scopesArrayOop->byte_at_addr(0), code_metadata.get_scopes_desc(), code_metadata.get_scopes_size());
1102     HotSpotMetaData::set_scopesDescBytes(metadata_handle, scopesArrayOop());
1103   }
1104 
1105   RelocBuffer* reloc_buffer = code_metadata.get_reloc_buffer();
1106   typeArrayHandle relocArrayOop = oopFactory::new_byteArray_handle((int) reloc_buffer->size(), CHECK_(JVMCIEnv::cache_full));
1107   if (reloc_buffer->size() > 0) {
1108     memcpy(relocArrayOop->byte_at_addr(0), reloc_buffer->begin(), reloc_buffer->size());
1109   }
1110   HotSpotMetaData::set_relocBytes(metadata_handle, relocArrayOop());
1111 
1112   const OopMapSet* oopMapSet = installer.oopMapSet();
1113   {
1114     ResourceMark mark;
1115     ImmutableOopMapBuilder builder(oopMapSet);
1116     int oopmap_size = builder.heap_size();
1117     typeArrayHandle oopMapArrayHandle = oopFactory::new_byteArray_handle(oopmap_size, CHECK_(JVMCIEnv::cache_full));
1118     builder.generate_into((address) oopMapArrayHandle->byte_at_addr(0));
1119     HotSpotMetaData::set_oopMaps(metadata_handle, oopMapArrayHandle());
1120   }
1121 
1122   AOTOopRecorder* recorder = code_metadata.get_oop_recorder();
1123 
1124   int nr_meta_strings = recorder->nr_meta_strings();
1125   objArrayOop metadataArray = oopFactory::new_objectArray(nr_meta_strings, CHECK_(JVMCIEnv::cache_full));
1126   objArrayHandle metadataArrayHandle(THREAD, metadataArray);
1127   for (int i = 0; i < nr_meta_strings; ++i) {
1128     const char* element = recorder->meta_element(i);
1129     Handle java_string = java_lang_String::create_from_str(element, CHECK_(JVMCIEnv::cache_full));
1130     metadataArrayHandle->obj_at_put(i, java_string());
1131   }
1132   HotSpotMetaData::set_metadata(metadata_handle, metadataArrayHandle());
1133 
1134   ExceptionHandlerTable* handler = code_metadata.get_exception_table();
1135   int table_size = handler->size_in_bytes();
1136   typeArrayHandle exceptionArrayOop = oopFactory::new_byteArray_handle(table_size, CHECK_(JVMCIEnv::cache_full));
1137 
1138   if (table_size > 0) {
1139     handler->copy_bytes_to((address) exceptionArrayOop->byte_at_addr(0));
1140   }
1141   HotSpotMetaData::set_exceptionBytes(metadata_handle, exceptionArrayOop());
1142 
1143   return result;
1144 C2V_END
1145 
1146 C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv *jniEnv, jobject))
1147   JVMCICompiler* compiler = JVMCICompiler::instance(CHECK);
1148   CompilerStatistics* stats = compiler->stats();
1149   stats->_standard.reset();
1150   stats->_osr.reset();
1151 C2V_END
1152 
1153 C2V_VMENTRY(jobject, disassembleCodeBlob, (JNIEnv *jniEnv, jobject, jobject installedCode))
1154   ResourceMark rm;
1155   HandleMark hm;
1156 
1157   if (installedCode == NULL) {
1158     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), "installedCode is null");
1159   }
1160 
1161   jlong codeBlob = InstalledCode::address(installedCode);
1162   if (codeBlob == 0L) {
1163     return NULL;
1164   }
1165 
1166   CodeBlob* cb = (CodeBlob*) (address) codeBlob;
1167   if (cb == NULL) {
1168     return NULL;
1169   }
1170 
1171   // We don't want the stringStream buffer to resize during disassembly as it
1172   // uses scoped resource memory. If a nested function called during disassembly uses
1173   // a ResourceMark and the buffer expands within the scope of the mark,
1174   // the buffer becomes garbage when that scope is exited. Experience shows that
1175   // the disassembled code is typically about 10x the code size so a fixed buffer
1176   // sized to 20x code size plus a fixed amount for header info should be sufficient.
1177   int bufferSize = cb->code_size() * 20 + 1024;
1178   char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize);
1179   stringStream st(buffer, bufferSize);
1180   if (cb->is_nmethod()) {
1181     nmethod* nm = (nmethod*) cb;
1182     if (!nm->is_alive()) {
1183       return NULL;
1184     }
1185   }
1186   Disassembler::decode(cb, &st);
1187   if (st.size() <= 0) {
1188     return NULL;
1189   }
1190 
1191   Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
1192   return JNIHandles::make_local(THREAD, result());
1193 C2V_END
1194 
1195 C2V_VMENTRY(jobject, getStackTraceElement, (JNIEnv*, jobject, jobject jvmci_method, int bci))
1196   ResourceMark rm;
1197   HandleMark hm;
1198 
1199   methodHandle method = CompilerToVM::asMethod(jvmci_method);
1200   oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL);
1201   return JNIHandles::make_local(THREAD, element);
1202 C2V_END
1203 
1204 C2V_VMENTRY(jobject, executeInstalledCode, (JNIEnv*, jobject, jobject args, jobject hotspotInstalledCode))
1205   ResourceMark rm;
1206   HandleMark hm;
1207 
1208   jlong nmethodValue = InstalledCode::address(hotspotInstalledCode);
1209   if (nmethodValue == 0L) {
1210     THROW_NULL(vmSymbols::jdk_vm_ci_code_InvalidInstalledCodeException());
1211   }
1212   nmethod* nm = (nmethod*) (address) nmethodValue;
1213   methodHandle mh = nm->method();
1214   Symbol* signature = mh->signature();
1215   JavaCallArguments jca(mh->size_of_parameters());
1216 
1217   JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
1218   JavaValue result(jap.get_ret_type());
1219   jca.set_alternative_target(nm);
1220   JavaCalls::call(&result, mh, &jca, CHECK_NULL);
1221 
1222   if (jap.get_ret_type() == T_VOID) {
1223     return NULL;
1224   } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) {
1225     return JNIHandles::make_local(THREAD, (oop) result.get_jobject());
1226   } else {
1227     jvalue *value = (jvalue *) result.get_value_addr();
1228     // Narrow the value down if required (Important on big endian machines)
1229     switch (jap.get_ret_type()) {
1230       case T_BOOLEAN:
1231        value->z = (jboolean) value->i;
1232        break;
1233       case T_BYTE:
1234        value->b = (jbyte) value->i;
1235        break;
1236       case T_CHAR:
1237        value->c = (jchar) value->i;
1238        break;
1239       case T_SHORT:
1240        value->s = (jshort) value->i;
1241        break;
1242      }
1243     oop o = java_lang_boxing_object::create(jap.get_ret_type(), value, CHECK_NULL);
1244     return JNIHandles::make_local(THREAD, o);
1245   }
1246 C2V_END
1247 
1248 C2V_VMENTRY(jlongArray, getLineNumberTable, (JNIEnv *, jobject, jobject jvmci_method))
1249   Method* method = CompilerToVM::asMethod(jvmci_method);
1250   if (!method->has_linenumber_table()) {
1251     return NULL;
1252   }
1253   u2 num_entries = 0;
1254   CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table());
1255   while (streamForSize.read_pair()) {
1256     num_entries++;
1257   }
1258 
1259   CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
1260   typeArrayOop result = oopFactory::new_longArray(2 * num_entries, CHECK_NULL);
1261 
1262   int i = 0;
1263   jlong value;
1264   while (stream.read_pair()) {
1265     value = ((long) stream.bci());
1266     result->long_at_put(i, value);
1267     value = ((long) stream.line());
1268     result->long_at_put(i + 1, value);
1269     i += 2;
1270   }
1271 
1272   return (jlongArray) JNIHandles::make_local(THREAD, result);
1273 C2V_END
1274 
1275 C2V_VMENTRY(jlong, getLocalVariableTableStart, (JNIEnv *, jobject, jobject jvmci_method))
1276   ResourceMark rm;
1277   Method* method = CompilerToVM::asMethod(jvmci_method);
1278   if (!method->has_localvariable_table()) {
1279     return 0;
1280   }
1281   return (jlong) (address) method->localvariable_table_start();
1282 C2V_END
1283 
1284 C2V_VMENTRY(jint, getLocalVariableTableLength, (JNIEnv *, jobject, jobject jvmci_method))
1285   ResourceMark rm;
1286   Method* method = CompilerToVM::asMethod(jvmci_method);
1287   return method->localvariable_table_length();
1288 C2V_END
1289 
1290 C2V_VMENTRY(void, reprofile, (JNIEnv*, jobject, jobject jvmci_method))
1291   Method* method = CompilerToVM::asMethod(jvmci_method);
1292   MethodCounters* mcs = method->method_counters();
1293   if (mcs != NULL) {
1294     mcs->clear_counters();
1295   }
1296   NOT_PRODUCT(method->set_compiled_invocation_count(0));
1297 
1298   CompiledMethod* code = method->code();
1299   if (code != NULL) {
1300     code->make_not_entrant();
1301   }
1302 
1303   MethodData* method_data = method->method_data();
1304   if (method_data == NULL) {
1305     ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
1306     method_data = MethodData::allocate(loader_data, method, CHECK);
1307     method->set_method_data(method_data);
1308   } else {
1309     method_data->initialize();
1310   }
1311 C2V_END
1312 
1313 
1314 C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject installed_code))
1315   Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code));
1316   nmethod::invalidate_installed_code(installed_code_handle, CHECK);
1317 C2V_END
1318 
1319 C2V_VMENTRY(jlongArray, collectCounters, (JNIEnv*, jobject))
1320   typeArrayOop arrayOop = oopFactory::new_longArray(JVMCICounterSize, CHECK_NULL);
1321   JavaThread::collect_counters(arrayOop);
1322   return (jlongArray) JNIHandles::make_local(THREAD, arrayOop);
1323 C2V_END
1324 
1325 C2V_VMENTRY(int, allocateCompileId, (JNIEnv*, jobject, jobject jvmci_method, int entry_bci))
1326   HandleMark hm;
1327   ResourceMark rm;
1328   if (JNIHandles::resolve(jvmci_method) == NULL) {
1329     THROW_0(vmSymbols::java_lang_NullPointerException());
1330   }
1331   Method* method = CompilerToVM::asMethod(jvmci_method);
1332   if (entry_bci >= method->code_size() || entry_bci < -1) {
1333     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), err_msg("Unexpected bci %d", entry_bci));
1334   }
1335   return CompileBroker::assign_compile_id_unlocked(THREAD, method, entry_bci);
1336 C2V_END
1337 
1338 
1339 C2V_VMENTRY(jboolean, isMature, (JNIEnv*, jobject, jlong metaspace_method_data))
1340   MethodData* mdo = CompilerToVM::asMethodData(metaspace_method_data);
1341   return mdo != NULL && mdo->is_mature();
1342 C2V_END
1343 
1344 C2V_VMENTRY(jboolean, hasCompiledCodeForOSR, (JNIEnv*, jobject, jobject jvmci_method, int entry_bci, int comp_level))
1345   Method* method = CompilerToVM::asMethod(jvmci_method);
1346   return method->lookup_osr_nmethod_for(entry_bci, comp_level, true) != NULL;
1347 C2V_END
1348 
1349 C2V_VMENTRY(jobject, getSymbol, (JNIEnv*, jobject, jlong symbol))
1350   Handle sym = java_lang_String::create_from_symbol((Symbol*)(address)symbol, CHECK_NULL);
1351   return JNIHandles::make_local(THREAD, sym());
1352 C2V_END
1353 
1354 bool matches(jobjectArray methods, Method* method) {
1355   objArrayOop methods_oop = (objArrayOop) JNIHandles::resolve(methods);
1356 
1357   for (int i = 0; i < methods_oop->length(); i++) {
1358     oop resolved = methods_oop->obj_at(i);
1359     if (resolved->is_a(HotSpotResolvedJavaMethodImpl::klass()) && CompilerToVM::asMethod(resolved) == method) {
1360       return true;
1361     }
1362   }
1363   return false;
1364 }
1365 
1366 C2V_VMENTRY(jobject, getNextStackFrame, (JNIEnv*, jobject compilerToVM, jobject hs_frame, jobjectArray methods, jint initialSkip))
1367   ResourceMark rm;
1368 
1369   if (!thread->has_last_Java_frame()) return NULL;
1370   Handle result = HotSpotStackFrameReference::klass()->allocate_instance_handle(thread);
1371   HotSpotStackFrameReference::klass()->initialize(thread);
1372 
1373   StackFrameStream fst(thread);
1374   if (hs_frame != NULL) {
1375     // look for the correct stack frame if one is given
1376     intptr_t* stack_pointer = (intptr_t*) HotSpotStackFrameReference::stackPointer(hs_frame);
1377     while (fst.current()->sp() != stack_pointer && !fst.is_done()) {
1378       fst.next();
1379     }
1380     if (fst.current()->sp() != stack_pointer) {
1381       THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "stack frame not found")
1382     }
1383   }
1384 
1385   int frame_number = 0;
1386   vframe* vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1387   if (hs_frame != NULL) {
1388     // look for the correct vframe within the stack frame if one is given
1389     int last_frame_number = HotSpotStackFrameReference::frameNumber(hs_frame);
1390     while (frame_number < last_frame_number) {
1391       if (vf->is_top()) {
1392         THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "invalid frame number")
1393       }
1394       vf = vf->sender();
1395       frame_number ++;
1396     }
1397     // move one frame forward
1398     if (vf->is_top()) {
1399       if (fst.is_done()) {
1400         return NULL;
1401       }
1402       fst.next();
1403       vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1404       frame_number = 0;
1405     } else {
1406       vf = vf->sender();
1407       frame_number++;
1408     }
1409   }
1410 
1411   while (true) {
1412     // look for the given method
1413     while (true) {
1414       StackValueCollection* locals = NULL;
1415       if (vf->is_compiled_frame()) {
1416         // compiled method frame
1417         compiledVFrame* cvf = compiledVFrame::cast(vf);
1418         if (methods == NULL || matches(methods, cvf->method())) {
1419           if (initialSkip > 0) {
1420             initialSkip --;
1421           } else {
1422             ScopeDesc* scope = cvf->scope();
1423             // native wrapper do not have a scope
1424             if (scope != NULL && scope->objects() != NULL) {
1425               bool realloc_failures = Deoptimization::realloc_objects(thread, fst.current(), scope->objects(), THREAD);
1426               Deoptimization::reassign_fields(fst.current(), fst.register_map(), scope->objects(), realloc_failures, false);
1427 
1428               GrowableArray<ScopeValue*>* local_values = scope->locals();
1429               typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), thread);
1430               typeArrayHandle array(THREAD, array_oop);
1431               for (int i = 0; i < local_values->length(); i++) {
1432                 ScopeValue* value = local_values->at(i);
1433                 if (value->is_object()) {
1434                   array->bool_at_put(i, true);
1435                 }
1436               }
1437               HotSpotStackFrameReference::set_localIsVirtual(result, array());
1438             } else {
1439               HotSpotStackFrameReference::set_localIsVirtual(result, NULL);
1440             }
1441 
1442             locals = cvf->locals();
1443             HotSpotStackFrameReference::set_bci(result, cvf->bci());
1444             oop method = CompilerToVM::get_jvmci_method(cvf->method(), CHECK_NULL);
1445             HotSpotStackFrameReference::set_method(result, method);
1446           }
1447         }
1448       } else if (vf->is_interpreted_frame()) {
1449         // interpreted method frame
1450         interpretedVFrame* ivf = interpretedVFrame::cast(vf);
1451         if (methods == NULL || matches(methods, ivf->method())) {
1452           if (initialSkip > 0) {
1453             initialSkip --;
1454           } else {
1455             locals = ivf->locals();
1456             HotSpotStackFrameReference::set_bci(result, ivf->bci());
1457             oop method = CompilerToVM::get_jvmci_method(ivf->method(), CHECK_NULL);
1458             HotSpotStackFrameReference::set_method(result, method);
1459             HotSpotStackFrameReference::set_localIsVirtual(result, NULL);
1460           }
1461         }
1462       }
1463 
1464       // locals != NULL means that we found a matching frame and result is already partially initialized
1465       if (locals != NULL) {
1466         HotSpotStackFrameReference::set_compilerToVM(result, JNIHandles::resolve(compilerToVM));
1467         HotSpotStackFrameReference::set_stackPointer(result, (jlong) fst.current()->sp());
1468         HotSpotStackFrameReference::set_frameNumber(result, frame_number);
1469 
1470         // initialize the locals array
1471         objArrayOop array_oop = oopFactory::new_objectArray(locals->size(), CHECK_NULL);
1472         objArrayHandle array(THREAD, array_oop);
1473         for (int i = 0; i < locals->size(); i++) {
1474           StackValue* var = locals->at(i);
1475           if (var->type() == T_OBJECT) {
1476             array->obj_at_put(i, locals->at(i)->get_obj()());
1477           }
1478         }
1479         HotSpotStackFrameReference::set_locals(result, array());
1480 
1481         return JNIHandles::make_local(thread, result());
1482       }
1483 
1484       if (vf->is_top()) {
1485         break;
1486       }
1487       frame_number++;
1488       vf = vf->sender();
1489     } // end of vframe loop
1490 
1491     if (fst.is_done()) {
1492       break;
1493     }
1494     fst.next();
1495     vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1496     frame_number = 0;
1497   } // end of frame loop
1498 
1499   // the end was reached without finding a matching method
1500   return NULL;
1501 C2V_END
1502 
1503 C2V_VMENTRY(void, resolveInvokeDynamicInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
1504   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
1505   CallInfo callInfo;
1506   LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokedynamic, CHECK);
1507   ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(index);
1508   cp_cache_entry->set_dynamic_call(cp, callInfo);
1509 C2V_END
1510 
1511 C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
1512   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
1513   Klass* holder = cp->klass_ref_at(index, CHECK);
1514   Symbol* name = cp->name_ref_at(index);
1515   if (MethodHandles::is_signature_polymorphic_name(holder, name)) {
1516     CallInfo callInfo;
1517     LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokehandle, CHECK);
1518     ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1519     cp_cache_entry->set_method_handle(cp, callInfo);
1520   }
1521 C2V_END
1522 
1523 C2V_VMENTRY(jobject, getSignaturePolymorphicHolders, (JNIEnv*, jobject))
1524   objArrayHandle holders = oopFactory::new_objArray_handle(SystemDictionary::String_klass(), 2, CHECK_NULL);
1525   Handle mh = java_lang_String::create_from_str("Ljava/lang/invoke/MethodHandle;", CHECK_NULL);
1526   Handle vh = java_lang_String::create_from_str("Ljava/lang/invoke/VarHandle;", CHECK_NULL);
1527   holders->obj_at_put(0, mh());
1528   holders->obj_at_put(1, vh());
1529   return JNIHandles::make_local(THREAD, holders());
1530 C2V_END
1531 
1532 C2V_VMENTRY(jboolean, shouldDebugNonSafepoints, (JNIEnv*, jobject))
1533   //see compute_recording_non_safepoints in debugInfroRec.cpp
1534   if (JvmtiExport::should_post_compiled_method_load() && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
1535     return true;
1536   }
1537   return DebugNonSafepoints;
1538 C2V_END
1539 
1540 // public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
1541 C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv*, jobject, jobject hs_frame, bool invalidate))
1542   ResourceMark rm;
1543 
1544   if (hs_frame == NULL) {
1545     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "stack frame is null")
1546   }
1547 
1548   HotSpotStackFrameReference::klass()->initialize(thread);
1549 
1550   // look for the given stack frame
1551   StackFrameStream fst(thread);
1552   intptr_t* stack_pointer = (intptr_t*) HotSpotStackFrameReference::stackPointer(hs_frame);
1553   while (fst.current()->sp() != stack_pointer && !fst.is_done()) {
1554     fst.next();
1555   }
1556   if (fst.current()->sp() != stack_pointer) {
1557     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found")
1558   }
1559 
1560   if (invalidate) {
1561     if (!fst.current()->is_compiled_frame()) {
1562       THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected")
1563     }
1564     assert(fst.current()->cb()->is_nmethod(), "nmethod expected");
1565     ((nmethod*) fst.current()->cb())->make_not_entrant();
1566   }
1567   Deoptimization::deoptimize(thread, *fst.current(), fst.register_map(), Deoptimization::Reason_none);
1568   // look for the frame again as it has been updated by deopt (pc, deopt state...)
1569   StackFrameStream fstAfterDeopt(thread);
1570   while (fstAfterDeopt.current()->sp() != stack_pointer && !fstAfterDeopt.is_done()) {
1571     fstAfterDeopt.next();
1572   }
1573   if (fstAfterDeopt.current()->sp() != stack_pointer) {
1574     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found after deopt")
1575   }
1576 
1577   vframe* vf = vframe::new_vframe(fstAfterDeopt.current(), fstAfterDeopt.register_map(), thread);
1578   if (!vf->is_compiled_frame()) {
1579     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected")
1580   }
1581 
1582   GrowableArray<compiledVFrame*>* virtualFrames = new GrowableArray<compiledVFrame*>(10);
1583   while (true) {
1584     assert(vf->is_compiled_frame(), "Wrong frame type");
1585     virtualFrames->push(compiledVFrame::cast(vf));
1586     if (vf->is_top()) {
1587       break;
1588     }
1589     vf = vf->sender();
1590   }
1591 
1592   int last_frame_number = HotSpotStackFrameReference::frameNumber(hs_frame);
1593   if (last_frame_number >= virtualFrames->length()) {
1594     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "invalid frame number")
1595   }
1596 
1597   // Reallocate the non-escaping objects and restore their fields.
1598   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1599   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1600 
1601   if (objects == NULL) {
1602     // no objects to materialize
1603     return;
1604   }
1605 
1606   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), objects, THREAD);
1607   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1608 
1609   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1610     compiledVFrame* cvf = virtualFrames->at(frame_index);
1611 
1612     GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1613     StackValueCollection* locals = cvf->locals();
1614 
1615     if (locals != NULL) {
1616       for (int i2 = 0; i2 < locals->size(); i2++) {
1617         StackValue* var = locals->at(i2);
1618         if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1619           jvalue val;
1620           val.l = (jobject) locals->at(i2)->get_obj()();
1621           cvf->update_local(T_OBJECT, i2, val);
1622         }
1623       }
1624     }
1625   }
1626 
1627   // all locals are materialized by now
1628   HotSpotStackFrameReference::set_localIsVirtual(hs_frame, NULL);
1629 
1630   // update the locals array
1631   objArrayHandle array(THREAD, HotSpotStackFrameReference::locals(hs_frame));
1632   StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals();
1633   for (int i = 0; i < locals->size(); i++) {
1634     StackValue* var = locals->at(i);
1635     if (var->type() == T_OBJECT) {
1636       array->obj_at_put(i, locals->at(i)->get_obj()());
1637     }
1638   }
1639 C2V_END
1640 
1641 C2V_VMENTRY(void, writeDebugOutput, (JNIEnv*, jobject, jbyteArray bytes, jint offset, jint length))
1642   if (bytes == NULL) {
1643     THROW(vmSymbols::java_lang_NullPointerException());
1644   }
1645   typeArrayOop array = (typeArrayOop) JNIHandles::resolve(bytes);
1646 
1647   // Check if offset and length are non negative.
1648   if (offset < 0 || length < 0) {
1649     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
1650   }
1651   // Check if the range is valid.
1652   if ((((unsigned int) length + (unsigned int) offset) > (unsigned int) array->length())) {
1653     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
1654   }
1655   while (length > 0) {
1656     jbyte* start = array->byte_at_addr(offset);
1657     tty->write((char*) start, MIN2(length, O_BUFLEN));
1658     length -= O_BUFLEN;
1659     offset += O_BUFLEN;
1660   }
1661 C2V_END
1662 
1663 C2V_VMENTRY(void, flushDebugOutput, (JNIEnv*, jobject))
1664   tty->flush();
1665 C2V_END
1666 
1667 C2V_VMENTRY(int, methodDataProfileDataSize, (JNIEnv*, jobject, jlong metaspace_method_data, jint position))
1668   ResourceMark rm;
1669   MethodData* mdo = CompilerToVM::asMethodData(metaspace_method_data);
1670   ProfileData* profile_data = mdo->data_at(position);
1671   if (mdo->is_valid(profile_data)) {
1672     return profile_data->size_in_bytes();
1673   }
1674   DataLayout* data    = mdo->extra_data_base();
1675   DataLayout* end   = mdo->extra_data_limit();
1676   for (;; data = mdo->next_extra(data)) {
1677     assert(data < end, "moved past end of extra data");
1678     profile_data = data->data_in();
1679     if (mdo->dp_to_di(profile_data->dp()) == position) {
1680       return profile_data->size_in_bytes();
1681     }
1682   }
1683   THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), err_msg("Invalid profile data position %d", position));
1684 C2V_END
1685 
1686 C2V_VMENTRY(jlong, getFingerprint, (JNIEnv*, jobject, jlong metaspace_klass))
1687   Klass *k = CompilerToVM::asKlass(metaspace_klass);
1688   if (k->is_instance_klass()) {
1689     return InstanceKlass::cast(k)->get_stored_fingerprint();
1690   } else {
1691     return 0;
1692   }
1693 C2V_END
1694 
1695 C2V_VMENTRY(int, interpreterFrameSize, (JNIEnv*, jobject, jobject bytecode_frame_handle))
1696   if (bytecode_frame_handle == NULL) {
1697     THROW_0(vmSymbols::java_lang_NullPointerException());
1698   }
1699 
1700   oop top_bytecode_frame = JNIHandles::resolve_non_null(bytecode_frame_handle);
1701   oop bytecode_frame = top_bytecode_frame;
1702   int size = 0;
1703   int callee_parameters = 0;
1704   int callee_locals = 0;
1705   Method* method = getMethodFromHotSpotMethod(BytecodePosition::method(bytecode_frame));
1706   int extra_args = method->max_stack() - BytecodeFrame::numStack(bytecode_frame);
1707 
1708   while (bytecode_frame != NULL) {
1709     int locks = BytecodeFrame::numLocks(bytecode_frame);
1710     int temps = BytecodeFrame::numStack(bytecode_frame);
1711     bool is_top_frame = (bytecode_frame == top_bytecode_frame);
1712     Method* method = getMethodFromHotSpotMethod(BytecodePosition::method(bytecode_frame));
1713 
1714     int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
1715                                                                  temps + callee_parameters,
1716                                                                  extra_args,
1717                                                                  locks,
1718                                                                  callee_parameters,
1719                                                                  callee_locals,
1720                                                                  is_top_frame);
1721     size += frame_size;
1722 
1723     callee_parameters = method->size_of_parameters();
1724     callee_locals = method->max_locals();
1725     extra_args = 0;
1726     bytecode_frame = BytecodePosition::caller(bytecode_frame);
1727   }
1728   return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
1729 C2V_END
1730 
1731 C2V_VMENTRY(void, compileToBytecode, (JNIEnv*, jobject, jobject lambda_form_handle))
1732   Handle lambda_form(THREAD, JNIHandles::resolve_non_null(lambda_form_handle));
1733   if (lambda_form->is_a(SystemDictionary::LambdaForm_klass())) {
1734     TempNewSymbol compileToBytecode = SymbolTable::new_symbol("compileToBytecode", CHECK);
1735     JavaValue result(T_VOID);
1736     JavaCalls::call_special(&result, lambda_form, SystemDictionary::LambdaForm_klass(), compileToBytecode, vmSymbols::void_method_signature(), CHECK);
1737   } else {
1738     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1739                 err_msg("Unexpected type: %s", lambda_form->klass()->external_name()));
1740   }
1741 C2V_END
1742 
1743 #define CC (char*)  /*cast a literal from (const char*)*/
1744 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
1745 
1746 #define STRING                "Ljava/lang/String;"
1747 #define OBJECT                "Ljava/lang/Object;"
1748 #define CLASS                 "Ljava/lang/Class;"
1749 #define EXECUTABLE            "Ljava/lang/reflect/Executable;"
1750 #define STACK_TRACE_ELEMENT   "Ljava/lang/StackTraceElement;"
1751 #define INSTALLED_CODE        "Ljdk/vm/ci/code/InstalledCode;"
1752 #define TARGET_DESCRIPTION    "Ljdk/vm/ci/code/TargetDescription;"
1753 #define BYTECODE_FRAME        "Ljdk/vm/ci/code/BytecodeFrame;"
1754 #define RESOLVED_METHOD       "Ljdk/vm/ci/meta/ResolvedJavaMethod;"
1755 #define HS_RESOLVED_METHOD    "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;"
1756 #define HS_RESOLVED_KLASS     "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;"
1757 #define HS_CONSTANT_POOL      "Ljdk/vm/ci/hotspot/HotSpotConstantPool;"
1758 #define HS_COMPILED_CODE      "Ljdk/vm/ci/hotspot/HotSpotCompiledCode;"
1759 #define HS_CONFIG             "Ljdk/vm/ci/hotspot/HotSpotVMConfig;"
1760 #define HS_METADATA           "Ljdk/vm/ci/hotspot/HotSpotMetaData;"
1761 #define HS_STACK_FRAME_REF    "Ljdk/vm/ci/hotspot/HotSpotStackFrameReference;"
1762 #define HS_SPECULATION_LOG    "Ljdk/vm/ci/hotspot/HotSpotSpeculationLog;"
1763 #define METASPACE_METHOD_DATA "J"
1764 
1765 JNINativeMethod CompilerToVM::methods[] = {
1766   {CC "getBytecode",                                  CC "(" HS_RESOLVED_METHOD ")[B",                                                      FN_PTR(getBytecode)},
1767   {CC "getExceptionTableStart",                       CC "(" HS_RESOLVED_METHOD ")J",                                                       FN_PTR(getExceptionTableStart)},
1768   {CC "getExceptionTableLength",                      CC "(" HS_RESOLVED_METHOD ")I",                                                       FN_PTR(getExceptionTableLength)},
1769   {CC "findUniqueConcreteMethod",                     CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")" HS_RESOLVED_METHOD,                   FN_PTR(findUniqueConcreteMethod)},
1770   {CC "getImplementor",                               CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_KLASS,                                       FN_PTR(getImplementor)},
1771   {CC "getStackTraceElement",                         CC "(" HS_RESOLVED_METHOD "I)" STACK_TRACE_ELEMENT,                                   FN_PTR(getStackTraceElement)},
1772   {CC "methodIsIgnoredBySecurityStackWalk",           CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(methodIsIgnoredBySecurityStackWalk)},
1773   {CC "setNotInlineableOrCompileable",                CC "(" HS_RESOLVED_METHOD ")V",                                                       FN_PTR(setNotInlineableOrCompileable)},
1774   {CC "isCompilable",                                 CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(isCompilable)},
1775   {CC "hasNeverInlineDirective",                      CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(hasNeverInlineDirective)},
1776   {CC "shouldInlineMethod",                           CC "(" HS_RESOLVED_METHOD ")Z",                                                       FN_PTR(shouldInlineMethod)},
1777   {CC "lookupType",                                   CC "(" STRING CLASS "Z)" HS_RESOLVED_KLASS,                                           FN_PTR(lookupType)},
1778   {CC "lookupNameInPool",                             CC "(" HS_CONSTANT_POOL "I)" STRING,                                                  FN_PTR(lookupNameInPool)},
1779   {CC "lookupNameAndTypeRefIndexInPool",              CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(lookupNameAndTypeRefIndexInPool)},
1780   {CC "lookupSignatureInPool",                        CC "(" HS_CONSTANT_POOL "I)" STRING,                                                  FN_PTR(lookupSignatureInPool)},
1781   {CC "lookupKlassRefIndexInPool",                    CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(lookupKlassRefIndexInPool)},
1782   {CC "lookupKlassInPool",                            CC "(" HS_CONSTANT_POOL "I)Ljava/lang/Object;",                                       FN_PTR(lookupKlassInPool)},
1783   {CC "lookupAppendixInPool",                         CC "(" HS_CONSTANT_POOL "I)" OBJECT,                                                  FN_PTR(lookupAppendixInPool)},
1784   {CC "lookupMethodInPool",                           CC "(" HS_CONSTANT_POOL "IB)" HS_RESOLVED_METHOD,                                     FN_PTR(lookupMethodInPool)},
1785   {CC "constantPoolRemapInstructionOperandFromCache", CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(constantPoolRemapInstructionOperandFromCache)},
1786   {CC "resolveConstantInPool",                        CC "(" HS_CONSTANT_POOL "I)" OBJECT,                                                  FN_PTR(resolveConstantInPool)},
1787   {CC "resolvePossiblyCachedConstantInPool",          CC "(" HS_CONSTANT_POOL "I)" OBJECT,                                                  FN_PTR(resolvePossiblyCachedConstantInPool)},
1788   {CC "resolveTypeInPool",                            CC "(" HS_CONSTANT_POOL "I)" HS_RESOLVED_KLASS,                                       FN_PTR(resolveTypeInPool)},
1789   {CC "resolveFieldInPool",                           CC "(" HS_CONSTANT_POOL "I" HS_RESOLVED_METHOD "B[I)" HS_RESOLVED_KLASS,              FN_PTR(resolveFieldInPool)},
1790   {CC "resolveInvokeDynamicInPool",                   CC "(" HS_CONSTANT_POOL "I)V",                                                        FN_PTR(resolveInvokeDynamicInPool)},
1791   {CC "resolveInvokeHandleInPool",                    CC "(" HS_CONSTANT_POOL "I)V",                                                        FN_PTR(resolveInvokeHandleInPool)},
1792   {CC "resolveMethod",                                CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD, FN_PTR(resolveMethod)},
1793   {CC "getSignaturePolymorphicHolders",               CC "()[" STRING,                                                                      FN_PTR(getSignaturePolymorphicHolders)},
1794   {CC "getVtableIndexForInterfaceMethod",             CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")I",                                     FN_PTR(getVtableIndexForInterfaceMethod)},
1795   {CC "getClassInitializer",                          CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD,                                      FN_PTR(getClassInitializer)},
1796   {CC "hasFinalizableSubclass",                       CC "(" HS_RESOLVED_KLASS ")Z",                                                        FN_PTR(hasFinalizableSubclass)},
1797   {CC "getMaxCallTargetOffset",                       CC "(J)J",                                                                            FN_PTR(getMaxCallTargetOffset)},
1798   {CC "asResolvedJavaMethod",                         CC "(" EXECUTABLE ")" HS_RESOLVED_METHOD,                                             FN_PTR(asResolvedJavaMethod)},
1799   {CC "getResolvedJavaMethod",                        CC "(Ljava/lang/Object;J)" HS_RESOLVED_METHOD,                                        FN_PTR(getResolvedJavaMethod)},
1800   {CC "getConstantPool",                              CC "(Ljava/lang/Object;)" HS_CONSTANT_POOL,                                           FN_PTR(getConstantPool)},
1801   {CC "getResolvedJavaType",                          CC "(Ljava/lang/Object;JZ)" HS_RESOLVED_KLASS,                                        FN_PTR(getResolvedJavaType)},
1802   {CC "readConfiguration",                            CC "()[" OBJECT,                                                                      FN_PTR(readConfiguration)},
1803   {CC "installCode",                                  CC "(" TARGET_DESCRIPTION HS_COMPILED_CODE INSTALLED_CODE HS_SPECULATION_LOG ")I",    FN_PTR(installCode)},
1804   {CC "getMetadata",                                  CC "(" TARGET_DESCRIPTION HS_COMPILED_CODE HS_METADATA ")I",                          FN_PTR(getMetadata)},
1805   {CC "resetCompilationStatistics",                   CC "()V",                                                                             FN_PTR(resetCompilationStatistics)},
1806   {CC "disassembleCodeBlob",                          CC "(" INSTALLED_CODE ")" STRING,                                                     FN_PTR(disassembleCodeBlob)},
1807   {CC "executeInstalledCode",                         CC "([" OBJECT INSTALLED_CODE ")" OBJECT,                                             FN_PTR(executeInstalledCode)},
1808   {CC "getLineNumberTable",                           CC "(" HS_RESOLVED_METHOD ")[J",                                                      FN_PTR(getLineNumberTable)},
1809   {CC "getLocalVariableTableStart",                   CC "(" HS_RESOLVED_METHOD ")J",                                                       FN_PTR(getLocalVariableTableStart)},
1810   {CC "getLocalVariableTableLength",                  CC "(" HS_RESOLVED_METHOD ")I",                                                       FN_PTR(getLocalVariableTableLength)},
1811   {CC "reprofile",                                    CC "(" HS_RESOLVED_METHOD ")V",                                                       FN_PTR(reprofile)},
1812   {CC "invalidateInstalledCode",                      CC "(" INSTALLED_CODE ")V",                                                           FN_PTR(invalidateInstalledCode)},
1813   {CC "collectCounters",                              CC "()[J",                                                                            FN_PTR(collectCounters)},
1814   {CC "allocateCompileId",                            CC "(" HS_RESOLVED_METHOD "I)I",                                                      FN_PTR(allocateCompileId)},
1815   {CC "isMature",                                     CC "(" METASPACE_METHOD_DATA ")Z",                                                    FN_PTR(isMature)},
1816   {CC "hasCompiledCodeForOSR",                        CC "(" HS_RESOLVED_METHOD "II)Z",                                                     FN_PTR(hasCompiledCodeForOSR)},
1817   {CC "getSymbol",                                    CC "(J)" STRING,                                                                      FN_PTR(getSymbol)},
1818   {CC "getNextStackFrame",                            CC "(" HS_STACK_FRAME_REF "[" RESOLVED_METHOD "I)" HS_STACK_FRAME_REF,                FN_PTR(getNextStackFrame)},
1819   {CC "materializeVirtualObjects",                    CC "(" HS_STACK_FRAME_REF "Z)V",                                                      FN_PTR(materializeVirtualObjects)},
1820   {CC "shouldDebugNonSafepoints",                     CC "()Z",                                                                             FN_PTR(shouldDebugNonSafepoints)},
1821   {CC "writeDebugOutput",                             CC "([BII)V",                                                                         FN_PTR(writeDebugOutput)},
1822   {CC "flushDebugOutput",                             CC "()V",                                                                             FN_PTR(flushDebugOutput)},
1823   {CC "methodDataProfileDataSize",                    CC "(JI)I",                                                                           FN_PTR(methodDataProfileDataSize)},
1824   {CC "getFingerprint",                               CC "(J)J",                                                                            FN_PTR(getFingerprint)},
1825   {CC "interpreterFrameSize",                         CC "(" BYTECODE_FRAME ")I",                                                           FN_PTR(interpreterFrameSize)},
1826   {CC "compileToBytecode",                            CC "(" OBJECT ")V",                                                                   FN_PTR(compileToBytecode)},
1827   {CC "getFlagValue",                                 CC "(" STRING ")" OBJECT,                                                             FN_PTR(getFlagValue)},
1828 };
1829 
1830 int CompilerToVM::methods_count() {
1831   return sizeof(methods) / sizeof(JNINativeMethod);
1832 }
--- EOF ---