1 /*
   2  * Copyright (c) 2011, 2015, 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 "code/codeCache.hpp"
  26 #include "code/scopeDesc.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "memory/oopFactory.hpp"
  29 #include "oops/generateOopMap.hpp"
  30 #include "oops/fieldStreams.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "oops/objArrayOop.inline.hpp"
  33 #include "runtime/fieldDescriptor.hpp"
  34 #include "runtime/javaCalls.hpp"
  35 #include "jvmci/jvmciRuntime.hpp"
  36 #include "compiler/abstractCompiler.hpp"
  37 #include "compiler/compileBroker.hpp"
  38 #include "compiler/compilerOracle.hpp"
  39 #include "compiler/disassembler.hpp"
  40 #include "compiler/oopMap.hpp"
  41 #include "jvmci/jvmciCompilerToVM.hpp"
  42 #include "jvmci/jvmciCompiler.hpp"
  43 #include "jvmci/jvmciEnv.hpp"
  44 #include "jvmci/jvmciJavaClasses.hpp"
  45 #include "jvmci/jvmciCodeInstaller.hpp"
  46 #include "gc/g1/heapRegion.hpp"
  47 #include "runtime/javaCalls.hpp"
  48 #include "runtime/deoptimization.hpp"
  49 #include "runtime/vframe.hpp"
  50 #include "runtime/vframe_hp.hpp"
  51 #include "runtime/vmStructs.hpp"
  52 
  53 
  54 // Entry to native method implementation that transitions current thread to '_thread_in_vm'.
  55 #define C2V_VMENTRY(result_type, name, signature) \
  56   JNIEXPORT result_type JNICALL c2v_ ## name signature { \
  57   TRACE_jvmci_1("CompilerToVM::" #name); \
  58   TRACE_CALL(result_type, jvmci_ ## name signature) \
  59   JVMCI_VM_ENTRY_MARK; \
  60 
  61 #define C2V_END }
  62 
  63 oop CompilerToVM::get_jvmci_method(methodHandle method, TRAPS) {
  64   if (method() != NULL) {
  65     JavaValue result(T_OBJECT);
  66     JavaCallArguments args;
  67     args.push_long((jlong) (address) method());
  68     JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, CHECK_NULL);
  69 
  70     return (oop)result.get_jobject();
  71   }
  72   return NULL;
  73 }
  74 
  75 oop CompilerToVM::get_jvmci_type(KlassHandle klass, TRAPS) {
  76   if (klass() != NULL) {
  77     JavaValue result(T_OBJECT);
  78     JavaCallArguments args;
  79     args.push_oop(klass->java_mirror());
  80     JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedObjectTypeImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::klass_fromMetaspace_signature(), &args, CHECK_NULL);
  81 
  82     return (oop)result.get_jobject();
  83   }
  84   return NULL;
  85 }
  86 
  87 extern "C" {
  88 extern VMStructEntry* gHotSpotVMStructs;
  89 extern uint64_t gHotSpotVMStructEntryTypeNameOffset;
  90 extern uint64_t gHotSpotVMStructEntryFieldNameOffset;
  91 extern uint64_t gHotSpotVMStructEntryTypeStringOffset;
  92 extern uint64_t gHotSpotVMStructEntryIsStaticOffset;
  93 extern uint64_t gHotSpotVMStructEntryOffsetOffset;
  94 extern uint64_t gHotSpotVMStructEntryAddressOffset;
  95 extern uint64_t gHotSpotVMStructEntryArrayStride;
  96 
  97 extern VMTypeEntry* gHotSpotVMTypes;
  98 extern uint64_t gHotSpotVMTypeEntryTypeNameOffset;
  99 extern uint64_t gHotSpotVMTypeEntrySuperclassNameOffset;
 100 extern uint64_t gHotSpotVMTypeEntryIsOopTypeOffset;
 101 extern uint64_t gHotSpotVMTypeEntryIsIntegerTypeOffset;
 102 extern uint64_t gHotSpotVMTypeEntryIsUnsignedOffset;
 103 extern uint64_t gHotSpotVMTypeEntrySizeOffset;
 104 extern uint64_t gHotSpotVMTypeEntryArrayStride;
 105 
 106 extern VMIntConstantEntry* gHotSpotVMIntConstants;
 107 extern uint64_t gHotSpotVMIntConstantEntryNameOffset;
 108 extern uint64_t gHotSpotVMIntConstantEntryValueOffset;
 109 extern uint64_t gHotSpotVMIntConstantEntryArrayStride;
 110 
 111 extern VMLongConstantEntry* gHotSpotVMLongConstants;
 112 extern uint64_t gHotSpotVMLongConstantEntryNameOffset;
 113 extern uint64_t gHotSpotVMLongConstantEntryValueOffset;
 114 extern uint64_t gHotSpotVMLongConstantEntryArrayStride;
 115 
 116 extern VMAddressEntry* gHotSpotVMAddresses;
 117 extern uint64_t gHotSpotVMAddressEntryNameOffset;
 118 extern uint64_t gHotSpotVMAddressEntryValueOffset;
 119 extern uint64_t gHotSpotVMAddressEntryArrayStride;
 120 }
 121 
 122 // FIXME This is only temporary until the GC code is changed.
 123 bool       CompilerToVM::_supports_inline_contig_alloc;
 124 HeapWord** CompilerToVM::_heap_end_addr;
 125 HeapWord** CompilerToVM::_heap_top_addr;
 126 
 127 /**
 128  * We put all gHotSpotVM values in an array so we can read them easily from Java.
 129  */
 130 static uintptr_t ciHotSpotVMData[28];
 131 
 132 C2V_VMENTRY(jlong, initializeConfiguration, (JNIEnv *env, jobject))
 133   ciHotSpotVMData[0] = (uintptr_t) gHotSpotVMStructs;
 134   ciHotSpotVMData[1] = gHotSpotVMStructEntryTypeNameOffset;
 135   ciHotSpotVMData[2] = gHotSpotVMStructEntryFieldNameOffset;
 136   ciHotSpotVMData[3] = gHotSpotVMStructEntryTypeStringOffset;
 137   ciHotSpotVMData[4] = gHotSpotVMStructEntryIsStaticOffset;
 138   ciHotSpotVMData[5] = gHotSpotVMStructEntryOffsetOffset;
 139   ciHotSpotVMData[6] = gHotSpotVMStructEntryAddressOffset;
 140   ciHotSpotVMData[7] = gHotSpotVMStructEntryArrayStride;
 141 
 142   ciHotSpotVMData[8] = (uintptr_t) gHotSpotVMTypes;
 143   ciHotSpotVMData[9] = gHotSpotVMTypeEntryTypeNameOffset;
 144   ciHotSpotVMData[10] = gHotSpotVMTypeEntrySuperclassNameOffset;
 145   ciHotSpotVMData[11] = gHotSpotVMTypeEntryIsOopTypeOffset;
 146   ciHotSpotVMData[12] = gHotSpotVMTypeEntryIsIntegerTypeOffset;
 147   ciHotSpotVMData[13] = gHotSpotVMTypeEntryIsUnsignedOffset;
 148   ciHotSpotVMData[14] = gHotSpotVMTypeEntrySizeOffset;
 149   ciHotSpotVMData[15] = gHotSpotVMTypeEntryArrayStride;
 150 
 151   ciHotSpotVMData[16] = (uintptr_t) gHotSpotVMIntConstants;
 152   ciHotSpotVMData[17] = gHotSpotVMIntConstantEntryNameOffset;
 153   ciHotSpotVMData[18] = gHotSpotVMIntConstantEntryValueOffset;
 154   ciHotSpotVMData[19] = gHotSpotVMIntConstantEntryArrayStride;
 155 
 156   ciHotSpotVMData[20] = (uintptr_t) gHotSpotVMLongConstants;
 157   ciHotSpotVMData[21] = gHotSpotVMLongConstantEntryNameOffset;
 158   ciHotSpotVMData[22] = gHotSpotVMLongConstantEntryValueOffset;
 159   ciHotSpotVMData[23] = gHotSpotVMLongConstantEntryArrayStride;
 160 
 161   ciHotSpotVMData[24] = (uintptr_t) gHotSpotVMAddresses;
 162   ciHotSpotVMData[25] = gHotSpotVMAddressEntryNameOffset;
 163   ciHotSpotVMData[26] = gHotSpotVMAddressEntryValueOffset;
 164   ciHotSpotVMData[27] = gHotSpotVMAddressEntryArrayStride;
 165 
 166   // FIXME This is only temporary until the GC code is changed.
 167   CompilerToVM::_supports_inline_contig_alloc = Universe::heap()->supports_inline_contig_alloc();
 168   CompilerToVM::_heap_end_addr = CompilerToVM::_supports_inline_contig_alloc ? Universe::heap()->end_addr() : (HeapWord**) -1;
 169   CompilerToVM::_heap_top_addr = CompilerToVM::_supports_inline_contig_alloc ? Universe::heap()->top_addr() : (HeapWord**) -1;
 170 
 171   return (jlong) (address) &ciHotSpotVMData;
 172 C2V_END
 173 
 174 C2V_VMENTRY(jbyteArray, getBytecode, (JNIEnv *, jobject, jobject jvmci_method))
 175   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 176   ResourceMark rm;
 177 
 178   int code_size = method->code_size();
 179   typeArrayOop reconstituted_code = oopFactory::new_byteArray(code_size, CHECK_NULL);
 180 
 181   guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten");
 182   // iterate over all bytecodes and replace non-Java bytecodes
 183 
 184   for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) {
 185     Bytecodes::Code code = s.code();
 186     Bytecodes::Code raw_code = s.raw_code();
 187     int bci = s.bci();
 188     int len = s.instruction_size();
 189 
 190     // Restore original byte code.
 191     reconstituted_code->byte_at_put(bci, (jbyte) (s.is_wide()? Bytecodes::_wide : code));
 192     if (len > 1) {
 193       memcpy(reconstituted_code->byte_at_addr(bci + 1), s.bcp()+1, len-1);
 194     }
 195 
 196     if (len > 1) {
 197       // Restore the big-endian constant pool indexes.
 198       // Cf. Rewriter::scan_method
 199       switch (code) {
 200         case Bytecodes::_getstatic:
 201         case Bytecodes::_putstatic:
 202         case Bytecodes::_getfield:
 203         case Bytecodes::_putfield:
 204         case Bytecodes::_invokevirtual:
 205         case Bytecodes::_invokespecial:
 206         case Bytecodes::_invokestatic:
 207         case Bytecodes::_invokeinterface:
 208         case Bytecodes::_invokehandle: {
 209           int cp_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1));
 210           Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index);
 211           break;
 212         }
 213 
 214         case Bytecodes::_invokedynamic:
 215           int cp_index = Bytes::get_native_u4((address) reconstituted_code->byte_at_addr(bci + 1));
 216           Bytes::put_Java_u4((address) reconstituted_code->byte_at_addr(bci + 1), (u4) cp_index);
 217           break;
 218       }
 219 
 220       // Not all ldc byte code are rewritten.
 221       switch (raw_code) {
 222         case Bytecodes::_fast_aldc: {
 223           int cpc_index = reconstituted_code->byte_at(bci + 1) & 0xff;
 224           int cp_index = method->constants()->object_to_cp_index(cpc_index);
 225           assert(cp_index < method->constants()->length(), "sanity check");
 226           reconstituted_code->byte_at_put(bci + 1, (jbyte) cp_index);
 227           break;
 228         }
 229 
 230         case Bytecodes::_fast_aldc_w: {
 231           int cpc_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1));
 232           int cp_index = method->constants()->object_to_cp_index(cpc_index);
 233           assert(cp_index < method->constants()->length(), "sanity check");
 234           Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index);
 235           break;
 236         }
 237       }
 238     }
 239   }
 240 
 241   return (jbyteArray) JNIHandles::make_local(THREAD, reconstituted_code);
 242 C2V_END
 243 
 244 C2V_VMENTRY(jint, getExceptionTableLength, (JNIEnv *, jobject, jobject jvmci_method))
 245   ResourceMark rm;
 246   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 247   return method->exception_table_length();
 248 C2V_END
 249 
 250 C2V_VMENTRY(jlong, getExceptionTableStart, (JNIEnv *, jobject, jobject jvmci_method))
 251   ResourceMark rm;
 252   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 253   if (method->exception_table_length() == 0) {
 254     return 0L;
 255   }
 256   return (jlong) (address) method->exception_table_start();
 257 C2V_END
 258 
 259 C2V_VMENTRY(jobject, getResolvedJavaMethodAtSlot, (JNIEnv *, jobject, jclass holder_handle, jint slot))
 260   oop java_class = JNIHandles::resolve(holder_handle);
 261   Klass* holder = java_lang_Class::as_Klass(java_class);
 262   methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot);
 263   oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL);
 264   return JNIHandles::make_local(THREAD, result);
 265 }
 266 
 267 C2V_VMENTRY(jobject, getResolvedJavaMethod, (JNIEnv *, jobject, jobject base, jlong offset))
 268   methodHandle method;
 269   oop base_object = JNIHandles::resolve(base);
 270   if (base_object == NULL) {
 271     method = *((Method**)(offset));
 272   } else if (base_object->is_a(SystemDictionary::MemberName_klass())) {
 273     method = (Method*) (intptr_t) base_object->long_field(offset);
 274   } else if (base_object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) {
 275     method = *((Method**)(HotSpotResolvedJavaMethodImpl::metaspaceMethod(base_object) + offset));
 276   } else {
 277     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 278                 err_msg("Unexpected type: %s", base_object->klass()->external_name()));
 279   }
 280   assert (method.is_null() || method->is_method(), "invalid read");
 281   oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL);
 282   return JNIHandles::make_local(THREAD, result);
 283 }
 284 
 285 C2V_VMENTRY(jobject, getConstantPool, (JNIEnv *, jobject, jobject base, jlong offset))
 286   constantPoolHandle cp;
 287   oop base_object = JNIHandles::resolve(base);
 288   jlong base_address = 0;
 289   if (base_object != NULL) {
 290     if (base_object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) {
 291       base_address = HotSpotResolvedJavaMethodImpl::metaspaceMethod(base_object);
 292     } else if (base_object->is_a(SystemDictionary::HotSpotConstantPool_klass())) {
 293       base_address = HotSpotConstantPool::metaspaceConstantPool(base_object);
 294     } else if (base_object->is_a(SystemDictionary::HotSpotResolvedObjectTypeImpl_klass())) {
 295       base_address = (jlong) CompilerToVM::asKlass(base_object);
 296     } else {
 297       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 298                   err_msg("Unexpected type: %s", base_object->klass()->external_name()));
 299     }
 300   }
 301   cp = *((ConstantPool**) (intptr_t) (base_address + offset));
 302   if (!cp.is_null()) {
 303     JavaValue method_result(T_OBJECT);
 304     JavaCallArguments args;
 305     args.push_long((jlong) (address) cp());
 306     JavaCalls::call_static(&method_result, SystemDictionary::HotSpotConstantPool_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::constantPool_fromMetaspace_signature(), &args, CHECK_NULL);
 307     return JNIHandles::make_local(THREAD, (oop)method_result.get_jobject());
 308   }
 309   return NULL;
 310 }
 311 
 312 C2V_VMENTRY(jobject, getResolvedJavaType, (JNIEnv *, jobject, jobject base, jlong offset, jboolean compressed))
 313   KlassHandle klass;
 314   oop base_object = JNIHandles::resolve(base);
 315   jlong base_address = 0;
 316   if (base_object != NULL && offset == oopDesc::klass_offset_in_bytes()) {
 317     klass = base_object->klass();
 318   } else if (!compressed) {
 319     if (base_object != NULL) {
 320       if (base_object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) {
 321         base_address = HotSpotResolvedJavaMethodImpl::metaspaceMethod(base_object);
 322       } else if (base_object->is_a(SystemDictionary::HotSpotConstantPool_klass())) {
 323         base_address = HotSpotConstantPool::metaspaceConstantPool(base_object);
 324       } else if (base_object->is_a(SystemDictionary::HotSpotResolvedObjectTypeImpl_klass())) {
 325         base_address = (jlong) CompilerToVM::asKlass(base_object);
 326       } else if (base_object->is_a(SystemDictionary::Class_klass())) {
 327         base_address = (jlong) (address) base_object;
 328       } else {
 329         THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 330                     err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false"));
 331       }
 332     }
 333     klass = *((Klass**) (intptr_t) (base_address + offset));
 334   } else {
 335     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 336                 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false"));
 337   }
 338   assert (klass.is_null() || klass->is_klass(), "invalid read");
 339   oop result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
 340   return JNIHandles::make_local(THREAD, result);
 341 }
 342 
 343 C2V_VMENTRY(jobject, findUniqueConcreteMethod, (JNIEnv *, jobject, jobject jvmci_type, jobject jvmci_method))
 344   ResourceMark rm;
 345   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 346   KlassHandle holder = CompilerToVM::asKlass(jvmci_type);
 347   if (holder->is_interface()) {
 348     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Interface %s should be handled in Java code", holder->external_name()));
 349   }
 350 
 351   methodHandle ucm;
 352   {
 353     MutexLocker locker(Compile_lock);
 354     ucm = Dependencies::find_unique_concrete_method(holder(), method());
 355   }
 356   oop result = CompilerToVM::get_jvmci_method(ucm, CHECK_NULL);
 357   return JNIHandles::make_local(THREAD, result);
 358 C2V_END
 359 
 360 C2V_VMENTRY(jobject, getImplementor, (JNIEnv *, jobject, jobject jvmci_type))
 361   InstanceKlass* klass = (InstanceKlass*) CompilerToVM::asKlass(jvmci_type);
 362   oop implementor = CompilerToVM::get_jvmci_type(klass->implementor(), CHECK_NULL);
 363   return JNIHandles::make_local(THREAD, implementor); 
 364 C2V_END
 365 
 366 C2V_VMENTRY(jboolean, methodIsIgnoredBySecurityStackWalk,(JNIEnv *, jobject, jobject jvmci_method))
 367   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 368   return method->is_ignored_by_security_stack_walk();
 369 C2V_END
 370 
 371 C2V_VMENTRY(jboolean, canInlineMethod,(JNIEnv *, jobject, jobject jvmci_method))
 372   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 373   return !method->is_not_compilable() && !CompilerOracle::should_not_inline(method) && !method->dont_inline();
 374 C2V_END
 375 
 376 C2V_VMENTRY(jboolean, shouldInlineMethod,(JNIEnv *, jobject, jobject jvmci_method))
 377   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 378   return CompilerOracle::should_inline(method) || method->force_inline();
 379 C2V_END
 380 
 381 C2V_VMENTRY(jobject, lookupType, (JNIEnv*, jobject, jstring jname, jclass accessing_class, jboolean resolve))
 382   ResourceMark rm;
 383   Handle name = JNIHandles::resolve(jname);
 384   Symbol* class_name = java_lang_String::as_symbol(name, CHECK_0);
 385   if (java_lang_String::length(name()) <= 1) {
 386     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string()));
 387   }
 388 
 389   Klass* resolved_klass = NULL;
 390   Handle class_loader;
 391   Handle protection_domain;
 392   if (JNIHandles::resolve(accessing_class) == NULL) {
 393     THROW_0(vmSymbols::java_lang_NullPointerException());
 394   }
 395   Klass* accessing_klass = java_lang_Class::as_Klass(JNIHandles::resolve(accessing_class));
 396   class_loader = accessing_klass->class_loader();
 397   protection_domain = accessing_klass->protection_domain();
 398 
 399   if (resolve) {
 400     resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_0);
 401   } else {
 402     if (class_name->byte_at(0) == 'L' &&
 403       class_name->byte_at(class_name->utf8_length()-1) == ';') {
 404       // This is a name from a signature.  Strip off the trimmings.
 405       // Call recursive to keep scope of strippedsym.
 406       TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1,
 407                                                           class_name->utf8_length()-2,
 408                                                           CHECK_0);
 409       resolved_klass = SystemDictionary::find(strippedsym, class_loader, protection_domain, CHECK_0);
 410     } else if (FieldType::is_array(class_name)) {
 411       FieldArrayInfo fd;
 412       // dimension and object_key in FieldArrayInfo are assigned as a side-effect
 413       // of this call
 414       BasicType t = FieldType::get_array_info(class_name, fd, CHECK_0);
 415       if (t == T_OBJECT) {
 416         TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1+fd.dimension(),
 417                                                             class_name->utf8_length()-2-fd.dimension(),
 418                                                             CHECK_0);
 419         // naked oop "k" is OK here -- we assign back into it
 420         resolved_klass = SystemDictionary::find(strippedsym,
 421                                                              class_loader,
 422                                                              protection_domain,
 423                                                              CHECK_0);
 424         if (resolved_klass != NULL) {
 425           resolved_klass = resolved_klass->array_klass(fd.dimension(), CHECK_0);
 426         }
 427       } else {
 428         resolved_klass = Universe::typeArrayKlassObj(t);
 429         resolved_klass = TypeArrayKlass::cast(resolved_klass)->array_klass(fd.dimension(), CHECK_0);
 430       }
 431     }
 432   }
 433   Handle result = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
 434   return JNIHandles::make_local(THREAD, result());
 435 C2V_END
 436 
 437 C2V_VMENTRY(jobject, resolveConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 438   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 439   oop result = cp->resolve_constant_at(index, CHECK_NULL);
 440   return JNIHandles::make_local(THREAD, result);
 441 C2V_END
 442 
 443 C2V_VMENTRY(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 444   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 445   oop result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
 446   return JNIHandles::make_local(THREAD, result);
 447 C2V_END
 448 
 449 C2V_VMENTRY(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 450   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 451   return cp->name_and_type_ref_index_at(index);
 452 C2V_END
 453 
 454 C2V_VMENTRY(jobject, lookupNameInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint which))
 455   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 456   Handle sym = java_lang_String::create_from_symbol(cp->name_ref_at(which), CHECK_NULL);
 457   return JNIHandles::make_local(THREAD, sym());
 458 C2V_END
 459 
 460 C2V_VMENTRY(jobject, lookupSignatureInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint which))
 461   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 462   Handle sym = java_lang_String::create_from_symbol(cp->signature_ref_at(which), CHECK_NULL);
 463   return JNIHandles::make_local(THREAD, sym());
 464 C2V_END
 465 
 466 C2V_VMENTRY(jint, lookupKlassRefIndexInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 467   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 468   return cp->klass_ref_index_at(index);
 469 C2V_END
 470 
 471 C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 472   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 473   Klass* resolved_klass = cp->klass_at(index, CHECK_NULL);
 474   Handle klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
 475   return JNIHandles::make_local(THREAD, klass());
 476 C2V_END
 477 
 478 C2V_VMENTRY(jobject, lookupKlassInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
 479   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 480   KlassHandle loading_klass(cp->pool_holder());
 481   bool is_accessible = false;
 482   KlassHandle klass = JVMCIEnv::get_klass_by_index(cp, index, is_accessible, loading_klass);
 483   Symbol* symbol = NULL;
 484   if (klass.is_null()) {
 485     symbol = cp->klass_name_at(index);
 486   }
 487   Handle result;
 488   if (!klass.is_null()) {
 489     result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
 490   } else {
 491     result = java_lang_String::create_from_symbol(symbol, CHECK_NULL);
 492   }
 493   return JNIHandles::make_local(THREAD, result());
 494 C2V_END
 495 
 496 C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 497   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 498   oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index);
 499   return JNIHandles::make_local(THREAD, appendix_oop);
 500 C2V_END
 501 
 502 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
 503   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 504   instanceKlassHandle pool_holder(cp->pool_holder());
 505   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
 506   methodHandle method = JVMCIEnv::get_method_by_index(cp, index, bc, pool_holder);
 507   oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL);
 508   return JNIHandles::make_local(THREAD, result);
 509 C2V_END
 510 
 511 C2V_VMENTRY(jint, constantPoolRemapInstructionOperandFromCache, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
 512   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 513   return cp->remap_instruction_operand_from_cache(index);
 514 C2V_END
 515 
 516 C2V_VMENTRY(jobject, resolveFieldInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode, jlongArray info_handle))
 517   ResourceMark rm;
 518   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
 519   Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
 520   fieldDescriptor fd;
 521   LinkInfo link_info(cp, index, CHECK_0);
 522   LinkResolver::resolve_field(fd, link_info, Bytecodes::java_code(code), false, CHECK_0);
 523   typeArrayOop info = (typeArrayOop) JNIHandles::resolve(info_handle);
 524   assert(info != NULL && info->length() == 2, "must be");
 525   info->long_at_put(0, (jlong) fd.access_flags().as_int());
 526   info->long_at_put(1, (jlong) fd.offset());
 527   oop field_holder = CompilerToVM::get_jvmci_type(fd.field_holder(), CHECK_NULL);
 528   return JNIHandles::make_local(THREAD, field_holder);
 529 C2V_END
 530 
 531 C2V_VMENTRY(jint, getVtableIndexForInterfaceMethod, (JNIEnv *, jobject, jobject jvmci_type, jobject jvmci_method))
 532   ResourceMark rm;
 533   Klass* klass = CompilerToVM::asKlass(jvmci_type);
 534   Method* method = CompilerToVM::asMethod(jvmci_method);
 535   if (klass->is_interface()) {
 536     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Interface %s should be handled in Java code", klass->external_name()));
 537   }
 538   if (!method->method_holder()->is_interface()) {
 539     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()));
 540   }
 541   if (!InstanceKlass::cast(klass)->is_initialized()) {
 542     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Class %s must be initialized", klass->external_name()));
 543   }
 544   return LinkResolver::vtable_index_of_interface_method(klass, method);
 545 C2V_END
 546 
 547 C2V_VMENTRY(jobject, resolveMethod, (JNIEnv *, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type))
 548   Klass* recv_klass = CompilerToVM::asKlass(receiver_jvmci_type);
 549   Klass* caller_klass = CompilerToVM::asKlass(caller_jvmci_type);
 550   Method* method = CompilerToVM::asMethod(jvmci_method);
 551 
 552   if (recv_klass->oop_is_array() || (InstanceKlass::cast(recv_klass)->is_linked())) {
 553     Klass* holder_klass = method->method_holder();
 554     Symbol* method_name = method->name();
 555     Symbol* method_signature = method->signature();
 556 
 557     if (holder_klass->is_interface()) {
 558       // do link-time resolution to check all access rules.
 559       LinkInfo link_info(holder_klass, method_name, method_signature, caller_klass, true);
 560       methodHandle resolved_method = LinkResolver::linktime_resolve_interface_method_or_null(link_info);
 561       if (resolved_method.is_null() || resolved_method->is_private()) {
 562         return NULL;
 563       }
 564       assert(recv_klass->is_subtype_of(holder_klass), "");
 565       // do actual lookup
 566       methodHandle sel_method = LinkResolver::lookup_instance_method_in_klasses(recv_klass, resolved_method->name(), resolved_method->signature(), CHECK_AND_CLEAR_0);
 567       oop result = CompilerToVM::get_jvmci_method(sel_method, CHECK_NULL);
 568       return JNIHandles::make_local(THREAD, result);
 569     } else {
 570       // do link-time resolution to check all access rules.
 571       LinkInfo link_info(holder_klass, method_name, method_signature, caller_klass, true);
 572       methodHandle resolved_method = LinkResolver::linktime_resolve_virtual_method_or_null(link_info);
 573       if (resolved_method.is_null()) {
 574           return NULL;
 575       }
 576       // do actual lookup (see LinkResolver::runtime_resolve_virtual_method)
 577       int vtable_index = Method::invalid_vtable_index;
 578       Method* selected_method;
 579 
 580       if (resolved_method->method_holder()->is_interface()) { // miranda method
 581         vtable_index = LinkResolver::vtable_index_of_interface_method(holder_klass, resolved_method);
 582         assert(vtable_index >= 0 , "we should have valid vtable index at this point");
 583 
 584         InstanceKlass* inst = InstanceKlass::cast(recv_klass);
 585         selected_method = inst->method_at_vtable(vtable_index);
 586       } else {
 587         // at this point we are sure that resolved_method is virtual and not
 588         // a miranda method; therefore, it must have a valid vtable index.
 589         assert(!resolved_method->has_itable_index(), "");
 590         vtable_index = resolved_method->vtable_index();
 591         // We could get a negative vtable_index for final methods,
 592         // because as an optimization they are they are never put in the vtable,
 593         // unless they override an existing method.
 594         // If we do get a negative, it means the resolved method is the the selected
 595         // method, and it can never be changed by an override.
 596         if (vtable_index == Method::nonvirtual_vtable_index) {
 597           assert(resolved_method->can_be_statically_bound(), "cannot override this method");
 598           selected_method = resolved_method();
 599         } else {
 600           // recv_klass might be an arrayKlassOop but all vtables start at
 601           // the same place. The cast is to avoid virtual call and assertion.
 602           InstanceKlass* inst = (InstanceKlass*)recv_klass;
 603           selected_method = inst->method_at_vtable(vtable_index);
 604         }
 605       }
 606       oop result = CompilerToVM::get_jvmci_method(selected_method, CHECK_NULL);
 607       return JNIHandles::make_local(THREAD, result);
 608     }
 609   }
 610   return NULL;
 611 C2V_END
 612 
 613 C2V_VMENTRY(jboolean, hasFinalizableSubclass,(JNIEnv *, jobject, jobject jvmci_type))
 614   Klass* klass = CompilerToVM::asKlass(jvmci_type);
 615   assert(klass != NULL, "method must not be called for primitive types");
 616   return Dependencies::find_finalizable_subclass(klass) != NULL;
 617 C2V_END
 618 
 619 C2V_VMENTRY(jobject, getClassInitializer, (JNIEnv *, jobject, jobject jvmci_type))
 620   InstanceKlass* klass = (InstanceKlass*) CompilerToVM::asKlass(jvmci_type);
 621   oop result = CompilerToVM::get_jvmci_method(klass->class_initializer(), CHECK_NULL);
 622   return JNIHandles::make_local(THREAD, result);
 623 C2V_END
 624 
 625 C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv*, jobject, jlong addr))
 626   address target_addr = (address) addr;
 627   if (target_addr != 0x0) {
 628     int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
 629     int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
 630     return MAX2(ABS(off_low), ABS(off_high));
 631   }
 632   return -1;
 633 C2V_END
 634 
 635 C2V_VMENTRY(void, doNotInlineOrCompile,(JNIEnv *, jobject,  jobject jvmci_method))
 636   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 637   method->set_not_c1_compilable();
 638   method->set_not_c2_compilable();
 639   method->set_dont_inline(true);
 640 C2V_END
 641 
 642 C2V_VMENTRY(jint, installCode, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject installed_code, jobject speculation_log))
 643   ResourceMark rm;
 644   HandleMark hm;
 645   Handle target_handle = JNIHandles::resolve(target);
 646   Handle compiled_code_handle = JNIHandles::resolve(compiled_code);
 647   CodeBlob* cb = NULL;
 648   Handle installed_code_handle = JNIHandles::resolve(installed_code);
 649   Handle speculation_log_handle = JNIHandles::resolve(speculation_log);
 650 
 651   JVMCICompiler* compiler = JVMCICompiler::instance(CHECK_JNI_ERR);
 652 
 653   TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer());
 654   CodeInstaller installer;
 655   JVMCIEnv::CodeInstallResult result = installer.install(compiler, target_handle, compiled_code_handle, cb, installed_code_handle, speculation_log_handle);
 656 
 657   if (PrintCodeCacheOnCompilation) {
 658     stringStream s;
 659     // Dump code cache  into a buffer before locking the tty,
 660     {
 661       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 662       CodeCache::print_summary(&s, false);
 663     }
 664     ttyLocker ttyl;
 665     tty->print_raw_cr(s.as_string());
 666   }
 667 
 668   if (result != JVMCIEnv::ok) {
 669     assert(cb == NULL, "should be");
 670   } else {
 671     if (!installed_code_handle.is_null()) {
 672       assert(installed_code_handle->is_a(InstalledCode::klass()), "wrong type");
 673       InstalledCode::set_address(installed_code_handle, (jlong) cb);
 674       InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1);
 675       if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) {
 676         HotSpotInstalledCode::set_size(installed_code_handle, cb->size());
 677         HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin());
 678         HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size());
 679       }
 680       nmethod* nm = cb->as_nmethod_or_null();
 681       if (nm != NULL && installed_code_handle->is_scavengable()) {
 682         assert(nm->detect_scavenge_root_oops(), "nm should be scavengable if installed_code is scavengable");
 683         if (!UseG1GC) {
 684           assert(nm->on_scavenge_root_list(), "nm should be on scavengable list");
 685         }
 686       }
 687     }
 688   }
 689   return result;
 690 C2V_END
 691 
 692 C2V_VMENTRY(jint, getMetadata, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject metadata))
 693   ResourceMark rm;
 694   HandleMark hm;
 695 
 696   Handle target_handle = JNIHandles::resolve(target);
 697   Handle compiled_code_handle = JNIHandles::resolve(compiled_code);
 698   Handle metadata_handle = JNIHandles::resolve(metadata);
 699 
 700   HotSpotOopMap::klass()->initialize(thread);
 701 
 702   CodeMetadata code_metadata;
 703   CodeBlob *cb = NULL;
 704   CodeInstaller installer;
 705 
 706   JVMCIEnv::CodeInstallResult result = installer.gather_metadata(target_handle, compiled_code_handle, code_metadata); //cb, pc_descs, nr_pc_descs, scopes_descs, scopes_size, reloc_buffer);
 707   if (result != JVMCIEnv::ok) {
 708     return result;
 709   }
 710 
 711   if (code_metadata.get_nr_pc_desc() > 0) {
 712     typeArrayHandle pcArrayOop = oopFactory::new_byteArray(sizeof(PcDesc) * code_metadata.get_nr_pc_desc(), CHECK_(JVMCIEnv::cache_full));
 713     memcpy(pcArrayOop->byte_at_addr(0), code_metadata.get_pc_desc(), sizeof(PcDesc) * code_metadata.get_nr_pc_desc());
 714     HotSpotMetaData::set_pcDescBytes(metadata_handle, pcArrayOop());
 715   }
 716 
 717   if (code_metadata.get_scopes_size() > 0) {
 718     typeArrayHandle scopesArrayOop = oopFactory::new_byteArray(code_metadata.get_scopes_size(), CHECK_(JVMCIEnv::cache_full));
 719     memcpy(scopesArrayOop->byte_at_addr(0), code_metadata.get_scopes_desc(), code_metadata.get_scopes_size());
 720     HotSpotMetaData::set_scopesDescBytes(metadata_handle, scopesArrayOop());
 721   }
 722 
 723   RelocBuffer* reloc_buffer = code_metadata.get_reloc_buffer();
 724   typeArrayHandle relocArrayOop = oopFactory::new_byteArray((int) reloc_buffer->size(), CHECK_(JVMCIEnv::cache_full));
 725   if (reloc_buffer->size() > 0) {
 726     memcpy(relocArrayOop->byte_at_addr(0), reloc_buffer->begin(), reloc_buffer->size());
 727   }
 728   HotSpotMetaData::set_relocBytes(metadata_handle, relocArrayOop());
 729 
 730   const OopMapSet* oopMapSet = installer.oopMapSet();
 731   {
 732     ResourceMark mark;
 733     ImmutableOopMapBuilder builder(oopMapSet);
 734     int oopmap_size = builder.heap_size();
 735     typeArrayHandle oopMapArrayHandle = oopFactory::new_byteArray(oopmap_size, CHECK_(JVMCIEnv::cache_full));
 736     builder.generate_into((address) oopMapArrayHandle->byte_at_addr(0));
 737     HotSpotMetaData::set_oopMaps(metadata_handle, oopMapArrayHandle());
 738   }
 739 
 740   HotSpotMetaData::set_metadata(metadata_handle, NULL);
 741 
 742   ExceptionHandlerTable* handler = code_metadata.get_exception_table();
 743   int table_size = handler->size_in_bytes();
 744   typeArrayHandle exceptionArrayOop = oopFactory::new_byteArray(table_size, CHECK_(JVMCIEnv::cache_full));
 745 
 746   if (table_size > 0) {
 747     handler->copy_bytes_to((address) exceptionArrayOop->byte_at_addr(0));
 748   }
 749   HotSpotMetaData::set_exceptionBytes(metadata_handle, exceptionArrayOop());
 750 
 751   return result;
 752 C2V_END
 753 
 754 C2V_VMENTRY(void, notifyCompilationStatistics, (JNIEnv *jniEnv, jobject, jint id, jobject hotspot_method, jboolean osr, jint processedBytecodes, jlong time, jlong timeUnitsPerSecond, jobject installed_code))
 755   JVMCICompiler* compiler = JVMCICompiler::instance(CHECK);
 756   CompilerStatistics* stats = compiler->stats();
 757 
 758   elapsedTimer timer = elapsedTimer(time, timeUnitsPerSecond);
 759   if (osr) {
 760     stats->_osr.update(timer, processedBytecodes);
 761   } else {
 762     stats->_standard.update(timer, processedBytecodes);
 763   }
 764   Handle installed_code_handle = JNIHandles::resolve(installed_code);
 765   if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) {
 766     stats->_nmethods_size += HotSpotInstalledCode::size(installed_code_handle);
 767     stats->_nmethods_code_size += HotSpotInstalledCode::codeSize(installed_code_handle);
 768   }
 769 
 770   if (CITimeEach) {
 771     methodHandle method = CompilerToVM::asMethod(hotspot_method);
 772     float bytes_per_sec = 1.0 * processedBytecodes / timer.seconds();
 773     tty->print_cr("%3d   seconds: %f bytes/sec: %f (bytes %d)",
 774                   id, timer.seconds(), bytes_per_sec, processedBytecodes);
 775   }
 776 C2V_END
 777 
 778 C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv *jniEnv, jobject))
 779   JVMCICompiler* compiler = JVMCICompiler::instance(CHECK);
 780   CompilerStatistics* stats = compiler->stats();
 781   stats->_standard.reset();
 782   stats->_osr.reset();
 783 C2V_END
 784 
 785 C2V_VMENTRY(jobject, disassembleCodeBlob, (JNIEnv *jniEnv, jobject, jlong codeBlob))
 786   ResourceMark rm;
 787   HandleMark hm;
 788 
 789   CodeBlob* cb = (CodeBlob*) (address) codeBlob;
 790   if (cb == NULL) {
 791     return NULL;
 792   }
 793 
 794   // We don't want the stringStream buffer to resize during disassembly as it
 795   // uses scoped resource memory. If a nested function called during disassembly uses
 796   // a ResourceMark and the buffer expands within the scope of the mark,
 797   // the buffer becomes garbage when that scope is exited. Experience shows that
 798   // the disassembled code is typically about 10x the code size so a fixed buffer
 799   // sized to 20x code size plus a fixed amount for header info should be sufficient.
 800   int bufferSize = cb->code_size() * 20 + 1024;
 801   char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize);
 802   stringStream st(buffer, bufferSize);
 803   if (cb->is_nmethod()) {
 804     nmethod* nm = (nmethod*) cb;
 805     if (!nm->is_alive()) {
 806       return NULL;
 807     }
 808     Disassembler::decode(nm, &st);
 809   } else {
 810     Disassembler::decode(cb, &st);
 811   }
 812   if (st.size() <= 0) {
 813     return NULL;
 814   }
 815 
 816   Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
 817   return JNIHandles::make_local(THREAD, result());
 818 C2V_END
 819 
 820 C2V_VMENTRY(jobject, getStackTraceElement, (JNIEnv*, jobject, jobject jvmci_method, int bci))
 821   ResourceMark rm;
 822   HandleMark hm;
 823 
 824   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 825   oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL);
 826   return JNIHandles::make_local(THREAD, element);
 827 C2V_END
 828 
 829 C2V_VMENTRY(jobject, executeInstalledCode, (JNIEnv*, jobject, jobject args, jobject hotspotInstalledCode))
 830   ResourceMark rm;
 831   HandleMark hm;
 832 
 833   jlong nmethodValue = InstalledCode::address(hotspotInstalledCode);
 834   if (nmethodValue == 0L) {
 835     THROW_NULL(vmSymbols::jdk_vm_ci_code_InvalidInstalledCodeException());
 836   }
 837   nmethod* nm = (nmethod*) (address) nmethodValue;
 838   methodHandle mh = nm->method();
 839   Symbol* signature = mh->signature();
 840   JavaCallArguments jca(mh->size_of_parameters());
 841 
 842   JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
 843   JavaValue result(jap.get_ret_type());
 844   jca.set_alternative_target(nm);
 845   JavaCalls::call(&result, mh, &jca, CHECK_NULL);
 846 
 847   if (jap.get_ret_type() == T_VOID) {
 848     return NULL;
 849   } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) {
 850     return JNIHandles::make_local(THREAD, (oop) result.get_jobject());
 851   } else {
 852     jvalue *value = (jvalue *) result.get_value_addr();
 853     // Narrow the value down if required (Important on big endian machines)
 854     switch (jap.get_ret_type()) {
 855       case T_BOOLEAN:
 856        value->z = (jboolean) value->i;
 857        break;
 858       case T_BYTE:
 859        value->b = (jbyte) value->i;
 860        break;
 861       case T_CHAR:
 862        value->c = (jchar) value->i;
 863        break;
 864       case T_SHORT:
 865        value->s = (jshort) value->i;
 866        break;
 867      }
 868     oop o = java_lang_boxing_object::create(jap.get_ret_type(), value, CHECK_NULL);
 869     return JNIHandles::make_local(THREAD, o);
 870   }
 871 C2V_END
 872 
 873 C2V_VMENTRY(jlongArray, getLineNumberTable, (JNIEnv *, jobject, jobject jvmci_method))
 874   Method* method = CompilerToVM::asMethod(jvmci_method);
 875   if (!method->has_linenumber_table()) {
 876     return NULL;
 877   }
 878   u2 num_entries = 0;
 879   CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table());
 880   while (streamForSize.read_pair()) {
 881     num_entries++;
 882   }
 883 
 884   CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
 885   typeArrayOop result = oopFactory::new_longArray(2 * num_entries, CHECK_NULL);
 886 
 887   int i = 0;
 888   jlong value;
 889   while (stream.read_pair()) {
 890     value = ((long) stream.bci());
 891     result->long_at_put(i, value);
 892     value = ((long) stream.line());
 893     result->long_at_put(i + 1, value);
 894     i += 2;
 895   }
 896 
 897   return (jlongArray) JNIHandles::make_local(THREAD, result);
 898 C2V_END
 899 
 900 C2V_VMENTRY(jlong, getLocalVariableTableStart, (JNIEnv *, jobject, jobject jvmci_method))
 901   ResourceMark rm;
 902   Method* method = CompilerToVM::asMethod(jvmci_method);
 903   if (!method->has_localvariable_table()) {
 904     return 0;
 905   }
 906   return (jlong) (address) method->localvariable_table_start();
 907 C2V_END
 908 
 909 C2V_VMENTRY(jint, getLocalVariableTableLength, (JNIEnv *, jobject, jobject jvmci_method))
 910   ResourceMark rm;
 911   Method* method = CompilerToVM::asMethod(jvmci_method);
 912   return method->localvariable_table_length();
 913 C2V_END
 914 
 915 C2V_VMENTRY(void, reprofile, (JNIEnv*, jobject, jobject jvmci_method))
 916   Method* method = CompilerToVM::asMethod(jvmci_method);
 917   MethodCounters* mcs = method->method_counters();
 918   if (mcs != NULL) {
 919     mcs->clear_counters();
 920   }
 921   NOT_PRODUCT(method->set_compiled_invocation_count(0));
 922 
 923   nmethod* code = method->code();
 924   if (code != NULL) {
 925     code->make_not_entrant();
 926   }
 927 
 928   MethodData* method_data = method->method_data();
 929   if (method_data == NULL) {
 930     ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
 931     method_data = MethodData::allocate(loader_data, method, CHECK);
 932     method->set_method_data(method_data);
 933   } else {
 934     method_data->initialize();
 935   }
 936 C2V_END
 937 
 938 
 939 C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject hotspotInstalledCode))
 940   jlong nativeMethod = InstalledCode::address(hotspotInstalledCode);
 941   nmethod* m = (nmethod*)nativeMethod;
 942   if (m != NULL && !m->is_not_entrant()) {
 943     m->mark_for_deoptimization();
 944     VM_Deoptimize op;
 945     VMThread::execute(&op);
 946   }
 947   InstalledCode::set_address(hotspotInstalledCode, 0);
 948 C2V_END
 949 
 950 C2V_VMENTRY(jobject, readUncompressedOop, (JNIEnv*, jobject, jlong addr))
 951   oop ret = oopDesc::load_decode_heap_oop((oop*)(address)addr);
 952   return JNIHandles::make_local(THREAD, ret);
 953 C2V_END
 954 
 955 C2V_VMENTRY(jlongArray, collectCounters, (JNIEnv*, jobject))
 956   typeArrayOop arrayOop = oopFactory::new_longArray(JVMCICounterSize, CHECK_NULL);
 957   JavaThread::collect_counters(arrayOop);
 958   return (jlongArray) JNIHandles::make_local(THREAD, arrayOop);
 959 C2V_END
 960 
 961 C2V_VMENTRY(int, allocateCompileId, (JNIEnv*, jobject, jobject jvmci_method, int entry_bci))
 962   HandleMark hm;
 963   ResourceMark rm;
 964   if (JNIHandles::resolve(jvmci_method) == NULL) {
 965     THROW_0(vmSymbols::java_lang_NullPointerException());
 966   }
 967   Method* method = CompilerToVM::asMethod(jvmci_method);
 968   if (entry_bci >= method->code_size() || entry_bci < -1) {
 969     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), err_msg("Unexpected bci %d", entry_bci));
 970   }
 971   return CompileBroker::assign_compile_id_unlocked(THREAD, method, entry_bci);
 972 C2V_END
 973 
 974 
 975 C2V_VMENTRY(jboolean, isMature, (JNIEnv*, jobject, jlong metaspace_method_data))
 976   MethodData* mdo = CompilerToVM::asMethodData(metaspace_method_data);
 977   return mdo != NULL && mdo->is_mature();
 978 C2V_END
 979 
 980 C2V_VMENTRY(jboolean, hasCompiledCodeForOSR, (JNIEnv*, jobject, jobject jvmci_method, int entry_bci, int comp_level))
 981   Method* method = CompilerToVM::asMethod(jvmci_method);
 982   return method->lookup_osr_nmethod_for(entry_bci, comp_level, true) != NULL;
 983 C2V_END
 984 
 985 C2V_VMENTRY(jobject, getSymbol, (JNIEnv*, jobject, jlong symbol))
 986   Handle sym = java_lang_String::create_from_symbol((Symbol*)(address)symbol, CHECK_NULL);
 987   return JNIHandles::make_local(THREAD, sym());
 988 C2V_END
 989 
 990 bool matches(jobjectArray methods, Method* method) {
 991   objArrayOop methods_oop = (objArrayOop) JNIHandles::resolve(methods);
 992 
 993   for (int i = 0; i < methods_oop->length(); i++) {
 994     if (CompilerToVM::asMethod(methods_oop->obj_at(i)) == method) {
 995       return true;
 996     }
 997   }
 998   return false;
 999 }
