Mercurial > hg > truffle
comparison src/share/vm/oops/constantPoolOop.cpp @ 1602:136b78722a08
6939203: JSR 292 needs method handle constants
Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode.
Reviewed-by: twisti, never
author | jrose |
---|---|
date | Wed, 09 Jun 2010 18:50:45 -0700 |
parents | e9ff18c4ace7 |
children | 083fde3b838e |
comparison
equal
deleted
inserted
replaced
1585:49fac4acd688 | 1602:136b78722a08 |
---|---|
356 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) { | 356 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) { |
357 jint ref_index = klass_ref_index_at(which); | 357 jint ref_index = klass_ref_index_at(which); |
358 return klass_at_noresolve(ref_index); | 358 return klass_at_noresolve(ref_index); |
359 } | 359 } |
360 | 360 |
361 symbolOop constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) { | |
362 jint ref_index = uncached_klass_ref_index_at(which); | |
363 return klass_at_noresolve(ref_index); | |
364 } | |
365 | |
361 char* constantPoolOopDesc::string_at_noresolve(int which) { | 366 char* constantPoolOopDesc::string_at_noresolve(int which) { |
362 // Test entry type in case string is resolved while in here. | 367 // Test entry type in case string is resolved while in here. |
363 oop entry = *(obj_at_addr(which)); | 368 oop entry = *(obj_at_addr(which)); |
364 if (entry->is_symbol()) { | 369 if (entry->is_symbol()) { |
365 return ((symbolOop)entry)->as_C_string(); | 370 return ((symbolOop)entry)->as_C_string(); |
379 void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) { | 384 void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) { |
380 for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused | 385 for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused |
381 if (this_oop->tag_at(index).is_unresolved_string()) { | 386 if (this_oop->tag_at(index).is_unresolved_string()) { |
382 this_oop->string_at(index, CHECK); | 387 this_oop->string_at(index, CHECK); |
383 } | 388 } |
389 } | |
390 } | |
391 | |
392 oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) { | |
393 oop result_oop = NULL; | |
394 if (cache_index >= 0) { | |
395 assert(index < 0, "only one kind of index at a time"); | |
396 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); | |
397 result_oop = cpc_entry->f1(); | |
398 if (result_oop != NULL) { | |
399 return result_oop; // that was easy... | |
400 } | |
401 index = cpc_entry->constant_pool_index(); | |
402 } | |
403 | |
404 int tag_value = this_oop->tag_at(index).value(); | |
405 switch (tag_value) { | |
406 | |
407 case JVM_CONSTANT_UnresolvedClass: | |
408 case JVM_CONSTANT_UnresolvedClassInError: | |
409 case JVM_CONSTANT_Class: | |
410 { | |
411 klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL); | |
412 // ldc wants the java mirror. | |
413 result_oop = resolved->klass_part()->java_mirror(); | |
414 break; | |
415 } | |
416 | |
417 case JVM_CONSTANT_String: | |
418 case JVM_CONSTANT_UnresolvedString: | |
419 if (this_oop->is_pseudo_string_at(index)) { | |
420 result_oop = this_oop->pseudo_string_at(index); | |
421 break; | |
422 } | |
423 result_oop = string_at_impl(this_oop, index, CHECK_NULL); | |
424 break; | |
425 | |
426 case JVM_CONSTANT_Object: | |
427 result_oop = this_oop->object_at(index); | |
428 break; | |
429 | |
430 case JVM_CONSTANT_MethodHandle: | |
431 { | |
432 int ref_kind = this_oop->method_handle_ref_kind_at(index); | |
433 int callee_index = this_oop->method_handle_klass_index_at(index); | |
434 symbolHandle name(THREAD, this_oop->method_handle_name_ref_at(index)); | |
435 symbolHandle signature(THREAD, this_oop->method_handle_signature_ref_at(index)); | |
436 if (PrintMiscellaneous) | |
437 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s", | |
438 ref_kind, index, this_oop->method_handle_index_at(index), | |
439 callee_index, name->as_C_string(), signature->as_C_string()); | |
440 KlassHandle callee; | |
441 { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL); | |
442 callee = KlassHandle(THREAD, k); | |
443 } | |
444 KlassHandle klass(THREAD, this_oop->pool_holder()); | |
445 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind, | |
446 callee, name, signature, | |
447 CHECK_NULL); | |
448 result_oop = value(); | |
449 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error. | |
450 break; | |
451 } | |
452 | |
453 case JVM_CONSTANT_MethodType: | |
454 { | |
455 symbolHandle signature(THREAD, this_oop->method_type_signature_at(index)); | |
456 if (PrintMiscellaneous) | |
457 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s", | |
458 index, this_oop->method_type_index_at(index), | |
459 signature->as_C_string()); | |
460 KlassHandle klass(THREAD, this_oop->pool_holder()); | |
461 bool ignore_is_on_bcp = false; | |
462 Handle value = SystemDictionary::find_method_handle_type(signature, | |
463 klass, | |
464 ignore_is_on_bcp, | |
465 CHECK_NULL); | |
466 result_oop = value(); | |
467 // FIXME: Uniquify errors, using SystemDictionary::find_resolution_error. | |
468 break; | |
469 } | |
470 | |
471 /* maybe some day | |
472 case JVM_CONSTANT_Integer: | |
473 case JVM_CONSTANT_Float: | |
474 case JVM_CONSTANT_Long: | |
475 case JVM_CONSTANT_Double: | |
476 result_oop = java_lang_boxing_object::create(...); | |
477 break; | |
478 */ | |
479 | |
480 default: | |
481 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d", | |
482 this_oop(), index, cache_index, tag_value) ); | |
483 assert(false, "unexpected constant tag"); | |
484 break; | |
485 } | |
486 | |
487 if (cache_index >= 0) { | |
488 // Cache the oop here also. | |
489 Handle result(THREAD, result_oop); | |
490 result_oop = NULL; // safety | |
491 ObjectLocker ol(this_oop, THREAD); | |
492 ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index); | |
493 oop result_oop2 = cpc_entry->f1(); | |
494 if (result_oop2 != NULL) { | |
495 // Race condition: May already be filled in while we were trying to lock. | |
496 return result_oop2; | |
497 } | |
498 cpc_entry->set_f1(result()); | |
499 return result(); | |
500 } else { | |
501 return result_oop; | |
384 } | 502 } |
385 } | 503 } |
386 | 504 |
387 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) { | 505 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) { |
388 oop entry = *(this_oop->obj_at_addr(which)); | 506 oop entry = *(this_oop->obj_at_addr(which)); |
688 if (k1 == k2) { | 806 if (k1 == k2) { |
689 return true; | 807 return true; |
690 } | 808 } |
691 } break; | 809 } break; |
692 | 810 |
811 case JVM_CONSTANT_MethodType: | |
812 { | |
813 int k1 = method_type_index_at(index1); | |
814 int k2 = cp2->method_type_index_at(index2); | |
815 if (k1 == k2) { | |
816 return true; | |
817 } | |
818 } break; | |
819 | |
820 case JVM_CONSTANT_MethodHandle: | |
821 { | |
822 int k1 = method_handle_ref_kind_at(index1); | |
823 int k2 = cp2->method_handle_ref_kind_at(index2); | |
824 if (k1 == k2) { | |
825 int i1 = method_handle_index_at(index1); | |
826 int i2 = cp2->method_handle_index_at(index2); | |
827 if (i1 == i2) { | |
828 return true; | |
829 } | |
830 } | |
831 } break; | |
832 | |
693 case JVM_CONSTANT_UnresolvedString: | 833 case JVM_CONSTANT_UnresolvedString: |
694 { | 834 { |
695 symbolOop s1 = unresolved_string_at(index1); | 835 symbolOop s1 = unresolved_string_at(index1); |
696 symbolOop s2 = cp2->unresolved_string_at(index2); | 836 symbolOop s2 = cp2->unresolved_string_at(index2); |
697 if (s1 == s2) { | 837 if (s1 == s2) { |
859 | 999 |
860 case JVM_CONSTANT_Utf8: | 1000 case JVM_CONSTANT_Utf8: |
861 { | 1001 { |
862 symbolOop s = symbol_at(from_i); | 1002 symbolOop s = symbol_at(from_i); |
863 to_cp->symbol_at_put(to_i, s); | 1003 to_cp->symbol_at_put(to_i, s); |
1004 } break; | |
1005 | |
1006 case JVM_CONSTANT_MethodType: | |
1007 { | |
1008 jint k = method_type_index_at(from_i); | |
1009 to_cp->method_type_index_at_put(to_i, k); | |
1010 } break; | |
1011 | |
1012 case JVM_CONSTANT_MethodHandle: | |
1013 { | |
1014 int k1 = method_handle_ref_kind_at(from_i); | |
1015 int k2 = method_handle_index_at(from_i); | |
1016 to_cp->method_handle_index_at_put(to_i, k1, k2); | |
864 } break; | 1017 } break; |
865 | 1018 |
866 // Invalid is used as the tag for the second constant pool entry | 1019 // Invalid is used as the tag for the second constant pool entry |
867 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should | 1020 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should |
868 // not be seen by itself. | 1021 // not be seen by itself. |
1064 case JVM_CONSTANT_ClassIndex: | 1217 case JVM_CONSTANT_ClassIndex: |
1065 case JVM_CONSTANT_UnresolvedClass: | 1218 case JVM_CONSTANT_UnresolvedClass: |
1066 case JVM_CONSTANT_UnresolvedClassInError: | 1219 case JVM_CONSTANT_UnresolvedClassInError: |
1067 case JVM_CONSTANT_StringIndex: | 1220 case JVM_CONSTANT_StringIndex: |
1068 case JVM_CONSTANT_UnresolvedString: | 1221 case JVM_CONSTANT_UnresolvedString: |
1222 case JVM_CONSTANT_MethodType: | |
1069 return 3; | 1223 return 3; |
1224 | |
1225 case JVM_CONSTANT_MethodHandle: | |
1226 return 4; //tag, ref_kind, ref_index | |
1070 | 1227 |
1071 case JVM_CONSTANT_Integer: | 1228 case JVM_CONSTANT_Integer: |
1072 case JVM_CONSTANT_Float: | 1229 case JVM_CONSTANT_Float: |
1073 case JVM_CONSTANT_Fieldref: | 1230 case JVM_CONSTANT_Fieldref: |
1074 case JVM_CONSTANT_Methodref: | 1231 case JVM_CONSTANT_Methodref: |
1269 idx1 = string_index_at(idx); | 1426 idx1 = string_index_at(idx); |
1270 Bytes::put_Java_u2((address) (bytes+1), idx1); | 1427 Bytes::put_Java_u2((address) (bytes+1), idx1); |
1271 DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1)); | 1428 DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1)); |
1272 break; | 1429 break; |
1273 } | 1430 } |
1431 case JVM_CONSTANT_MethodHandle: { | |
1432 *bytes = JVM_CONSTANT_MethodHandle; | |
1433 int kind = method_handle_ref_kind_at(idx); | |
1434 idx1 = method_handle_index_at(idx); | |
1435 *(bytes+1) = (unsigned char) kind; | |
1436 Bytes::put_Java_u2((address) (bytes+2), idx1); | |
1437 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1)); | |
1438 break; | |
1439 } | |
1440 case JVM_CONSTANT_MethodType: { | |
1441 *bytes = JVM_CONSTANT_MethodType; | |
1442 idx1 = method_type_index_at(idx); | |
1443 Bytes::put_Java_u2((address) (bytes+1), idx1); | |
1444 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1)); | |
1445 break; | |
1446 } | |
1274 } | 1447 } |
1275 DBG(printf("\n")); | 1448 DBG(printf("\n")); |
1276 bytes += ent_size; | 1449 bytes += ent_size; |
1277 size += ent_size; | 1450 size += ent_size; |
1278 } | 1451 } |