1 /*
   2  * Copyright (c) 2011, 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 "runtime/fieldDescriptor.hpp"
  26 #include "memory/oopFactory.hpp"
  27 #include "oops/generateOopMap.hpp"
  28 #include "oops/fieldStreams.hpp"
  29 #include "runtime/javaCalls.hpp"
  30 #include "graal/graalRuntime.hpp"
  31 #include "compiler/compileBroker.hpp"
  32 #include "compiler/compilerOracle.hpp"
  33 #include "compiler/disassembler.hpp"
  34 #include "graal/graalCompilerToVM.hpp"
  35 #include "graal/graalCompiler.hpp"
  36 #include "graal/graalEnv.hpp"
  37 #include "graal/graalJavaAccess.hpp"
  38 #include "graal/graalCodeInstaller.hpp"
  39 #include "graal/graalVMToCompiler.hpp"
  40 #include "gc_implementation/g1/heapRegion.hpp"
  41 
  42 
  43 Method* getMethodFromHotSpotMethod(oop hotspot_method) {
  44   assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethod::klass()), "sanity");
  45   return asMethod(HotSpotResolvedJavaMethod::metaspaceMethod(hotspot_method));
  46 }
  47 
  48 // Entry to native method implementation that transitions current thread to '_thread_in_vm'.
  49 #define C2V_VMENTRY(result_type, name, signature) \
  50   JNIEXPORT result_type JNICALL c2v_ ## name signature { \
  51   TRACE_graal_3("CompilerToVM::" #name); \
  52   GRAAL_VM_ENTRY_MARK; \
  53 
  54 // Entry to native method implementation that calls a JNI function
  55 // and hence cannot transition current thread to '_thread_in_vm'.
  56 #define C2V_ENTRY(result_type, name, signature) \
  57   JNIEXPORT result_type JNICALL c2v_ ## name signature { \
  58   TRACE_graal_3("CompilerToVM::" #name); \
  59 
  60 #define C2V_END }
  61 
  62 C2V_ENTRY(jbyteArray, initializeBytecode, (JNIEnv *env, jobject, jlong metaspace_method, jbyteArray result))
  63   methodHandle method = asMethod(metaspace_method);
  64   ResourceMark rm;
  65 
  66   int code_size = method->code_size();
  67   jbyte* reconstituted_code = NULL;
  68 
  69   // replace all breakpoints - must be done before undoing any rewriting
  70   if (method->number_of_breakpoints() > 0) {
  71     reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size);
  72     memcpy(reconstituted_code, (jbyte *) method->code_base(), code_size);
  73     BreakpointInfo* bp = InstanceKlass::cast(method->method_holder())->breakpoints();
  74     for (; bp != NULL; bp = bp->next()) {
  75       if (bp->match(method())) {
  76         jbyte code = bp->orig_bytecode();
  77         reconstituted_code[bp->bci()] = code;
  78       }
  79     }
  80   }
  81 
  82   // iterate over all bytecodes and replace non-Java bytecodes
  83   if (RewriteBytecodes || RewriteFrequentPairs || InstanceKlass::cast(method->method_holder())->is_rewritten()) {
  84     if (reconstituted_code == NULL) {
  85       reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size);
  86       memcpy(reconstituted_code, (jbyte *) method->code_base(), code_size);
  87     }
  88     BytecodeStream s(method);
  89     while (!s.is_last_bytecode()) {
  90       s.next();
  91       Bytecodes::Code opcode = s.raw_code();
  92       if (!Bytecodes::is_java_code(opcode)) {
  93         jbyte original_opcode = Bytecodes::java_code(opcode);
  94         int bci = s.bci();
  95         reconstituted_code[bci] = original_opcode;
  96         if (opcode == Bytecodes::_fast_aldc_w) {
  97           int cpci = Bytes::get_native_u2((address) reconstituted_code + bci + 1);
  98           int i = method->constants()->object_to_cp_index(cpci);
  99           assert(i < method->constants()->length(), "sanity check");
 100           Bytes::put_Java_u2((address) reconstituted_code + bci + 1, (u2)i);
 101         } else if (opcode == Bytecodes::_fast_aldc) {
 102           int cpci = reconstituted_code[bci + 1] & 0xff;
 103           int i = method->constants()->object_to_cp_index(cpci);
 104           assert(i < method->constants()->length(), "sanity check");
 105           reconstituted_code[bci + 1] = (jbyte)i;
 106         }
 107       }
 108     }
 109   }
 110 
 111   if (reconstituted_code == NULL) {
 112     env->SetByteArrayRegion(result, 0, code_size, (jbyte *) method->code_base());
 113   } else {
 114     env->SetByteArrayRegion(result, 0, code_size, reconstituted_code);
 115   }
 116 
 117   return result;
 118 C2V_END
 119 
 120 C2V_VMENTRY(jstring, getSignature, (JNIEnv *env, jobject, jlong metaspace_method))
 121   Method* method = asMethod(metaspace_method);
 122   assert(method != NULL && method->signature() != NULL, "signature required");
 123   return (jstring)JNIHandles::make_local(java_lang_String::create_from_symbol(method->signature(), THREAD)());
 124 C2V_END
 125 
 126 C2V_VMENTRY(jobjectArray, initializeExceptionHandlers, (JNIEnv *, jobject, jlong metaspace_method, jobjectArray java_handlers))
 127   ResourceMark rm;
 128   methodHandle method = asMethod(metaspace_method);
 129   int handler_count = method->exception_table_length();
 130   objArrayHandle array = (objArrayOop) JNIHandles::resolve(java_handlers);
 131   assert(array->length() == handler_count, "wrong length");
 132   ExceptionTableElement* handlers = handler_count == 0 ? NULL : method->exception_table_start();
 133 
 134   for (int i = 0; i < handler_count; i++) {
 135     ExceptionTableElement* handler = handlers + i;
 136     Handle entry = array->obj_at(i);
 137     assert(!entry.is_null(), "entry should not be null");
 138     ExceptionHandler::set_startBCI(entry, handler->start_pc);
 139     ExceptionHandler::set_endBCI(entry, handler->end_pc);
 140     ExceptionHandler::set_handlerBCI(entry, handler->handler_pc);
 141     int catch_class_index = handler->catch_type_index;
 142     ExceptionHandler::set_catchTypeCPI(entry, catch_class_index);
 143 
 144     if (catch_class_index == 0) {
 145       ExceptionHandler::set_catchType(entry, NULL);
 146     } else {
 147       ConstantPool* cp = InstanceKlass::cast(method->method_holder())->constants();
 148       KlassHandle loading_klass = method->method_holder();
 149       Handle catch_class = GraalCompiler::get_JavaType(cp, catch_class_index, loading_klass, CHECK_NULL);
 150       if (catch_class->klass() == HotSpotResolvedObjectType::klass() && java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(catch_class)) == SystemDictionary::Throwable_klass()) {
 151         ExceptionHandler::set_catchType(entry, NULL);
 152         ExceptionHandler::set_catchTypeCPI(entry, 0);
 153       } else {
 154         ExceptionHandler::set_catchType(entry, catch_class());
 155       }
 156     }
 157     array->obj_at_put(i, entry());
 158   }
 159 
 160   return (jobjectArray) JNIHandles::make_local(array());
 161 C2V_END
 162 
 163 C2V_VMENTRY(jint, hasBalancedMonitors, (JNIEnv *, jobject, jlong metaspace_method))
 164 
 165   // Analyze the method to see if monitors are used properly.
 166   methodHandle method(THREAD, asMethod(metaspace_method));
 167   assert(method->has_monitor_bytecodes(), "should have checked this");
 168 
 169   // Check to see if a previous compilation computed the monitor-matching analysis.
 170   if (method->guaranteed_monitor_matching()) {
 171     return true;
 172   }
 173 
 174   {
 175     EXCEPTION_MARK;
 176     ResourceMark rm(THREAD);
 177     GeneratePairingInfo gpi(method);
 178     gpi.compute_map(CATCH);
 179     if (!gpi.monitor_safe()) {
 180       return false;
 181     }
 182     method->set_guaranteed_monitor_matching();
 183   }
 184   return true;
 185 C2V_END
 186 
 187 C2V_VMENTRY(jlong, getMetaspaceMethod, (JNIEnv *, jobject, jobject reflection_method_handle, jobject resultHolder))
 188   oop reflection_method = JNIHandles::resolve(reflection_method_handle);
 189   oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method);
 190   int slot = java_lang_reflect_Method::slot(reflection_method);
 191   Klass* holder = java_lang_Class::as_Klass(reflection_holder);
 192   methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot);
 193   Handle type = GraalCompiler::createHotSpotResolvedObjectType(method, CHECK_0);
 194   objArrayOop(JNIHandles::resolve(resultHolder))->obj_at_put(0, type());
 195   return (jlong) (address) method();
 196 }
 197 
 198 C2V_VMENTRY(jlong, getMetaspaceConstructor, (JNIEnv *, jobject, jobject reflection_ctor_handle, jobject resultHolder))
 199   oop reflection_ctor = JNIHandles::resolve(reflection_ctor_handle);
 200   oop reflection_holder = java_lang_reflect_Constructor::clazz(reflection_ctor);
 201   int slot = java_lang_reflect_Constructor::slot(reflection_ctor);
 202   Klass* holder = java_lang_Class::as_Klass(reflection_holder);
 203   methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot);
 204   Handle type = GraalCompiler::createHotSpotResolvedObjectType(method, CHECK_0);
 205   objArrayOop(JNIHandles::resolve(resultHolder))->obj_at_put(0, type());
 206   return (jlong) (address) method();
 207 }
 208 
 209 C2V_VMENTRY(jobject, getJavaField, (JNIEnv *, jobject, jobject reflection_field_handle))
 210   oop reflection_field = JNIHandles::resolve(reflection_field_handle);
 211   oop reflection_holder = java_lang_reflect_Field::clazz(reflection_field);
 212   int slot = java_lang_reflect_Field::slot(reflection_field);
 213   InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(reflection_holder));
 214 
 215   int offset = holder->field_offset(slot);
 216   int flags = holder->field_access_flags(slot);
 217   Symbol* field_name = holder->field_name(slot);
 218   Handle field_holder = GraalCompiler::get_JavaTypeFromClass(reflection_holder, CHECK_NULL);
 219   Handle field_type = GraalCompiler::get_JavaTypeFromClass(java_lang_reflect_Field::type(reflection_field), CHECK_NULL);
 220 
 221   Handle ret = GraalCompiler::get_JavaField(offset, flags, field_name, field_holder, field_type, CHECK_NULL);
 222   return JNIHandles::make_local(THREAD, ret());
 223 }
 224 
 225 C2V_VMENTRY(jlong, getUniqueConcreteMethod, (JNIEnv *, jobject, jlong metaspace_method, jobject resultHolder))
 226   methodHandle method = asMethod(metaspace_method);
 227   KlassHandle holder = method->method_holder();
 228   if (holder->is_interface()) {
 229     // Cannot trust interfaces. Because of:
 230     // interface I { void foo(); }
 231     // class A { public void foo() {} }
 232     // class B extends A implements I { }
 233     // class C extends B { public void foo() { } }
 234     // class D extends B { }
 235     // Would lead to identify C.foo() as the unique concrete method for I.foo() without seeing A.foo().
 236     return 0L;
 237   }
 238   methodHandle ucm;
 239   {
 240     ResourceMark rm;
 241     MutexLocker locker(Compile_lock);
 242     ucm = Dependencies::find_unique_concrete_method(holder(), method());
 243   }
 244 
 245   if (ucm.is_null()) {
 246     return 0L;
 247   }
 248 
 249   Handle type = GraalCompiler::createHotSpotResolvedObjectType(ucm(), CHECK_0);
 250   objArrayOop(JNIHandles::resolve(resultHolder))->obj_at_put(0, type());
 251   return (jlong) (address) ucm();
 252 C2V_END
 253 
 254 C2V_VMENTRY(jobject, getUniqueImplementor, (JNIEnv *, jobject, jobject interface_type))
 255   InstanceKlass* klass = (InstanceKlass*) asKlass(HotSpotResolvedObjectType::metaspaceKlass(interface_type));
 256   assert(klass->is_interface(), "must be");
 257   if (klass->nof_implementors() == 1) {
 258     InstanceKlass* implementor = (InstanceKlass*) klass->implementor();
 259     if (!implementor->is_abstract() && !implementor->is_interface() && implementor->is_leaf_class()) {
 260       Handle type = GraalCompiler::get_JavaType(implementor, CHECK_NULL);
 261       return JNIHandles::make_local(THREAD, type());
 262     }
 263   }
 264   return NULL;
 265 C2V_END
 266 
 267 C2V_ENTRY(jint, getInvocationCount, (JNIEnv *, jobject, jlong metaspace_method))
 268   Method* method = asMethod(metaspace_method);
 269   return method->invocation_count();
 270 C2V_END
 271 
 272 C2V_VMENTRY(void, initializeMethod,(JNIEnv *, jobject, jlong metaspace_method, jobject hotspot_method))
 273   methodHandle method = asMethod(metaspace_method);
 274   Handle name = java_lang_String::create_from_symbol(method->name(), CHECK);
 275   InstanceKlass::cast(HotSpotResolvedJavaMethod::klass())->initialize(CHECK);
 276   HotSpotResolvedJavaMethod::set_name(hotspot_method, name());
 277   HotSpotResolvedJavaMethod::set_codeSize(hotspot_method, method->code_size());
 278   HotSpotResolvedJavaMethod::set_exceptionHandlerCount(hotspot_method, method->exception_table_length());
 279 C2V_END
 280 
 281 C2V_VMENTRY(jboolean, isMethodCompilable,(JNIEnv *, jobject, jlong metaspace_method))
 282   methodHandle method = asMethod(metaspace_method);
 283   return !method->is_not_compilable() && !CompilerOracle::should_not_inline(method);
 284 C2V_END
 285 
 286 C2V_VMENTRY(void, initializeMethodData,(JNIEnv *, jobject, jlong metaspace_method_data, jobject hotspot_method_data))
 287   MethodData* method_data = asMethodData(metaspace_method_data);
 288   HotSpotMethodData::set_normalDataSize(hotspot_method_data, method_data->data_size());
 289   HotSpotMethodData::set_extraDataSize(hotspot_method_data, method_data->extra_data_size());
 290 C2V_END
 291 
 292 // ------------------------------------------------------------------
 293 // Adjust a CounterData count to be commensurate with
 294 // interpreter_invocation_count.  If the MDO exists for
 295 // only 25% of the time the method exists, then the
 296 // counts in the MDO should be scaled by 4X, so that
 297 // they can be usefully and stably compared against the
 298 // invocation counts in methods.
 299 int scale_count(MethodData* method_data, int count) {
 300   if (count > 0) {
 301     int counter_life;
 302     int method_life = method_data->method()->interpreter_invocation_count();
 303     int current_mileage = MethodData::mileage_of(method_data->method());
 304     int creation_mileage = method_data->creation_mileage();
 305     counter_life = current_mileage - creation_mileage;
 306 
 307     // counter_life due to backedge_counter could be > method_life
 308     if (counter_life > method_life)
 309       counter_life = method_life;
 310     if (0 < counter_life && counter_life <= method_life) {
 311       count = (int)((double)count * method_life / counter_life + 0.5);
 312       count = (count > 0) ? count : 1;
 313     }
 314   }
 315   return count;
 316 }
 317 
 318 C2V_ENTRY(jint, getCompiledCodeSize, (JNIEnv *env, jobject, jlong metaspace_method))
 319   nmethod* code = (asMethod(metaspace_method))->code();
 320   return code == NULL ? 0 : code->insts_size();
 321 C2V_END
 322 
 323 C2V_VMENTRY(jint, constantPoolLength, (JNIEnv *env, jobject, jobject type))
 324   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 325   return cp->length();
 326 C2V_END
 327 
 328 C2V_VMENTRY(jobject, lookupType, (JNIEnv *env, jobject, jstring jname, jobject accessingClass, jboolean eagerResolve))
 329   ResourceMark rm;
 330 
 331   Handle name = JNIHandles::resolve(jname);
 332   Symbol* nameSymbol = java_lang_String::as_symbol(name, THREAD);
 333   assert(nameSymbol != NULL, "name to symbol creation failed");
 334 
 335   oop result = NULL;
 336   if (nameSymbol == vmSymbols::int_signature()) {
 337     result = VMToCompiler::createPrimitiveJavaType((int) T_INT, THREAD);
 338   } else if (nameSymbol == vmSymbols::long_signature()) {
 339     result = VMToCompiler::createPrimitiveJavaType((int) T_LONG, THREAD);
 340   } else if (nameSymbol == vmSymbols::bool_signature()) {
 341     result = VMToCompiler::createPrimitiveJavaType((int) T_BOOLEAN, THREAD);
 342   } else if (nameSymbol == vmSymbols::char_signature()) {
 343     result = VMToCompiler::createPrimitiveJavaType((int) T_CHAR, THREAD);
 344   } else if (nameSymbol == vmSymbols::short_signature()) {
 345     result = VMToCompiler::createPrimitiveJavaType((int) T_SHORT, THREAD);
 346   } else if (nameSymbol == vmSymbols::byte_signature()) {
 347     result = VMToCompiler::createPrimitiveJavaType((int) T_BYTE, THREAD);
 348   } else if (nameSymbol == vmSymbols::double_signature()) {
 349     result = VMToCompiler::createPrimitiveJavaType((int) T_DOUBLE, THREAD);
 350   } else if (nameSymbol == vmSymbols::float_signature()) {
 351     result = VMToCompiler::createPrimitiveJavaType((int) T_FLOAT, THREAD);
 352   } else if (nameSymbol == vmSymbols::void_signature()) {
 353     result = VMToCompiler::createPrimitiveJavaType((int) T_VOID, THREAD);
 354   } else {
 355     Klass* resolved_type = NULL;
 356     Handle classloader;
 357     Handle protectionDomain;
 358     if (JNIHandles::resolve(accessingClass) != NULL) {
 359       classloader = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->class_loader();
 360       protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->protection_domain();
 361     }
 362 
 363     if (eagerResolve) {
 364       resolved_type = SystemDictionary::resolve_or_fail(nameSymbol, classloader, protectionDomain, true, THREAD);
 365     } else {
 366       resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD);
 367     }
 368 
 369     if (!HAS_PENDING_EXCEPTION) {
 370       if (resolved_type == NULL) {
 371         assert(!eagerResolve, "failed eager resolution should have caused an exception");
 372         Handle type = VMToCompiler::createUnresolvedJavaType(name, THREAD);
 373         result = type();
 374       } else {
 375         Handle type = GraalCompiler::createHotSpotResolvedObjectType(resolved_type, name, CHECK_NULL);
 376         result = type();
 377       }
 378     }
 379   }
 380 
 381   return JNIHandles::make_local(THREAD, result);
 382 C2V_END
 383 
 384 C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jobject type, jint index))
 385 
 386   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 387 
 388   oop result = NULL;
 389   constantTag tag = cp->tag_at(index);
 390   if (tag.is_int()) {
 391     result = VMToCompiler::createConstant(Kind::Int(), cp->int_at(index), CHECK_0);
 392   } else if (tag.is_long()) {
 393     result = VMToCompiler::createConstant(Kind::Long(), cp->long_at(index), CHECK_0);
 394   } else if (tag.is_float()) {
 395     result = VMToCompiler::createConstantFloat(cp->float_at(index), CHECK_0);
 396   } else if (tag.is_double()) {
 397     result = VMToCompiler::createConstantDouble(cp->double_at(index), CHECK_0);
 398   } else if (tag.is_string()) {
 399     oop string = NULL;
 400     if (cp->is_pseudo_string_at(index)) {
 401       int obj_index = cp->cp_to_object_index(index);
 402       string = cp->pseudo_string_at(index, obj_index);
 403     } else {
 404       string = cp->string_at(index, THREAD);
 405       if (HAS_PENDING_EXCEPTION) {
 406         CLEAR_PENDING_EXCEPTION;
 407         // TODO: Gracefully exit compilation.
 408         fatal("out of memory during compilation!");
 409         return NULL;
 410       }
 411     }
 412     result = VMToCompiler::createConstantObject(string, CHECK_0);
 413   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 414     Handle type = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
 415     result = type();
 416   } else {
 417     tty->print("unknown constant pool tag (%s) at cpi %d in %s: ", tag.internal_name(), index, cp->pool_holder()->name()->as_C_string());
 418     ShouldNotReachHere();
 419   }
 420 
 421   return JNIHandles::make_local(THREAD, result);
 422 C2V_END
 423 
 424 C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode))
 425   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
 426   index = GraalCompiler::to_cp_index(index, bc);
 427   constantPoolHandle cpool(InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants());
 428   oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, index);
 429 
 430   return JNIHandles::make_local(THREAD, appendix_oop);
 431 C2V_END
 432 
 433 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode))
 434   constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 435   instanceKlassHandle pool_holder(cp->pool_holder());
 436 
 437   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
 438   index = GraalCompiler::to_cp_index(index, bc);
 439 
 440   methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, pool_holder);
 441   if (!method.is_null()) {
 442     Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL);
 443     return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD));
 444   } else {
 445     // Get the method's name and signature.
 446     Handle name = java_lang_String::create_from_symbol(cp->name_ref_at(index), CHECK_NULL);
 447     Handle signature  = java_lang_String::create_from_symbol(cp->signature_ref_at(index), CHECK_NULL);
 448     Handle type;
 449     if (bc != Bytecodes::_invokedynamic) {
 450       int holder_index = cp->klass_ref_index_at(index);
 451       type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
 452     } else {
 453       type = Handle(SystemDictionary::MethodHandle_klass()->java_mirror());
 454     }
 455     return JNIHandles::make_local(THREAD, VMToCompiler::createUnresolvedJavaMethod(name, signature, type, THREAD));
 456   }
 457 C2V_END
 458 
 459 C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jobject type, jint index))
 460 
 461   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 462   Handle result = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
 463   return JNIHandles::make_local(THREAD, result());
 464 C2V_END
 465 
 466 C2V_VMENTRY(void, lookupReferencedTypeInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte op))
 467   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 468   Bytecodes::Code bc = (Bytecodes::Code) (((int) op) & 0xFF);
 469   if (bc != Bytecodes::_checkcast && bc != Bytecodes::_instanceof && bc != Bytecodes::_new && bc != Bytecodes::_anewarray
 470       && bc != Bytecodes::_multianewarray && bc != Bytecodes::_ldc && bc != Bytecodes::_ldc_w && bc != Bytecodes::_ldc2_w)
 471   {
 472     index = cp->remap_instruction_operand_from_cache(GraalCompiler::to_cp_index(index, bc));
 473   }
 474   constantTag tag = cp->tag_at(index);
 475   if (tag.is_field_or_method()) {
 476     index = cp->uncached_klass_ref_index_at(index);
 477     tag = cp->tag_at(index);
 478   }
 479 
 480   if (tag.is_unresolved_klass() || tag.is_klass()) {
 481     Klass* klass = cp->klass_at(index, CHECK);
 482     if (klass->oop_is_instance()) {
 483       InstanceKlass::cast(klass)->initialize(CHECK);
 484     }
 485   }
 486 C2V_END
 487 
 488 C2V_VMENTRY(jobject, lookupFieldInPool, (JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte opcode))
 489   ResourceMark rm;
 490 
 491   index = GraalCompiler::to_cp_index_u2(index);
 492   constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(constantPoolHolder)))->constants();
 493 
 494   int nt_index = cp->name_and_type_ref_index_at(index);
 495   int sig_index = cp->signature_ref_index_at(nt_index);
 496   Symbol* signature = cp->symbol_at(sig_index);
 497   int name_index = cp->name_ref_index_at(nt_index);
 498   Symbol* name = cp->symbol_at(name_index);
 499   int holder_index = cp->klass_ref_index_at(index);
 500   Handle holder = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
 501   instanceKlassHandle holder_klass;
 502 
 503   Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
 504   int offset = -1;
 505   AccessFlags flags;
 506   BasicType basic_type;
 507   if (holder->klass() == SystemDictionary::HotSpotResolvedObjectType_klass()) {
 508     FieldAccessInfo result;
 509     LinkResolver::resolve_field(result, cp, index,
 510                                 Bytecodes::java_code(code),
 511                                 true, false, Thread::current());
 512     if (HAS_PENDING_EXCEPTION) {
 513       CLEAR_PENDING_EXCEPTION;
 514     } else {
 515       offset = result.field_offset();
 516       flags = result.access_flags();
 517       holder_klass = result.klass()();
 518       basic_type = result.field_type();
 519       holder = GraalCompiler::get_JavaType(holder_klass, CHECK_NULL);
 520     }
 521   }
 522 
 523   Handle type = GraalCompiler::get_JavaTypeFromSignature(signature, cp->pool_holder(), CHECK_NULL);
 524   Handle field_handle = GraalCompiler::get_JavaField(offset, flags.as_int(), name, holder, type, THREAD);
 525 
 526   return JNIHandles::make_local(THREAD, field_handle());
 527 C2V_END
 528 
 529 C2V_VMENTRY(jobject, resolveMethod, (JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature))
 530 
 531   assert(JNIHandles::resolve(resolved_type) != NULL, "");
 532   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(resolved_type));
 533   Symbol* name_symbol = java_lang_String::as_symbol(JNIHandles::resolve(name), THREAD);
 534   Symbol* signature_symbol = java_lang_String::as_symbol(JNIHandles::resolve(signature), THREAD);
 535   methodHandle method = klass->lookup_method(name_symbol, signature_symbol);
 536   if (method.is_null()) {
 537     if (TraceGraal >= 3) {
 538       ResourceMark rm;
 539       tty->print_cr("Could not resolve method %s %s on klass %s", name_symbol->as_C_string(), signature_symbol->as_C_string(), klass->name()->as_C_string());
 540     }
 541     return NULL;
 542   }
 543   Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL);
 544   return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD));
 545 C2V_END
 546 
 547 C2V_VMENTRY(jboolean, isTypeInitialized,(JNIEnv *, jobject, jobject hotspot_klass))
 548   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(hotspot_klass));
 549   assert(klass != NULL, "method must not be called for primitive types");
 550   return InstanceKlass::cast(klass)->is_initialized();
 551 C2V_END
 552 
 553 C2V_VMENTRY(void, initializeType, (JNIEnv *, jobject, jobject hotspot_klass))
 554   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(hotspot_klass));
 555   assert(klass != NULL, "method must not be called for primitive types");
 556   InstanceKlass::cast(klass)->initialize(JavaThread::current());
 557 C2V_END
 558 
 559 C2V_VMENTRY(jobject, getInstanceFields, (JNIEnv *, jobject, jobject klass))
 560   ResourceMark rm;
 561 
 562   instanceKlassHandle k = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(klass));
 563   GrowableArray<Handle> fields(k->java_fields_count());
 564 
 565   for (AllFieldStream fs(k()); !fs.done(); fs.next()) {
 566     if (!fs.access_flags().is_static()) {
 567       Handle type = GraalCompiler::get_JavaTypeFromSignature(fs.signature(), k, Thread::current());
 568       int flags = fs.access_flags().as_int();
 569       bool internal = fs.access_flags().is_internal();
 570       Handle name = java_lang_String::create_from_symbol(fs.name(), Thread::current());
 571       Handle field = VMToCompiler::createJavaField(JNIHandles::resolve(klass), name, type, fs.offset(), flags, internal, Thread::current());
 572       fields.append(field());
 573     }
 574   }
 575   objArrayHandle field_array = oopFactory::new_objArray(SystemDictionary::HotSpotResolvedJavaField_klass(), fields.length(), CHECK_NULL);
 576   for (int i = 0; i < fields.length(); ++i) {
 577     field_array->obj_at_put(i, fields.at(i)());
 578   }
 579   return JNIHandles::make_local(field_array());
 580 C2V_END
 581 
 582 C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv *env, jobject, jlong stub))
 583   address target_addr = (address) stub;
 584   if (target_addr != 0x0) {
 585     int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
 586     int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
 587     return MAX2(ABS(off_low), ABS(off_high));
 588   }
 589   return -1;
 590 C2V_END
 591 
 592 C2V_VMENTRY(jobject, getResolvedType, (JNIEnv *env, jobject, jobject javaClass))
 593   oop java_mirror = JNIHandles::resolve(javaClass);
 594   assert(java_mirror != NULL, "argument to CompilerToVM.getResolvedType must not be NULL");
 595   Handle type = GraalCompiler::get_JavaTypeFromClass(java_mirror, CHECK_NULL);
 596   return JNIHandles::make_local(THREAD, type());
 597 C2V_END
 598 
 599 
 600 // helpers used to set fields in the HotSpotVMConfig object
 601 jfieldID getFieldID(JNIEnv* env, jobject obj, const char* name, const char* sig) {
 602   jfieldID id = env->GetFieldID(env->GetObjectClass(obj), name, sig);
 603   if (id == NULL) {
 604     fatal(err_msg("field not found: %s (%s)", name, sig));
 605   }
 606   return id;
 607 }
 608 
 609 BasicType basicTypes[] = { T_BOOLEAN, T_BYTE, T_SHORT, T_CHAR, T_INT, T_FLOAT, T_LONG, T_DOUBLE, T_OBJECT };
 610 int basicTypeCount = sizeof(basicTypes) / sizeof(BasicType);
 611 
 612 C2V_ENTRY(void, initializeConfiguration, (JNIEnv *env, jobject, jobject config))
 613 
 614 #define set_boolean(name, value) do { env->SetBooleanField(config, getFieldID(env, config, name, "Z"), value); } while (0)
 615 #define set_int(name, value) do { env->SetIntField(config, getFieldID(env, config, name, "I"), value); } while (0)
 616 #define set_long(name, value) do { env->SetLongField(config, getFieldID(env, config, name, "J"), value); } while (0)
 617 #define set_stub(name, value) do { set_long(name, (jlong) value); } while (0)
 618 #define set_object(name, value) do { env->SetObjectField(config, getFieldID(env, config, name, "Ljava/lang/Object;"), value); } while (0)
 619 #define set_int_array(name, value) do { env->SetObjectField(config, getFieldID(env, config, name, "[I"), value); } while (0)
 620 
 621   guarantee(HeapWordSize == sizeof(char*), "Graal assumption that HeadWordSize == machine word size is wrong");
 622 #ifdef _WIN64
 623   set_boolean("windowsOs", true);
 624 #else
 625   set_boolean("windowsOs", false);
 626 #endif
 627   set_boolean("verifyOops", VerifyOops);
 628   set_boolean("ciTime", CITime);
 629   set_boolean("compileTheWorld", CompileTheWorld);
 630   set_int("compileTheWorldStartAt", CompileTheWorldStartAt);
 631   set_int("compileTheWorldStopAt", CompileTheWorldStopAt);
 632   set_boolean("printCompilation", PrintCompilation);
 633   set_boolean("printInlining", PrintInlining);
 634   set_boolean("useFastLocking", GraalUseFastLocking);
 635   set_boolean("useBiasedLocking", UseBiasedLocking);
 636   set_boolean("usePopCountInstruction", UsePopCountInstruction);
 637   set_boolean("useAESIntrinsics", UseAESIntrinsics);
 638   set_boolean("useTLAB", UseTLAB);
 639   set_boolean("useG1GC", UseG1GC);
 640   set_int("codeEntryAlignment", CodeEntryAlignment);
 641   set_int("stackShadowPages", StackShadowPages);
 642   set_int("hubOffset", oopDesc::klass_offset_in_bytes());
 643   set_int("markOffset", oopDesc::mark_offset_in_bytes());
 644   set_int("prototypeMarkWordOffset", in_bytes(Klass::prototype_header_offset()));
 645   set_int("superCheckOffsetOffset", in_bytes(Klass::super_check_offset_offset()));
 646   set_int("secondarySuperCacheOffset", in_bytes(Klass::secondary_super_cache_offset()));
 647   set_int("secondarySupersOffset", in_bytes(Klass::secondary_supers_offset()));
 648   set_int("subklassOffset", in_bytes(Klass::subklass_offset()));
 649   set_int("nextSiblingOffset", in_bytes(Klass::next_sibling_offset()));
 650   set_int("arrayLengthOffset", arrayOopDesc::length_offset_in_bytes());
 651   set_int("klassStateOffset", in_bytes(InstanceKlass::init_state_offset()));
 652   set_int("klassStateFullyInitialized", (int)InstanceKlass::fully_initialized);
 653   set_int("threadTlabTopOffset", in_bytes(JavaThread::tlab_top_offset()));
 654   set_int("threadTlabEndOffset", in_bytes(JavaThread::tlab_end_offset()));
 655   set_int("threadObjectOffset", in_bytes(JavaThread::threadObj_offset()));
 656   set_int("osThreadOffset", in_bytes(JavaThread::osthread_offset()));
 657   set_int("osThreadInterruptedOffset", in_bytes(OSThread::interrupted_offset()));
 658   set_int("unlockedMask", (int) markOopDesc::unlocked_value);
 659   set_int("biasedLockMaskInPlace", (int) markOopDesc::biased_lock_mask_in_place);
 660   set_int("ageMaskInPlace", (int) markOopDesc::age_mask_in_place);
 661   set_int("epochMaskInPlace", (int) markOopDesc::epoch_mask_in_place);
 662   set_int("biasedLockPattern", (int) markOopDesc::biased_lock_pattern);
 663   set_int("methodMaxLocalsOffset", in_bytes(ConstMethod::size_of_locals_offset()));
 664   set_int("methodConstMethodOffset", in_bytes(Method::const_offset()));
 665   set_int("constMethodMaxStackOffset", in_bytes(ConstMethod::max_stack_offset()));
 666   set_int("extraStackEntries", Method::extra_stack_entries());
 667   set_int("methodAccessFlagsOffset", in_bytes(Method::access_flags_offset()));
 668   set_int("methodIntrinsicIdOffset", Method::intrinsic_id_offset_in_bytes());
 669   set_int("klassHasFinalizerFlag", JVM_ACC_HAS_FINALIZER);
 670   set_int("threadExceptionOopOffset", in_bytes(JavaThread::exception_oop_offset()));
 671   set_int("threadExceptionPcOffset", in_bytes(JavaThread::exception_pc_offset()));
 672   set_boolean("isPollingPageFar", Assembler::is_polling_page_far());
 673   set_int("classMirrorOffset", in_bytes(Klass::java_mirror_offset()));
 674   set_int("runtimeCallStackSize", (jint)frame::arg_reg_save_area_bytes);
 675   set_int("klassModifierFlagsOffset", in_bytes(Klass::modifier_flags_offset()));
 676   set_int("klassAccessFlagsOffset", in_bytes(Klass::access_flags_offset()));
 677   set_int("klassOffset", java_lang_Class::klass_offset_in_bytes());
 678   set_int("graalMirrorInClassOffset", java_lang_Class::graal_mirror_offset_in_bytes());
 679   set_int("klassLayoutHelperOffset", in_bytes(Klass::layout_helper_offset()));
 680   set_int("klassSuperKlassOffset", in_bytes(Klass::super_offset()));
 681   set_int("methodDataOffset", in_bytes(Method::method_data_offset()));
 682   set_int("nmethodEntryOffset", nmethod::verified_entry_point_offset());
 683   set_int("methodCompiledEntryOffset", in_bytes(Method::from_compiled_offset()));
 684   set_int("basicLockSize", sizeof(BasicLock));
 685   set_int("basicLockDisplacedHeaderOffset", BasicLock::displaced_header_offset_in_bytes());
 686   set_int("uninitializedIdentityHashCodeValue", markOopDesc::no_hash);
 687   set_int("identityHashCodeShift", markOopDesc::hash_shift);
 688 
 689   set_int("arrayKlassLayoutHelperIdentifier", 0x80000000);
 690   assert((Klass::_lh_array_tag_obj_value & Klass::_lh_array_tag_type_value & 0x80000000) != 0, "obj_array and type_array must have first bit set");
 691   set_int("arrayKlassComponentMirrorOffset", in_bytes(ArrayKlass::component_mirror_offset()));
 692 
 693 
 694   set_int("pendingDeoptimizationOffset", in_bytes(ThreadShadow::pending_deoptimization_offset()));
 695 
 696   set_int("metaspaceArrayLengthOffset", Array<Klass*>::length_offset_in_bytes());
 697   set_int("metaspaceArrayBaseOffset", Array<Klass*>::base_offset_in_bytes());
 698   set_int("methodDataOopDataOffset", in_bytes(MethodData::data_offset()));
 699   set_int("methodDataOopTrapHistoryOffset", in_bytes(MethodData::trap_history_offset()));
 700   set_int("dataLayoutHeaderSize", DataLayout::header_size_in_bytes());
 701   set_int("dataLayoutTagOffset", in_bytes(DataLayout::tag_offset()));
 702   set_int("dataLayoutFlagsOffset", in_bytes(DataLayout::flags_offset()));
 703   set_int("dataLayoutBCIOffset", in_bytes(DataLayout::bci_offset()));
 704   set_int("dataLayoutCellsOffset", in_bytes(DataLayout::cell_offset(0)));
 705   set_int("dataLayoutCellSize", DataLayout::cell_size);
 706   set_int("bciProfileWidth", BciProfileWidth);
 707   set_int("typeProfileWidth", TypeProfileWidth);
 708 
 709   set_int("tlabAlignmentReserve", (int32_t)ThreadLocalAllocBuffer::alignment_reserve());
 710   set_long("tlabIntArrayMarkWord", (intptr_t)markOopDesc::prototype()->copy_set_hash(0x2));
 711   set_long("heapTopAddress", (jlong)(address) Universe::heap()->top_addr());
 712   set_long("heapEndAddress", (jlong)(address) Universe::heap()->end_addr());
 713   set_int("threadTlabStartOffset", in_bytes(JavaThread::tlab_start_offset()));
 714   set_int("threadTlabSizeOffset", in_bytes(JavaThread::tlab_size_offset()));
 715   set_int("threadAllocatedBytesOffset", in_bytes(JavaThread::allocated_bytes_offset()));
 716   set_int("tlabSlowAllocationsOffset", in_bytes(JavaThread::tlab_slow_allocations_offset()));
 717   set_int("tlabFastRefillWasteOffset", in_bytes(JavaThread::tlab_fast_refill_waste_offset()));
 718   set_int("tlabNumberOfRefillsOffset", in_bytes(JavaThread::tlab_number_of_refills_offset()));
 719   set_int("tlabRefillWasteLimitOffset", in_bytes(JavaThread::tlab_refill_waste_limit_offset()));
 720   set_int("tlabRefillWasteIncrement", (int32_t) ThreadLocalAllocBuffer::refill_waste_limit_increment());
 721   set_int("klassInstanceSizeOffset", in_bytes(Klass::layout_helper_offset()));
 722   set_boolean("tlabStats", TLABStats);
 723   set_boolean("inlineContiguousAllocationSupported", !CMSIncrementalMode && Universe::heap()->supports_inline_contig_alloc());
 724 
 725   set_long("arrayPrototypeMarkWord", (intptr_t)markOopDesc::prototype());
 726   set_int("layoutHelperLog2ElementSizeShift", Klass::_lh_log2_element_size_shift);
 727   set_int("layoutHelperLog2ElementSizeMask", Klass::_lh_log2_element_size_mask);
 728   set_int("layoutHelperElementTypeShift", Klass::_lh_element_type_shift);
 729   set_int("layoutHelperElementTypeMask", Klass::_lh_element_type_mask);
 730   // this filters out the bit that differentiates a type array from an object array
 731   set_int("layoutHelperElementTypePrimitiveInPlace", (Klass::_lh_array_tag_type_value & ~Klass::_lh_array_tag_obj_value) << Klass::_lh_array_tag_shift);
 732   set_int("layoutHelperHeaderSizeShift", Klass::_lh_header_size_shift);
 733   set_int("layoutHelperHeaderSizeMask", Klass::_lh_header_size_mask);
 734   set_int("layoutHelperOffset", in_bytes(Klass::layout_helper_offset()));
 735 
 736 
 737   set_stub("wbPreCallStub", GraalRuntime::entry_for(GraalRuntime::wb_pre_call_id));
 738   set_stub("wbPostCallStub", GraalRuntime::entry_for(GraalRuntime::wb_post_call_id));
 739 
 740   set_stub("newInstanceStub", GraalRuntime::entry_for(GraalRuntime::new_instance_id));
 741   set_stub("newArrayStub", GraalRuntime::entry_for(GraalRuntime::new_array_id));
 742   set_stub("newMultiArrayStub", GraalRuntime::entry_for(GraalRuntime::new_multi_array_id));
 743   set_stub("identityHashCodeStub", GraalRuntime::entry_for(GraalRuntime::identity_hash_code_id));
 744   set_stub("threadIsInterruptedStub", GraalRuntime::entry_for(GraalRuntime::thread_is_interrupted_id));
 745   set_stub("inlineCacheMissStub", SharedRuntime::get_ic_miss_stub());
 746   set_stub("handleExceptionStub", GraalRuntime::entry_for(GraalRuntime::handle_exception_nofpu_id));
 747   set_stub("handleDeoptStub", SharedRuntime::deopt_blob()->unpack());
 748   set_stub("monitorEnterStub", GraalRuntime::entry_for(GraalRuntime::monitorenter_id));
 749   set_stub("monitorExitStub", GraalRuntime::entry_for(GraalRuntime::monitorexit_id));
 750   set_stub("verifyOopStub", GraalRuntime::entry_for(GraalRuntime::verify_oop_id));
 751   set_stub("vmErrorStub", GraalRuntime::entry_for(GraalRuntime::vm_error_id));
 752   set_stub("deoptimizeStub", SharedRuntime::deopt_blob()->uncommon_trap());
 753   set_stub("unwindExceptionStub", GraalRuntime::entry_for(GraalRuntime::unwind_exception_call_id));
 754   set_stub("osrMigrationEndStub", GraalRuntime::entry_for(GraalRuntime::OSR_migration_end_id));
 755   set_stub("registerFinalizerStub", GraalRuntime::entry_for(GraalRuntime::register_finalizer_id));
 756   set_stub("createNullPointerExceptionStub", GraalRuntime::entry_for(GraalRuntime::create_null_pointer_exception_id));
 757   set_stub("createOutOfBoundsExceptionStub", GraalRuntime::entry_for(GraalRuntime::create_out_of_bounds_exception_id));
 758   set_stub("javaTimeMillisStub", CAST_FROM_FN_PTR(address, os::javaTimeMillis));
 759   set_stub("javaTimeNanosStub", CAST_FROM_FN_PTR(address, os::javaTimeNanos));
 760   set_stub("arithmeticFremStub", GraalRuntime::entry_for(GraalRuntime::arithmetic_frem_id));
 761   set_stub("arithmeticDremStub", GraalRuntime::entry_for(GraalRuntime::arithmetic_drem_id));
 762   set_stub("arithmeticSinStub", CAST_FROM_FN_PTR(address, SharedRuntime::dsin));
 763   set_stub("arithmeticCosStub", CAST_FROM_FN_PTR(address, SharedRuntime::dcos));
 764   set_stub("arithmeticTanStub", CAST_FROM_FN_PTR(address, SharedRuntime::dtan));
 765   set_stub("logPrimitiveStub", GraalRuntime::entry_for(GraalRuntime::log_primitive_id));
 766   set_stub("logObjectStub", GraalRuntime::entry_for(GraalRuntime::log_object_id));
 767   set_stub("logPrintfStub", GraalRuntime::entry_for(GraalRuntime::log_printf_id));
 768   set_stub("aescryptEncryptBlockStub", StubRoutines::aescrypt_encryptBlock());
 769   set_stub("aescryptDecryptBlockStub", StubRoutines::aescrypt_decryptBlock());
 770   set_stub("cipherBlockChainingEncryptAESCryptStub", StubRoutines::cipherBlockChaining_encryptAESCrypt());
 771   set_stub("cipherBlockChainingDecryptAESCryptStub", StubRoutines::cipherBlockChaining_decryptAESCrypt());
 772 
 773   set_int("deoptReasonNone", Deoptimization::Reason_none);
 774   set_int("deoptReasonNullCheck", Deoptimization::Reason_null_check);
 775   set_int("deoptReasonRangeCheck", Deoptimization::Reason_range_check);
 776   set_int("deoptReasonClassCheck", Deoptimization::Reason_class_check);
 777   set_int("deoptReasonArrayCheck", Deoptimization::Reason_array_check);
 778   set_int("deoptReasonUnreached0", Deoptimization::Reason_unreached0);
 779   set_int("deoptReasonTypeCheckInlining", Deoptimization::Reason_type_checked_inlining);
 780   set_int("deoptReasonOptimizedTypeCheck", Deoptimization::Reason_optimized_type_check);
 781   set_int("deoptReasonNotCompiledExceptionHandler", Deoptimization::Reason_not_compiled_exception_handler);
 782   set_int("deoptReasonUnresolved", Deoptimization::Reason_unresolved);
 783   set_int("deoptReasonJsrMismatch", Deoptimization::Reason_jsr_mismatch);
 784   set_int("deoptReasonDiv0Check", Deoptimization::Reason_div0_check);
 785   set_int("deoptReasonConstraint", Deoptimization::Reason_constraint);
 786 
 787   set_int("deoptActionNone", Deoptimization::Action_none);
 788   set_int("deoptActionMaybeRecompile", Deoptimization::Action_maybe_recompile);
 789   set_int("deoptActionReinterpret", Deoptimization::Action_reinterpret);
 790   set_int("deoptActionMakeNotEntrant", Deoptimization::Action_make_not_entrant);
 791   set_int("deoptActionMakeNotCompilable", Deoptimization::Action_make_not_compilable);
 792 
 793   set_int("vmIntrinsicInvokeBasic", vmIntrinsics::_invokeBasic);
 794   set_int("vmIntrinsicLinkToVirtual", vmIntrinsics::_linkToVirtual);
 795   set_int("vmIntrinsicLinkToStatic", vmIntrinsics::_linkToStatic);
 796   set_int("vmIntrinsicLinkToSpecial", vmIntrinsics::_linkToSpecial);
 797   set_int("vmIntrinsicLinkToInterface", vmIntrinsics::_linkToInterface);
 798 
 799   set_int("g1CardQueueIndexOffset", in_bytes(JavaThread::dirty_card_queue_offset() + PtrQueue::byte_offset_of_index()));
 800   set_int("g1CardQueueBufferOffset", in_bytes(JavaThread::dirty_card_queue_offset() + PtrQueue::byte_offset_of_buf()));
 801   set_int("logOfHRGrainBytes", HeapRegion::LogOfHRGrainBytes);
 802   set_int("g1SATBQueueMarkingOffset", in_bytes(JavaThread::satb_mark_queue_offset() + PtrQueue::byte_offset_of_active()));
 803   set_int("g1SATBQueueIndexOffset", in_bytes(JavaThread::satb_mark_queue_offset() +  PtrQueue::byte_offset_of_index()));
 804   set_int("g1SATBQueueBufferOffset", in_bytes(JavaThread::satb_mark_queue_offset() + PtrQueue::byte_offset_of_buf()));
 805 
 806   BarrierSet* bs = Universe::heap()->barrier_set();
 807   switch (bs->kind()) {
 808     case BarrierSet::CardTableModRef:
 809     case BarrierSet::CardTableExtension:
 810     case BarrierSet::G1SATBCT:
 811     case BarrierSet::G1SATBCTLogging:{
 812       jlong base = (jlong)((CardTableModRefBS*)bs)->byte_map_base;
 813       assert(base != 0, "unexpected byte_map_base");
 814       set_long("cardtableStartAddress", base);
 815       set_int("cardtableShift", CardTableModRefBS::card_shift);
 816       break;
 817     }
 818     case BarrierSet::ModRef:
 819     case BarrierSet::Other:
 820       set_long("cardtableStartAddress", 0);
 821       set_int("cardtableShift", 0);
 822       // No post barriers
 823       break;
 824     default:
 825       ShouldNotReachHere();
 826       break;
 827     }
 828 
 829   set_int("arrayClassElementOffset", in_bytes(ObjArrayKlass::element_klass_offset()));
 830 
 831 #undef set_boolean
 832 #undef set_int
 833 #undef set_long
 834 #undef set_object
 835 #undef set_int_array
 836 
 837 C2V_END
 838 
 839 C2V_VMENTRY(jint, installCode0, (JNIEnv *jniEnv, jobject, jobject compResult, jobject installed_code, jobject triggered_deoptimizations))
 840   ResourceMark rm;
 841   HandleMark hm;
 842   Handle compResultHandle = JNIHandles::resolve(compResult);
 843   nmethod* nm = NULL;
 844   methodHandle method = getMethodFromHotSpotMethod(HotSpotCompilationResult::method(compResult));
 845   Handle installed_code_handle = JNIHandles::resolve(installed_code);
 846   Handle triggered_deoptimizations_handle = JNIHandles::resolve(triggered_deoptimizations);
 847   GraalEnv::CodeInstallResult result;
 848   CodeInstaller installer(compResultHandle, method, result, nm, installed_code_handle, triggered_deoptimizations_handle);
 849 
 850   if (PrintCodeCacheOnCompilation) {
 851     stringStream s;
 852     // Dump code cache  into a buffer before locking the tty,
 853     {
 854       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 855       CodeCache::print_summary(&s, false);
 856     }
 857     ttyLocker ttyl;
 858     tty->print_cr(s.as_string());
 859   }
 860 
 861   if (result != GraalEnv::ok) {
 862     assert(nm == NULL, "should be");
 863   } else {
 864     if (!installed_code_handle.is_null()) {
 865       assert(installed_code_handle->is_a(HotSpotInstalledCode::klass()), "wrong type");
 866       HotSpotInstalledCode::set_nmethod(installed_code_handle, (jlong) nm);
 867       HotSpotInstalledCode::set_method(installed_code_handle, HotSpotCompilationResult::method(compResult));
 868       HotSpotInstalledCode::set_start(installed_code_handle, (jlong) nm->code_begin());
 869       assert(nm == NULL || !installed_code_handle->is_scavengable() || nm->on_scavenge_root_list(), "nm should be scavengable if installed_code is scavengable");
 870     }
 871   }
 872   return result;
 873 C2V_END
 874 
 875 C2V_VMENTRY(void, clearQueuedForCompilation, (JNIEnv *jniEnv, jobject, jobject resolvedMethod))
 876   methodHandle method = getMethodFromHotSpotMethod(JNIHandles::resolve(resolvedMethod));
 877   method->clear_queued_for_compilation();
 878 C2V_END
 879 
 880 C2V_VMENTRY(jobject, getCode, (JNIEnv *jniEnv, jobject,  jlong metaspace_nmethod))
 881   ResourceMark rm;
 882   HandleMark hm;
 883 
 884   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 885   if (nm == NULL || !nm->is_alive()) {
 886     return NULL;
 887   }
 888   int length = nm->code_size();
 889   arrayOop codeCopy = oopFactory::new_byteArray(length, CHECK_0);
 890   memcpy(codeCopy->base(T_BYTE), nm->code_begin(), length);
 891   return JNIHandles::make_local(codeCopy);
 892 C2V_END
 893 
 894 C2V_VMENTRY(jobject, disassembleNMethod, (JNIEnv *jniEnv, jobject, jlong metaspace_nmethod))
 895   ResourceMark rm;
 896   HandleMark hm;
 897 
 898   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 899   if (nm == NULL || !nm->is_alive()) {
 900     return NULL;
 901   }
 902   stringStream(st);
 903   Disassembler::decode(nm, &st);
 904 
 905   Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
 906   return JNIHandles::make_local(result());
 907 C2V_END
 908 
 909 C2V_VMENTRY(jobject, getStackTraceElement, (JNIEnv *env, jobject, jlong metaspace_method, int bci))
 910   ResourceMark rm;
 911   HandleMark hm;
 912 
 913   methodHandle method = asMethod(metaspace_method);
 914   oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL);
 915   return JNIHandles::make_local(element);
 916 C2V_END
 917 
 918 C2V_VMENTRY(jobject, executeCompiledMethodVarargs, (JNIEnv *env, jobject, jlong metaspace_method, jlong metaspace_nmethod, jobject args))
 919   ResourceMark rm;
 920   HandleMark hm;
 921 
 922   assert(metaspace_method != 0, "just checking");
 923   methodHandle mh = asMethod(metaspace_method);
 924   Symbol* signature = mh->signature();
 925   JavaCallArguments jca(mh->size_of_parameters());
 926 
 927   JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
 928   JavaValue result(jap.get_ret_type());
 929 
 930   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 931   if (nm == NULL || !nm->is_alive()) {
 932     THROW_0(vmSymbols::MethodInvalidatedException());
 933   }
 934 
 935   jca.set_alternative_target(nm);
 936   JavaCalls::call(&result, mh, &jca, CHECK_NULL);
 937 
 938   if (jap.get_ret_type() == T_VOID) {
 939     return NULL;
 940   } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) {
 941     return JNIHandles::make_local((oop) result.get_jobject());
 942   } else {
 943     oop o = java_lang_boxing_object::create(jap.get_ret_type(), (jvalue *) result.get_value_addr(), CHECK_NULL);
 944     return JNIHandles::make_local(o);
 945   }
 946 C2V_END
 947 
 948 C2V_VMENTRY(jobject, executeCompiledMethod, (JNIEnv *env, jobject, jlong metaspace_method, jlong metaspace_nmethod, jobject arg1, jobject arg2, jobject arg3))
 949   ResourceMark rm;
 950   HandleMark hm;
 951 
 952   methodHandle method = asMethod(metaspace_method);
 953   assert(!method.is_null(), "just checking");
 954   JavaValue result(T_OBJECT);
 955   JavaCallArguments args;
 956   args.push_oop(JNIHandles::resolve(arg1));
 957   args.push_oop(JNIHandles::resolve(arg2));
 958   args.push_oop(JNIHandles::resolve(arg3));
 959 
 960   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 961   if (nm == NULL || !nm->is_alive()) {
 962     THROW_0(vmSymbols::MethodInvalidatedException());
 963   }
 964 
 965   args.set_alternative_target(nm);
 966   JavaCalls::call(&result, method, &args, CHECK_NULL);
 967 
 968   return JNIHandles::make_local((oop) result.get_jobject());
 969 C2V_END
 970 
 971 C2V_VMENTRY(jint, getVtableEntryOffset, (JNIEnv *, jobject, jlong metaspace_method))
 972 
 973   Method* method = asMethod(metaspace_method);
 974   assert(!InstanceKlass::cast(method->method_holder())->is_interface(), "vtableEntryOffset cannot be called for interface methods");
 975   assert(InstanceKlass::cast(method->method_holder())->is_linked(), "vtableEntryOffset cannot be called is holder is not linked");
 976 
 977   // get entry offset in words
 978   int vtable_entry_offset = InstanceKlass::vtable_start_offset() + method->vtable_index() * vtableEntry::size();
 979   // convert to bytes
 980   vtable_entry_offset = vtable_entry_offset * wordSize + vtableEntry::method_offset_in_bytes();
 981 
 982   return vtable_entry_offset;
 983 C2V_END
 984 
 985 C2V_VMENTRY(jobject, getDeoptedLeafGraphIds, (JNIEnv *, jobject))
 986 
 987   // the contract for this method is as follows:
 988   // returning null: no deopted leaf graphs
 989   // returning array (size > 0): the ids of the deopted leaf graphs
 990   // returning array (size == 0): there was an overflow, the compiler needs to clear its cache completely
 991 
 992   oop array = GraalCompiler::instance()->dump_deopted_leaf_graphs(CHECK_NULL);
 993   return JNIHandles::make_local(array);
 994 C2V_END
 995 
 996 C2V_ENTRY(jlongArray, getLineNumberTable, (JNIEnv *env, jobject, jobject hotspot_method))
 997   Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method));
 998   if (!method->has_linenumber_table()) {
 999     return NULL;
1000   }
1001   u2 num_entries = 0;
1002   CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table());
1003   while (streamForSize.read_pair()) {
1004     num_entries++;
1005   }
1006 
1007   CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
1008   jlongArray result = env->NewLongArray(2 * num_entries);
1009 
1010   int i = 0;
1011   jlong value;
1012   while (stream.read_pair()) {
1013     value = ((long) stream.bci());
1014     env->SetLongArrayRegion(result,i,1,&value);
1015     value = ((long) stream.line());
1016     env->SetLongArrayRegion(result,i + 1,1,&value);
1017     i += 2;
1018   }
1019 
1020   return result;
1021 C2V_END
1022 
1023 C2V_VMENTRY(jobject, getLocalVariableTable, (JNIEnv *, jobject, jobject hotspot_method))
1024   ResourceMark rm;
1025 
1026   Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method));
1027   if (!method->has_localvariable_table()) {
1028     return NULL;
1029   }
1030   int localvariable_table_length = method->localvariable_table_length();
1031 
1032   objArrayHandle local_array = oopFactory::new_objArray(SystemDictionary::LocalImpl_klass(), localvariable_table_length, CHECK_NULL);
1033   LocalVariableTableElement* table = method->localvariable_table_start();
1034   for (int i = 0; i < localvariable_table_length; i++) {
1035     u2 start_bci = table[i].start_bci;
1036     u4 end_bci = (u4)(start_bci + table[i].length);
1037     u2 nameCPIdx = table[i].name_cp_index;
1038     u2 typeCPIdx = table[i].descriptor_cp_index;
1039     u2 slot = table[i].slot;
1040 
1041     char* name = method->constants()->symbol_at(nameCPIdx)->as_C_string();
1042     Handle nameHandle = java_lang_String::create_from_str(name, CHECK_NULL);
1043 
1044     char* typeInfo = method->constants()->symbol_at(typeCPIdx)->as_C_string();
1045     Handle typeHandle = java_lang_String::create_from_str(typeInfo, CHECK_NULL);
1046 
1047     Handle holderHandle = GraalCompiler::createHotSpotResolvedObjectType(method, CHECK_0);
1048     Handle local = VMToCompiler::createLocal(nameHandle, typeHandle, (int) start_bci, (int) end_bci, (int) slot, holderHandle, Thread::current());
1049     local_array->obj_at_put(i, local());
1050   }
1051 
1052   return JNIHandles::make_local(local_array());
1053 C2V_END
1054 
1055 
1056 C2V_VMENTRY(jobject, getFileName, (JNIEnv *, jobject, jobject klass))
1057   ResourceMark rm;
1058   InstanceKlass* k = (InstanceKlass*) asKlass(HotSpotResolvedObjectType::metaspaceKlass(klass));
1059   Symbol *s = k->source_file_name();
1060   int length;
1061   jchar *name = s->as_unicode(length);
1062 
1063   Handle result = java_lang_String::create_from_unicode(name, length, CHECK_NULL);
1064   return JNIHandles::make_local(result());
1065 
1066 C2V_END
1067 
1068 
1069 C2V_VMENTRY(void, reprofile, (JNIEnv *env, jobject, jlong metaspace_method))
1070   Method* method = asMethod(metaspace_method);
1071   method->reset_counters();
1072 
1073   nmethod* code = method->code();
1074   if (code != NULL) {
1075     code->make_not_entrant();
1076   }
1077 
1078   MethodData* method_data = method->method_data();
1079   if (method_data == NULL) {
1080     ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
1081     method_data = MethodData::allocate(loader_data, method, CHECK);
1082     method->set_method_data(method_data);
1083   } else {
1084     method_data->initialize();
1085   }
1086 C2V_END
1087 
1088 
1089 
1090 #define CC (char*)  /*cast a literal from (const char*)*/
1091 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
1092 
1093 #define RESOLVED_TYPE         "Lcom/oracle/graal/api/meta/ResolvedJavaType;"
1094 #define TYPE                  "Lcom/oracle/graal/api/meta/JavaType;"
1095 #define METHOD                "Lcom/oracle/graal/api/meta/JavaMethod;"
1096 #define FIELD                 "Lcom/oracle/graal/api/meta/JavaField;"
1097 #define SIGNATURE             "Lcom/oracle/graal/api/meta/Signature;"
1098 #define CONSTANT_POOL         "Lcom/oracle/graal/api/meta/ConstantPool;"
1099 #define CONSTANT              "Lcom/oracle/graal/api/meta/Constant;"
1100 #define KIND                  "Lcom/oracle/graal/api/meta/Kind;"
1101 #define LOCAL                  "Lcom/oracle/graal/api/meta/Local;"
1102 #define RUNTIME_CALL          "Lcom/oracle/graal/api/code/RuntimeCall;"
1103 #define EXCEPTION_HANDLERS    "[Lcom/oracle/graal/api/meta/ExceptionHandler;"
1104 #define REFLECT_METHOD        "Ljava/lang/reflect/Method;"
1105 #define REFLECT_CONSTRUCTOR   "Ljava/lang/reflect/Constructor;"
1106 #define REFLECT_FIELD         "Ljava/lang/reflect/Field;"
1107 #define STRING                "Ljava/lang/String;"
1108 #define OBJECT                "Ljava/lang/Object;"
1109 #define CLASS                 "Ljava/lang/Class;"
1110 #define STACK_TRACE_ELEMENT   "Ljava/lang/StackTraceElement;"
1111 #define HS_RESOLVED_TYPE      "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;"
1112 #define HS_RESOLVED_JAVA_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaType;"
1113 #define HS_RESOLVED_METHOD    "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;"
1114 #define HS_RESOLVED_FIELD     "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaField;"
1115 #define HS_COMP_RESULT        "Lcom/oracle/graal/hotspot/HotSpotCompilationResult;"
1116 #define HS_CONFIG             "Lcom/oracle/graal/hotspot/HotSpotVMConfig;"
1117 #define HS_METHOD             "Lcom/oracle/graal/hotspot/meta/HotSpotMethod;"
1118 #define HS_INSTALLED_CODE     "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;"
1119 #define METHOD_DATA           "Lcom/oracle/graal/hotspot/meta/HotSpotMethodData;"
1120 #define METASPACE_METHOD      "J"
1121 #define METASPACE_METHOD_DATA "J"
1122 #define NMETHOD               "J"
1123 
1124 JNINativeMethod CompilerToVM_methods[] = {
1125   {CC"initializeBytecode",            CC"("METASPACE_METHOD"[B)[B",                                     FN_PTR(initializeBytecode)},
1126   {CC"getSignature",                  CC"("METASPACE_METHOD")"STRING,                                   FN_PTR(getSignature)},
1127   {CC"initializeExceptionHandlers",   CC"("METASPACE_METHOD EXCEPTION_HANDLERS")"EXCEPTION_HANDLERS,    FN_PTR(initializeExceptionHandlers)},
1128   {CC"hasBalancedMonitors",           CC"("METASPACE_METHOD")Z",                                        FN_PTR(hasBalancedMonitors)},
1129   {CC"getUniqueConcreteMethod",       CC"("METASPACE_METHOD"["HS_RESOLVED_TYPE")"METASPACE_METHOD,      FN_PTR(getUniqueConcreteMethod)},
1130   {CC"getUniqueImplementor",          CC"("HS_RESOLVED_TYPE")"RESOLVED_TYPE,                            FN_PTR(getUniqueImplementor)},
1131   {CC"getStackTraceElement",          CC"("METASPACE_METHOD"I)"STACK_TRACE_ELEMENT,                     FN_PTR(getStackTraceElement)},
1132   {CC"initializeMethod",              CC"("METASPACE_METHOD HS_RESOLVED_METHOD")V",                     FN_PTR(initializeMethod)},
1133   {CC"initializeMethodData",          CC"("METASPACE_METHOD_DATA METHOD_DATA")V",                       FN_PTR(initializeMethodData)},
1134   {CC"isMethodCompilable",            CC"("METASPACE_METHOD")Z",                                        FN_PTR(isMethodCompilable)},
1135   {CC"getInvocationCount",            CC"("METASPACE_METHOD")I",                                        FN_PTR(getInvocationCount)},
1136   {CC"getCompiledCodeSize",           CC"("METASPACE_METHOD")I",                                        FN_PTR(getCompiledCodeSize)},
1137   {CC"getVtableEntryOffset",          CC"("METASPACE_METHOD")I",                                        FN_PTR(getVtableEntryOffset)},
1138   {CC"constantPoolLength",            CC"("HS_RESOLVED_TYPE")I",                                        FN_PTR(constantPoolLength)},
1139   {CC"lookupType",                    CC"("STRING HS_RESOLVED_TYPE"Z)"TYPE,                             FN_PTR(lookupType)},
1140   {CC"lookupConstantInPool",          CC"("HS_RESOLVED_TYPE"I)"OBJECT,                                  FN_PTR(lookupConstantInPool)},
1141   {CC"lookupAppendixInPool",          CC"("HS_RESOLVED_TYPE"IB)"OBJECT,                                 FN_PTR(lookupAppendixInPool)},
1142   {CC"lookupMethodInPool",            CC"("HS_RESOLVED_TYPE"IB)"METHOD,                                 FN_PTR(lookupMethodInPool)},
1143   {CC"lookupTypeInPool",              CC"("HS_RESOLVED_TYPE"I)"TYPE,                                    FN_PTR(lookupTypeInPool)},
1144   {CC"lookupReferencedTypeInPool",    CC"("HS_RESOLVED_TYPE"IB)V",                                      FN_PTR(lookupReferencedTypeInPool)},
1145   {CC"lookupFieldInPool",             CC"("HS_RESOLVED_TYPE"IB)"FIELD,                                  FN_PTR(lookupFieldInPool)},
1146   {CC"resolveMethod",                 CC"("HS_RESOLVED_TYPE STRING STRING")"METHOD,                     FN_PTR(resolveMethod)},
1147   {CC"getInstanceFields",             CC"("HS_RESOLVED_TYPE")["HS_RESOLVED_FIELD,                       FN_PTR(getInstanceFields)},
1148   {CC"isTypeInitialized",             CC"("HS_RESOLVED_TYPE")Z",                                        FN_PTR(isTypeInitialized)},
1149   {CC"initializeType",                CC"("HS_RESOLVED_TYPE")V",                                        FN_PTR(initializeType)},
1150   {CC"getMaxCallTargetOffset",        CC"(J)J",                                                         FN_PTR(getMaxCallTargetOffset)},
1151   {CC"getResolvedType",               CC"("CLASS")"RESOLVED_TYPE,                                       FN_PTR(getResolvedType)},
1152   {CC"getMetaspaceMethod",            CC"("REFLECT_METHOD"["HS_RESOLVED_TYPE")"METASPACE_METHOD,        FN_PTR(getMetaspaceMethod)},
1153   {CC"getMetaspaceConstructor",       CC"("REFLECT_CONSTRUCTOR"["HS_RESOLVED_TYPE")"METASPACE_METHOD,   FN_PTR(getMetaspaceConstructor)},
1154   {CC"getJavaField",                  CC"("REFLECT_FIELD")"HS_RESOLVED_FIELD,                           FN_PTR(getJavaField)},
1155   {CC"initializeConfiguration",       CC"("HS_CONFIG")V",                                               FN_PTR(initializeConfiguration)},
1156   {CC"installCode0",                  CC"("HS_COMP_RESULT HS_INSTALLED_CODE"[Z)I",                      FN_PTR(installCode0)},
1157   {CC"getCode",                       CC"(J)[B",                                                        FN_PTR(getCode)},
1158   {CC"disassembleNMethod",            CC"(J)"STRING,                                                    FN_PTR(disassembleNMethod)},
1159   {CC"executeCompiledMethod",         CC"("METASPACE_METHOD NMETHOD OBJECT OBJECT OBJECT")"OBJECT,      FN_PTR(executeCompiledMethod)},
1160   {CC"executeCompiledMethodVarargs",  CC"("METASPACE_METHOD NMETHOD "["OBJECT")"OBJECT,                 FN_PTR(executeCompiledMethodVarargs)},
1161   {CC"getDeoptedLeafGraphIds",        CC"()[J",                                                         FN_PTR(getDeoptedLeafGraphIds)},
1162   {CC"getLineNumberTable",            CC"("HS_RESOLVED_METHOD")[J",                                     FN_PTR(getLineNumberTable)},
1163   {CC"getLocalVariableTable",         CC"("HS_RESOLVED_METHOD")["LOCAL,                                 FN_PTR(getLocalVariableTable)},
1164   {CC"getFileName",                   CC"("HS_RESOLVED_JAVA_TYPE")"STRING,                              FN_PTR(getFileName)},
1165   {CC"clearQueuedForCompilation",     CC"("HS_RESOLVED_METHOD")V",                                      FN_PTR(clearQueuedForCompilation)},
1166   {CC"reprofile",                     CC"("METASPACE_METHOD")V",                                        FN_PTR(reprofile)},
1167 };
1168 
1169 int CompilerToVM_methods_count() {
1170   return sizeof(CompilerToVM_methods) / sizeof(JNINativeMethod);
1171 }
1172