comparison src/share/vm/graal/graalCompilerToVM.cpp @ 8945:7ef66078d837

add basic invokedynamic support
author Andreas Woess <andreas.woess@jku.at>
date Tue, 09 Apr 2013 17:11:17 +0200
parents cd9e8dd9f488
children 0ba33199edc0
comparison
equal deleted inserted replaced
8939:8fab4f4fde34 8945:7ef66078d837
60 #define C2V_END } 60 #define C2V_END }
61 61
62 C2V_ENTRY(jbyteArray, initializeBytecode, (JNIEnv *env, jobject, jlong metaspace_method, jbyteArray result)) 62 C2V_ENTRY(jbyteArray, initializeBytecode, (JNIEnv *env, jobject, jlong metaspace_method, jbyteArray result))
63 methodHandle method = asMethod(metaspace_method); 63 methodHandle method = asMethod(metaspace_method);
64 ResourceMark rm; 64 ResourceMark rm;
65 65
66 int code_size = method->code_size(); 66 int code_size = method->code_size();
67 jbyte* reconstituted_code = NULL; 67 jbyte* reconstituted_code = NULL;
68 68
69 // replace all breakpoints - must be done before undoing any rewriting 69 // replace all breakpoints - must be done before undoing any rewriting
70 if (method->number_of_breakpoints() > 0) { 70 if (method->number_of_breakpoints() > 0) {
414 } 414 }
415 415
416 return JNIHandles::make_local(THREAD, result); 416 return JNIHandles::make_local(THREAD, result);
417 C2V_END 417 C2V_END
418 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
419 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode)) 427 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode))
420 index = GraalCompiler::to_cp_index_u2(index);
421 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants(); 428 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
422 instanceKlassHandle pool_holder(cp->pool_holder()); 429 instanceKlassHandle pool_holder(cp->pool_holder());
423 430
424 Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF); 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
425 methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, pool_holder); 434 methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, pool_holder);
426 if (!method.is_null()) { 435 if (!method.is_null()) {
427 Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL); 436 Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL);
428 return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD)); 437 return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD));
429 } else { 438 } else {
430 // Get the method's name and signature. 439 // Get the method's name and signature.
431 Handle name = java_lang_String::create_from_symbol(cp->name_ref_at(index), CHECK_NULL); 440 Handle name = java_lang_String::create_from_symbol(cp->name_ref_at(index), CHECK_NULL);
432 Handle signature = java_lang_String::create_from_symbol(cp->signature_ref_at(index), CHECK_NULL); 441 Handle signature = java_lang_String::create_from_symbol(cp->signature_ref_at(index), CHECK_NULL);
433 int holder_index = cp->klass_ref_index_at(index); 442 Handle type;
434 Handle type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL); 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 }
435 return JNIHandles::make_local(THREAD, VMToCompiler::createUnresolvedJavaMethod(name, signature, type, THREAD)); 449 return JNIHandles::make_local(THREAD, VMToCompiler::createUnresolvedJavaMethod(name, signature, type, THREAD));
436 } 450 }
437 C2V_END 451 C2V_END
438 452
439 C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jobject type, jint index)) 453 C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jobject type, jint index))
477 int name_index = cp->name_ref_index_at(nt_index); 491 int name_index = cp->name_ref_index_at(nt_index);
478 Symbol* name = cp->symbol_at(name_index); 492 Symbol* name = cp->symbol_at(name_index);
479 int holder_index = cp->klass_ref_index_at(index); 493 int holder_index = cp->klass_ref_index_at(index);
480 Handle holder = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL); 494 Handle holder = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
481 instanceKlassHandle holder_klass; 495 instanceKlassHandle holder_klass;
482 496
483 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF); 497 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
484 int offset = -1; 498 int offset = -1;
485 AccessFlags flags; 499 AccessFlags flags;
486 BasicType basic_type; 500 BasicType basic_type;
487 if (holder->klass() == SystemDictionary::HotSpotResolvedObjectType_klass()) { 501 if (holder->klass() == SystemDictionary::HotSpotResolvedObjectType_klass()) {
497 holder_klass = result.klass()(); 511 holder_klass = result.klass()();
498 basic_type = result.field_type(); 512 basic_type = result.field_type();
499 holder = GraalCompiler::get_JavaType(holder_klass, CHECK_NULL); 513 holder = GraalCompiler::get_JavaType(holder_klass, CHECK_NULL);
500 } 514 }
501 } 515 }
502 516
503 Handle type = GraalCompiler::get_JavaTypeFromSignature(signature, cp->pool_holder(), CHECK_NULL); 517 Handle type = GraalCompiler::get_JavaTypeFromSignature(signature, cp->pool_holder(), CHECK_NULL);
504 Handle field_handle = GraalCompiler::get_JavaField(offset, flags.as_int(), name, holder, type, THREAD); 518 Handle field_handle = GraalCompiler::get_JavaField(offset, flags.as_int(), name, holder, type, THREAD);
505 519
506 return JNIHandles::make_local(THREAD, field_handle()); 520 return JNIHandles::make_local(THREAD, field_handle());
507 C2V_END 521 C2V_END
661 set_int("identityHashCodeShift", markOopDesc::hash_shift); 675 set_int("identityHashCodeShift", markOopDesc::hash_shift);
662 676
663 set_int("arrayKlassLayoutHelperIdentifier", 0x80000000); 677 set_int("arrayKlassLayoutHelperIdentifier", 0x80000000);
664 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"); 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");
665 set_int("arrayKlassComponentMirrorOffset", in_bytes(ArrayKlass::component_mirror_offset())); 679 set_int("arrayKlassComponentMirrorOffset", in_bytes(ArrayKlass::component_mirror_offset()));
666 680
667 681
668 set_int("pendingDeoptimizationOffset", in_bytes(ThreadShadow::pending_deoptimization_offset())); 682 set_int("pendingDeoptimizationOffset", in_bytes(ThreadShadow::pending_deoptimization_offset()));
669 683
670 set_int("metaspaceArrayLengthOffset", Array<Klass*>::length_offset_in_bytes()); 684 set_int("metaspaceArrayLengthOffset", Array<Klass*>::length_offset_in_bytes());
671 set_int("metaspaceArrayBaseOffset", Array<Klass*>::base_offset_in_bytes()); 685 set_int("metaspaceArrayBaseOffset", Array<Klass*>::base_offset_in_bytes());
1102 {CC"getInvocationCount", CC"("METASPACE_METHOD")I", FN_PTR(getInvocationCount)}, 1116 {CC"getInvocationCount", CC"("METASPACE_METHOD")I", FN_PTR(getInvocationCount)},
1103 {CC"getCompiledCodeSize", CC"("METASPACE_METHOD")I", FN_PTR(getCompiledCodeSize)}, 1117 {CC"getCompiledCodeSize", CC"("METASPACE_METHOD")I", FN_PTR(getCompiledCodeSize)},
1104 {CC"getVtableEntryOffset", CC"("METASPACE_METHOD")I", FN_PTR(getVtableEntryOffset)}, 1118 {CC"getVtableEntryOffset", CC"("METASPACE_METHOD")I", FN_PTR(getVtableEntryOffset)},
1105 {CC"lookupType", CC"("STRING HS_RESOLVED_TYPE"Z)"TYPE, FN_PTR(lookupType)}, 1119 {CC"lookupType", CC"("STRING HS_RESOLVED_TYPE"Z)"TYPE, FN_PTR(lookupType)},
1106 {CC"lookupConstantInPool", CC"("HS_RESOLVED_TYPE"I)"OBJECT, FN_PTR(lookupConstantInPool)}, 1120 {CC"lookupConstantInPool", CC"("HS_RESOLVED_TYPE"I)"OBJECT, FN_PTR(lookupConstantInPool)},
1121 {CC"lookupAppendixInPool", CC"("HS_RESOLVED_TYPE"I)"OBJECT, FN_PTR(lookupAppendixInPool)},
1107 {CC"lookupMethodInPool", CC"("HS_RESOLVED_TYPE"IB)"METHOD, FN_PTR(lookupMethodInPool)}, 1122 {CC"lookupMethodInPool", CC"("HS_RESOLVED_TYPE"IB)"METHOD, FN_PTR(lookupMethodInPool)},
1108 {CC"lookupTypeInPool", CC"("HS_RESOLVED_TYPE"I)"TYPE, FN_PTR(lookupTypeInPool)}, 1123 {CC"lookupTypeInPool", CC"("HS_RESOLVED_TYPE"I)"TYPE, FN_PTR(lookupTypeInPool)},
1109 {CC"lookupReferencedTypeInPool", CC"("HS_RESOLVED_TYPE"IB)V", FN_PTR(lookupReferencedTypeInPool)}, 1124 {CC"lookupReferencedTypeInPool", CC"("HS_RESOLVED_TYPE"IB)V", FN_PTR(lookupReferencedTypeInPool)},
1110 {CC"lookupFieldInPool", CC"("HS_RESOLVED_TYPE"IB)"FIELD, FN_PTR(lookupFieldInPool)}, 1125 {CC"lookupFieldInPool", CC"("HS_RESOLVED_TYPE"IB)"FIELD, FN_PTR(lookupFieldInPool)},
1111 {CC"resolveMethod", CC"("HS_RESOLVED_TYPE STRING STRING")"METHOD, FN_PTR(resolveMethod)}, 1126 {CC"resolveMethod", CC"("HS_RESOLVED_TYPE STRING STRING")"METHOD, FN_PTR(resolveMethod)},