Thu, 12 Mar 2009 18:16:36 -0700
Merge
duke@435 | 1 | /* |
xdono@1014 | 2 | * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // A constantPool is an array containing class constants as described in the |
duke@435 | 26 | // class file. |
duke@435 | 27 | // |
duke@435 | 28 | // Most of the constant pool entries are written during class parsing, which |
duke@435 | 29 | // is safe. For klass and string types, the constant pool entry is |
duke@435 | 30 | // modified when the entry is resolved. If a klass or string constant pool |
duke@435 | 31 | // entry is read without a lock, only the resolved state guarantees that |
duke@435 | 32 | // the entry in the constant pool is a klass or String object and |
duke@435 | 33 | // not a symbolOop. |
duke@435 | 34 | |
duke@435 | 35 | class SymbolHashMap; |
duke@435 | 36 | |
coleenp@548 | 37 | class constantPoolOopDesc : public oopDesc { |
duke@435 | 38 | friend class VMStructs; |
duke@435 | 39 | friend class BytecodeInterpreter; // Directly extracts an oop in the pool for fast instanceof/checkcast |
duke@435 | 40 | private: |
duke@435 | 41 | typeArrayOop _tags; // the tag array describing the constant pool's contents |
duke@435 | 42 | constantPoolCacheOop _cache; // the cache holding interpreter runtime information |
duke@435 | 43 | klassOop _pool_holder; // the corresponding class |
jrose@866 | 44 | int _flags; // a few header bits to describe contents for GC |
coleenp@548 | 45 | int _length; // number of elements in the array |
jmasa@953 | 46 | volatile bool _is_conc_safe; // if true, safe for concurrent |
jmasa@953 | 47 | // GC processing |
duke@435 | 48 | // only set to non-zero if constant pool is merged by RedefineClasses |
duke@435 | 49 | int _orig_length; |
duke@435 | 50 | |
duke@435 | 51 | void set_tags(typeArrayOop tags) { oop_store_without_check((oop*)&_tags, tags); } |
duke@435 | 52 | void tag_at_put(int which, jbyte t) { tags()->byte_at_put(which, t); } |
duke@435 | 53 | void release_tag_at_put(int which, jbyte t) { tags()->release_byte_at_put(which, t); } |
duke@435 | 54 | |
jrose@866 | 55 | enum FlagBit { |
jrose@866 | 56 | FB_has_pseudo_string = 2 |
jrose@866 | 57 | }; |
jrose@866 | 58 | |
jrose@866 | 59 | int flags() const { return _flags; } |
jrose@866 | 60 | void set_flags(int f) { _flags = f; } |
jrose@866 | 61 | bool flag_at(FlagBit fb) const { return (_flags & (1 << (int)fb)) != 0; } |
jrose@866 | 62 | void set_flag_at(FlagBit fb); |
jrose@866 | 63 | // no clear_flag_at function; they only increase |
jrose@866 | 64 | |
duke@435 | 65 | private: |
duke@435 | 66 | intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(constantPoolOopDesc)); } |
duke@435 | 67 | oop* tags_addr() { return (oop*)&_tags; } |
duke@435 | 68 | oop* cache_addr() { return (oop*)&_cache; } |
duke@435 | 69 | |
duke@435 | 70 | oop* obj_at_addr(int which) const { |
duke@435 | 71 | assert(is_within_bounds(which), "index out of bounds"); |
duke@435 | 72 | return (oop*) &base()[which]; |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | jint* int_at_addr(int which) const { |
duke@435 | 76 | assert(is_within_bounds(which), "index out of bounds"); |
duke@435 | 77 | return (jint*) &base()[which]; |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | jlong* long_at_addr(int which) const { |
duke@435 | 81 | assert(is_within_bounds(which), "index out of bounds"); |
duke@435 | 82 | return (jlong*) &base()[which]; |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | jfloat* float_at_addr(int which) const { |
duke@435 | 86 | assert(is_within_bounds(which), "index out of bounds"); |
duke@435 | 87 | return (jfloat*) &base()[which]; |
duke@435 | 88 | } |
duke@435 | 89 | |
duke@435 | 90 | jdouble* double_at_addr(int which) const { |
duke@435 | 91 | assert(is_within_bounds(which), "index out of bounds"); |
duke@435 | 92 | return (jdouble*) &base()[which]; |
duke@435 | 93 | } |
duke@435 | 94 | |
duke@435 | 95 | public: |
duke@435 | 96 | typeArrayOop tags() const { return _tags; } |
duke@435 | 97 | |
jrose@866 | 98 | bool has_pseudo_string() const { return flag_at(FB_has_pseudo_string); } |
jrose@866 | 99 | void set_pseudo_string() { set_flag_at(FB_has_pseudo_string); } |
jrose@866 | 100 | |
duke@435 | 101 | // Klass holding pool |
duke@435 | 102 | klassOop pool_holder() const { return _pool_holder; } |
duke@435 | 103 | void set_pool_holder(klassOop k) { oop_store_without_check((oop*)&_pool_holder, (oop) k); } |
duke@435 | 104 | oop* pool_holder_addr() { return (oop*)&_pool_holder; } |
duke@435 | 105 | |
duke@435 | 106 | // Interpreter runtime support |
duke@435 | 107 | constantPoolCacheOop cache() const { return _cache; } |
duke@435 | 108 | void set_cache(constantPoolCacheOop cache){ oop_store((oop*)&_cache, cache); } |
duke@435 | 109 | |
duke@435 | 110 | // Assembly code support |
duke@435 | 111 | static int tags_offset_in_bytes() { return offset_of(constantPoolOopDesc, _tags); } |
duke@435 | 112 | static int cache_offset_in_bytes() { return offset_of(constantPoolOopDesc, _cache); } |
duke@435 | 113 | static int pool_holder_offset_in_bytes() { return offset_of(constantPoolOopDesc, _pool_holder); } |
duke@435 | 114 | |
duke@435 | 115 | // Storing constants |
duke@435 | 116 | |
duke@435 | 117 | void klass_at_put(int which, klassOop k) { |
duke@435 | 118 | oop_store_without_check((volatile oop *)obj_at_addr(which), oop(k)); |
duke@435 | 119 | // The interpreter assumes when the tag is stored, the klass is resolved |
duke@435 | 120 | // and the klassOop is a klass rather than a symbolOop, so we need |
duke@435 | 121 | // hardware store ordering here. |
duke@435 | 122 | release_tag_at_put(which, JVM_CONSTANT_Class); |
duke@435 | 123 | if (UseConcMarkSweepGC) { |
duke@435 | 124 | // In case the earlier card-mark was consumed by a concurrent |
duke@435 | 125 | // marking thread before the tag was updated, redirty the card. |
duke@435 | 126 | oop_store_without_check((volatile oop *)obj_at_addr(which), oop(k)); |
duke@435 | 127 | } |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | // For temporary use while constructing constant pool |
duke@435 | 131 | void klass_index_at_put(int which, int name_index) { |
duke@435 | 132 | tag_at_put(which, JVM_CONSTANT_ClassIndex); |
duke@435 | 133 | *int_at_addr(which) = name_index; |
duke@435 | 134 | } |
duke@435 | 135 | |
duke@435 | 136 | // Temporary until actual use |
duke@435 | 137 | void unresolved_klass_at_put(int which, symbolOop s) { |
duke@435 | 138 | // Overwrite the old index with a GC friendly value so |
duke@435 | 139 | // that if GC looks during the transition it won't try |
duke@435 | 140 | // to treat a small integer as oop. |
duke@435 | 141 | *obj_at_addr(which) = NULL; |
duke@435 | 142 | release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass); |
duke@435 | 143 | oop_store_without_check(obj_at_addr(which), oop(s)); |
duke@435 | 144 | } |
duke@435 | 145 | |
duke@435 | 146 | // Temporary until actual use |
duke@435 | 147 | void unresolved_string_at_put(int which, symbolOop s) { |
duke@435 | 148 | *obj_at_addr(which) = NULL; |
duke@435 | 149 | release_tag_at_put(which, JVM_CONSTANT_UnresolvedString); |
duke@435 | 150 | oop_store_without_check(obj_at_addr(which), oop(s)); |
duke@435 | 151 | } |
duke@435 | 152 | |
duke@435 | 153 | void int_at_put(int which, jint i) { |
duke@435 | 154 | tag_at_put(which, JVM_CONSTANT_Integer); |
duke@435 | 155 | *int_at_addr(which) = i; |
duke@435 | 156 | } |
duke@435 | 157 | |
duke@435 | 158 | void long_at_put(int which, jlong l) { |
duke@435 | 159 | tag_at_put(which, JVM_CONSTANT_Long); |
duke@435 | 160 | // *long_at_addr(which) = l; |
duke@435 | 161 | Bytes::put_native_u8((address)long_at_addr(which), *((u8*) &l)); |
duke@435 | 162 | } |
duke@435 | 163 | |
duke@435 | 164 | void float_at_put(int which, jfloat f) { |
duke@435 | 165 | tag_at_put(which, JVM_CONSTANT_Float); |
duke@435 | 166 | *float_at_addr(which) = f; |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | void double_at_put(int which, jdouble d) { |
duke@435 | 170 | tag_at_put(which, JVM_CONSTANT_Double); |
duke@435 | 171 | // *double_at_addr(which) = d; |
duke@435 | 172 | // u8 temp = *(u8*) &d; |
duke@435 | 173 | Bytes::put_native_u8((address) double_at_addr(which), *((u8*) &d)); |
duke@435 | 174 | } |
duke@435 | 175 | |
duke@435 | 176 | void symbol_at_put(int which, symbolOop s) { |
duke@435 | 177 | tag_at_put(which, JVM_CONSTANT_Utf8); |
duke@435 | 178 | oop_store_without_check(obj_at_addr(which), oop(s)); |
duke@435 | 179 | } |
duke@435 | 180 | |
duke@435 | 181 | void string_at_put(int which, oop str) { |
duke@435 | 182 | oop_store((volatile oop*)obj_at_addr(which), str); |
duke@435 | 183 | release_tag_at_put(which, JVM_CONSTANT_String); |
duke@435 | 184 | if (UseConcMarkSweepGC) { |
duke@435 | 185 | // In case the earlier card-mark was consumed by a concurrent |
duke@435 | 186 | // marking thread before the tag was updated, redirty the card. |
duke@435 | 187 | oop_store_without_check((volatile oop *)obj_at_addr(which), str); |
duke@435 | 188 | } |
duke@435 | 189 | } |
duke@435 | 190 | |
duke@435 | 191 | // For temporary use while constructing constant pool |
duke@435 | 192 | void string_index_at_put(int which, int string_index) { |
duke@435 | 193 | tag_at_put(which, JVM_CONSTANT_StringIndex); |
duke@435 | 194 | *int_at_addr(which) = string_index; |
duke@435 | 195 | } |
duke@435 | 196 | |
duke@435 | 197 | void field_at_put(int which, int class_index, int name_and_type_index) { |
duke@435 | 198 | tag_at_put(which, JVM_CONSTANT_Fieldref); |
duke@435 | 199 | *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; |
duke@435 | 200 | } |
duke@435 | 201 | |
duke@435 | 202 | void method_at_put(int which, int class_index, int name_and_type_index) { |
duke@435 | 203 | tag_at_put(which, JVM_CONSTANT_Methodref); |
duke@435 | 204 | *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; |
duke@435 | 205 | } |
duke@435 | 206 | |
duke@435 | 207 | void interface_method_at_put(int which, int class_index, int name_and_type_index) { |
duke@435 | 208 | tag_at_put(which, JVM_CONSTANT_InterfaceMethodref); |
duke@435 | 209 | *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; // Not so nice |
duke@435 | 210 | } |
duke@435 | 211 | |
duke@435 | 212 | void name_and_type_at_put(int which, int name_index, int signature_index) { |
duke@435 | 213 | tag_at_put(which, JVM_CONSTANT_NameAndType); |
duke@435 | 214 | *int_at_addr(which) = ((jint) signature_index<<16) | name_index; // Not so nice |
duke@435 | 215 | } |
duke@435 | 216 | |
duke@435 | 217 | // Tag query |
duke@435 | 218 | |
duke@435 | 219 | constantTag tag_at(int which) const { return (constantTag)tags()->byte_at_acquire(which); } |
duke@435 | 220 | |
duke@435 | 221 | // Whether the entry is a pointer that must be GC'd. |
duke@435 | 222 | bool is_pointer_entry(int which) { |
duke@435 | 223 | constantTag tag = tag_at(which); |
duke@435 | 224 | return tag.is_klass() || |
duke@435 | 225 | tag.is_unresolved_klass() || |
duke@435 | 226 | tag.is_symbol() || |
duke@435 | 227 | tag.is_unresolved_string() || |
duke@435 | 228 | tag.is_string(); |
duke@435 | 229 | } |
duke@435 | 230 | |
duke@435 | 231 | // Fetching constants |
duke@435 | 232 | |
duke@435 | 233 | klassOop klass_at(int which, TRAPS) { |
duke@435 | 234 | constantPoolHandle h_this(THREAD, this); |
duke@435 | 235 | return klass_at_impl(h_this, which, CHECK_NULL); |
duke@435 | 236 | } |
duke@435 | 237 | |
duke@435 | 238 | symbolOop klass_name_at(int which); // Returns the name, w/o resolving. |
duke@435 | 239 | |
duke@435 | 240 | klassOop resolved_klass_at(int which) { // Used by Compiler |
duke@435 | 241 | guarantee(tag_at(which).is_klass(), "Corrupted constant pool"); |
duke@435 | 242 | // Must do an acquire here in case another thread resolved the klass |
duke@435 | 243 | // behind our back, lest we later load stale values thru the oop. |
duke@435 | 244 | return klassOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | // This method should only be used with a cpool lock or during parsing or gc |
duke@435 | 248 | symbolOop unresolved_klass_at(int which) { // Temporary until actual use |
duke@435 | 249 | symbolOop s = symbolOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); |
duke@435 | 250 | // check that the klass is still unresolved. |
duke@435 | 251 | assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool"); |
duke@435 | 252 | return s; |
duke@435 | 253 | } |
duke@435 | 254 | |
duke@435 | 255 | // RedefineClasses() API support: |
duke@435 | 256 | symbolOop klass_at_noresolve(int which) { return klass_name_at(which); } |
duke@435 | 257 | |
duke@435 | 258 | jint int_at(int which) { |
duke@435 | 259 | assert(tag_at(which).is_int(), "Corrupted constant pool"); |
duke@435 | 260 | return *int_at_addr(which); |
duke@435 | 261 | } |
duke@435 | 262 | |
duke@435 | 263 | jlong long_at(int which) { |
duke@435 | 264 | assert(tag_at(which).is_long(), "Corrupted constant pool"); |
duke@435 | 265 | // return *long_at_addr(which); |
duke@435 | 266 | u8 tmp = Bytes::get_native_u8((address)&base()[which]); |
duke@435 | 267 | return *((jlong*)&tmp); |
duke@435 | 268 | } |
duke@435 | 269 | |
duke@435 | 270 | jfloat float_at(int which) { |
duke@435 | 271 | assert(tag_at(which).is_float(), "Corrupted constant pool"); |
duke@435 | 272 | return *float_at_addr(which); |
duke@435 | 273 | } |
duke@435 | 274 | |
duke@435 | 275 | jdouble double_at(int which) { |
duke@435 | 276 | assert(tag_at(which).is_double(), "Corrupted constant pool"); |
duke@435 | 277 | u8 tmp = Bytes::get_native_u8((address)&base()[which]); |
duke@435 | 278 | return *((jdouble*)&tmp); |
duke@435 | 279 | } |
duke@435 | 280 | |
duke@435 | 281 | symbolOop symbol_at(int which) { |
duke@435 | 282 | assert(tag_at(which).is_utf8(), "Corrupted constant pool"); |
duke@435 | 283 | return symbolOop(*obj_at_addr(which)); |
duke@435 | 284 | } |
duke@435 | 285 | |
duke@435 | 286 | oop string_at(int which, TRAPS) { |
duke@435 | 287 | constantPoolHandle h_this(THREAD, this); |
duke@435 | 288 | return string_at_impl(h_this, which, CHECK_NULL); |
duke@435 | 289 | } |
duke@435 | 290 | |
jrose@866 | 291 | // A "pseudo-string" is an non-string oop that has found is way into |
jrose@866 | 292 | // a String entry. |
jrose@866 | 293 | // Under AnonymousClasses this can happen if the user patches a live |
jrose@866 | 294 | // object into a CONSTANT_String entry of an anonymous class. |
jrose@866 | 295 | // Method oops internally created for method handles may also |
jrose@866 | 296 | // use pseudo-strings to link themselves to related metaobjects. |
jrose@866 | 297 | |
jrose@866 | 298 | bool is_pseudo_string_at(int which); |
jrose@866 | 299 | |
jrose@866 | 300 | oop pseudo_string_at(int which) { |
jrose@866 | 301 | assert(tag_at(which).is_string(), "Corrupted constant pool"); |
jrose@866 | 302 | return *obj_at_addr(which); |
jrose@866 | 303 | } |
jrose@866 | 304 | |
jrose@866 | 305 | void pseudo_string_at_put(int which, oop x) { |
jrose@866 | 306 | assert(AnonymousClasses, ""); |
jrose@866 | 307 | set_pseudo_string(); // mark header |
jrose@866 | 308 | assert(tag_at(which).is_string() || tag_at(which).is_unresolved_string(), "Corrupted constant pool"); |
jrose@866 | 309 | string_at_put(which, x); // this works just fine |
jrose@866 | 310 | } |
jrose@866 | 311 | |
duke@435 | 312 | // only called when we are sure a string entry is already resolved (via an |
duke@435 | 313 | // earlier string_at call. |
duke@435 | 314 | oop resolved_string_at(int which) { |
duke@435 | 315 | assert(tag_at(which).is_string(), "Corrupted constant pool"); |
duke@435 | 316 | // Must do an acquire here in case another thread resolved the klass |
duke@435 | 317 | // behind our back, lest we later load stale values thru the oop. |
duke@435 | 318 | return (oop)OrderAccess::load_ptr_acquire(obj_at_addr(which)); |
duke@435 | 319 | } |
duke@435 | 320 | |
duke@435 | 321 | // This method should only be used with a cpool lock or during parsing or gc |
duke@435 | 322 | symbolOop unresolved_string_at(int which) { // Temporary until actual use |
duke@435 | 323 | symbolOop s = symbolOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); |
duke@435 | 324 | // check that the string is still unresolved. |
duke@435 | 325 | assert(tag_at(which).is_unresolved_string(), "Corrupted constant pool"); |
duke@435 | 326 | return s; |
duke@435 | 327 | } |
duke@435 | 328 | |
duke@435 | 329 | // Returns an UTF8 for a CONSTANT_String entry at a given index. |
duke@435 | 330 | // UTF8 char* representation was chosen to avoid conversion of |
duke@435 | 331 | // java_lang_Strings at resolved entries into symbolOops |
duke@435 | 332 | // or vice versa. |
jrose@866 | 333 | // Caller is responsible for checking for pseudo-strings. |
duke@435 | 334 | char* string_at_noresolve(int which); |
duke@435 | 335 | |
duke@435 | 336 | jint name_and_type_at(int which) { |
duke@435 | 337 | assert(tag_at(which).is_name_and_type(), "Corrupted constant pool"); |
duke@435 | 338 | return *int_at_addr(which); |
duke@435 | 339 | } |
duke@435 | 340 | |
duke@435 | 341 | // The following methods (klass_ref_at, klass_ref_at_noresolve, name_ref_at, |
duke@435 | 342 | // signature_ref_at, klass_ref_index_at, name_and_type_ref_index_at, |
duke@435 | 343 | // name_ref_index_at, signature_ref_index_at) all expect constant pool indices |
duke@435 | 344 | // from the bytecodes to be passed in, which are actually potentially byte-swapped |
duke@435 | 345 | // contstant pool cache indices. See field_or_method_at. |
duke@435 | 346 | |
duke@435 | 347 | // Lookup for entries consisting of (klass_index, name_and_type index) |
duke@435 | 348 | klassOop klass_ref_at(int which, TRAPS); |
duke@435 | 349 | symbolOop klass_ref_at_noresolve(int which); |
duke@435 | 350 | symbolOop name_ref_at(int which); |
duke@435 | 351 | symbolOop signature_ref_at(int which); // the type descriptor |
duke@435 | 352 | |
duke@435 | 353 | int klass_ref_index_at(int which); |
duke@435 | 354 | int name_and_type_ref_index_at(int which); |
duke@435 | 355 | |
duke@435 | 356 | // Lookup for entries consisting of (name_index, signature_index) |
duke@435 | 357 | int name_ref_index_at(int which); |
duke@435 | 358 | int signature_ref_index_at(int which); |
duke@435 | 359 | |
duke@435 | 360 | BasicType basic_type_for_signature_at(int which); |
duke@435 | 361 | |
duke@435 | 362 | // Resolve string constants (to prevent allocation during compilation) |
duke@435 | 363 | void resolve_string_constants(TRAPS) { |
duke@435 | 364 | constantPoolHandle h_this(THREAD, this); |
duke@435 | 365 | resolve_string_constants_impl(h_this, CHECK); |
duke@435 | 366 | } |
duke@435 | 367 | |
duke@435 | 368 | // Klass name matches name at offset |
duke@435 | 369 | bool klass_name_at_matches(instanceKlassHandle k, int which); |
duke@435 | 370 | |
duke@435 | 371 | // Sizing |
coleenp@548 | 372 | int length() const { return _length; } |
coleenp@548 | 373 | void set_length(int length) { _length = length; } |
coleenp@548 | 374 | |
coleenp@548 | 375 | // Tells whether index is within bounds. |
coleenp@548 | 376 | bool is_within_bounds(int index) const { |
coleenp@548 | 377 | return 0 <= index && index < length(); |
coleenp@548 | 378 | } |
coleenp@548 | 379 | |
duke@435 | 380 | static int header_size() { return sizeof(constantPoolOopDesc)/HeapWordSize; } |
duke@435 | 381 | static int object_size(int length) { return align_object_size(header_size() + length); } |
duke@435 | 382 | int object_size() { return object_size(length()); } |
duke@435 | 383 | |
jmasa@953 | 384 | bool is_conc_safe() { return _is_conc_safe; } |
jmasa@953 | 385 | void set_is_conc_safe(bool v) { _is_conc_safe = v; } |
jmasa@953 | 386 | |
duke@435 | 387 | friend class constantPoolKlass; |
duke@435 | 388 | friend class ClassFileParser; |
duke@435 | 389 | friend class SystemDictionary; |
duke@435 | 390 | |
duke@435 | 391 | // Used by compiler to prevent classloading. |
duke@435 | 392 | static klassOop klass_at_if_loaded (constantPoolHandle this_oop, int which); |
duke@435 | 393 | static klassOop klass_ref_at_if_loaded (constantPoolHandle this_oop, int which); |
duke@435 | 394 | // Same as above - but does LinkResolving. |
duke@435 | 395 | static klassOop klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS); |
duke@435 | 396 | |
duke@435 | 397 | // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the |
duke@435 | 398 | // future by other Java code. These take constant pool indices rather than possibly-byte-swapped |
duke@435 | 399 | // constant pool cache indices as do the peer methods above. |
duke@435 | 400 | symbolOop uncached_name_ref_at(int which); |
duke@435 | 401 | symbolOop uncached_signature_ref_at(int which); |
duke@435 | 402 | int uncached_klass_ref_index_at(int which); |
duke@435 | 403 | int uncached_name_and_type_ref_index_at(int which); |
duke@435 | 404 | |
duke@435 | 405 | // Sharing |
duke@435 | 406 | int pre_resolve_shared_klasses(TRAPS); |
duke@435 | 407 | void shared_symbols_iterate(OopClosure* closure0); |
duke@435 | 408 | void shared_tags_iterate(OopClosure* closure0); |
duke@435 | 409 | void shared_strings_iterate(OopClosure* closure0); |
duke@435 | 410 | |
duke@435 | 411 | // Debugging |
duke@435 | 412 | const char* printable_name_at(int which) PRODUCT_RETURN0; |
duke@435 | 413 | |
duke@435 | 414 | private: |
duke@435 | 415 | |
duke@435 | 416 | // Takes either a constant pool cache index in possibly byte-swapped |
duke@435 | 417 | // byte order (which comes from the bytecodes after rewriting) or, |
duke@435 | 418 | // if "uncached" is true, a vanilla constant pool index |
duke@435 | 419 | jint field_or_method_at(int which, bool uncached) { |
duke@435 | 420 | int i = -1; |
duke@435 | 421 | if (uncached || cache() == NULL) { |
duke@435 | 422 | i = which; |
duke@435 | 423 | } else { |
duke@435 | 424 | // change byte-ordering and go via cache |
duke@435 | 425 | i = cache()->entry_at(Bytes::swap_u2(which))->constant_pool_index(); |
duke@435 | 426 | } |
duke@435 | 427 | assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
duke@435 | 428 | return *int_at_addr(i); |
duke@435 | 429 | } |
duke@435 | 430 | |
duke@435 | 431 | // Used while constructing constant pool (only by ClassFileParser) |
duke@435 | 432 | jint klass_index_at(int which) { |
duke@435 | 433 | assert(tag_at(which).is_klass_index(), "Corrupted constant pool"); |
duke@435 | 434 | return *int_at_addr(which); |
duke@435 | 435 | } |
duke@435 | 436 | |
duke@435 | 437 | jint string_index_at(int which) { |
duke@435 | 438 | assert(tag_at(which).is_string_index(), "Corrupted constant pool"); |
duke@435 | 439 | return *int_at_addr(which); |
duke@435 | 440 | } |
duke@435 | 441 | |
duke@435 | 442 | // Performs the LinkResolver checks |
duke@435 | 443 | static void verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle klass, TRAPS); |
duke@435 | 444 | |
duke@435 | 445 | // Implementation of methods that needs an exposed 'this' pointer, in order to |
duke@435 | 446 | // handle GC while executing the method |
duke@435 | 447 | static klassOop klass_at_impl(constantPoolHandle this_oop, int which, TRAPS); |
duke@435 | 448 | static oop string_at_impl(constantPoolHandle this_oop, int which, TRAPS); |
duke@435 | 449 | |
duke@435 | 450 | // Resolve string constants (to prevent allocation during compilation) |
duke@435 | 451 | static void resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS); |
duke@435 | 452 | |
duke@435 | 453 | public: |
duke@435 | 454 | // Merging constantPoolOop support: |
duke@435 | 455 | bool compare_entry_to(int index1, constantPoolHandle cp2, int index2, TRAPS); |
duke@435 | 456 | void copy_cp_to(int start_i, int end_i, constantPoolHandle to_cp, int to_i, |
duke@435 | 457 | TRAPS); |
duke@435 | 458 | void copy_entry_to(int from_i, constantPoolHandle to_cp, int to_i, TRAPS); |
duke@435 | 459 | int find_matching_entry(int pattern_i, constantPoolHandle search_cp, TRAPS); |
duke@435 | 460 | int orig_length() const { return _orig_length; } |
duke@435 | 461 | void set_orig_length(int orig_length) { _orig_length = orig_length; } |
duke@435 | 462 | |
duke@435 | 463 | |
duke@435 | 464 | // JVMTI accesss - GetConstantPool, RetransformClasses, ... |
duke@435 | 465 | friend class JvmtiConstantPoolReconstituter; |
duke@435 | 466 | |
duke@435 | 467 | private: |
duke@435 | 468 | jint cpool_entry_size(jint idx); |
duke@435 | 469 | jint hash_entries_to(SymbolHashMap *symmap, SymbolHashMap *classmap); |
duke@435 | 470 | |
duke@435 | 471 | // Copy cpool bytes into byte array. |
duke@435 | 472 | // Returns: |
duke@435 | 473 | // int > 0, count of the raw cpool bytes that have been copied |
duke@435 | 474 | // 0, OutOfMemory error |
duke@435 | 475 | // -1, Internal error |
duke@435 | 476 | int copy_cpool_bytes(int cpool_size, |
duke@435 | 477 | SymbolHashMap* tbl, |
duke@435 | 478 | unsigned char *bytes); |
duke@435 | 479 | }; |
duke@435 | 480 | |
duke@435 | 481 | class SymbolHashMapEntry : public CHeapObj { |
duke@435 | 482 | private: |
duke@435 | 483 | unsigned int _hash; // 32-bit hash for item |
duke@435 | 484 | SymbolHashMapEntry* _next; // Next element in the linked list for this bucket |
duke@435 | 485 | symbolOop _symbol; // 1-st part of the mapping: symbol => value |
duke@435 | 486 | u2 _value; // 2-nd part of the mapping: symbol => value |
duke@435 | 487 | |
duke@435 | 488 | public: |
duke@435 | 489 | unsigned int hash() const { return _hash; } |
duke@435 | 490 | void set_hash(unsigned int hash) { _hash = hash; } |
duke@435 | 491 | |
duke@435 | 492 | SymbolHashMapEntry* next() const { return _next; } |
duke@435 | 493 | void set_next(SymbolHashMapEntry* next) { _next = next; } |
duke@435 | 494 | |
duke@435 | 495 | symbolOop symbol() const { return _symbol; } |
duke@435 | 496 | void set_symbol(symbolOop sym) { _symbol = sym; } |
duke@435 | 497 | |
duke@435 | 498 | u2 value() const { return _value; } |
duke@435 | 499 | void set_value(u2 value) { _value = value; } |
duke@435 | 500 | |
duke@435 | 501 | SymbolHashMapEntry(unsigned int hash, symbolOop symbol, u2 value) |
duke@435 | 502 | : _hash(hash), _symbol(symbol), _value(value), _next(NULL) {} |
duke@435 | 503 | |
duke@435 | 504 | }; // End SymbolHashMapEntry class |
duke@435 | 505 | |
duke@435 | 506 | |
duke@435 | 507 | class SymbolHashMapBucket : public CHeapObj { |
duke@435 | 508 | |
duke@435 | 509 | private: |
duke@435 | 510 | SymbolHashMapEntry* _entry; |
duke@435 | 511 | |
duke@435 | 512 | public: |
duke@435 | 513 | SymbolHashMapEntry* entry() const { return _entry; } |
duke@435 | 514 | void set_entry(SymbolHashMapEntry* entry) { _entry = entry; } |
duke@435 | 515 | void clear() { _entry = NULL; } |
duke@435 | 516 | |
duke@435 | 517 | }; // End SymbolHashMapBucket class |
duke@435 | 518 | |
duke@435 | 519 | |
duke@435 | 520 | class SymbolHashMap: public CHeapObj { |
duke@435 | 521 | |
duke@435 | 522 | private: |
duke@435 | 523 | // Default number of entries in the table |
duke@435 | 524 | enum SymbolHashMap_Constants { |
duke@435 | 525 | _Def_HashMap_Size = 256 |
duke@435 | 526 | }; |
duke@435 | 527 | |
duke@435 | 528 | int _table_size; |
duke@435 | 529 | SymbolHashMapBucket* _buckets; |
duke@435 | 530 | |
duke@435 | 531 | void initialize_table(int table_size) { |
duke@435 | 532 | _table_size = table_size; |
duke@435 | 533 | _buckets = NEW_C_HEAP_ARRAY(SymbolHashMapBucket, table_size); |
duke@435 | 534 | for (int index = 0; index < table_size; index++) { |
duke@435 | 535 | _buckets[index].clear(); |
duke@435 | 536 | } |
duke@435 | 537 | } |
duke@435 | 538 | |
duke@435 | 539 | public: |
duke@435 | 540 | |
duke@435 | 541 | int table_size() const { return _table_size; } |
duke@435 | 542 | |
duke@435 | 543 | SymbolHashMap() { initialize_table(_Def_HashMap_Size); } |
duke@435 | 544 | SymbolHashMap(int table_size) { initialize_table(table_size); } |
duke@435 | 545 | |
duke@435 | 546 | // hash P(31) from Kernighan & Ritchie |
duke@435 | 547 | static unsigned int compute_hash(const char* str, int len) { |
duke@435 | 548 | unsigned int hash = 0; |
duke@435 | 549 | while (len-- > 0) { |
duke@435 | 550 | hash = 31*hash + (unsigned) *str; |
duke@435 | 551 | str++; |
duke@435 | 552 | } |
duke@435 | 553 | return hash; |
duke@435 | 554 | } |
duke@435 | 555 | |
duke@435 | 556 | SymbolHashMapEntry* bucket(int i) { |
duke@435 | 557 | return _buckets[i].entry(); |
duke@435 | 558 | } |
duke@435 | 559 | |
duke@435 | 560 | void add_entry(symbolOop sym, u2 value); |
duke@435 | 561 | SymbolHashMapEntry* find_entry(symbolOop sym); |
duke@435 | 562 | |
duke@435 | 563 | u2 symbol_to_value(symbolOop sym) { |
duke@435 | 564 | SymbolHashMapEntry *entry = find_entry(sym); |
duke@435 | 565 | return (entry == NULL) ? 0 : entry->value(); |
duke@435 | 566 | } |
duke@435 | 567 | |
duke@435 | 568 | ~SymbolHashMap() { |
duke@435 | 569 | SymbolHashMapEntry* next; |
duke@435 | 570 | for (int i = 0; i < _table_size; i++) { |
duke@435 | 571 | for (SymbolHashMapEntry* cur = bucket(i); cur != NULL; cur = next) { |
duke@435 | 572 | next = cur->next(); |
duke@435 | 573 | delete(cur); |
duke@435 | 574 | } |
duke@435 | 575 | } |
duke@435 | 576 | delete _buckets; |
duke@435 | 577 | } |
duke@435 | 578 | }; // End SymbolHashMap class |