comparison src/share/vm/c1x/c1x_VMEntries.cpp @ 1941:79d04223b8a5

Added caching for resolved types and resolved fields. This is crucial, because the local load elimination will lead to wrong results, if field equality (of two RiField objects with the same object and the same RiType) is not given. The caching makes sure that the default equals implementation is sufficient.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 28 Dec 2010 18:33:26 +0100
parents b7fb5f1e0747
children 00bc9eaf0e24
comparison
equal deleted inserted replaced
1940:e92a9a73324e 1941:79d04223b8a5
111 cimethod = (ciMethod*)CURRENT_ENV->get_object(VmIds::get<methodOop>(vmId)); 111 cimethod = (ciMethod*)CURRENT_ENV->get_object(VmIds::get<methodOop>(vmId));
112 } 112 }
113 return cimethod->has_balanced_monitors(); 113 return cimethod->has_balanced_monitors();
114 } 114 }
115 115
116 // public RiType RiSignature_lookupType(String returnType, long accessingClassVmId); 116 // public RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass);
117 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jlong accessingClassVmId) { 117 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) {
118 VM_ENTRY_MARK; 118 VM_ENTRY_MARK;
119 119
120 symbolOop nameSymbol = VmIds::toSymbol(jname); 120 symbolOop nameSymbol = VmIds::toSymbol(jname);
121 Handle name = JNIHandles::resolve(jname); 121 Handle name = JNIHandles::resolve(jname);
122 122
139 result = VMExits::createRiTypePrimitive((int) T_FLOAT, THREAD); 139 result = VMExits::createRiTypePrimitive((int) T_FLOAT, THREAD);
140 } else { 140 } else {
141 klassOop resolved_type = NULL; 141 klassOop resolved_type = NULL;
142 // if the name isn't in the symbol table then the class isn't loaded anyway... 142 // if the name isn't in the symbol table then the class isn't loaded anyway...
143 if (nameSymbol != NULL) { 143 if (nameSymbol != NULL) {
144 Handle classloader; 144 Handle classloader = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(accessingClass))->klass_part()->class_loader();
145 Handle protectionDomain; 145 Handle protectionDomain = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(accessingClass))->klass_part()->protection_domain();
146 if (accessingClassVmId != 0) {
147 classloader = VmIds::get<klassOop>(accessingClassVmId)->klass_part()->class_loader();
148 protectionDomain = VmIds::get<klassOop>(accessingClassVmId)->klass_part()->protection_domain();
149 }
150 resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD); 146 resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD);
151 if (HAS_PENDING_EXCEPTION) { 147 if (HAS_PENDING_EXCEPTION) {
152 CLEAR_PENDING_EXCEPTION; 148 CLEAR_PENDING_EXCEPTION;
153 resolved_type = NULL; 149 resolved_type = NULL;
154 } 150 }
155 } 151 }
156 if (resolved_type != NULL) { 152 if (resolved_type != NULL) {
157 result = C1XCompiler::createHotSpotTypeResolved(resolved_type, name, CHECK_NULL); 153 result = C1XCompiler::createHotSpotTypeResolved(resolved_type, name, CHECK_NULL);
158 } else { 154 } else {
159 result = VMExits::createRiTypeUnresolved(name, accessingClassVmId, THREAD); 155 result = VMExits::createRiTypeUnresolved(name, THREAD);
160 } 156 }
161 } 157 }
162 158
163 return JNIHandles::make_local(THREAD, result); 159 return JNIHandles::make_local(THREAD, result);
164 } 160 }
308 } 304 }
309 } 305 }
310 return JNIHandles::make_local(THREAD, field_handle()); 306 return JNIHandles::make_local(THREAD, field_handle());
311 } 307 }
312 308
313 // public RiConstantPool RiType_constantPool(long vmId); 309 // public RiConstantPool RiType_constantPool(HotSpotTypeResolved klass);
314 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1constantPool(JNIEnv *, jobject, jlong vmId) { 310 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1constantPool(JNIEnv *, jobject, jobject klass) {
315 VM_ENTRY_MARK; 311 VM_ENTRY_MARK;
316 312
317 constantPoolOop constantPool = instanceKlass::cast(VmIds::get<klassOop>(vmId))->constants(); 313 constantPoolOop constantPool = ((instanceKlass*)java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))->klass_part())->constants();
318 return JNIHandles::make_local(VMExits::createRiConstantPool(VmIds::add<constantPoolOop>(constantPool), THREAD)); 314 return JNIHandles::make_local(VMExits::createRiConstantPool(VmIds::add<constantPoolOop>(constantPool), THREAD));
319 } 315 }
320 316
321 // public RiMethod RiType_resolveMethodImpl(long vmId, String name, String signature); 317 // public RiMethod RiType_resolveMethodImpl(HotSpotTypeResolved klass, String name, String signature);
322 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_3resolveMethodImpl(JNIEnv *, jobject, jlong vmId, jstring name, jstring signature) { 318 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_3resolveMethodImpl(JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature) {
323 VM_ENTRY_MARK; 319 VM_ENTRY_MARK;
324 320
325 klassOop klass = VmIds::get<klassOop>(vmId); 321 klassOop klass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(resolved_type));
326 symbolOop name_symbol = VmIds::toSymbol(name); 322 symbolOop name_symbol = VmIds::toSymbol(name);
327 symbolOop signature_symbol = VmIds::toSymbol(signature); 323 symbolOop signature_symbol = VmIds::toSymbol(signature);
328 methodOop method = klass->klass_part()->lookup_method(name_symbol, signature_symbol); 324 methodOop method = klass->klass_part()->lookup_method(name_symbol, signature_symbol);
329 if (method == NULL) { 325 if (method == NULL) {
330 if (TraceC1X >= 3) { 326 if (TraceC1X >= 3) {
334 return NULL; 330 return NULL;
335 } 331 }
336 return JNIHandles::make_local(THREAD, VMExits::createRiMethodResolved(VmIds::add<methodOop>(method), Handle(JNIHandles::resolve(name)), THREAD)); 332 return JNIHandles::make_local(THREAD, VMExits::createRiMethodResolved(VmIds::add<methodOop>(method), Handle(JNIHandles::resolve(name)), THREAD));
337 } 333 }
338 334
339 // public boolean RiType_isSubtypeOf(long vmId, RiType other); 335 // public boolean RiType_isSubtypeOf(HotSpotTypeResolved klass, RiType other);
340 JNIEXPORT jboolean JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_2isSubtypeOf(JNIEnv *, jobject, jlong vmId, jobject jother) { 336 JNIEXPORT jboolean JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_2isSubtypeOf(JNIEnv *, jobject, jobject klass, jobject jother) {
341 oop other = JNIHandles::resolve(jother); 337 oop other = JNIHandles::resolve(jother);
342 assert(other->is_a(HotSpotTypeResolved::klass()), "resolved hotspot type expected"); 338 assert(other->is_a(HotSpotTypeResolved::klass()), "resolved hotspot type expected");
343 klassOop thisKlass = VmIds::get<klassOop>(vmId); 339 klassOop thisKlass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass));
344 klassOop otherKlass = VmIds::get<klassOop>(HotSpotTypeResolved::vmId(other)); 340 klassOop otherKlass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(other));
345 if (thisKlass->klass_part()->oop_is_instance_slow()) { 341 if (thisKlass->klass_part()->oop_is_instance_slow()) {
346 return instanceKlass::cast(thisKlass)->is_subtype_of(otherKlass); 342 return instanceKlass::cast(thisKlass)->is_subtype_of(otherKlass);
347 } else if (thisKlass->klass_part()->oop_is_array()) { 343 } else if (thisKlass->klass_part()->oop_is_array()) {
348 return arrayKlass::cast(thisKlass)->is_subtype_of(otherKlass); 344 return arrayKlass::cast(thisKlass)->is_subtype_of(otherKlass);
349 } else { 345 } else {
350 fatal("unexpected class type"); 346 fatal("unexpected class type");
351 } 347 }
352 } 348 }
353 349
354 // public RiType RiType_componentType(long vmId); 350 // public RiType RiType_componentType(HotSpotResolvedType klass);
355 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1componentType(JNIEnv *, jobject, jlong vmId) { 351 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1componentType(JNIEnv *, jobject, jobject klass) {
356 ciArrayKlass* klass; 352 ciArrayKlass* array_klass;
357 { 353 {
358 VM_ENTRY_MARK; 354 VM_ENTRY_MARK;
359 klass = (ciArrayKlass *) CURRENT_ENV->get_object(VmIds::get<klassOop>(vmId)); 355 array_klass = (ciArrayKlass *) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)));
360 } 356 }
361 ciType* element_type = klass->element_type(); 357 ciType* element_type = array_klass->element_type();
362 358
363 VM_ENTRY_MARK; 359 VM_ENTRY_MARK;
364 return JNIHandles::make_local(C1XCompiler::get_RiType(element_type, VmIds::get<klassOop>(vmId), THREAD)); 360 return JNIHandles::make_local(C1XCompiler::get_RiType(element_type, java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)), THREAD));
365 } 361 }
366 362
367 // public RiType RiType_arrayOf(long vmId); 363 // public RiType RiType_arrayOf(long vmId);
368 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1arrayOf(JNIEnv *, jobject, jlong vmId) { 364 JNIEXPORT jobject JNICALL Java_com_sun_hotspot_c1x_VMEntries_RiType_1arrayOf(JNIEnv *, jobject, jlong vmId) {
369 VM_ENTRY_MARK; 365 VM_ENTRY_MARK;
526 #define CC (char*) /*cast a literal from (const char*)*/ 522 #define CC (char*) /*cast a literal from (const char*)*/
527 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) 523 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
528 524
529 #define PROXY "J" 525 #define PROXY "J"
530 #define TYPE "Lcom/sun/cri/ri/RiType;" 526 #define TYPE "Lcom/sun/cri/ri/RiType;"
527 #define RESOLVED_TYPE "Lcom/sun/hotspot/c1x/HotSpotTypeResolved;"
531 #define METHOD "Lcom/sun/cri/ri/RiMethod;" 528 #define METHOD "Lcom/sun/cri/ri/RiMethod;"
532 #define SIGNATURE "Lcom/sun/cri/ri/RiSignature;" 529 #define SIGNATURE "Lcom/sun/cri/ri/RiSignature;"
533 #define FIELD "Lcom/sun/cri/ri/RiField;" 530 #define FIELD "Lcom/sun/cri/ri/RiField;"
534 #define CONSTANT_POOL "Lcom/sun/cri/ri/RiConstantPool;" 531 #define CONSTANT_POOL "Lcom/sun/cri/ri/RiConstantPool;"
535 #define EXCEPTION_HANDLERS "[Lcom/sun/cri/ri/RiExceptionHandler;" 532 #define EXCEPTION_HANDLERS "[Lcom/sun/cri/ri/RiExceptionHandler;"
541 #define STRING "Ljava/lang/String;" 538 #define STRING "Ljava/lang/String;"
542 #define OBJECT "Ljava/lang/Object;" 539 #define OBJECT "Ljava/lang/Object;"
543 #define CLASS "Ljava/lang/Class;" 540 #define CLASS "Ljava/lang/Class;"
544 541
545 JNINativeMethod VMEntries_methods[] = { 542 JNINativeMethod VMEntries_methods[] = {
546 {CC"RiMethod_code", CC"("PROXY")[B", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1code)}, 543 {CC"RiMethod_code", CC"("PROXY")[B", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1code)},
547 {CC"RiMethod_maxStackSize", CC"("PROXY")I", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1maxStackSize)}, 544 {CC"RiMethod_maxStackSize", CC"("PROXY")I", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1maxStackSize)},
548 {CC"RiMethod_maxLocals", CC"("PROXY")I", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1maxLocals)}, 545 {CC"RiMethod_maxLocals", CC"("PROXY")I", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1maxLocals)},
549 {CC"RiMethod_holder", CC"("PROXY")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1holder)}, 546 {CC"RiMethod_holder", CC"("PROXY")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1holder)},
550 {CC"RiMethod_signature", CC"("PROXY")"STRING, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1signature)}, 547 {CC"RiMethod_signature", CC"("PROXY")"STRING, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1signature)},
551 {CC"RiMethod_accessFlags", CC"("PROXY")I", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1accessFlags)}, 548 {CC"RiMethod_accessFlags", CC"("PROXY")I", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1accessFlags)},
552 {CC"RiMethod_exceptionHandlers", CC"("PROXY")"EXCEPTION_HANDLERS, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1exceptionHandlers)}, 549 {CC"RiMethod_exceptionHandlers", CC"("PROXY")"EXCEPTION_HANDLERS, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1exceptionHandlers)},
553 {CC"RiMethod_hasBalancedMonitors", CC"("PROXY")Z", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1hasBalancedMonitors)}, 550 {CC"RiMethod_hasBalancedMonitors", CC"("PROXY")Z", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiMethod_1hasBalancedMonitors)},
554 {CC"RiSignature_lookupType", CC"("STRING PROXY")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiSignature_1lookupType)}, 551 {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiSignature_1lookupType)},
555 {CC"RiConstantPool_lookupConstant", CC"("PROXY"I)"OBJECT, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupConstant)}, 552 {CC"RiConstantPool_lookupConstant", CC"("PROXY"I)"OBJECT, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupConstant)},
556 {CC"RiConstantPool_lookupMethod", CC"("PROXY"IB)"METHOD, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupMethod)}, 553 {CC"RiConstantPool_lookupMethod", CC"("PROXY"IB)"METHOD, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupMethod)},
557 {CC"RiConstantPool_lookupSignature", CC"("PROXY"I)"SIGNATURE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupSignature)}, 554 {CC"RiConstantPool_lookupSignature", CC"("PROXY"I)"SIGNATURE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupSignature)},
558 {CC"RiConstantPool_lookupType", CC"("PROXY"I)"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupType)}, 555 {CC"RiConstantPool_lookupType", CC"("PROXY"I)"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupType)},
559 {CC"RiConstantPool_lookupField", CC"("PROXY"IB)"FIELD, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupField)}, 556 {CC"RiConstantPool_lookupField", CC"("PROXY"IB)"FIELD, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiConstantPool_1lookupField)},
560 {CC"RiType_constantPool", CC"("PROXY")"CONSTANT_POOL, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_1constantPool)}, 557 {CC"RiType_constantPool", CC"("RESOLVED_TYPE")"CONSTANT_POOL, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_1constantPool)},
561 {CC"RiType_resolveMethodImpl", CC"("PROXY STRING STRING")"METHOD, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_3resolveMethodImpl)}, 558 {CC"RiType_resolveMethodImpl", CC"("RESOLVED_TYPE STRING STRING")"METHOD, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_3resolveMethodImpl)},
562 {CC"RiType_isSubtypeOf", CC"("PROXY TYPE")Z", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_2isSubtypeOf)}, 559 {CC"RiType_isSubtypeOf", CC"("RESOLVED_TYPE TYPE")Z", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_2isSubtypeOf)},
563 {CC"RiType_componentType", CC"("PROXY")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_1componentType)}, 560 {CC"RiType_componentType", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_1componentType)},
564 {CC"RiType_arrayOf", CC"("PROXY")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_1arrayOf)}, 561 {CC"RiType_arrayOf", CC"("PROXY")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_RiType_1arrayOf)},
565 {CC"getPrimitiveArrayType", CC"("CI_KIND")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_getPrimitiveArrayType)}, 562 {CC"getPrimitiveArrayType", CC"("CI_KIND")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_getPrimitiveArrayType)},
566 {CC"getType", CC"("CLASS")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_getType)}, 563 {CC"getType", CC"("CLASS")"TYPE, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_getType)},
567 {CC"getConfiguration", CC"()"CONFIG, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_getConfiguration)}, 564 {CC"getConfiguration", CC"()"CONFIG, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_getConfiguration)},
568 {CC"installMethod", CC"("TARGET_METHOD")V", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_installMethod)}, 565 {CC"installMethod", CC"("TARGET_METHOD")V", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_installMethod)},
569 {CC"installStub", CC"("TARGET_METHOD")"PROXY, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_installStub)}, 566 {CC"installStub", CC"("TARGET_METHOD")"PROXY, FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_installStub)},
570 {CC"recordBailout", CC"("STRING")V", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_recordBailout)} 567 {CC"recordBailout", CC"("STRING")V", FN_PTR(Java_com_sun_hotspot_c1x_VMEntries_recordBailout)}
571 }; 568 };
572 569
573 int VMEntries_methods_count() { 570 int VMEntries_methods_count() {
574 return sizeof(VMEntries_methods) / sizeof(JNINativeMethod); 571 return sizeof(VMEntries_methods) / sizeof(JNINativeMethod);
575 } 572 }