comparison src/share/vm/oops/constantPool.cpp @ 8124:5fc51c1ecdeb

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 05 Mar 2013 23:44:54 +0100
parents 3ac7d10a6572 f16e75e0cf11
children b9a918201d47
comparison
equal deleted inserted replaced
7943:a413bcd552a4 8124:5fc51c1ecdeb
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "classfile/classLoaderData.hpp" 26 #include "classfile/classLoaderData.hpp"
27 #include "classfile/javaClasses.hpp" 27 #include "classfile/javaClasses.hpp"
28 #include "classfile/metadataOnStackMark.hpp"
28 #include "classfile/symbolTable.hpp" 29 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp" 30 #include "classfile/systemDictionary.hpp"
30 #include "classfile/vmSymbols.hpp" 31 #include "classfile/vmSymbols.hpp"
31 #include "interpreter/linkResolver.hpp" 32 #include "interpreter/linkResolver.hpp"
33 #include "memory/heapInspection.hpp"
32 #include "memory/metadataFactory.hpp" 34 #include "memory/metadataFactory.hpp"
33 #include "memory/oopFactory.hpp" 35 #include "memory/oopFactory.hpp"
34 #include "oops/constantPool.hpp" 36 #include "oops/constantPool.hpp"
35 #include "oops/instanceKlass.hpp" 37 #include "oops/instanceKlass.hpp"
36 #include "oops/objArrayKlass.hpp" 38 #include "oops/objArrayKlass.hpp"
37 #include "prims/jvmtiRedefineClasses.hpp"
38 #include "runtime/fieldType.hpp" 39 #include "runtime/fieldType.hpp"
39 #include "runtime/init.hpp" 40 #include "runtime/init.hpp"
40 #include "runtime/javaCalls.hpp" 41 #include "runtime/javaCalls.hpp"
41 #include "runtime/signature.hpp" 42 #include "runtime/signature.hpp"
42 #include "runtime/vframe.hpp" 43 #include "runtime/vframe.hpp"
63 set_reference_map(NULL); 64 set_reference_map(NULL);
64 set_resolved_references(NULL); 65 set_resolved_references(NULL);
65 set_operands(NULL); 66 set_operands(NULL);
66 set_pool_holder(NULL); 67 set_pool_holder(NULL);
67 set_flags(0); 68 set_flags(0);
69
68 // only set to non-zero if constant pool is merged by RedefineClasses 70 // only set to non-zero if constant pool is merged by RedefineClasses
69 set_version(0); 71 set_version(0);
70 set_lock(new Monitor(Monitor::nonleaf + 2, "A constant pool lock")); 72 set_lock(new Monitor(Monitor::nonleaf + 2, "A constant pool lock"));
71 // all fields are initialized; needed for GC
72 set_on_stack(false);
73 73
74 // initialize tag array 74 // initialize tag array
75 int length = tags->length(); 75 int length = tags->length();
76 for (int index = 0; index < length; index++) { 76 for (int index = 0; index < length; index++) {
77 tags->at_put(index, JVM_CONSTANT_Invalid); 77 tags->at_put(index, JVM_CONSTANT_Invalid);
96 // walk constant pool and decrement symbol reference counts 96 // walk constant pool and decrement symbol reference counts
97 unreference_symbols(); 97 unreference_symbols();
98 98
99 delete _lock; 99 delete _lock;
100 set_lock(NULL); 100 set_lock(NULL);
101 }
102
103 void ConstantPool::set_flag_at(FlagBit fb) {
104 const int MAX_STATE_CHANGES = 2;
105 for (int i = MAX_STATE_CHANGES + 10; i > 0; i--) {
106 int oflags = _flags;
107 int nflags = oflags | (1 << (int)fb);
108 if (Atomic::cmpxchg(nflags, &_flags, oflags) == oflags)
109 return;
110 }
111 assert(false, "failed to cmpxchg flags");
112 _flags |= (1 << (int)fb); // better than nothing
113 } 101 }
114 102
115 objArrayOop ConstantPool::resolved_references() const { 103 objArrayOop ConstantPool::resolved_references() const {
116 return (objArrayOop)JNIHandles::resolve(_resolved_references); 104 return (objArrayOop)JNIHandles::resolve(_resolved_references);
117 } 105 }
705 break; 693 break;
706 } 694 }
707 result_oop = string_at_impl(this_oop, index, cache_index, CHECK_NULL); 695 result_oop = string_at_impl(this_oop, index, cache_index, CHECK_NULL);
708 break; 696 break;
709 697
710 case JVM_CONSTANT_Object:
711 result_oop = this_oop->object_at(index);
712 break;
713
714 case JVM_CONSTANT_MethodHandleInError: 698 case JVM_CONSTANT_MethodHandleInError:
715 case JVM_CONSTANT_MethodTypeInError: 699 case JVM_CONSTANT_MethodTypeInError:
716 { 700 {
717 Symbol* error = SystemDictionary::find_resolution_error(this_oop, index); 701 Symbol* error = SystemDictionary::find_resolution_error(this_oop, index);
718 guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table"); 702 guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table");
1109 1093
1110 return false; 1094 return false;
1111 } // end compare_entry_to() 1095 } // end compare_entry_to()
1112 1096
1113 1097
1114 // Copy this constant pool's entries at start_i to end_i (inclusive) 1098 void ConstantPool::copy_operands(constantPoolHandle from_cp,
1115 // to the constant pool to_cp's entries starting at to_i. A total of 1099 constantPoolHandle to_cp,
1116 // (end_i - start_i) + 1 entries are copied. 1100 TRAPS) {
1117 void ConstantPool::copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i,
1118 constantPoolHandle to_cp, int to_i, TRAPS) {
1119
1120 int dest_i = to_i; // leave original alone for debug purposes
1121
1122 for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) {
1123 copy_entry_to(from_cp, src_i, to_cp, dest_i, CHECK);
1124
1125 switch (from_cp->tag_at(src_i).value()) {
1126 case JVM_CONSTANT_Double:
1127 case JVM_CONSTANT_Long:
1128 // double and long take two constant pool entries
1129 src_i += 2;
1130 dest_i += 2;
1131 break;
1132
1133 default:
1134 // all others take one constant pool entry
1135 src_i++;
1136 dest_i++;
1137 break;
1138 }
1139 }
1140 1101
1141 int from_oplen = operand_array_length(from_cp->operands()); 1102 int from_oplen = operand_array_length(from_cp->operands());
1142 int old_oplen = operand_array_length(to_cp->operands()); 1103 int old_oplen = operand_array_length(to_cp->operands());
1143 if (from_oplen != 0) { 1104 if (from_oplen != 0) {
1144 ClassLoaderData* loader_data = to_cp->pool_holder()->class_loader_data(); 1105 ClassLoaderData* loader_data = to_cp->pool_holder()->class_loader_data();
1162 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(0), 1123 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(0),
1163 new_operands->adr_at(fillp), 1124 new_operands->adr_at(fillp),
1164 (len = old_off) * sizeof(u2)); 1125 (len = old_off) * sizeof(u2));
1165 fillp += len; 1126 fillp += len;
1166 // first part of src 1127 // first part of src
1167 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(0), 1128 Copy::conjoint_memory_atomic(from_cp->operands()->adr_at(0),
1168 new_operands->adr_at(fillp), 1129 new_operands->adr_at(fillp),
1169 (len = from_off) * sizeof(u2)); 1130 (len = from_off) * sizeof(u2));
1170 fillp += len; 1131 fillp += len;
1171 // second part of dest 1132 // second part of dest
1172 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(old_off), 1133 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(old_off),
1173 new_operands->adr_at(fillp), 1134 new_operands->adr_at(fillp),
1174 (len = old_len - old_off) * sizeof(u2)); 1135 (len = old_len - old_off) * sizeof(u2));
1175 fillp += len; 1136 fillp += len;
1176 // second part of src 1137 // second part of src
1177 Copy::conjoint_memory_atomic(to_cp->operands()->adr_at(from_off), 1138 Copy::conjoint_memory_atomic(from_cp->operands()->adr_at(from_off),
1178 new_operands->adr_at(fillp), 1139 new_operands->adr_at(fillp),
1179 (len = from_len - from_off) * sizeof(u2)); 1140 (len = from_len - from_off) * sizeof(u2));
1180 fillp += len; 1141 fillp += len;
1181 assert(fillp == new_operands->length(), ""); 1142 assert(fillp == new_operands->length(), "");
1182 1143
1190 1151
1191 // replace target operands array with combined array 1152 // replace target operands array with combined array
1192 to_cp->set_operands(new_operands); 1153 to_cp->set_operands(new_operands);
1193 } 1154 }
1194 } 1155 }
1195 1156 } // end copy_operands()
1196 } // end copy_cp_to() 1157
1158
1159 // Copy this constant pool's entries at start_i to end_i (inclusive)
1160 // to the constant pool to_cp's entries starting at to_i. A total of
1161 // (end_i - start_i) + 1 entries are copied.
1162 void ConstantPool::copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i,
1163 constantPoolHandle to_cp, int to_i, TRAPS) {
1164
1165
1166 int dest_i = to_i; // leave original alone for debug purposes
1167
1168 for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) {
1169 copy_entry_to(from_cp, src_i, to_cp, dest_i, CHECK);
1170
1171 switch (from_cp->tag_at(src_i).value()) {
1172 case JVM_CONSTANT_Double:
1173 case JVM_CONSTANT_Long:
1174 // double and long take two constant pool entries
1175 src_i += 2;
1176 dest_i += 2;
1177 break;
1178
1179 default:
1180 // all others take one constant pool entry
1181 src_i++;
1182 dest_i++;
1183 break;
1184 }
1185 }
1186 copy_operands(from_cp, to_cp, CHECK);
1187
1188 } // end copy_cp_to_impl()
1197 1189
1198 1190
1199 // Copy this constant pool's entry at from_i to the constant pool 1191 // Copy this constant pool's entry at from_i to the constant pool
1200 // to_cp's entry at to_i. 1192 // to_cp's entry at to_i.
1201 void ConstantPool::copy_entry_to(constantPoolHandle from_cp, int from_i, 1193 void ConstantPool::copy_entry_to(constantPoolHandle from_cp, int from_i,
1753 return (int)(bytes - start_bytes); 1745 return (int)(bytes - start_bytes);
1754 } /* end copy_cpool_bytes */ 1746 } /* end copy_cpool_bytes */
1755 1747
1756 1748
1757 void ConstantPool::set_on_stack(const bool value) { 1749 void ConstantPool::set_on_stack(const bool value) {
1758 _on_stack = value; 1750 if (value) {
1751 _flags |= _on_stack;
1752 } else {
1753 _flags &= ~_on_stack;
1754 }
1759 if (value) MetadataOnStackMark::record(this); 1755 if (value) MetadataOnStackMark::record(this);
1760 } 1756 }
1761 1757
1762 // JSR 292 support for patching constant pool oops after the class is linked and 1758 // JSR 292 support for patching constant pool oops after the class is linked and
1763 // the oop array for resolved references are created. 1759 // the oop array for resolved references are created.
1822 EXCEPTION_MARK; 1818 EXCEPTION_MARK;
1823 assert(is_constantPool(), "must be constantPool"); 1819 assert(is_constantPool(), "must be constantPool");
1824 st->print_cr(internal_name()); 1820 st->print_cr(internal_name());
1825 if (flags() != 0) { 1821 if (flags() != 0) {
1826 st->print(" - flags: 0x%x", flags()); 1822 st->print(" - flags: 0x%x", flags());
1827 if (has_pseudo_string()) st->print(" has_pseudo_string");
1828 if (has_invokedynamic()) st->print(" has_invokedynamic");
1829 if (has_preresolution()) st->print(" has_preresolution"); 1823 if (has_preresolution()) st->print(" has_preresolution");
1824 if (on_stack()) st->print(" on_stack");
1830 st->cr(); 1825 st->cr();
1831 } 1826 }
1832 if (pool_holder() != NULL) { 1827 if (pool_holder() != NULL) {
1833 st->print_cr(" - holder: " INTPTR_FORMAT, pool_holder()); 1828 st->print_cr(" - holder: " INTPTR_FORMAT, pool_holder());
1834 } 1829 }
1866 case JVM_CONSTANT_InterfaceMethodref : 1861 case JVM_CONSTANT_InterfaceMethodref :
1867 st->print("klass_index=%d", uncached_klass_ref_index_at(index)); 1862 st->print("klass_index=%d", uncached_klass_ref_index_at(index));
1868 st->print(" name_and_type_index=%d", uncached_name_and_type_ref_index_at(index)); 1863 st->print(" name_and_type_index=%d", uncached_name_and_type_ref_index_at(index));
1869 break; 1864 break;
1870 case JVM_CONSTANT_String : 1865 case JVM_CONSTANT_String :
1871 unresolved_string_at(index)->print_value_on(st); 1866 if (is_pseudo_string_at(index)) {
1867 oop anObj = pseudo_string_at(index);
1868 anObj->print_value_on(st);
1869 st->print(" {0x%lx}", (address)anObj);
1870 } else {
1871 unresolved_string_at(index)->print_value_on(st);
1872 }
1872 break; 1873 break;
1873 case JVM_CONSTANT_Object : {
1874 oop anObj = object_at(index);
1875 anObj->print_value_on(st);
1876 st->print(" {0x%lx}", (address)anObj);
1877 } break;
1878 case JVM_CONSTANT_Integer : 1874 case JVM_CONSTANT_Integer :
1879 st->print("%d", int_at(index)); 1875 st->print("%d", int_at(index));
1880 break; 1876 break;
1881 case JVM_CONSTANT_Float : 1877 case JVM_CONSTANT_Float :
1882 st->print("%f", float_at(index)); 1878 st->print("%f", float_at(index));
1936 } 1932 }
1937 1933
1938 void ConstantPool::print_value_on(outputStream* st) const { 1934 void ConstantPool::print_value_on(outputStream* st) const {
1939 assert(is_constantPool(), "must be constantPool"); 1935 assert(is_constantPool(), "must be constantPool");
1940 st->print("constant pool [%d]", length()); 1936 st->print("constant pool [%d]", length());
1941 if (has_pseudo_string()) st->print("/pseudo_string");
1942 if (has_invokedynamic()) st->print("/invokedynamic");
1943 if (has_preresolution()) st->print("/preresolution"); 1937 if (has_preresolution()) st->print("/preresolution");
1944 if (operands() != NULL) st->print("/operands[%d]", operands()->length()); 1938 if (operands() != NULL) st->print("/operands[%d]", operands()->length());
1945 print_address_on(st); 1939 print_address_on(st);
1946 st->print(" for "); 1940 st->print(" for ");
1947 pool_holder()->print_value_on(st); 1941 pool_holder()->print_value_on(st);
1952 if (cache() != NULL) { 1946 if (cache() != NULL) {
1953 st->print(" cache=" PTR_FORMAT, cache()); 1947 st->print(" cache=" PTR_FORMAT, cache());
1954 } 1948 }
1955 } 1949 }
1956 1950
1951 #if INCLUDE_SERVICES
1952 // Size Statistics
1953 void ConstantPool::collect_statistics(KlassSizeStats *sz) const {
1954 sz->_cp_all_bytes += (sz->_cp_bytes = sz->count(this));
1955 sz->_cp_all_bytes += (sz->_cp_tags_bytes = sz->count_array(tags()));
1956 sz->_cp_all_bytes += (sz->_cp_cache_bytes = sz->count(cache()));
1957 sz->_cp_all_bytes += (sz->_cp_operands_bytes = sz->count_array(operands()));
1958 sz->_cp_all_bytes += (sz->_cp_refmap_bytes = sz->count_array(reference_map()));
1959
1960 sz->_ro_bytes += sz->_cp_operands_bytes + sz->_cp_tags_bytes +
1961 sz->_cp_refmap_bytes;
1962 sz->_rw_bytes += sz->_cp_bytes + sz->_cp_cache_bytes;
1963 }
1964 #endif // INCLUDE_SERVICES
1957 1965
1958 // Verification 1966 // Verification
1959 1967
1960 void ConstantPool::verify_on(outputStream* st) { 1968 void ConstantPool::verify_on(outputStream* st) {
1961 guarantee(is_constantPool(), "object must be constant pool"); 1969 guarantee(is_constantPool(), "object must be constant pool");