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(jobject, lookupType, (JNIEnv *env, jobject, jstring jname, jobject accessingClass, jboolean eagerResolve))
 324   ResourceMark rm;
 325 
 326   Handle name = JNIHandles::resolve(jname);
 327   Symbol* nameSymbol = java_lang_String::as_symbol(name, THREAD);
 328   assert(nameSymbol != NULL, "name to symbol creation failed");
 329 
 330   oop result = NULL;
 331   if (nameSymbol == vmSymbols::int_signature()) {
 332     result = VMToCompiler::createPrimitiveJavaType((int) T_INT, THREAD);
 333   } else if (nameSymbol == vmSymbols::long_signature()) {
 334     result = VMToCompiler::createPrimitiveJavaType((int) T_LONG, THREAD);
 335   } else if (nameSymbol == vmSymbols::bool_signature()) {
 336     result = VMToCompiler::createPrimitiveJavaType((int) T_BOOLEAN, THREAD);
 337   } else if (nameSymbol == vmSymbols::char_signature()) {
 338     result = VMToCompiler::createPrimitiveJavaType((int) T_CHAR, THREAD);
 339   } else if (nameSymbol == vmSymbols::short_signature()) {
 340     result = VMToCompiler::createPrimitiveJavaType((int) T_SHORT, THREAD);
 341   } else if (nameSymbol == vmSymbols::byte_signature()) {
 342     result = VMToCompiler::createPrimitiveJavaType((int) T_BYTE, THREAD);
 343   } else if (nameSymbol == vmSymbols::double_signature()) {
 344     result = VMToCompiler::createPrimitiveJavaType((int) T_DOUBLE, THREAD);
 345   } else if (nameSymbol == vmSymbols::float_signature()) {
 346     result = VMToCompiler::createPrimitiveJavaType((int) T_FLOAT, THREAD);
 347   } else if (nameSymbol == vmSymbols::void_signature()) {
 348     result = VMToCompiler::createPrimitiveJavaType((int) T_VOID, THREAD);
 349   } else {
 350     Klass* resolved_type = NULL;
 351     Handle classloader;
 352     Handle protectionDomain;
 353     if (JNIHandles::resolve(accessingClass) != NULL) {
 354       classloader = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->class_loader();
 355       protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->protection_domain();
 356     }
 357 
 358     if (eagerResolve) {
 359       resolved_type = SystemDictionary::resolve_or_fail(nameSymbol, classloader, protectionDomain, true, THREAD);
 360     } else {
 361       resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD);
 362     }
 363 
 364     if (!HAS_PENDING_EXCEPTION) {
 365       if (resolved_type == NULL) {
 366         assert(!eagerResolve, "failed eager resolution should have caused an exception");
 367         Handle type = VMToCompiler::createUnresolvedJavaType(name, THREAD);
 368         result = type();
 369       } else {
 370         Handle type = GraalCompiler::createHotSpotResolvedObjectType(resolved_type, name, CHECK_NULL);
 371         result = type();
 372       }
 373     }
 374   }
 375 
 376   return JNIHandles::make_local(THREAD, result);
 377 C2V_END
 378 
 379 C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jobject type, jint index))
 380 
 381   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 382 
 383   oop result = NULL;
 384   constantTag tag = cp->tag_at(index);
 385   if (tag.is_int()) {
 386     result = VMToCompiler::createConstant(Kind::Int(), cp->int_at(index), CHECK_0);
 387   } else if (tag.is_long()) {
 388     result = VMToCompiler::createConstant(Kind::Long(), cp->long_at(index), CHECK_0);
 389   } else if (tag.is_float()) {
 390     result = VMToCompiler::createConstantFloat(cp->float_at(index), CHECK_0);
 391   } else if (tag.is_double()) {
 392     result = VMToCompiler::createConstantDouble(cp->double_at(index), CHECK_0);
 393   } else if (tag.is_string()) {
 394     oop string = NULL;
 395     if (cp->is_pseudo_string_at(index)) {
 396       int obj_index = cp->cp_to_object_index(index);
 397       string = cp->pseudo_string_at(index, obj_index);
 398     } else {
 399       string = cp->string_at(index, THREAD);
 400       if (HAS_PENDING_EXCEPTION) {
 401         CLEAR_PENDING_EXCEPTION;
 402         // TODO: Gracefully exit compilation.
 403         fatal("out of memory during compilation!");
 404         return NULL;
 405       }
 406     }
 407     result = VMToCompiler::createConstantObject(string, CHECK_0);
 408   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 409     Handle type = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
 410     result = type();
 411   } else {
 412     tty->print("unknown constant pool tag (%s) at cpi %d in %s: ", tag.internal_name(), index, cp->pool_holder()->name()->as_C_string());
 413     ShouldNotReachHere();
 414   }
 415 
 416   return JNIHandles::make_local(THREAD, result);
 417 C2V_END
 418 
 419 C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv *env, jobject, jobject type, jint index))
 420   assert(GraalCompiler::to_index_u4(index) < 0, "not an invokedynamic constant pool index");
 421   constantPoolHandle cpool(InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants());
 422   oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, GraalCompiler::to_index_u4(index));
 423 
 424   return JNIHandles::make_local(THREAD, appendix_oop);
 425 C2V_END
 426 
 427 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode))
 428   constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 429   instanceKlassHandle pool_holder(cp->pool_holder());
 430 
 431   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
 432   index = (bc == Bytecodes::_invokedynamic) ? GraalCompiler::to_index_u4(index) : GraalCompiler::to_cp_index_u2(index);
 433 
 434   methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, pool_holder);
 435   if (!method.is_null()) {
 436     Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL);
 437     return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD));
 438   } else {
 439     // Get the method's name and signature.
 440     Handle name = java_lang_String::create_from_symbol(cp->name_ref_at(index), CHECK_NULL);
 441     Handle signature  = java_lang_String::create_from_symbol(cp->signature_ref_at(index), CHECK_NULL);
 442     Handle type;
 443     if (bc != Bytecodes::_invokedynamic) {
 444       int holder_index = cp->klass_ref_index_at(index);
 445       type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
 446     } else {
 447       type = Handle(SystemDictionary::MethodHandle_klass()->java_mirror());
 448     }
 449     return JNIHandles::make_local(THREAD, VMToCompiler::createUnresolvedJavaMethod(name, signature, type, THREAD));
 450   }
 451 C2V_END
 452 
 453 C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jobject type, jint index))
 454 
 455   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 456   Handle result = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
 457   return JNIHandles::make_local(THREAD, result());
 458 C2V_END
 459 
 460 C2V_VMENTRY(void, lookupReferencedTypeInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte op))
 461   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
 462   int opcode = (op & 0xFF);
 463   if (opcode != Bytecodes::_checkcast && opcode != Bytecodes::_instanceof && opcode != Bytecodes::_new && opcode != Bytecodes::_anewarray
 464       && opcode != Bytecodes::_multianewarray && opcode != Bytecodes::_ldc && opcode != Bytecodes::_ldc_w && opcode != Bytecodes::_ldc2_w)
 465   {
 466     index = cp->remap_instruction_operand_from_cache((opcode == Bytecodes::_invokedynamic) ? GraalCompiler::to_index_u4(index) : GraalCompiler::to_cp_index_u2(index));
 467   }
 468   constantTag tag = cp->tag_at(index);
 469   if (tag.is_field_or_method()) {
 470     index = cp->uncached_klass_ref_index_at(index);
 471     tag = cp->tag_at(index);
 472   }
 473 
 474   if (tag.is_unresolved_klass() || tag.is_klass()) {
 475     Klass* klass = cp->klass_at(index, CHECK);
 476     if (klass->oop_is_instance()) {
 477       InstanceKlass::cast(klass)->initialize(CHECK);
 478     }
 479   }
 480 C2V_END
 481 
 482 C2V_VMENTRY(jobject, lookupFieldInPool, (JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte opcode))
 483   ResourceMark rm;
 484 
 485   index = GraalCompiler::to_cp_index_u2(index);
 486   constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(constantPoolHolder)))->constants();
 487 
 488   int nt_index = cp->name_and_type_ref_index_at(index);
 489   int sig_index = cp->signature_ref_index_at(nt_index);
 490   Symbol* signature = cp->symbol_at(sig_index);
 491   int name_index = cp->name_ref_index_at(nt_index);
 492   Symbol* name = cp->symbol_at(name_index);
 493   int holder_index = cp->klass_ref_index_at(index);
 494   Handle holder = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
 495   instanceKlassHandle holder_klass;
 496 
 497   Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
 498   int offset = -1;
 499   AccessFlags flags;
 500   BasicType basic_type;
 501   if (holder->klass() == SystemDictionary::HotSpotResolvedObjectType_klass()) {
 502     FieldAccessInfo result;
 503     LinkResolver::resolve_field(result, cp, index,
 504                                 Bytecodes::java_code(code),
 505                                 true, false, Thread::current());
 506     if (HAS_PENDING_EXCEPTION) {
 507       CLEAR_PENDING_EXCEPTION;
 508     } else {
 509       offset = result.field_offset();
 510       flags = result.access_flags();
 511       holder_klass = result.klass()();
 512       basic_type = result.field_type();
 513       holder = GraalCompiler::get_JavaType(holder_klass, CHECK_NULL);
 514     }
 515   }
 516 
 517   Handle type = GraalCompiler::get_JavaTypeFromSignature(signature, cp->pool_holder(), CHECK_NULL);
 518   Handle field_handle = GraalCompiler::get_JavaField(offset, flags.as_int(), name, holder, type, THREAD);
 519 
 520   return JNIHandles::make_local(THREAD, field_handle());
 521 C2V_END
 522 
 523 C2V_VMENTRY(jobject, resolveMethod, (JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature))
 524 
 525   assert(JNIHandles::resolve(resolved_type) != NULL, "");
 526   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(resolved_type));
 527   Symbol* name_symbol = java_lang_String::as_symbol(JNIHandles::resolve(name), THREAD);
 528   Symbol* signature_symbol = java_lang_String::as_symbol(JNIHandles::resolve(signature), THREAD);
 529   methodHandle method = klass->lookup_method(name_symbol, signature_symbol);
 530   if (method.is_null()) {
 531     if (TraceGraal >= 3) {
 532       ResourceMark rm;
 533       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());
 534     }
 535     return NULL;
 536   }
 537   Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL);
 538   return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD));
 539 C2V_END
 540 
 541 C2V_VMENTRY(jboolean, isTypeInitialized,(JNIEnv *, jobject, jobject hotspot_klass))
 542   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(hotspot_klass));
 543   assert(klass != NULL, "method must not be called for primitive types");
 544   return InstanceKlass::cast(klass)->is_initialized();
 545 C2V_END
 546 
 547 C2V_VMENTRY(void, initializeType, (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   InstanceKlass::cast(klass)->initialize(JavaThread::current());
 551 C2V_END
 552 
 553 C2V_VMENTRY(jobject, getInstanceFields, (JNIEnv *, jobject, jobject klass))
 554   ResourceMark rm;
 555 
 556   instanceKlassHandle k = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(klass));
 557   GrowableArray<Handle> fields(k->java_fields_count());
 558 
 559   for (AllFieldStream fs(k()); !fs.done(); fs.next()) {
 560     if (!fs.access_flags().is_static()) {
 561       Handle type = GraalCompiler::get_JavaTypeFromSignature(fs.signature(), k, Thread::current());
 562       int flags = fs.access_flags().as_int();
 563       bool internal = fs.access_flags().is_internal();
 564       Handle name = java_lang_String::create_from_symbol(fs.name(), Thread::current());
 565       Handle field = VMToCompiler::createJavaField(JNIHandles::resolve(klass), name, type, fs.offset(), flags, internal, Thread::current());
 566       fields.append(field());
 567     }
 568   }
 569   objArrayHandle field_array = oopFactory::new_objArray(SystemDictionary::HotSpotResolvedJavaField_klass(), fields.length(), CHECK_NULL);
 570   for (int i = 0; i < fields.length(); ++i) {
 571     field_array->obj_at_put(i, fields.at(i)());
 572   }
 573   return JNIHandles::make_local(field_array());
 574 C2V_END
 575 
 576 C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv *env, jobject, jlong stub))
 577   address target_addr = (address) stub;
 578   if (target_addr != 0x0) {
 579     int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
 580     int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
 581     return MAX2(ABS(off_low), ABS(off_high));
 582   }
 583   return -1;
 584 C2V_END
 585 
 586 C2V_VMENTRY(jobject, getResolvedType, (JNIEnv *env, jobject, jobject javaClass))
 587   oop java_mirror = JNIHandles::resolve(javaClass);
 588   assert(java_mirror != NULL, "argument to CompilerToVM.getResolvedType must not be NULL");
 589   Handle type = GraalCompiler::get_JavaTypeFromClass(java_mirror, CHECK_NULL);
 590   return JNIHandles::make_local(THREAD, type());
 591 C2V_END
 592 
 593 
 594 // helpers used to set fields in the HotSpotVMConfig object
 595 jfieldID getFieldID(JNIEnv* env, jobject obj, const char* name, const char* sig) {
 596   jfieldID id = env->GetFieldID(env->GetObjectClass(obj), name, sig);
 597   if (id == NULL) {
 598     fatal(err_msg("field not found: %s (%s)", name, sig));
 599   }
 600   return id;
 601 }
 602 
 603 BasicType basicTypes[] = { T_BOOLEAN, T_BYTE, T_SHORT, T_CHAR, T_INT, T_FLOAT, T_LONG, T_DOUBLE, T_OBJECT };
 604 int basicTypeCount = sizeof(basicTypes) / sizeof(BasicType);
 605 
 606 C2V_ENTRY(void, initializeConfiguration, (JNIEnv *env, jobject, jobject config))
 607 
 608 #define set_boolean(name, value) do { env->SetBooleanField(config, getFieldID(env, config, name, "Z"), value); } while (0)
 609 #define set_int(name, value) do { env->SetIntField(config, getFieldID(env, config, name, "I"), value); } while (0)
 610 #define set_long(name, value) do { env->SetLongField(config, getFieldID(env, config, name, "J"), value); } while (0)
 611 #define set_stub(name, value) do { set_long(name, (jlong) value); } while (0)
 612 #define set_object(name, value) do { env->SetObjectField(config, getFieldID(env, config, name, "Ljava/lang/Object;"), value); } while (0)
 613 #define set_int_array(name, value) do { env->SetObjectField(config, getFieldID(env, config, name, "[I"), value); } while (0)
 614 
 615   guarantee(HeapWordSize == sizeof(char*), "Graal assumption that HeadWordSize == machine word size is wrong");
 616 #ifdef _WIN64
 617   set_boolean("windowsOs", true);
 618 #else
 619   set_boolean("windowsOs", false);
 620 #endif
 621   set_boolean("verifyOops", VerifyOops);
 622   set_boolean("ciTime", CITime);
 623   set_boolean("useFastLocking", GraalUseFastLocking);
 624   set_boolean("useBiasedLocking", UseBiasedLocking);
 625   set_boolean("usePopCountInstruction", UsePopCountInstruction);
 626   set_boolean("useAESIntrinsics", UseAESIntrinsics);
 627   set_boolean("useTLAB", UseTLAB);
 628   set_boolean("useG1GC", UseG1GC);
 629   set_int("codeEntryAlignment", CodeEntryAlignment);
 630   set_int("stackShadowPages", StackShadowPages);
 631   set_int("hubOffset", oopDesc::klass_offset_in_bytes());
 632   set_int("markOffset", oopDesc::mark_offset_in_bytes());
 633   set_int("prototypeMarkWordOffset", in_bytes(Klass::prototype_header_offset()));
 634   set_int("superCheckOffsetOffset", in_bytes(Klass::super_check_offset_offset()));
 635   set_int("secondarySuperCacheOffset", in_bytes(Klass::secondary_super_cache_offset()));
 636   set_int("secondarySupersOffset", in_bytes(Klass::secondary_supers_offset()));
 637   set_int("subklassOffset", in_bytes(Klass::subklass_offset()));
 638   set_int("nextSiblingOffset", in_bytes(Klass::next_sibling_offset()));
 639   set_int("arrayLengthOffset", arrayOopDesc::length_offset_in_bytes());
 640   set_int("klassStateOffset", in_bytes(InstanceKlass::init_state_offset()));
 641   set_int("klassStateFullyInitialized", (int)InstanceKlass::fully_initialized);
 642   set_int("threadTlabTopOffset", in_bytes(JavaThread::tlab_top_offset()));
 643   set_int("threadTlabEndOffset", in_bytes(JavaThread::tlab_end_offset()));
 644   set_int("threadObjectOffset", in_bytes(JavaThread::threadObj_offset()));
 645   set_int("osThreadOffset", in_bytes(JavaThread::osthread_offset()));
 646   set_int("osThreadInterruptedOffset", in_bytes(OSThread::interrupted_offset()));
 647   set_int("unlockedMask", (int) markOopDesc::unlocked_value);
 648   set_int("biasedLockMaskInPlace", (int) markOopDesc::biased_lock_mask_in_place);
 649   set_int("ageMaskInPlace", (int) markOopDesc::age_mask_in_place);
 650   set_int("epochMaskInPlace", (int) markOopDesc::epoch_mask_in_place);
 651   set_int("biasedLockPattern", (int) markOopDesc::biased_lock_pattern);
 652   set_int("methodMaxLocalsOffset", in_bytes(ConstMethod::size_of_locals_offset()));
 653   set_int("methodConstMethodOffset", in_bytes(Method::const_offset()));
 654   set_int("constMethodMaxStackOffset", in_bytes(ConstMethod::max_stack_offset()));
 655   set_int("extraStackEntries", Method::extra_stack_entries());
 656   set_int("methodAccessFlagsOffset", in_bytes(Method::access_flags_offset()));
 657   set_int("klassHasFinalizerFlag", JVM_ACC_HAS_FINALIZER);
 658   set_int("threadExceptionOopOffset", in_bytes(JavaThread::exception_oop_offset()));
 659   set_int("threadExceptionPcOffset", in_bytes(JavaThread::exception_pc_offset()));
 660   set_boolean("isPollingPageFar", Assembler::is_polling_page_far());
 661   set_int("classMirrorOffset", in_bytes(Klass::java_mirror_offset()));
 662   set_int("runtimeCallStackSize", (jint)frame::arg_reg_save_area_bytes);
 663   set_int("klassModifierFlagsOffset", in_bytes(Klass::modifier_flags_offset()));
 664   set_int("klassAccessFlagsOffset", in_bytes(Klass::access_flags_offset()));
 665   set_int("klassOffset", java_lang_Class::klass_offset_in_bytes());
 666   set_int("graalMirrorInClassOffset", java_lang_Class::graal_mirror_offset_in_bytes());
 667   set_int("klassLayoutHelperOffset", in_bytes(Klass::layout_helper_offset()));
 668   set_int("klassSuperKlassOffset", in_bytes(Klass::super_offset()));
 669   set_int("methodDataOffset", in_bytes(Method::method_data_offset()));
 670   set_int("nmethodEntryOffset", nmethod::verified_entry_point_offset());
 671   set_int("methodCompiledEntryOffset", in_bytes(Method::from_compiled_offset()));
 672   set_int("basicLockSize", sizeof(BasicLock));
 673   set_int("basicLockDisplacedHeaderOffset", BasicLock::displaced_header_offset_in_bytes());
 674   set_int("uninitializedIdentityHashCodeValue", markOopDesc::no_hash);
 675   set_int("identityHashCodeShift", markOopDesc::hash_shift);
 676 
 677   set_int("arrayKlassLayoutHelperIdentifier", 0x80000000);
 678   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");
 679   set_int("arrayKlassComponentMirrorOffset", in_bytes(ArrayKlass::component_mirror_offset()));
 680 
 681 
 682   set_int("pendingDeoptimizationOffset", in_bytes(ThreadShadow::pending_deoptimization_offset()));
 683 
 684   set_int("metaspaceArrayLengthOffset", Array<Klass*>::length_offset_in_bytes());
 685   set_int("metaspaceArrayBaseOffset", Array<Klass*>::base_offset_in_bytes());
 686   set_int("methodDataOopDataOffset", in_bytes(MethodData::data_offset()));
 687   set_int("methodDataOopTrapHistoryOffset", in_bytes(MethodData::trap_history_offset()));
 688   set_int("dataLayoutHeaderSize", DataLayout::header_size_in_bytes());
 689   set_int("dataLayoutTagOffset", in_bytes(DataLayout::tag_offset()));
 690   set_int("dataLayoutFlagsOffset", in_bytes(DataLayout::flags_offset()));
 691   set_int("dataLayoutBCIOffset", in_bytes(DataLayout::bci_offset()));
 692   set_int("dataLayoutCellsOffset", in_bytes(DataLayout::cell_offset(0)));
 693   set_int("dataLayoutCellSize", DataLayout::cell_size);
 694   set_int("bciProfileWidth", BciProfileWidth);
 695   set_int("typeProfileWidth", TypeProfileWidth);
 696 
 697   set_int("tlabAlignmentReserve", (int32_t)ThreadLocalAllocBuffer::alignment_reserve());
 698   set_long("tlabIntArrayMarkWord", (intptr_t)markOopDesc::prototype()->copy_set_hash(0x2));
 699   set_long("heapTopAddress", (jlong)(address) Universe::heap()->top_addr());
 700   set_long("heapEndAddress", (jlong)(address) Universe::heap()->end_addr());
 701   set_int("threadTlabStartOffset", in_bytes(JavaThread::tlab_start_offset()));
 702   set_int("threadTlabSizeOffset", in_bytes(JavaThread::tlab_size_offset()));
 703   set_int("threadAllocatedBytesOffset", in_bytes(JavaThread::allocated_bytes_offset()));
 704   set_int("tlabSlowAllocationsOffset", in_bytes(JavaThread::tlab_slow_allocations_offset()));
 705   set_int("tlabFastRefillWasteOffset", in_bytes(JavaThread::tlab_fast_refill_waste_offset()));
 706   set_int("tlabNumberOfRefillsOffset", in_bytes(JavaThread::tlab_number_of_refills_offset()));
 707   set_int("tlabRefillWasteLimitOffset", in_bytes(JavaThread::tlab_refill_waste_limit_offset()));
 708   set_int("tlabRefillWasteIncrement", (int32_t) ThreadLocalAllocBuffer::refill_waste_limit_increment());
 709   set_int("klassInstanceSizeOffset", in_bytes(Klass::layout_helper_offset()));
 710   set_boolean("tlabStats", TLABStats);
 711   set_boolean("inlineContiguousAllocationSupported", !CMSIncrementalMode && Universe::heap()->supports_inline_contig_alloc());
 712 
 713   set_long("arrayPrototypeMarkWord", (intptr_t)markOopDesc::prototype());
 714   set_int("layoutHelperLog2ElementSizeShift", Klass::_lh_log2_element_size_shift);
 715   set_int("layoutHelperLog2ElementSizeMask", Klass::_lh_log2_element_size_mask);
 716   set_int("layoutHelperElementTypeShift", Klass::_lh_element_type_shift);
 717   set_int("layoutHelperElementTypeMask", Klass::_lh_element_type_mask);
 718   // this filters out the bit that differentiates a type array from an object array
 719   set_int("layoutHelperElementTypePrimitiveInPlace", (Klass::_lh_array_tag_type_value & ~Klass::_lh_array_tag_obj_value) << Klass::_lh_array_tag_shift);
 720   set_int("layoutHelperHeaderSizeShift", Klass::_lh_header_size_shift);
 721   set_int("layoutHelperHeaderSizeMask", Klass::_lh_header_size_mask);
 722   set_int("layoutHelperOffset", in_bytes(Klass::layout_helper_offset()));
 723 
 724 
 725   set_stub("wbPreCallStub", GraalRuntime::entry_for(GraalRuntime::wb_pre_call_id));
 726   set_stub("wbPostCallStub", GraalRuntime::entry_for(GraalRuntime::wb_post_call_id));
 727 
 728   set_stub("newInstanceStub", GraalRuntime::entry_for(GraalRuntime::new_instance_id));
 729   set_stub("newArrayStub", GraalRuntime::entry_for(GraalRuntime::new_array_id));
 730   set_stub("newMultiArrayStub", GraalRuntime::entry_for(GraalRuntime::new_multi_array_id));
 731   set_stub("identityHashCodeStub", GraalRuntime::entry_for(GraalRuntime::identity_hash_code_id));
 732   set_stub("threadIsInterruptedStub", GraalRuntime::entry_for(GraalRuntime::thread_is_interrupted_id));
 733   set_stub("inlineCacheMissStub", SharedRuntime::get_ic_miss_stub());
 734   set_stub("handleExceptionStub", GraalRuntime::entry_for(GraalRuntime::handle_exception_nofpu_id));
 735   set_stub("handleDeoptStub", SharedRuntime::deopt_blob()->unpack());
 736   set_stub("monitorEnterStub", GraalRuntime::entry_for(GraalRuntime::monitorenter_id));
 737   set_stub("monitorExitStub", GraalRuntime::entry_for(GraalRuntime::monitorexit_id));
 738   set_stub("verifyOopStub", GraalRuntime::entry_for(GraalRuntime::verify_oop_id));
 739   set_stub("vmErrorStub", GraalRuntime::entry_for(GraalRuntime::vm_error_id));
 740   set_stub("deoptimizeStub", SharedRuntime::deopt_blob()->uncommon_trap());
 741   set_stub("unwindExceptionStub", GraalRuntime::entry_for(GraalRuntime::unwind_exception_call_id));
 742   set_stub("osrMigrationEndStub", GraalRuntime::entry_for(GraalRuntime::OSR_migration_end_id));
 743   set_stub("registerFinalizerStub", GraalRuntime::entry_for(GraalRuntime::register_finalizer_id));
 744   set_stub("createNullPointerExceptionStub", GraalRuntime::entry_for(GraalRuntime::create_null_pointer_exception_id));
 745   set_stub("createOutOfBoundsExceptionStub", GraalRuntime::entry_for(GraalRuntime::create_out_of_bounds_exception_id));
 746   set_stub("javaTimeMillisStub", CAST_FROM_FN_PTR(address, os::javaTimeMillis));
 747   set_stub("javaTimeNanosStub", CAST_FROM_FN_PTR(address, os::javaTimeNanos));
 748   set_stub("arithmeticFremStub", GraalRuntime::entry_for(GraalRuntime::arithmetic_frem_id));
 749   set_stub("arithmeticDremStub", GraalRuntime::entry_for(GraalRuntime::arithmetic_drem_id));
 750   set_stub("arithmeticSinStub", CAST_FROM_FN_PTR(address, SharedRuntime::dsin));
 751   set_stub("arithmeticCosStub", CAST_FROM_FN_PTR(address, SharedRuntime::dcos));
 752   set_stub("arithmeticTanStub", CAST_FROM_FN_PTR(address, SharedRuntime::dtan));
 753   set_stub("logPrimitiveStub", GraalRuntime::entry_for(GraalRuntime::log_primitive_id));
 754   set_stub("logObjectStub", GraalRuntime::entry_for(GraalRuntime::log_object_id));
 755   set_stub("logPrintfStub", GraalRuntime::entry_for(GraalRuntime::log_printf_id));
 756   set_stub("aescryptEncryptBlockStub", StubRoutines::aescrypt_encryptBlock());
 757   set_stub("aescryptDecryptBlockStub", StubRoutines::aescrypt_decryptBlock());
 758   set_stub("cipherBlockChainingEncryptAESCryptStub", StubRoutines::cipherBlockChaining_encryptAESCrypt());
 759   set_stub("cipherBlockChainingDecryptAESCryptStub", StubRoutines::cipherBlockChaining_decryptAESCrypt());
 760 
 761   set_int("deoptReasonNone", Deoptimization::Reason_none);
 762   set_int("deoptReasonNullCheck", Deoptimization::Reason_null_check);
 763   set_int("deoptReasonRangeCheck", Deoptimization::Reason_range_check);
 764   set_int("deoptReasonClassCheck", Deoptimization::Reason_class_check);
 765   set_int("deoptReasonArrayCheck", Deoptimization::Reason_array_check);
 766   set_int("deoptReasonUnreached0", Deoptimization::Reason_unreached0);
 767   set_int("deoptReasonTypeCheckInlining", Deoptimization::Reason_type_checked_inlining);
 768   set_int("deoptReasonOptimizedTypeCheck", Deoptimization::Reason_optimized_type_check);
 769   set_int("deoptReasonNotCompiledExceptionHandler", Deoptimization::Reason_not_compiled_exception_handler);
 770   set_int("deoptReasonUnresolved", Deoptimization::Reason_unresolved);
 771   set_int("deoptReasonJsrMismatch", Deoptimization::Reason_jsr_mismatch);
 772   set_int("deoptReasonDiv0Check", Deoptimization::Reason_div0_check);
 773   set_int("deoptReasonConstraint", Deoptimization::Reason_constraint);
 774 
 775   set_int("deoptActionNone", Deoptimization::Action_none);
 776   set_int("deoptActionMaybeRecompile", Deoptimization::Action_maybe_recompile);
 777   set_int("deoptActionReinterpret", Deoptimization::Action_reinterpret);
 778   set_int("deoptActionMakeNotEntrant", Deoptimization::Action_make_not_entrant);
 779   set_int("deoptActionMakeNotCompilable", Deoptimization::Action_make_not_compilable);
 780   set_int("g1CardQueueIndexOffset", in_bytes(JavaThread::dirty_card_queue_offset() + PtrQueue::byte_offset_of_index()));
 781   set_int("g1CardQueueBufferOffset", in_bytes(JavaThread::dirty_card_queue_offset() + PtrQueue::byte_offset_of_buf()));
 782   set_int("logOfHRGrainBytes", HeapRegion::LogOfHRGrainBytes);
 783   set_int("g1SATBQueueMarkingOffset", in_bytes(JavaThread::satb_mark_queue_offset() + PtrQueue::byte_offset_of_active()));
 784   set_int("g1SATBQueueIndexOffset", in_bytes(JavaThread::satb_mark_queue_offset() +  PtrQueue::byte_offset_of_index()));
 785   set_int("g1SATBQueueBufferOffset", in_bytes(JavaThread::satb_mark_queue_offset() + PtrQueue::byte_offset_of_buf()));
 786 
 787   BarrierSet* bs = Universe::heap()->barrier_set();
 788   switch (bs->kind()) {
 789     case BarrierSet::CardTableModRef:
 790     case BarrierSet::CardTableExtension:
 791     case BarrierSet::G1SATBCT:
 792     case BarrierSet::G1SATBCTLogging:{
 793       jlong base = (jlong)((CardTableModRefBS*)bs)->byte_map_base;
 794       assert(base != 0, "unexpected byte_map_base");
 795       set_long("cardtableStartAddress", base);
 796       set_int("cardtableShift", CardTableModRefBS::card_shift);
 797       break;
 798     }
 799     case BarrierSet::ModRef:
 800     case BarrierSet::Other:
 801       set_long("cardtableStartAddress", 0);
 802       set_int("cardtableShift", 0);
 803       // No post barriers
 804       break;
 805     default:
 806       ShouldNotReachHere();
 807       break;
 808     }
 809 
 810   set_int("arrayClassElementOffset", in_bytes(ObjArrayKlass::element_klass_offset()));
 811 
 812 #undef set_boolean
 813 #undef set_int
 814 #undef set_long
 815 #undef set_object
 816 #undef set_int_array
 817 
 818 C2V_END
 819 
 820 C2V_VMENTRY(jint, installCode0, (JNIEnv *jniEnv, jobject, jobject compResult, jobject installed_code, jobject triggered_deoptimizations))
 821   ResourceMark rm;
 822   HandleMark hm;
 823   Handle compResultHandle = JNIHandles::resolve(compResult);
 824   nmethod* nm = NULL;
 825   methodHandle method = getMethodFromHotSpotMethod(HotSpotCompilationResult::method(compResult));
 826   Handle installed_code_handle = JNIHandles::resolve(installed_code);
 827   Handle triggered_deoptimizations_handle = JNIHandles::resolve(triggered_deoptimizations);
 828   GraalEnv::CodeInstallResult result;
 829   CodeInstaller installer(compResultHandle, method, result, nm, installed_code_handle, triggered_deoptimizations_handle);
 830 
 831   if (PrintCodeCacheOnCompilation) {
 832     stringStream s;
 833     // Dump code cache  into a buffer before locking the tty,
 834     {
 835       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 836       CodeCache::print_summary(&s, false);
 837     }
 838     ttyLocker ttyl;
 839     tty->print_cr(s.as_string());
 840   }
 841 
 842   if (result != GraalEnv::ok) {
 843     assert(nm == NULL, "should be");
 844   } else {
 845     if (!installed_code_handle.is_null()) {
 846       assert(installed_code_handle->is_a(HotSpotInstalledCode::klass()), "wrong type");
 847       HotSpotInstalledCode::set_nmethod(installed_code_handle, (jlong) nm);
 848       HotSpotInstalledCode::set_method(installed_code_handle, HotSpotCompilationResult::method(compResult));
 849       HotSpotInstalledCode::set_start(installed_code_handle, (jlong) nm->code_begin());
 850       assert(nm == NULL || !installed_code_handle->is_scavengable() || nm->on_scavenge_root_list(), "nm should be scavengable if installed_code is scavengable");
 851     }
 852   }
 853   return result;
 854 C2V_END
 855 
 856 C2V_VMENTRY(void, clearQueuedForCompilation, (JNIEnv *jniEnv, jobject, jobject resolvedMethod))
 857   methodHandle method = getMethodFromHotSpotMethod(JNIHandles::resolve(resolvedMethod));
 858   method->clear_queued_for_compilation();
 859 C2V_END
 860 
 861 C2V_VMENTRY(jobject, getCode, (JNIEnv *jniEnv, jobject,  jlong metaspace_nmethod))
 862   ResourceMark rm;
 863   HandleMark hm;
 864 
 865   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 866   if (nm == NULL || !nm->is_alive()) {
 867     return NULL;
 868   }
 869   int length = nm->code_size();
 870   arrayOop codeCopy = oopFactory::new_byteArray(length, CHECK_0);
 871   memcpy(codeCopy->base(T_BYTE), nm->code_begin(), length);
 872   return JNIHandles::make_local(codeCopy);
 873 C2V_END
 874 
 875 C2V_VMENTRY(jobject, disassembleNMethod, (JNIEnv *jniEnv, jobject, jlong metaspace_nmethod))
 876   ResourceMark rm;
 877   HandleMark hm;
 878 
 879   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 880   if (nm == NULL || !nm->is_alive()) {
 881     return NULL;
 882   }
 883   stringStream(st);
 884   Disassembler::decode(nm, &st);
 885 
 886   Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
 887   return JNIHandles::make_local(result());
 888 C2V_END
 889 
 890 C2V_VMENTRY(jobject, getStackTraceElement, (JNIEnv *env, jobject, jlong metaspace_method, int bci))
 891   ResourceMark rm;
 892   HandleMark hm;
 893 
 894   methodHandle method = asMethod(metaspace_method);
 895   oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL);
 896   return JNIHandles::make_local(element);
 897 C2V_END
 898 
 899 C2V_VMENTRY(jobject, executeCompiledMethodVarargs, (JNIEnv *env, jobject, jlong metaspace_method, jlong metaspace_nmethod, jobject args))
 900   ResourceMark rm;
 901   HandleMark hm;
 902 
 903   assert(metaspace_method != 0, "just checking");
 904   methodHandle mh = asMethod(metaspace_method);
 905   Symbol* signature = mh->signature();
 906   JavaCallArguments jca(mh->size_of_parameters());
 907 
 908   JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
 909   JavaValue result(jap.get_ret_type());
 910 
 911   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 912   if (nm == NULL || !nm->is_alive()) {
 913     THROW_0(vmSymbols::MethodInvalidatedException());
 914   }
 915 
 916   jca.set_alternative_target(nm);
 917   JavaCalls::call(&result, mh, &jca, CHECK_NULL);
 918 
 919   if (jap.get_ret_type() == T_VOID) {
 920     return NULL;
 921   } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) {
 922     return JNIHandles::make_local((oop) result.get_jobject());
 923   } else {
 924     oop o = java_lang_boxing_object::create(jap.get_ret_type(), (jvalue *) result.get_value_addr(), CHECK_NULL);
 925     return JNIHandles::make_local(o);
 926   }
 927 C2V_END
 928 
 929 C2V_VMENTRY(jobject, executeCompiledMethod, (JNIEnv *env, jobject, jlong metaspace_method, jlong metaspace_nmethod, jobject arg1, jobject arg2, jobject arg3))
 930   ResourceMark rm;
 931   HandleMark hm;
 932 
 933   methodHandle method = asMethod(metaspace_method);
 934   assert(!method.is_null(), "just checking");
 935   JavaValue result(T_OBJECT);
 936   JavaCallArguments args;
 937   args.push_oop(JNIHandles::resolve(arg1));
 938   args.push_oop(JNIHandles::resolve(arg2));
 939   args.push_oop(JNIHandles::resolve(arg3));
 940 
 941   nmethod* nm = (nmethod*) (address) metaspace_nmethod;
 942   if (nm == NULL || !nm->is_alive()) {
 943     THROW_0(vmSymbols::MethodInvalidatedException());
 944   }
 945 
 946   args.set_alternative_target(nm);
 947   JavaCalls::call(&result, method, &args, CHECK_NULL);
 948 
 949   return JNIHandles::make_local((oop) result.get_jobject());
 950 C2V_END
 951 
 952 C2V_VMENTRY(jint, getVtableEntryOffset, (JNIEnv *, jobject, jlong metaspace_method))
 953 
 954   Method* method = asMethod(metaspace_method);
 955   assert(!InstanceKlass::cast(method->method_holder())->is_interface(), "vtableEntryOffset cannot be called for interface methods");
 956   assert(InstanceKlass::cast(method->method_holder())->is_linked(), "vtableEntryOffset cannot be called is holder is not linked");
 957 
 958   // get entry offset in words
 959   int vtable_entry_offset = InstanceKlass::vtable_start_offset() + method->vtable_index() * vtableEntry::size();
 960   // convert to bytes
 961   vtable_entry_offset = vtable_entry_offset * wordSize + vtableEntry::method_offset_in_bytes();
 962 
 963   return vtable_entry_offset;
 964 C2V_END
 965 
 966 C2V_VMENTRY(jobject, getDeoptedLeafGraphIds, (JNIEnv *, jobject))
 967 
 968   // the contract for this method is as follows:
 969   // returning null: no deopted leaf graphs
 970   // returning array (size > 0): the ids of the deopted leaf graphs
 971   // returning array (size == 0): there was an overflow, the compiler needs to clear its cache completely
 972 
 973   oop array = GraalCompiler::instance()->dump_deopted_leaf_graphs(CHECK_NULL);
 974   return JNIHandles::make_local(array);
 975 C2V_END
 976 
 977 C2V_ENTRY(jlongArray, getLineNumberTable, (JNIEnv *env, jobject, jobject hotspot_method))
 978   Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method));
 979   if (!method->has_linenumber_table()) {
 980     return NULL;
 981   }
 982   u2 num_entries = 0;
 983   CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table());
 984   while (streamForSize.read_pair()) {
 985     num_entries++;
 986   }
 987 
 988   CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
 989   jlongArray result = env->NewLongArray(2 * num_entries);
 990 
 991   int i = 0;
 992   jlong value;
 993   while (stream.read_pair()) {
 994     value = ((long) stream.bci());
 995     env->SetLongArrayRegion(result,i,1,&value);
 996     value = ((long) stream.line());
 997     env->SetLongArrayRegion(result,i + 1,1,&value);
 998     i += 2;
 999   }