1000 
1001 C2V_VMENTRY(jobject, getNextStackFrame, (JNIEnv*, jobject compilerToVM, jobject hs_frame, jobjectArray methods, jint initialSkip))
1002   ResourceMark rm;
1003 
1004   if (!thread->has_last_Java_frame()) return NULL;
1005   Handle result = HotSpotStackFrameReference::klass()->allocate_instance(thread);
1006   HotSpotStackFrameReference::klass()->initialize(thread);
1007 
1008   StackFrameStream fst(thread);
1009   if (hs_frame != NULL) {
1010     // look for the correct stack frame if one is given
1011     intptr_t* stack_pointer = (intptr_t*) HotSpotStackFrameReference::stackPointer(hs_frame);
1012     while (fst.current()->sp() != stack_pointer && !fst.is_done()) {
1013       fst.next();
1014     }
1015     if (fst.current()->sp() != stack_pointer) {
1016       THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "stack frame not found")
1017     }
1018   }
1019 
1020   int frame_number = 0;
1021   vframe* vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1022   if (hs_frame != NULL) {
1023     // look for the correct vframe within the stack frame if one is given
1024     int last_frame_number = HotSpotStackFrameReference::frameNumber(hs_frame);
1025     while (frame_number < last_frame_number) {
1026       if (vf->is_top()) {
1027         THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "invalid frame number")
1028       }
1029       vf = vf->sender();
1030       frame_number ++;
1031     }
1032     // move one frame forward
1033     if (vf->is_top()) {
1034       if (fst.is_done()) {
1035         return NULL;
1036       }
1037       fst.next();
1038       vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1039       frame_number = 0;
1040     } else {
1041       vf = vf->sender();
1042       frame_number++;
1043     }
1044   }
1045 
1046   while (true) {
1047     // look for the given method
1048     while (true) {
1049       StackValueCollection* locals = NULL;
1050       if (vf->is_compiled_frame()) {
1051         // compiled method frame
1052         compiledVFrame* cvf = compiledVFrame::cast(vf);
1053         if (methods == NULL || matches(methods, cvf->method())) {
1054           if (initialSkip > 0) {
1055             initialSkip --;
1056           } else {
1057             ScopeDesc* scope = cvf->scope();
1058             // native wrapper do not have a scope
1059             if (scope != NULL && scope->objects() != NULL) {
1060               bool realloc_failures = Deoptimization::realloc_objects(thread, fst.current(), scope->objects(), THREAD);
1061               Deoptimization::reassign_fields(fst.current(), fst.register_map(), scope->objects(), realloc_failures, false);
1062 
1063               GrowableArray<ScopeValue*>* local_values = scope->locals();
1064               typeArrayHandle array = oopFactory::new_boolArray(local_values->length(), thread);
1065               for (int i = 0; i < local_values->length(); i++) {
1066                 ScopeValue* value = local_values->at(i);
1067                 if (value->is_object()) {
1068                   array->bool_at_put(i, true);
1069                 }
1070               }
1071               HotSpotStackFrameReference::set_localIsVirtual(result, array());
1072             } else {
1073               HotSpotStackFrameReference::set_localIsVirtual(result, NULL);
1074             }
1075 
1076             locals = cvf->locals();
1077             HotSpotStackFrameReference::set_bci(result, cvf->bci());
1078             oop method = CompilerToVM::get_jvmci_method(cvf->method(), CHECK_NULL);
1079             HotSpotStackFrameReference::set_method(result, method);
1080           }
1081         }
1082       } else if (vf->is_interpreted_frame()) {
1083         // interpreted method frame
1084         interpretedVFrame* ivf = interpretedVFrame::cast(vf);
1085         if (methods == NULL || matches(methods, ivf->method())) {
1086           if (initialSkip > 0) {
1087             initialSkip --;
1088           } else {
1089             locals = ivf->locals();
1090             HotSpotStackFrameReference::set_bci(result, ivf->bci());
1091             oop method = CompilerToVM::get_jvmci_method(ivf->method(), CHECK_NULL);
1092             HotSpotStackFrameReference::set_method(result, method);
1093             HotSpotStackFrameReference::set_localIsVirtual(result, NULL);
1094           }
1095         }
1096       }
1097 
1098       // locals != NULL means that we found a matching frame and result is already partially initialized
1099       if (locals != NULL) {
1100         HotSpotStackFrameReference::set_compilerToVM(result, JNIHandles::resolve(compilerToVM));
1101         HotSpotStackFrameReference::set_stackPointer(result, (jlong) fst.current()->sp());
1102         HotSpotStackFrameReference::set_frameNumber(result, frame_number);
1103 
1104         // initialize the locals array
1105         objArrayHandle array = oopFactory::new_objectArray(locals->size(), thread);
1106         for (int i = 0; i < locals->size(); i++) {
1107           StackValue* var = locals->at(i);
1108           if (var->type() == T_OBJECT) {
1109             array->obj_at_put(i, locals->at(i)->get_obj()());
1110           }
1111         }
1112         HotSpotStackFrameReference::set_locals(result, array());
1113 
1114         return JNIHandles::make_local(thread, result());
1115       }
1116 
1117       if (vf->is_top()) {
1118         break;
1119       }
1120       frame_number++;
1121       vf = vf->sender();
1122     } // end of vframe loop
1123 
1124     if (fst.is_done()) {
1125       break;
1126     }
1127     fst.next();
1128     vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1129     frame_number = 0;
1130   } // end of frame loop
1131 
1132   // the end was reached without finding a matching method
1133   return NULL;
1134 C2V_END
1135 
1136 C2V_VMENTRY(void, resolveInvokeDynamicInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
1137   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
1138   CallInfo callInfo;
1139   LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokedynamic, CHECK);
1140   ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(index);
1141   cp_cache_entry->set_dynamic_call(cp, callInfo);
1142 C2V_END
1143 
1144 C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
1145   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
1146   CallInfo callInfo;
1147   LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokehandle, CHECK);
1148   ConstantPoolCacheEntry* cp_cache_entry = cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1149   cp_cache_entry->set_method_handle(cp, callInfo);
1150 C2V_END
1151 
1152 C2V_VMENTRY(jboolean, shouldDebugNonSafepoints, (JNIEnv*, jobject))
1153   //see compute_recording_non_safepoints in debugInfroRec.cpp
1154   if (JvmtiExport::should_post_compiled_method_load() && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
1155     return true;
1156   }
1157   return DebugNonSafepoints;
1158 C2V_END
1159 
1160 // public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
1161 C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv*, jobject, jobject hs_frame, bool invalidate))
1162   ResourceMark rm;
1163 
1164   if (hs_frame == NULL) {
1165     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "stack frame is null")
1166   }
1167 
1168   HotSpotStackFrameReference::klass()->initialize(thread);
1169 
1170   // look for the given stack frame
1171   StackFrameStream fst(thread);
1172   intptr_t* stack_pointer = (intptr_t*) HotSpotStackFrameReference::stackPointer(hs_frame);
1173   while (fst.current()->sp() != stack_pointer && !fst.is_done()) {
1174     fst.next();
1175   }
1176   if (fst.current()->sp() != stack_pointer) {
1177     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found")
1178   }
1179 
1180   if (invalidate) {
1181     if (!fst.current()->is_compiled_frame()) {
1182       THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected")
1183     }
1184     assert(fst.current()->cb()->is_nmethod(), "nmethod expected");
1185     ((nmethod*) fst.current()->cb())->make_not_entrant();
1186   }
1187   Deoptimization::deoptimize(thread, *fst.current(), fst.register_map(), Deoptimization::Reason_none);
1188   // look for the frame again as it has been updated by deopt (pc, deopt state...)
1189   StackFrameStream fstAfterDeopt(thread);
1190   while (fstAfterDeopt.current()->sp() != stack_pointer && !fstAfterDeopt.is_done()) {
1191     fstAfterDeopt.next();
1192   }
1193   if (fstAfterDeopt.current()->sp() != stack_pointer) {
1194     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found after deopt")
1195   }
1196 
1197   vframe* vf = vframe::new_vframe(fstAfterDeopt.current(), fstAfterDeopt.register_map(), thread);
1198   if (!vf->is_compiled_frame()) {
1199     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected")
1200   }
1201 
1202   GrowableArray<compiledVFrame*>* virtualFrames = new GrowableArray<compiledVFrame*>(10);
1203   while (true) {
1204     assert(vf->is_compiled_frame(), "Wrong frame type");
1205     virtualFrames->push(compiledVFrame::cast(vf));
1206     if (vf->is_top()) {
1207       break;
1208     }
1209     vf = vf->sender();
1210   }
1211 
1212   int last_frame_number = HotSpotStackFrameReference::frameNumber(hs_frame);
1213   if (last_frame_number >= virtualFrames->length()) {
1214     THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "invalid frame number")
1215   }
1216 
1217   // Reallocate the non-escaping objects and restore their fields.
1218   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1219   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1220 
1221   if (objects == NULL) {
1222     // no objects to materialize
1223     return;
1224   }
1225 
1226   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), objects, THREAD);
1227   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1228 
1229   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1230     compiledVFrame* cvf = virtualFrames->at(frame_index);
1231 
1232     GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1233     StackValueCollection* locals = cvf->locals();
1234 
1235     if (locals != NULL) {
1236       for (int i2 = 0; i2 < locals->size(); i2++) {
1237         StackValue* var = locals->at(i2);
1238         if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1239           jvalue val;
1240           val.l = (jobject) locals->at(i2)->get_obj()();
1241           cvf->update_local(T_OBJECT, i2, val);
1242         }
1243       }
1244     }
1245   }
1246 
1247   // all locals are materialized by now
1248   HotSpotStackFrameReference::set_localIsVirtual(hs_frame, NULL);
1249 
1250   // update the locals array
1251   objArrayHandle array = HotSpotStackFrameReference::locals(hs_frame);
1252   StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals();
1253   for (int i = 0; i < locals->size(); i++) {
1254     StackValue* var = locals->at(i);
1255     if (var->type() == T_OBJECT) {
1256       array->obj_at_put(i, locals->at(i)->get_obj()());
1257     }
1258   }
1259 C2V_END
1260 
1261 C2V_VMENTRY(void, writeDebugOutput, (JNIEnv*, jobject, jbyteArray bytes, jint offset, jint length))
1262   if (bytes == NULL) {
1263     THROW(vmSymbols::java_lang_NullPointerException());
1264   }
1265   typeArrayOop array = (typeArrayOop) JNIHandles::resolve(bytes);
1266 
1267   // Check if offset and length are non negative.
1268   if (offset < 0 || length < 0) {
1269     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
1270   }
1271   // Check if the range is valid.
1272   if ((((unsigned int) length + (unsigned int) offset) > (unsigned int) array->length())) {
1273     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
1274   }
1275   while (length > 0) {
1276     jbyte* start = array->byte_at_addr(offset);
1277     tty->write((char*) start, MIN2(length, O_BUFLEN));
1278     length -= O_BUFLEN;
1279     offset += O_BUFLEN;
1280   }
1281 C2V_END
1282 
1283 C2V_VMENTRY(void, flushDebugOutput, (JNIEnv*, jobject))
1284   tty->flush();
1285 C2V_END
1286 
1287 
1288 #define CC (char*)  /*cast a literal from (const char*)*/
1289 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
1290 
1291 #define SPECULATION_LOG       "Ljdk/vm/ci/meta/SpeculationLog;"
1292 #define STRING                "Ljava/lang/String;"
1293 #define OBJECT                "Ljava/lang/Object;"
1294 #define CLASS                 "Ljava/lang/Class;"
1295 #define STACK_TRACE_ELEMENT   "Ljava/lang/StackTraceElement;"
1296 #define INSTALLED_CODE        "Ljdk/vm/ci/code/InstalledCode;"
1297 #define TARGET_DESCRIPTION    "Ljdk/vm/ci/code/TargetDescription;"
1298 #define RESOLVED_METHOD       "Ljdk/vm/ci/meta/ResolvedJavaMethod;"
1299 #define HS_RESOLVED_METHOD    "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;"
1300 #define HS_RESOLVED_KLASS     "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;"
1301 #define HS_CONSTANT_POOL      "Ljdk/vm/ci/hotspot/HotSpotConstantPool;"
1302 #define HS_COMPILED_CODE      "Ljdk/vm/ci/hotspot/HotSpotCompiledCode;"
1303 #define HS_METADATA           "Ljdk/vm/ci/hotspot/HotSpotMetaData;"
1304 #define HS_STACK_FRAME_REF    "Ljdk/vm/ci/hotspot/HotSpotStackFrameReference;"
1305 #define METASPACE_METHOD_DATA "J"
1306 
1307 JNINativeMethod CompilerToVM::methods[] = {
1308   {CC"getBytecode",                                  CC"("HS_RESOLVED_METHOD")[B",                                                     FN_PTR(getBytecode)},
1309   {CC"getExceptionTableStart",                       CC"("HS_RESOLVED_METHOD")J",                                                      FN_PTR(getExceptionTableStart)},
1310   {CC"getExceptionTableLength",                      CC"("HS_RESOLVED_METHOD")I",                                                      FN_PTR(getExceptionTableLength)},
1311   {CC"findUniqueConcreteMethod",                     CC"("HS_RESOLVED_KLASS HS_RESOLVED_METHOD")"HS_RESOLVED_METHOD,                   FN_PTR(findUniqueConcreteMethod)},
1312   {CC"getImplementor",                               CC"("HS_RESOLVED_KLASS")"HS_RESOLVED_KLASS,                                       FN_PTR(getImplementor)},
1313   {CC"getStackTraceElement",                         CC"("HS_RESOLVED_METHOD"I)"STACK_TRACE_ELEMENT,                                   FN_PTR(getStackTraceElement)},
1314   {CC"methodIsIgnoredBySecurityStackWalk",           CC"("HS_RESOLVED_METHOD")Z",                                                      FN_PTR(methodIsIgnoredBySecurityStackWalk)},
1315   {CC"doNotInlineOrCompile",                         CC"("HS_RESOLVED_METHOD")V",                                                      FN_PTR(doNotInlineOrCompile)},
1316   {CC"canInlineMethod",                              CC"("HS_RESOLVED_METHOD")Z",                                                      FN_PTR(canInlineMethod)},
1317   {CC"shouldInlineMethod",                           CC"("HS_RESOLVED_METHOD")Z",                                                      FN_PTR(shouldInlineMethod)},
1318   {CC"lookupType",                                   CC"("STRING CLASS"Z)"HS_RESOLVED_KLASS,                                           FN_PTR(lookupType)},
1319   {CC"lookupNameInPool",                             CC"("HS_CONSTANT_POOL"I)"STRING,                                                  FN_PTR(lookupNameInPool)},
1320   {CC"lookupNameAndTypeRefIndexInPool",              CC"("HS_CONSTANT_POOL"I)I",                                                       FN_PTR(lookupNameAndTypeRefIndexInPool)},
1321   {CC"lookupSignatureInPool",                        CC"("HS_CONSTANT_POOL"I)"STRING,                                                  FN_PTR(lookupSignatureInPool)},
1322   {CC"lookupKlassRefIndexInPool",                    CC"("HS_CONSTANT_POOL"I)I",                                                       FN_PTR(lookupKlassRefIndexInPool)},
1323   {CC"lookupKlassInPool",                            CC"("HS_CONSTANT_POOL"I)Ljava/lang/Object;",                                      FN_PTR(lookupKlassInPool)},
1324   {CC"lookupAppendixInPool",                         CC"("HS_CONSTANT_POOL"I)"OBJECT,                                                  FN_PTR(lookupAppendixInPool)},
1325   {CC"lookupMethodInPool",                           CC"("HS_CONSTANT_POOL"IB)"HS_RESOLVED_METHOD,                                     FN_PTR(lookupMethodInPool)},
1326   {CC"constantPoolRemapInstructionOperandFromCache", CC"("HS_CONSTANT_POOL"I)I",                                                       FN_PTR(constantPoolRemapInstructionOperandFromCache)},
1327   {CC"resolveConstantInPool",                        CC"("HS_CONSTANT_POOL"I)"OBJECT,                                                  FN_PTR(resolveConstantInPool)},
1328   {CC"resolvePossiblyCachedConstantInPool",          CC"("HS_CONSTANT_POOL"I)"OBJECT,                                                  FN_PTR(resolvePossiblyCachedConstantInPool)},
1329   {CC"resolveTypeInPool",                            CC"("HS_CONSTANT_POOL"I)"HS_RESOLVED_KLASS,                                       FN_PTR(resolveTypeInPool)},
1330   {CC"resolveFieldInPool",                           CC"("HS_CONSTANT_POOL"IB[J)"HS_RESOLVED_KLASS,                                    FN_PTR(resolveFieldInPool)},
1331   {CC"resolveInvokeDynamicInPool",                   CC"("HS_CONSTANT_POOL"I)V",                                                       FN_PTR(resolveInvokeDynamicInPool)},
1332   {CC"resolveInvokeHandleInPool",                    CC"("HS_CONSTANT_POOL"I)V",                                                       FN_PTR(resolveInvokeHandleInPool)},
1333   {CC"resolveMethod",                                CC"("HS_RESOLVED_KLASS HS_RESOLVED_METHOD HS_RESOLVED_KLASS")"HS_RESOLVED_METHOD, FN_PTR(resolveMethod)},
1334   {CC"getVtableIndexForInterfaceMethod",             CC"("HS_RESOLVED_KLASS HS_RESOLVED_METHOD")I",                                    FN_PTR(getVtableIndexForInterfaceMethod)},
1335   {CC"getClassInitializer",                          CC"("HS_RESOLVED_KLASS")"HS_RESOLVED_METHOD,                                      FN_PTR(getClassInitializer)},
1336   {CC"hasFinalizableSubclass",                       CC"("HS_RESOLVED_KLASS")Z",                                                       FN_PTR(hasFinalizableSubclass)},
1337   {CC"getMaxCallTargetOffset",                       CC"(J)J",                                                                         FN_PTR(getMaxCallTargetOffset)},
1338   {CC"getResolvedJavaMethodAtSlot",                  CC"("CLASS"I)"HS_RESOLVED_METHOD,                                                 FN_PTR(getResolvedJavaMethodAtSlot)},
1339   {CC"getResolvedJavaMethod",                        CC"(Ljava/lang/Object;J)"HS_RESOLVED_METHOD,                                      FN_PTR(getResolvedJavaMethod)},
1340   {CC"getConstantPool",                              CC"(Ljava/lang/Object;J)"HS_CONSTANT_POOL,                                        FN_PTR(getConstantPool)},
1341   {CC"getResolvedJavaType",                          CC"(Ljava/lang/Object;JZ)"HS_RESOLVED_KLASS,                                      FN_PTR(getResolvedJavaType)},
1342   {CC"initializeConfiguration",                      CC"()J",                                                                          FN_PTR(initializeConfiguration)},
1343   {CC"installCode",                                  CC"("TARGET_DESCRIPTION HS_COMPILED_CODE INSTALLED_CODE SPECULATION_LOG")I",      FN_PTR(installCode)},
1344   {CC"getMetadata",                                  CC"("TARGET_DESCRIPTION HS_COMPILED_CODE HS_METADATA")I",                         FN_PTR(getMetadata)},
1345   {CC"notifyCompilationStatistics",                  CC"(I"HS_RESOLVED_METHOD"ZIJJ"INSTALLED_CODE")V",                                 FN_PTR(notifyCompilationStatistics)},
1346   {CC"resetCompilationStatistics",                   CC"()V",                                                                          FN_PTR(resetCompilationStatistics)},
1347   {CC"disassembleCodeBlob",                          CC"(J)"STRING,                                                                    FN_PTR(disassembleCodeBlob)},
1348   {CC"executeInstalledCode",                         CC"(["OBJECT INSTALLED_CODE")"OBJECT,                                             FN_PTR(executeInstalledCode)},
1349   {CC"getLineNumberTable",                           CC"("HS_RESOLVED_METHOD")[J",                                                     FN_PTR(getLineNumberTable)},
1350   {CC"getLocalVariableTableStart",                   CC"("HS_RESOLVED_METHOD")J",                                                      FN_PTR(getLocalVariableTableStart)},
1351   {CC"getLocalVariableTableLength",                  CC"("HS_RESOLVED_METHOD")I",                                                      FN_PTR(getLocalVariableTableLength)},
1352   {CC"reprofile",                                    CC"("HS_RESOLVED_METHOD")V",                                                      FN_PTR(reprofile)},
1353   {CC"invalidateInstalledCode",                      CC"("INSTALLED_CODE")V",                                                          FN_PTR(invalidateInstalledCode)},
1354   {CC"readUncompressedOop",                          CC"(J)"OBJECT,                                                                    FN_PTR(readUncompressedOop)},
1355   {CC"collectCounters",                              CC"()[J",                                                                         FN_PTR(collectCounters)},
1356   {CC"allocateCompileId",                            CC"("HS_RESOLVED_METHOD"I)I",                                                     FN_PTR(allocateCompileId)},
1357   {CC"isMature",                                     CC"("METASPACE_METHOD_DATA")Z",                                                   FN_PTR(isMature)},
1358   {CC"hasCompiledCodeForOSR",                        CC"("HS_RESOLVED_METHOD"II)Z",                                                    FN_PTR(hasCompiledCodeForOSR)},
1359   {CC"getSymbol",                                    CC"(J)"STRING,                                                                    FN_PTR(getSymbol)},
1360   {CC"getNextStackFrame",                            CC"("HS_STACK_FRAME_REF "["HS_RESOLVED_METHOD"I)"HS_STACK_FRAME_REF,              FN_PTR(getNextStackFrame)},
1361   {CC"materializeVirtualObjects",                    CC"("HS_STACK_FRAME_REF"Z)V",                                                     FN_PTR(materializeVirtualObjects)},
1362   {CC"shouldDebugNonSafepoints",                     CC"()Z",                                                                          FN_PTR(shouldDebugNonSafepoints)},
1363   {CC"writeDebugOutput",                             CC"([BII)V",                                                                      FN_PTR(writeDebugOutput)},
1364   {CC"flushDebugOutput",                             CC"()V",                                                                          FN_PTR(flushDebugOutput)},
1365 };
1366 
1367 int CompilerToVM::methods_count() {
1368   return sizeof(methods) / sizeof(JNINativeMethod);
1369 }
1370