comparison src/share/vm/oops/constantPool.cpp @ 12355:cefad50507d8

Merge with hs25-b53
author Gilles Duboscq <duboscq@ssw.jku.at>
date Fri, 11 Oct 2013 10:38:03 +0200
parents 6b0fd0964b87 190899198332
children 096c224171c4
comparison
equal deleted inserted replaced
12058:ccb4f2af2319 12355:cefad50507d8
106 // to map it back for resolving and some unlikely miscellaneous uses. 106 // to map it back for resolving and some unlikely miscellaneous uses.
107 // The objects created by invokedynamic are appended to this list. 107 // The objects created by invokedynamic are appended to this list.
108 void ConstantPool::initialize_resolved_references(ClassLoaderData* loader_data, 108 void ConstantPool::initialize_resolved_references(ClassLoaderData* loader_data,
109 intStack reference_map, 109 intStack reference_map,
110 int constant_pool_map_length, 110 int constant_pool_map_length,
111 TRAPS) { 111 TRAPS) {
112 // Initialized the resolved object cache. 112 // Initialized the resolved object cache.
113 int map_length = reference_map.length(); 113 int map_length = reference_map.length();
114 if (map_length > 0) { 114 if (map_length > 0) {
115 // Only need mapping back to constant pool entries. The map isn't used for 115 // Only need mapping back to constant pool entries. The map isn't used for
116 // invokedynamic resolved_reference entries. The constant pool cache index 116 // invokedynamic resolved_reference entries. For invokedynamic entries,
117 // has the mapping back to both the constant pool and to the resolved 117 // the constant pool cache index has the mapping back to both the constant
118 // reference index. 118 // pool and to the resolved reference index.
119 if (constant_pool_map_length > 0) { 119 if (constant_pool_map_length > 0) {
120 Array<u2>* om = MetadataFactory::new_array<u2>(loader_data, map_length, CHECK); 120 Array<u2>* om = MetadataFactory::new_array<u2>(loader_data, constant_pool_map_length, CHECK);
121 121
122 for (int i = 0; i < constant_pool_map_length; i++) { 122 for (int i = 0; i < constant_pool_map_length; i++) {
123 int x = reference_map.at(i); 123 int x = reference_map.at(i);
124 assert(x == (int)(jushort) x, "klass index is too big"); 124 assert(x == (int)(jushort) x, "klass index is too big");
125 om->at_put(i, (jushort)x); 125 om->at_put(i, (jushort)x);
180 } 180 }
181 } 181 }
182 182
183 int ConstantPool::cp_to_object_index(int cp_index) { 183 int ConstantPool::cp_to_object_index(int cp_index) {
184 // this is harder don't do this so much. 184 // this is harder don't do this so much.
185 for (int i = 0; i< reference_map()->length(); i++) { 185 int i = reference_map()->find(cp_index);
186 if (reference_map()->at(i) == cp_index) return i; 186 // We might not find the index for jsr292 call.
187 // Zero entry is divider between constant pool indices for strings, 187 return (i < 0) ? _no_index_sentinel : i;
188 // method handles and method types. After that the index is a constant
189 // pool cache index for invokedynamic. Stop when zero (which can never
190 // be a constant pool index)
191 if (reference_map()->at(i) == 0) break;
192 }
193 // We might not find the index.
194 return _no_index_sentinel;
195 } 188 }
196 189
197 Klass* ConstantPool::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) { 190 Klass* ConstantPool::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
198 // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*. 191 // A resolved constantPool entry will contain a Klass*, otherwise a Symbol*.
199 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and 192 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
394 Klass* ConstantPool::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) { 387 Klass* ConstantPool::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) {
395 return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which)); 388 return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which));
396 } 389 }
397 390
398 391
399 // This is an interface for the compiler that allows accessing non-resolved entries
400 // in the constant pool - but still performs the validations tests. Must be used
401 // in a pre-parse of the compiler - to determine what it can do and not do.
402 // Note: We cannot update the ConstantPool from the vm_thread.
403 Klass* ConstantPool::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) {
404 int which = this_oop->klass_ref_index_at(index);
405 CPSlot entry = this_oop->slot_at(which);
406 if (entry.is_resolved()) {
407 assert(entry.get_klass()->is_klass(), "must be");
408 return entry.get_klass();
409 } else {
410 assert(entry.is_unresolved(), "must be either symbol or klass");
411 Symbol* name = entry.get_symbol();
412 oop loader = this_oop->pool_holder()->class_loader();
413 oop protection_domain = this_oop->pool_holder()->protection_domain();
414 Handle h_loader(THREAD, loader);
415 Handle h_prot (THREAD, protection_domain);
416 KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD));
417
418 // Do access check for klasses
419 if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL);
420 return k();
421 }
422 }
423
424
425 Method* ConstantPool::method_at_if_loaded(constantPoolHandle cpool, 392 Method* ConstantPool::method_at_if_loaded(constantPoolHandle cpool,
426 int which) { 393 int which) {
427 if (cpool->cache() == NULL) return NULL; // nothing to load yet 394 if (cpool->cache() == NULL) return NULL; // nothing to load yet
428 int cache_index = decode_cpcache_index(which, true); 395 int cache_index = decode_cpcache_index(which, true);
429 if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) { 396 if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) {
864 831
865 oop ConstantPool::string_at_impl(constantPoolHandle this_oop, int which, int obj_index, TRAPS) { 832 oop ConstantPool::string_at_impl(constantPoolHandle this_oop, int which, int obj_index, TRAPS) {
866 // If the string has already been interned, this entry will be non-null 833 // If the string has already been interned, this entry will be non-null
867 oop str = this_oop->resolved_references()->obj_at(obj_index); 834 oop str = this_oop->resolved_references()->obj_at(obj_index);
868 if (str != NULL) return str; 835 if (str != NULL) return str;
869 836 Symbol* sym = this_oop->unresolved_string_at(which);
870 Symbol* sym = this_oop->unresolved_string_at(which);
871 str = StringTable::intern(sym, CHECK_(NULL)); 837 str = StringTable::intern(sym, CHECK_(NULL));
872 this_oop->string_at_put(which, obj_index, str); 838 this_oop->string_at_put(which, obj_index, str);
873 assert(java_lang_String::is_instance(str), "must be string"); 839 assert(java_lang_String::is_instance(str), "must be string");
874 return str; 840 return str;
875 } 841 }
1643 case JVM_CONSTANT_ClassIndex: 1609 case JVM_CONSTANT_ClassIndex:
1644 case JVM_CONSTANT_UnresolvedClass: 1610 case JVM_CONSTANT_UnresolvedClass:
1645 case JVM_CONSTANT_UnresolvedClassInError: 1611 case JVM_CONSTANT_UnresolvedClassInError:
1646 case JVM_CONSTANT_StringIndex: 1612 case JVM_CONSTANT_StringIndex:
1647 case JVM_CONSTANT_MethodType: 1613 case JVM_CONSTANT_MethodType:
1614 case JVM_CONSTANT_MethodTypeInError:
1648 return 3; 1615 return 3;
1649 1616
1650 case JVM_CONSTANT_MethodHandle: 1617 case JVM_CONSTANT_MethodHandle:
1618 case JVM_CONSTANT_MethodHandleInError:
1651 return 4; //tag, ref_kind, ref_index 1619 return 4; //tag, ref_kind, ref_index
1652 1620
1653 case JVM_CONSTANT_Integer: 1621 case JVM_CONSTANT_Integer:
1654 case JVM_CONSTANT_Float: 1622 case JVM_CONSTANT_Float:
1655 case JVM_CONSTANT_Fieldref: 1623 case JVM_CONSTANT_Fieldref:
1826 break; 1794 break;
1827 } 1795 }
1828 case JVM_CONSTANT_MethodHandle: 1796 case JVM_CONSTANT_MethodHandle:
1829 case JVM_CONSTANT_MethodHandleInError: { 1797 case JVM_CONSTANT_MethodHandleInError: {
1830 *bytes = JVM_CONSTANT_MethodHandle; 1798 *bytes = JVM_CONSTANT_MethodHandle;
1831 int kind = method_handle_ref_kind_at(idx); 1799 int kind = method_handle_ref_kind_at_error_ok(idx);
1832 idx1 = method_handle_index_at(idx); 1800 idx1 = method_handle_index_at_error_ok(idx);
1833 *(bytes+1) = (unsigned char) kind; 1801 *(bytes+1) = (unsigned char) kind;
1834 Bytes::put_Java_u2((address) (bytes+2), idx1); 1802 Bytes::put_Java_u2((address) (bytes+2), idx1);
1835 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1)); 1803 DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1));
1836 break; 1804 break;
1837 } 1805 }
1838 case JVM_CONSTANT_MethodType: 1806 case JVM_CONSTANT_MethodType:
1839 case JVM_CONSTANT_MethodTypeInError: { 1807 case JVM_CONSTANT_MethodTypeInError: {
1840 *bytes = JVM_CONSTANT_MethodType; 1808 *bytes = JVM_CONSTANT_MethodType;
1841 idx1 = method_type_index_at(idx); 1809 idx1 = method_type_index_at_error_ok(idx);
1842 Bytes::put_Java_u2((address) (bytes+1), idx1); 1810 Bytes::put_Java_u2((address) (bytes+1), idx1);
1843 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1)); 1811 DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
1844 break; 1812 break;
1845 } 1813 }
1846 case JVM_CONSTANT_InvokeDynamic: { 1814 case JVM_CONSTANT_InvokeDynamic: {
1948 } 1916 }
1949 if (pool_holder() != NULL) { 1917 if (pool_holder() != NULL) {
1950 st->print_cr(" - holder: " INTPTR_FORMAT, pool_holder()); 1918 st->print_cr(" - holder: " INTPTR_FORMAT, pool_holder());
1951 } 1919 }
1952 st->print_cr(" - cache: " INTPTR_FORMAT, cache()); 1920 st->print_cr(" - cache: " INTPTR_FORMAT, cache());
1953 st->print_cr(" - resolved_references: " INTPTR_FORMAT, resolved_references()); 1921 st->print_cr(" - resolved_references: " INTPTR_FORMAT, (void *)resolved_references());
1954 st->print_cr(" - reference_map: " INTPTR_FORMAT, reference_map()); 1922 st->print_cr(" - reference_map: " INTPTR_FORMAT, reference_map());
1955 1923
1956 for (int index = 1; index < length(); index++) { // Index 0 is unused 1924 for (int index = 1; index < length(); index++) { // Index 0 is unused
1957 ((ConstantPool*)this)->print_entry_on(index, st); 1925 ((ConstantPool*)this)->print_entry_on(index, st);
1958 switch (tag_at(index).value()) { 1926 switch (tag_at(index).value()) {
2024 } 1992 }
2025 } 1993 }
2026 break; 1994 break;
2027 case JVM_CONSTANT_MethodHandle : 1995 case JVM_CONSTANT_MethodHandle :
2028 case JVM_CONSTANT_MethodHandleInError : 1996 case JVM_CONSTANT_MethodHandleInError :
2029 st->print("ref_kind=%d", method_handle_ref_kind_at(index)); 1997 st->print("ref_kind=%d", method_handle_ref_kind_at_error_ok(index));
2030 st->print(" ref_index=%d", method_handle_index_at(index)); 1998 st->print(" ref_index=%d", method_handle_index_at_error_ok(index));
2031 break; 1999 break;
2032 case JVM_CONSTANT_MethodType : 2000 case JVM_CONSTANT_MethodType :
2033 case JVM_CONSTANT_MethodTypeInError : 2001 case JVM_CONSTANT_MethodTypeInError :
2034 st->print("signature_index=%d", method_type_index_at(index)); 2002 st->print("signature_index=%d", method_type_index_at_error_ok(index));
2035 break; 2003 break;
2036 case JVM_CONSTANT_InvokeDynamic : 2004 case JVM_CONSTANT_InvokeDynamic :
2037 { 2005 {
2038 st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index)); 2006 st->print("bootstrap_method_index=%d", invoke_dynamic_bootstrap_method_ref_index_at(index));
2039 st->print(" name_and_type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index)); 2007 st->print(" name_and_type_index=%d", invoke_dynamic_name_and_type_ref_index_at(index));