1000 
1001   return result;
1002 C2V_END
1003 
1004 C2V_VMENTRY(jobject, getLocalVariableTable, (JNIEnv *, jobject, jobject hotspot_method))
1005   ResourceMark rm;
1006 
1007   Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method));
1008   if (!method->has_localvariable_table()) {
1009     return NULL;
1010   }
1011   int localvariable_table_length = method->localvariable_table_length();
1012 
1013   objArrayHandle local_array = oopFactory::new_objArray(SystemDictionary::LocalImpl_klass(), localvariable_table_length, CHECK_NULL);
1014   LocalVariableTableElement* table = method->localvariable_table_start();
1015   for (int i = 0; i < localvariable_table_length; i++) {
1016     u2 start_bci = table[i].start_bci;
1017     u4 end_bci = (u4)(start_bci + table[i].length);
1018     u2 nameCPIdx = table[i].name_cp_index;
1019     u2 typeCPIdx = table[i].descriptor_cp_index;
1020     u2 slot = table[i].slot;
1021 
1022     char* name = method->constants()->string_at_noresolve(nameCPIdx);
1023     Handle nameHandle = java_lang_String::create_from_str(name, CHECK_NULL);
1024 
1025     char* typeInfo = method->constants()->string_at_noresolve(typeCPIdx);
1026     Handle typeHandle = java_lang_String::create_from_str(typeInfo, CHECK_NULL);
1027 
1028     Handle holderHandle = GraalCompiler::createHotSpotResolvedObjectType(method, CHECK_0);
1029     Handle local = VMToCompiler::createLocal(nameHandle, typeHandle, (int) start_bci, (int) end_bci, (int) slot, holderHandle, Thread::current());
1030     local_array->obj_at_put(i, local());
1031   }
1032 
1033   return JNIHandles::make_local(local_array());
1034 C2V_END
1035 
1036 
1037 C2V_VMENTRY(jobject, getFileName, (JNIEnv *, jobject, jobject klass))
1038   ResourceMark rm;
1039   InstanceKlass* k = (InstanceKlass*) asKlass(HotSpotResolvedObjectType::metaspaceKlass(klass));
1040   Symbol *s = k->source_file_name();
1041   int length;
1042   jchar *name = s->as_unicode(length);
1043 
1044   Handle result = java_lang_String::create_from_unicode(name, length, CHECK_NULL);
1045   return JNIHandles::make_local(result());
1046 
1047 C2V_END
1048 
1049 
1050 C2V_VMENTRY(void, reprofile, (JNIEnv *env, jobject, jlong metaspace_method))
1051   Method* method = asMethod(metaspace_method);
1052   method->reset_counters();
1053 
1054   nmethod* code = method->code();
1055   if (code != NULL) {
1056     code->make_not_entrant();
1057   }
1058 
1059   MethodData* method_data = method->method_data();
1060   if (method_data == NULL) {
1061     ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
1062     method_data = MethodData::allocate(loader_data, method, CHECK);
1063     method->set_method_data(method_data);
1064   } else {
1065     method_data->initialize();
1066   }
1067 C2V_END
1068 
1069 
1070 
1071 #define CC (char*)  /*cast a literal from (const char*)*/
1072 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
1073 
1074 #define RESOLVED_TYPE         "Lcom/oracle/graal/api/meta/ResolvedJavaType;"
1075 #define TYPE                  "Lcom/oracle/graal/api/meta/JavaType;"
1076 #define METHOD                "Lcom/oracle/graal/api/meta/JavaMethod;"
1077 #define FIELD                 "Lcom/oracle/graal/api/meta/JavaField;"
1078 #define SIGNATURE             "Lcom/oracle/graal/api/meta/Signature;"
1079 #define CONSTANT_POOL         "Lcom/oracle/graal/api/meta/ConstantPool;"
1080 #define CONSTANT              "Lcom/oracle/graal/api/meta/Constant;"
1081 #define KIND                  "Lcom/oracle/graal/api/meta/Kind;"
1082 #define LOCAL                  "Lcom/oracle/graal/api/meta/Local;"
1083 #define RUNTIME_CALL          "Lcom/oracle/graal/api/code/RuntimeCall;"
1084 #define EXCEPTION_HANDLERS    "[Lcom/oracle/graal/api/meta/ExceptionHandler;"
1085 #define REFLECT_METHOD        "Ljava/lang/reflect/Method;"
1086 #define REFLECT_CONSTRUCTOR   "Ljava/lang/reflect/Constructor;"
1087 #define REFLECT_FIELD         "Ljava/lang/reflect/Field;"
1088 #define STRING                "Ljava/lang/String;"
1089 #define OBJECT                "Ljava/lang/Object;"
1090 #define CLASS                 "Ljava/lang/Class;"
1091 #define STACK_TRACE_ELEMENT   "Ljava/lang/StackTraceElement;"
1092 #define HS_RESOLVED_TYPE      "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;"
1093 #define HS_RESOLVED_JAVA_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaType;"
1094 #define HS_RESOLVED_METHOD    "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;"
1095 #define HS_RESOLVED_FIELD     "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaField;"
1096 #define HS_COMP_RESULT        "Lcom/oracle/graal/hotspot/HotSpotCompilationResult;"
1097 #define HS_CONFIG             "Lcom/oracle/graal/hotspot/HotSpotVMConfig;"
1098 #define HS_METHOD             "Lcom/oracle/graal/hotspot/meta/HotSpotMethod;"
1099 #define HS_INSTALLED_CODE     "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;"
1100 #define METHOD_DATA           "Lcom/oracle/graal/hotspot/meta/HotSpotMethodData;"
1101 #define METASPACE_METHOD      "J"
1102 #define METASPACE_METHOD_DATA "J"
1103 #define NMETHOD               "J"
1104 
1105 JNINativeMethod CompilerToVM_methods[] = {
1106   {CC"initializeBytecode",            CC"("METASPACE_METHOD"[B)[B",                                     FN_PTR(initializeBytecode)},
1107   {CC"getSignature",                  CC"("METASPACE_METHOD")"STRING,                                   FN_PTR(getSignature)},
1108   {CC"initializeExceptionHandlers",   CC"("METASPACE_METHOD EXCEPTION_HANDLERS")"EXCEPTION_HANDLERS,    FN_PTR(initializeExceptionHandlers)},
1109   {CC"hasBalancedMonitors",           CC"("METASPACE_METHOD")Z",                                        FN_PTR(hasBalancedMonitors)},
1110   {CC"getUniqueConcreteMethod",       CC"("METASPACE_METHOD"["HS_RESOLVED_TYPE")"METASPACE_METHOD,      FN_PTR(getUniqueConcreteMethod)},
1111   {CC"getUniqueImplementor",          CC"("HS_RESOLVED_TYPE")"RESOLVED_TYPE,                            FN_PTR(getUniqueImplementor)},
1112   {CC"getStackTraceElement",          CC"("METASPACE_METHOD"I)"STACK_TRACE_ELEMENT,                     FN_PTR(getStackTraceElement)},
1113   {CC"initializeMethod",              CC"("METASPACE_METHOD HS_RESOLVED_METHOD")V",                     FN_PTR(initializeMethod)},
1114   {CC"initializeMethodData",          CC"("METASPACE_METHOD_DATA METHOD_DATA")V",                       FN_PTR(initializeMethodData)},
1115   {CC"isMethodCompilable",            CC"("METASPACE_METHOD")Z",                                        FN_PTR(isMethodCompilable)},
1116   {CC"getInvocationCount",            CC"("METASPACE_METHOD")I",                                        FN_PTR(getInvocationCount)},
1117   {CC"getCompiledCodeSize",           CC"("METASPACE_METHOD")I",                                        FN_PTR(getCompiledCodeSize)},
1118   {CC"getVtableEntryOffset",          CC"("METASPACE_METHOD")I",                                        FN_PTR(getVtableEntryOffset)},
1119   {CC"lookupType",                    CC"("STRING HS_RESOLVED_TYPE"Z)"TYPE,                             FN_PTR(lookupType)},
1120   {CC"lookupConstantInPool",          CC"("HS_RESOLVED_TYPE"I)"OBJECT,                                  FN_PTR(lookupConstantInPool)},
1121   {CC"lookupAppendixInPool",          CC"("HS_RESOLVED_TYPE"I)"OBJECT,                                  FN_PTR(lookupAppendixInPool)},
1122   {CC"lookupMethodInPool",            CC"("HS_RESOLVED_TYPE"IB)"METHOD,                                 FN_PTR(lookupMethodInPool)},
1123   {CC"lookupTypeInPool",              CC"("HS_RESOLVED_TYPE"I)"TYPE,                                    FN_PTR(lookupTypeInPool)},
1124   {CC"lookupReferencedTypeInPool",    CC"("HS_RESOLVED_TYPE"IB)V",                                      FN_PTR(lookupReferencedTypeInPool)},
1125   {CC"lookupFieldInPool",             CC"("HS_RESOLVED_TYPE"IB)"FIELD,                                  FN_PTR(lookupFieldInPool)},
1126   {CC"resolveMethod",                 CC"("HS_RESOLVED_TYPE STRING STRING")"METHOD,                     FN_PTR(resolveMethod)},
1127   {CC"getInstanceFields",             CC"("HS_RESOLVED_TYPE")["HS_RESOLVED_FIELD,                       FN_PTR(getInstanceFields)},
1128   {CC"isTypeInitialized",             CC"("HS_RESOLVED_TYPE")Z",                                        FN_PTR(isTypeInitialized)},
1129   {CC"initializeType",                CC"("HS_RESOLVED_TYPE")V",                                        FN_PTR(initializeType)},
1130   {CC"getMaxCallTargetOffset",        CC"(J)J",                                                         FN_PTR(getMaxCallTargetOffset)},
1131   {CC"getResolvedType",               CC"("CLASS")"RESOLVED_TYPE,                                       FN_PTR(getResolvedType)},
1132   {CC"getMetaspaceMethod",            CC"("REFLECT_METHOD"["HS_RESOLVED_TYPE")"METASPACE_METHOD,        FN_PTR(getMetaspaceMethod)},
1133   {CC"getMetaspaceConstructor",       CC"("REFLECT_CONSTRUCTOR"["HS_RESOLVED_TYPE")"METASPACE_METHOD,   FN_PTR(getMetaspaceConstructor)},
1134   {CC"getJavaField",                  CC"("REFLECT_FIELD")"HS_RESOLVED_FIELD,                           FN_PTR(getJavaField)},
1135   {CC"initializeConfiguration",       CC"("HS_CONFIG")V",                                               FN_PTR(initializeConfiguration)},
1136   {CC"installCode0",                  CC"("HS_COMP_RESULT HS_INSTALLED_CODE"[Z)I",                      FN_PTR(installCode0)},
1137   {CC"getCode",                       CC"(J)[B",                                                        FN_PTR(getCode)},
1138   {CC"disassembleNMethod",            CC"(J)"STRING,                                                    FN_PTR(disassembleNMethod)},
1139   {CC"executeCompiledMethod",         CC"("METASPACE_METHOD NMETHOD OBJECT OBJECT OBJECT")"OBJECT,      FN_PTR(executeCompiledMethod)},
1140   {CC"executeCompiledMethodVarargs",  CC"("METASPACE_METHOD NMETHOD "["OBJECT")"OBJECT,                 FN_PTR(executeCompiledMethodVarargs)},
1141   {CC"getDeoptedLeafGraphIds",        CC"()[J",                                                         FN_PTR(getDeoptedLeafGraphIds)},
1142   {CC"getLineNumberTable",            CC"("HS_RESOLVED_METHOD")[J",                                     FN_PTR(getLineNumberTable)},
1143   {CC"getLocalVariableTable",         CC"("HS_RESOLVED_METHOD")["LOCAL,                                 FN_PTR(getLocalVariableTable)},
1144   {CC"getFileName",                   CC"("HS_RESOLVED_JAVA_TYPE")"STRING,                              FN_PTR(getFileName)},
1145   {CC"clearQueuedForCompilation",     CC"("HS_RESOLVED_METHOD")V",                                      FN_PTR(clearQueuedForCompilation)},
1146   {CC"reprofile",                     CC"("METASPACE_METHOD")V",                                        FN_PTR(reprofile)},
1147 };
1148 
1149 int CompilerToVM_methods_count() {
1150   return sizeof(CompilerToVM_methods) / sizeof(JNINativeMethod);
1151 }
1152