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