src/share/vm/oops/constantPoolOop.hpp

Tue, 13 Mar 2012 13:50:48 -0400

author
jiangli
date
Tue, 13 Mar 2012 13:50:48 -0400
changeset 3670
f7c4174b33ba
parent 2982
ddd894528dbc
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
Summary: Fold instanceKlass::_enclosing_method_class_index and instanceKlass::_enclosing_method_method_index into the instanceKlass::_inner_classes array.
Reviewed-by: never, coleenp
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>

duke@435 1 /*
twisti@2698 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP
stefank@2314 26 #define SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP
stefank@2314 27
stefank@2314 28 #include "oops/arrayOop.hpp"
stefank@2314 29 #include "oops/cpCacheOop.hpp"
coleenp@2497 30 #include "oops/symbol.hpp"
stefank@2314 31 #include "oops/typeArrayOop.hpp"
stefank@2314 32 #include "utilities/constantTag.hpp"
stefank@2314 33 #ifdef TARGET_ARCH_x86
stefank@2314 34 # include "bytes_x86.hpp"
stefank@2314 35 #endif
stefank@2314 36 #ifdef TARGET_ARCH_sparc
stefank@2314 37 # include "bytes_sparc.hpp"
stefank@2314 38 #endif
stefank@2314 39 #ifdef TARGET_ARCH_zero
stefank@2314 40 # include "bytes_zero.hpp"
stefank@2314 41 #endif
bobv@2508 42 #ifdef TARGET_ARCH_arm
bobv@2508 43 # include "bytes_arm.hpp"
bobv@2508 44 #endif
bobv@2508 45 #ifdef TARGET_ARCH_ppc
bobv@2508 46 # include "bytes_ppc.hpp"
bobv@2508 47 #endif
stefank@2314 48
duke@435 49 // A constantPool is an array containing class constants as described in the
duke@435 50 // class file.
duke@435 51 //
duke@435 52 // Most of the constant pool entries are written during class parsing, which
duke@435 53 // is safe. For klass and string types, the constant pool entry is
duke@435 54 // modified when the entry is resolved. If a klass or string constant pool
duke@435 55 // entry is read without a lock, only the resolved state guarantees that
duke@435 56 // the entry in the constant pool is a klass or String object and
coleenp@2497 57 // not a Symbol*.
duke@435 58
duke@435 59 class SymbolHashMap;
duke@435 60
coleenp@2497 61 class CPSlot VALUE_OBJ_CLASS_SPEC {
coleenp@2497 62 intptr_t _ptr;
coleenp@2497 63 public:
coleenp@2497 64 CPSlot(intptr_t ptr): _ptr(ptr) {}
coleenp@2497 65 CPSlot(void* ptr): _ptr((intptr_t)ptr) {}
coleenp@2497 66 CPSlot(oop ptr): _ptr((intptr_t)ptr) {}
coleenp@2497 67 CPSlot(Symbol* ptr): _ptr((intptr_t)ptr | 1) {}
coleenp@2497 68
coleenp@2497 69 intptr_t value() { return _ptr; }
coleenp@2497 70 bool is_oop() { return (_ptr & 1) == 0; }
coleenp@2497 71 bool is_metadata() { return (_ptr & 1) == 1; }
coleenp@2497 72
coleenp@2497 73 oop get_oop() {
coleenp@2497 74 assert(is_oop(), "bad call");
coleenp@2497 75 return oop(_ptr);
coleenp@2497 76 }
coleenp@2497 77 Symbol* get_symbol() {
coleenp@2497 78 assert(is_metadata(), "bad call");
coleenp@2497 79 return (Symbol*)(_ptr & ~1);
coleenp@2497 80 }
coleenp@2497 81 };
coleenp@2497 82
coleenp@548 83 class constantPoolOopDesc : public oopDesc {
duke@435 84 friend class VMStructs;
duke@435 85 friend class BytecodeInterpreter; // Directly extracts an oop in the pool for fast instanceof/checkcast
duke@435 86 private:
duke@435 87 typeArrayOop _tags; // the tag array describing the constant pool's contents
duke@435 88 constantPoolCacheOop _cache; // the cache holding interpreter runtime information
duke@435 89 klassOop _pool_holder; // the corresponding class
jrose@2268 90 typeArrayOop _operands; // for variable-sized (InvokeDynamic) nodes, usually empty
jrose@866 91 int _flags; // a few header bits to describe contents for GC
coleenp@548 92 int _length; // number of elements in the array
jmasa@953 93 volatile bool _is_conc_safe; // if true, safe for concurrent
jmasa@953 94 // GC processing
duke@435 95 // only set to non-zero if constant pool is merged by RedefineClasses
duke@435 96 int _orig_length;
duke@435 97
duke@435 98 void set_tags(typeArrayOop tags) { oop_store_without_check((oop*)&_tags, tags); }
duke@435 99 void tag_at_put(int which, jbyte t) { tags()->byte_at_put(which, t); }
duke@435 100 void release_tag_at_put(int which, jbyte t) { tags()->release_byte_at_put(which, t); }
duke@435 101
jrose@2268 102 void set_operands(typeArrayOop operands) { oop_store_without_check((oop*)&_operands, operands); }
jrose@2268 103
jrose@866 104 enum FlagBit {
jrose@1161 105 FB_has_invokedynamic = 1,
jrose@2982 106 FB_has_pseudo_string = 2,
jrose@2982 107 FB_has_preresolution = 3
jrose@866 108 };
jrose@866 109
jrose@866 110 int flags() const { return _flags; }
jrose@866 111 void set_flags(int f) { _flags = f; }
jrose@866 112 bool flag_at(FlagBit fb) const { return (_flags & (1 << (int)fb)) != 0; }
jrose@866 113 void set_flag_at(FlagBit fb);
jrose@866 114 // no clear_flag_at function; they only increase
jrose@866 115
duke@435 116 private:
duke@435 117 intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(constantPoolOopDesc)); }
duke@435 118 oop* tags_addr() { return (oop*)&_tags; }
duke@435 119 oop* cache_addr() { return (oop*)&_cache; }
jrose@2268 120 oop* operands_addr() { return (oop*)&_operands; }
duke@435 121
coleenp@2497 122 CPSlot slot_at(int which) {
coleenp@2497 123 assert(is_within_bounds(which), "index out of bounds");
coleenp@2497 124 // There's a transitional value of zero when converting from
coleenp@2497 125 // Symbol->0->Klass for G1 when resolving classes and strings.
coleenp@2497 126 // wait for the value to be non-zero (this is temporary)
coleenp@2497 127 volatile intptr_t adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which));
coleenp@2497 128 if (adr == 0 && which != 0) {
coleenp@2497 129 constantTag t = tag_at(which);
coleenp@2497 130 if (t.is_unresolved_klass() || t.is_klass() ||
coleenp@2497 131 t.is_unresolved_string() || t.is_string()) {
coleenp@2497 132 while ((adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))) == 0);
coleenp@2497 133 }
coleenp@2497 134 }
coleenp@2497 135 return CPSlot(adr);
coleenp@2497 136 }
coleenp@2497 137
coleenp@2497 138 void slot_at_put(int which, CPSlot s) const {
coleenp@2497 139 assert(is_within_bounds(which), "index out of bounds");
coleenp@2497 140 *(intptr_t*)&base()[which] = s.value();
coleenp@2497 141 }
coleenp@2497 142 oop* obj_at_addr_raw(int which) const {
duke@435 143 assert(is_within_bounds(which), "index out of bounds");
duke@435 144 return (oop*) &base()[which];
duke@435 145 }
duke@435 146
coleenp@2497 147 void obj_at_put_without_check(int which, oop o) {
coleenp@2497 148 assert(is_within_bounds(which), "index out of bounds");
coleenp@2497 149 oop_store_without_check((volatile oop *)obj_at_addr_raw(which), o);
coleenp@2497 150 }
coleenp@2497 151
coleenp@2497 152 void obj_at_put(int which, oop o) const {
coleenp@2497 153 assert(is_within_bounds(which), "index out of bounds");
coleenp@2497 154 oop_store((volatile oop*)obj_at_addr_raw(which), o);
coleenp@2497 155 }
coleenp@2497 156
duke@435 157 jint* int_at_addr(int which) const {
duke@435 158 assert(is_within_bounds(which), "index out of bounds");
duke@435 159 return (jint*) &base()[which];
duke@435 160 }
duke@435 161
duke@435 162 jlong* long_at_addr(int which) const {
duke@435 163 assert(is_within_bounds(which), "index out of bounds");
duke@435 164 return (jlong*) &base()[which];
duke@435 165 }
duke@435 166
duke@435 167 jfloat* float_at_addr(int which) const {
duke@435 168 assert(is_within_bounds(which), "index out of bounds");
duke@435 169 return (jfloat*) &base()[which];
duke@435 170 }
duke@435 171
duke@435 172 jdouble* double_at_addr(int which) const {
duke@435 173 assert(is_within_bounds(which), "index out of bounds");
duke@435 174 return (jdouble*) &base()[which];
duke@435 175 }
duke@435 176
duke@435 177 public:
duke@435 178 typeArrayOop tags() const { return _tags; }
jrose@2268 179 typeArrayOop operands() const { return _operands; }
duke@435 180
jrose@866 181 bool has_pseudo_string() const { return flag_at(FB_has_pseudo_string); }
jrose@1161 182 bool has_invokedynamic() const { return flag_at(FB_has_invokedynamic); }
jrose@2982 183 bool has_preresolution() const { return flag_at(FB_has_preresolution); }
jrose@866 184 void set_pseudo_string() { set_flag_at(FB_has_pseudo_string); }
jrose@1161 185 void set_invokedynamic() { set_flag_at(FB_has_invokedynamic); }
jrose@2982 186 void set_preresolution() { set_flag_at(FB_has_preresolution); }
jrose@866 187
duke@435 188 // Klass holding pool
duke@435 189 klassOop pool_holder() const { return _pool_holder; }
duke@435 190 void set_pool_holder(klassOop k) { oop_store_without_check((oop*)&_pool_holder, (oop) k); }
duke@435 191 oop* pool_holder_addr() { return (oop*)&_pool_holder; }
duke@435 192
duke@435 193 // Interpreter runtime support
duke@435 194 constantPoolCacheOop cache() const { return _cache; }
duke@435 195 void set_cache(constantPoolCacheOop cache){ oop_store((oop*)&_cache, cache); }
duke@435 196
duke@435 197 // Assembly code support
duke@435 198 static int tags_offset_in_bytes() { return offset_of(constantPoolOopDesc, _tags); }
duke@435 199 static int cache_offset_in_bytes() { return offset_of(constantPoolOopDesc, _cache); }
jrose@2268 200 static int operands_offset_in_bytes() { return offset_of(constantPoolOopDesc, _operands); }
duke@435 201 static int pool_holder_offset_in_bytes() { return offset_of(constantPoolOopDesc, _pool_holder); }
duke@435 202
duke@435 203 // Storing constants
duke@435 204
duke@435 205 void klass_at_put(int which, klassOop k) {
coleenp@2497 206 // Overwrite the old index with a GC friendly value so
coleenp@2497 207 // that if G1 looks during the transition during oop_store it won't
coleenp@2497 208 // assert the symbol is not an oop.
coleenp@2497 209 *obj_at_addr_raw(which) = NULL;
coleenp@2497 210 assert(k != NULL, "resolved class shouldn't be null");
coleenp@2497 211 obj_at_put_without_check(which, k);
duke@435 212 // The interpreter assumes when the tag is stored, the klass is resolved
coleenp@2497 213 // and the klassOop is a klass rather than a Symbol*, so we need
duke@435 214 // hardware store ordering here.
duke@435 215 release_tag_at_put(which, JVM_CONSTANT_Class);
duke@435 216 if (UseConcMarkSweepGC) {
duke@435 217 // In case the earlier card-mark was consumed by a concurrent
duke@435 218 // marking thread before the tag was updated, redirty the card.
coleenp@2497 219 obj_at_put_without_check(which, k);
duke@435 220 }
duke@435 221 }
duke@435 222
duke@435 223 // For temporary use while constructing constant pool
duke@435 224 void klass_index_at_put(int which, int name_index) {
duke@435 225 tag_at_put(which, JVM_CONSTANT_ClassIndex);
duke@435 226 *int_at_addr(which) = name_index;
duke@435 227 }
duke@435 228
duke@435 229 // Temporary until actual use
coleenp@2497 230 void unresolved_klass_at_put(int which, Symbol* s) {
duke@435 231 release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass);
coleenp@2497 232 slot_at_put(which, s);
duke@435 233 }
duke@435 234
jrose@1957 235 void method_handle_index_at_put(int which, int ref_kind, int ref_index) {
jrose@1957 236 tag_at_put(which, JVM_CONSTANT_MethodHandle);
jrose@1957 237 *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind;
jrose@1957 238 }
jrose@1957 239
jrose@1957 240 void method_type_index_at_put(int which, int ref_index) {
jrose@1957 241 tag_at_put(which, JVM_CONSTANT_MethodType);
jrose@1957 242 *int_at_addr(which) = ref_index;
jrose@1957 243 }
jrose@1957 244
jrose@2353 245 void invoke_dynamic_at_put(int which, int bootstrap_specifier_index, int name_and_type_index) {
jrose@2015 246 tag_at_put(which, JVM_CONSTANT_InvokeDynamic);
jrose@2353 247 *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_specifier_index;
jrose@2015 248 }
jrose@2353 249
duke@435 250 // Temporary until actual use
coleenp@2497 251 void unresolved_string_at_put(int which, Symbol* s) {
duke@435 252 release_tag_at_put(which, JVM_CONSTANT_UnresolvedString);
coleenp@2497 253 slot_at_put(which, s);
duke@435 254 }
duke@435 255
duke@435 256 void int_at_put(int which, jint i) {
duke@435 257 tag_at_put(which, JVM_CONSTANT_Integer);
duke@435 258 *int_at_addr(which) = i;
duke@435 259 }
duke@435 260
duke@435 261 void long_at_put(int which, jlong l) {
duke@435 262 tag_at_put(which, JVM_CONSTANT_Long);
duke@435 263 // *long_at_addr(which) = l;
duke@435 264 Bytes::put_native_u8((address)long_at_addr(which), *((u8*) &l));
duke@435 265 }
duke@435 266
duke@435 267 void float_at_put(int which, jfloat f) {
duke@435 268 tag_at_put(which, JVM_CONSTANT_Float);
duke@435 269 *float_at_addr(which) = f;
duke@435 270 }
duke@435 271
duke@435 272 void double_at_put(int which, jdouble d) {
duke@435 273 tag_at_put(which, JVM_CONSTANT_Double);
duke@435 274 // *double_at_addr(which) = d;
duke@435 275 // u8 temp = *(u8*) &d;
duke@435 276 Bytes::put_native_u8((address) double_at_addr(which), *((u8*) &d));
duke@435 277 }
duke@435 278
coleenp@2497 279 Symbol** symbol_at_addr(int which) const {
coleenp@2497 280 assert(is_within_bounds(which), "index out of bounds");
coleenp@2497 281 return (Symbol**) &base()[which];
coleenp@2497 282 }
coleenp@2497 283
coleenp@2497 284 void symbol_at_put(int which, Symbol* s) {
coleenp@2497 285 assert(s->refcount() != 0, "should have nonzero refcount");
duke@435 286 tag_at_put(which, JVM_CONSTANT_Utf8);
coleenp@2497 287 slot_at_put(which, s);
duke@435 288 }
duke@435 289
duke@435 290 void string_at_put(int which, oop str) {
coleenp@2497 291 // Overwrite the old index with a GC friendly value so
coleenp@2497 292 // that if G1 looks during the transition during oop_store it won't
coleenp@2497 293 // assert the symbol is not an oop.
coleenp@2497 294 *obj_at_addr_raw(which) = NULL;
coleenp@2497 295 assert(str != NULL, "resolved string shouldn't be null");
coleenp@2497 296 obj_at_put(which, str);
duke@435 297 release_tag_at_put(which, JVM_CONSTANT_String);
duke@435 298 if (UseConcMarkSweepGC) {
duke@435 299 // In case the earlier card-mark was consumed by a concurrent
duke@435 300 // marking thread before the tag was updated, redirty the card.
coleenp@2497 301 obj_at_put_without_check(which, str);
duke@435 302 }
duke@435 303 }
duke@435 304
twisti@1573 305 void object_at_put(int which, oop str) {
coleenp@2497 306 obj_at_put(which, str);
twisti@1573 307 release_tag_at_put(which, JVM_CONSTANT_Object);
twisti@1573 308 if (UseConcMarkSweepGC) {
twisti@1573 309 // In case the earlier card-mark was consumed by a concurrent
twisti@1573 310 // marking thread before the tag was updated, redirty the card.
coleenp@2497 311 obj_at_put_without_check(which, str);
twisti@1573 312 }
twisti@1573 313 }
twisti@1573 314
duke@435 315 // For temporary use while constructing constant pool
duke@435 316 void string_index_at_put(int which, int string_index) {
duke@435 317 tag_at_put(which, JVM_CONSTANT_StringIndex);
duke@435 318 *int_at_addr(which) = string_index;
duke@435 319 }
duke@435 320
duke@435 321 void field_at_put(int which, int class_index, int name_and_type_index) {
duke@435 322 tag_at_put(which, JVM_CONSTANT_Fieldref);
duke@435 323 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index;
duke@435 324 }
duke@435 325
duke@435 326 void method_at_put(int which, int class_index, int name_and_type_index) {
duke@435 327 tag_at_put(which, JVM_CONSTANT_Methodref);
duke@435 328 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index;
duke@435 329 }
duke@435 330
duke@435 331 void interface_method_at_put(int which, int class_index, int name_and_type_index) {
duke@435 332 tag_at_put(which, JVM_CONSTANT_InterfaceMethodref);
duke@435 333 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; // Not so nice
duke@435 334 }
duke@435 335
duke@435 336 void name_and_type_at_put(int which, int name_index, int signature_index) {
duke@435 337 tag_at_put(which, JVM_CONSTANT_NameAndType);
duke@435 338 *int_at_addr(which) = ((jint) signature_index<<16) | name_index; // Not so nice
duke@435 339 }
duke@435 340
duke@435 341 // Tag query
duke@435 342
duke@435 343 constantTag tag_at(int which) const { return (constantTag)tags()->byte_at_acquire(which); }
duke@435 344
duke@435 345 // Whether the entry is a pointer that must be GC'd.
duke@435 346 bool is_pointer_entry(int which) {
duke@435 347 constantTag tag = tag_at(which);
duke@435 348 return tag.is_klass() ||
twisti@1573 349 tag.is_string() ||
twisti@1573 350 tag.is_object();
duke@435 351 }
duke@435 352
coleenp@2497 353 // Whether the entry points to an object for ldc (resolved or not)
coleenp@2497 354 bool is_object_entry(int which) {
coleenp@2497 355 constantTag tag = tag_at(which);
coleenp@2497 356 return is_pointer_entry(which) ||
coleenp@2497 357 tag.is_unresolved_klass() ||
coleenp@2497 358 tag.is_unresolved_string() ||
coleenp@2497 359 tag.is_symbol();
coleenp@2497 360 }
coleenp@2497 361
duke@435 362 // Fetching constants
duke@435 363
duke@435 364 klassOop klass_at(int which, TRAPS) {
duke@435 365 constantPoolHandle h_this(THREAD, this);
duke@435 366 return klass_at_impl(h_this, which, CHECK_NULL);
duke@435 367 }
duke@435 368
coleenp@2497 369 Symbol* klass_name_at(int which); // Returns the name, w/o resolving.
duke@435 370
duke@435 371 klassOop resolved_klass_at(int which) { // Used by Compiler
duke@435 372 guarantee(tag_at(which).is_klass(), "Corrupted constant pool");
duke@435 373 // Must do an acquire here in case another thread resolved the klass
duke@435 374 // behind our back, lest we later load stale values thru the oop.
coleenp@2497 375 return klassOop(CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_oop());
duke@435 376 }
duke@435 377
duke@435 378 // This method should only be used with a cpool lock or during parsing or gc
coleenp@2497 379 Symbol* unresolved_klass_at(int which) { // Temporary until actual use
coleenp@2497 380 Symbol* s = CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_symbol();
duke@435 381 // check that the klass is still unresolved.
duke@435 382 assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool");
duke@435 383 return s;
duke@435 384 }
duke@435 385
duke@435 386 // RedefineClasses() API support:
coleenp@2497 387 Symbol* klass_at_noresolve(int which) { return klass_name_at(which); }
duke@435 388
duke@435 389 jint int_at(int which) {
duke@435 390 assert(tag_at(which).is_int(), "Corrupted constant pool");
duke@435 391 return *int_at_addr(which);
duke@435 392 }
duke@435 393
duke@435 394 jlong long_at(int which) {
duke@435 395 assert(tag_at(which).is_long(), "Corrupted constant pool");
duke@435 396 // return *long_at_addr(which);
duke@435 397 u8 tmp = Bytes::get_native_u8((address)&base()[which]);
duke@435 398 return *((jlong*)&tmp);
duke@435 399 }
duke@435 400
duke@435 401 jfloat float_at(int which) {
duke@435 402 assert(tag_at(which).is_float(), "Corrupted constant pool");
duke@435 403 return *float_at_addr(which);
duke@435 404 }
duke@435 405
duke@435 406 jdouble double_at(int which) {
duke@435 407 assert(tag_at(which).is_double(), "Corrupted constant pool");
duke@435 408 u8 tmp = Bytes::get_native_u8((address)&base()[which]);
duke@435 409 return *((jdouble*)&tmp);
duke@435 410 }
duke@435 411
coleenp@2497 412 Symbol* symbol_at(int which) {
duke@435 413 assert(tag_at(which).is_utf8(), "Corrupted constant pool");
coleenp@2497 414 return slot_at(which).get_symbol();
duke@435 415 }
duke@435 416
duke@435 417 oop string_at(int which, TRAPS) {
duke@435 418 constantPoolHandle h_this(THREAD, this);
duke@435 419 return string_at_impl(h_this, which, CHECK_NULL);
duke@435 420 }
duke@435 421
twisti@1573 422 oop object_at(int which) {
twisti@1573 423 assert(tag_at(which).is_object(), "Corrupted constant pool");
coleenp@2497 424 return slot_at(which).get_oop();
twisti@1573 425 }
twisti@1573 426
jrose@866 427 // A "pseudo-string" is an non-string oop that has found is way into
jrose@866 428 // a String entry.
twisti@2698 429 // Under EnableInvokeDynamic this can happen if the user patches a live
jrose@866 430 // object into a CONSTANT_String entry of an anonymous class.
jrose@866 431 // Method oops internally created for method handles may also
jrose@866 432 // use pseudo-strings to link themselves to related metaobjects.
jrose@866 433
jrose@866 434 bool is_pseudo_string_at(int which);
jrose@866 435
jrose@866 436 oop pseudo_string_at(int which) {
jrose@866 437 assert(tag_at(which).is_string(), "Corrupted constant pool");
coleenp@2497 438 return slot_at(which).get_oop();
jrose@866 439 }
jrose@866 440
jrose@866 441 void pseudo_string_at_put(int which, oop x) {
twisti@2698 442 assert(EnableInvokeDynamic, "");
jrose@866 443 set_pseudo_string(); // mark header
jrose@866 444 assert(tag_at(which).is_string() || tag_at(which).is_unresolved_string(), "Corrupted constant pool");
jrose@866 445 string_at_put(which, x); // this works just fine
jrose@866 446 }
jrose@866 447
duke@435 448 // only called when we are sure a string entry is already resolved (via an
duke@435 449 // earlier string_at call.
duke@435 450 oop resolved_string_at(int which) {
duke@435 451 assert(tag_at(which).is_string(), "Corrupted constant pool");
duke@435 452 // Must do an acquire here in case another thread resolved the klass
duke@435 453 // behind our back, lest we later load stale values thru the oop.
coleenp@2497 454 return CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_oop();
duke@435 455 }
duke@435 456
duke@435 457 // This method should only be used with a cpool lock or during parsing or gc
coleenp@2497 458 Symbol* unresolved_string_at(int which) { // Temporary until actual use
coleenp@2497 459 Symbol* s = CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_symbol();
duke@435 460 // check that the string is still unresolved.
duke@435 461 assert(tag_at(which).is_unresolved_string(), "Corrupted constant pool");
duke@435 462 return s;
duke@435 463 }
duke@435 464
duke@435 465 // Returns an UTF8 for a CONSTANT_String entry at a given index.
duke@435 466 // UTF8 char* representation was chosen to avoid conversion of
coleenp@2497 467 // java_lang_Strings at resolved entries into Symbol*s
duke@435 468 // or vice versa.
jrose@866 469 // Caller is responsible for checking for pseudo-strings.
duke@435 470 char* string_at_noresolve(int which);
duke@435 471
duke@435 472 jint name_and_type_at(int which) {
duke@435 473 assert(tag_at(which).is_name_and_type(), "Corrupted constant pool");
duke@435 474 return *int_at_addr(which);
duke@435 475 }
duke@435 476
jrose@1957 477 int method_handle_ref_kind_at(int which) {
jrose@1957 478 assert(tag_at(which).is_method_handle(), "Corrupted constant pool");
jrose@1957 479 return extract_low_short_from_int(*int_at_addr(which)); // mask out unwanted ref_index bits
jrose@1957 480 }
jrose@1957 481 int method_handle_index_at(int which) {
jrose@1957 482 assert(tag_at(which).is_method_handle(), "Corrupted constant pool");
jrose@1957 483 return extract_high_short_from_int(*int_at_addr(which)); // shift out unwanted ref_kind bits
jrose@1957 484 }
jrose@1957 485 int method_type_index_at(int which) {
jrose@1957 486 assert(tag_at(which).is_method_type(), "Corrupted constant pool");
jrose@1957 487 return *int_at_addr(which);
jrose@1957 488 }
jrose@1957 489 // Derived queries:
coleenp@2497 490 Symbol* method_handle_name_ref_at(int which) {
jrose@1957 491 int member = method_handle_index_at(which);
jrose@1957 492 return impl_name_ref_at(member, true);
jrose@1957 493 }
coleenp@2497 494 Symbol* method_handle_signature_ref_at(int which) {
jrose@1957 495 int member = method_handle_index_at(which);
jrose@1957 496 return impl_signature_ref_at(member, true);
jrose@1957 497 }
jrose@1957 498 int method_handle_klass_index_at(int which) {
jrose@1957 499 int member = method_handle_index_at(which);
jrose@1957 500 return impl_klass_ref_index_at(member, true);
jrose@1957 501 }
coleenp@2497 502 Symbol* method_type_signature_at(int which) {
jrose@1957 503 int sym = method_type_index_at(which);
jrose@1957 504 return symbol_at(sym);
jrose@1957 505 }
jrose@2268 506
jrose@2353 507 int invoke_dynamic_name_and_type_ref_index_at(int which) {
jrose@2353 508 assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool");
jrose@2353 509 return extract_high_short_from_int(*int_at_addr(which));
jrose@2268 510 }
jrose@2353 511 int invoke_dynamic_bootstrap_specifier_index(int which) {
jrose@2353 512 assert(tag_at(which).value() == JVM_CONSTANT_InvokeDynamic, "Corrupted constant pool");
jrose@2353 513 return extract_low_short_from_int(*int_at_addr(which));
jrose@2268 514 }
jrose@2353 515 int invoke_dynamic_operand_base(int which) {
jrose@2353 516 int bootstrap_specifier_index = invoke_dynamic_bootstrap_specifier_index(which);
jrose@2353 517 return operand_offset_at(operands(), bootstrap_specifier_index);
jrose@2268 518 }
jrose@2353 519 // The first part of the operands array consists of an index into the second part.
jrose@2353 520 // Extract a 32-bit index value from the first part.
jrose@2353 521 static int operand_offset_at(typeArrayOop operands, int bootstrap_specifier_index) {
jrose@2353 522 int n = (bootstrap_specifier_index * 2);
jrose@2353 523 assert(n >= 0 && n+2 <= operands->length(), "oob");
jrose@2353 524 // The first 32-bit index points to the beginning of the second part
jrose@2353 525 // of the operands array. Make sure this index is in the first part.
jrose@2353 526 DEBUG_ONLY(int second_part = build_int_from_shorts(operands->short_at(0),
jrose@2353 527 operands->short_at(1)));
jrose@2353 528 assert(second_part == 0 || n+2 <= second_part, "oob (2)");
jrose@2353 529 int offset = build_int_from_shorts(operands->short_at(n+0),
jrose@2353 530 operands->short_at(n+1));
jrose@2353 531 // The offset itself must point into the second part of the array.
jrose@2353 532 assert(offset == 0 || offset >= second_part && offset <= operands->length(), "oob (3)");
jrose@2353 533 return offset;
jrose@2268 534 }
jrose@2353 535 static void operand_offset_at_put(typeArrayOop operands, int bootstrap_specifier_index, int offset) {
jrose@2353 536 int n = bootstrap_specifier_index * 2;
jrose@2353 537 assert(n >= 0 && n+2 <= operands->length(), "oob");
jrose@2353 538 operands->short_at_put(n+0, extract_low_short_from_int(offset));
jrose@2353 539 operands->short_at_put(n+1, extract_high_short_from_int(offset));
jrose@2268 540 }
jrose@2353 541 static int operand_array_length(typeArrayOop operands) {
jrose@2353 542 if (operands == NULL || operands->length() == 0) return 0;
jrose@2353 543 int second_part = operand_offset_at(operands, 0);
jrose@2353 544 return (second_part / 2);
jrose@2268 545 }
jrose@2268 546
jrose@2353 547 #ifdef ASSERT
jrose@2353 548 // operand tuples fit together exactly, end to end
jrose@2353 549 static int operand_limit_at(typeArrayOop operands, int bootstrap_specifier_index) {
jrose@2353 550 int nextidx = bootstrap_specifier_index + 1;
jrose@2353 551 if (nextidx == operand_array_length(operands))
jrose@2353 552 return operands->length();
jrose@2353 553 else
jrose@2353 554 return operand_offset_at(operands, nextidx);
jrose@2353 555 }
jrose@2353 556 int invoke_dynamic_operand_limit(int which) {
jrose@2353 557 int bootstrap_specifier_index = invoke_dynamic_bootstrap_specifier_index(which);
jrose@2353 558 return operand_limit_at(operands(), bootstrap_specifier_index);
jrose@2353 559 }
jrose@2353 560 #endif //ASSERT
jrose@2353 561
jrose@2353 562 // layout of InvokeDynamic bootstrap method specifier (in second part of operands array):
jrose@2268 563 enum {
jrose@2268 564 _indy_bsm_offset = 0, // CONSTANT_MethodHandle bsm
jrose@2353 565 _indy_argc_offset = 1, // u2 argc
jrose@2353 566 _indy_argv_offset = 2 // u2 argv[argc]
jrose@2268 567 };
jrose@2015 568 int invoke_dynamic_bootstrap_method_ref_index_at(int which) {
jrose@2015 569 assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool");
jrose@2353 570 int op_base = invoke_dynamic_operand_base(which);
jrose@2353 571 return operands()->short_at(op_base + _indy_bsm_offset);
jrose@2268 572 }
jrose@2268 573 int invoke_dynamic_argument_count_at(int which) {
jrose@2268 574 assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool");
jrose@2353 575 int op_base = invoke_dynamic_operand_base(which);
jrose@2353 576 int argc = operands()->short_at(op_base + _indy_argc_offset);
jrose@2353 577 DEBUG_ONLY(int end_offset = op_base + _indy_argv_offset + argc;
jrose@2353 578 int next_offset = invoke_dynamic_operand_limit(which));
jrose@2353 579 assert(end_offset == next_offset, "matched ending");
jrose@2268 580 return argc;
jrose@2268 581 }
jrose@2268 582 int invoke_dynamic_argument_index_at(int which, int j) {
jrose@2353 583 int op_base = invoke_dynamic_operand_base(which);
jrose@2353 584 DEBUG_ONLY(int argc = operands()->short_at(op_base + _indy_argc_offset));
jrose@2353 585 assert((uint)j < (uint)argc, "oob");
jrose@2353 586 return operands()->short_at(op_base + _indy_argv_offset + j);
jrose@2015 587 }
jrose@1957 588
jrose@1161 589 // The following methods (name/signature/klass_ref_at, klass_ref_at_noresolve,
jrose@1494 590 // name_and_type_ref_index_at) all expect to be passed indices obtained
jrose@2265 591 // directly from the bytecode.
jrose@1494 592 // If the indices are meant to refer to fields or methods, they are
jrose@2265 593 // actually rewritten constant pool cache indices.
jrose@1494 594 // The routine remap_instruction_operand_from_cache manages the adjustment
jrose@1494 595 // of these values back to constant pool indices.
jrose@1161 596
jrose@1494 597 // There are also "uncached" versions which do not adjust the operand index; see below.
duke@435 598
jrose@2265 599 // FIXME: Consider renaming these with a prefix "cached_" to make the distinction clear.
jrose@2265 600 // In a few cases (the verifier) there are uses before a cpcache has been built,
jrose@2265 601 // which are handled by a dynamic check in remap_instruction_operand_from_cache.
jrose@2265 602 // FIXME: Remove the dynamic check, and adjust all callers to specify the correct mode.
jrose@2265 603
duke@435 604 // Lookup for entries consisting of (klass_index, name_and_type index)
duke@435 605 klassOop klass_ref_at(int which, TRAPS);
coleenp@2497 606 Symbol* klass_ref_at_noresolve(int which);
coleenp@2497 607 Symbol* name_ref_at(int which) { return impl_name_ref_at(which, false); }
coleenp@2497 608 Symbol* signature_ref_at(int which) { return impl_signature_ref_at(which, false); }
duke@435 609
jrose@1161 610 int klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, false); }
jrose@1161 611 int name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, false); }
duke@435 612
duke@435 613 // Lookup for entries consisting of (name_index, signature_index)
jrose@1161 614 int name_ref_index_at(int which_nt); // == low-order jshort of name_and_type_at(which_nt)
jrose@1161 615 int signature_ref_index_at(int which_nt); // == high-order jshort of name_and_type_at(which_nt)
duke@435 616
duke@435 617 BasicType basic_type_for_signature_at(int which);
duke@435 618
duke@435 619 // Resolve string constants (to prevent allocation during compilation)
duke@435 620 void resolve_string_constants(TRAPS) {
duke@435 621 constantPoolHandle h_this(THREAD, this);
duke@435 622 resolve_string_constants_impl(h_this, CHECK);
duke@435 623 }
duke@435 624
jrose@2268 625 private:
jrose@2268 626 enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };
jrose@2268 627 public:
jrose@2268 628
jrose@1957 629 // Resolve late bound constants.
jrose@1957 630 oop resolve_constant_at(int index, TRAPS) {
jrose@1957 631 constantPoolHandle h_this(THREAD, this);
jrose@2268 632 return resolve_constant_at_impl(h_this, index, _no_index_sentinel, THREAD);
jrose@1957 633 }
jrose@1957 634
jrose@1957 635 oop resolve_cached_constant_at(int cache_index, TRAPS) {
jrose@1957 636 constantPoolHandle h_this(THREAD, this);
jrose@2268 637 return resolve_constant_at_impl(h_this, _no_index_sentinel, cache_index, THREAD);
jrose@2268 638 }
jrose@2268 639
jrose@2268 640 oop resolve_possibly_cached_constant_at(int pool_index, TRAPS) {
jrose@2268 641 constantPoolHandle h_this(THREAD, this);
jrose@2268 642 return resolve_constant_at_impl(h_this, pool_index, _possible_index_sentinel, THREAD);
jrose@1957 643 }
jrose@1957 644
duke@435 645 // Klass name matches name at offset
duke@435 646 bool klass_name_at_matches(instanceKlassHandle k, int which);
duke@435 647
duke@435 648 // Sizing
coleenp@548 649 int length() const { return _length; }
coleenp@548 650 void set_length(int length) { _length = length; }
coleenp@548 651
coleenp@548 652 // Tells whether index is within bounds.
coleenp@548 653 bool is_within_bounds(int index) const {
coleenp@548 654 return 0 <= index && index < length();
coleenp@548 655 }
coleenp@548 656
duke@435 657 static int header_size() { return sizeof(constantPoolOopDesc)/HeapWordSize; }
duke@435 658 static int object_size(int length) { return align_object_size(header_size() + length); }
duke@435 659 int object_size() { return object_size(length()); }
duke@435 660
jmasa@953 661 bool is_conc_safe() { return _is_conc_safe; }
jmasa@953 662 void set_is_conc_safe(bool v) { _is_conc_safe = v; }
jmasa@953 663
duke@435 664 friend class constantPoolKlass;
duke@435 665 friend class ClassFileParser;
duke@435 666 friend class SystemDictionary;
duke@435 667
duke@435 668 // Used by compiler to prevent classloading.
jrose@2982 669 static methodOop method_at_if_loaded (constantPoolHandle this_oop, int which,
jrose@2982 670 Bytecodes::Code bc = Bytecodes::_illegal);
duke@435 671 static klassOop klass_at_if_loaded (constantPoolHandle this_oop, int which);
duke@435 672 static klassOop klass_ref_at_if_loaded (constantPoolHandle this_oop, int which);
duke@435 673 // Same as above - but does LinkResolving.
duke@435 674 static klassOop klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS);
duke@435 675
duke@435 676 // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the
jrose@2265 677 // future by other Java code. These take constant pool indices rather than
duke@435 678 // constant pool cache indices as do the peer methods above.
coleenp@2497 679 Symbol* uncached_klass_ref_at_noresolve(int which);
coleenp@2497 680 Symbol* uncached_name_ref_at(int which) { return impl_name_ref_at(which, true); }
coleenp@2497 681 Symbol* uncached_signature_ref_at(int which) { return impl_signature_ref_at(which, true); }
jrose@1161 682 int uncached_klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, true); }
jrose@1161 683 int uncached_name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, true); }
duke@435 684
duke@435 685 // Sharing
duke@435 686 int pre_resolve_shared_klasses(TRAPS);
coleenp@2497 687 void shared_symbols_iterate(SymbolClosure* closure0);
duke@435 688 void shared_tags_iterate(OopClosure* closure0);
duke@435 689 void shared_strings_iterate(OopClosure* closure0);
duke@435 690
duke@435 691 // Debugging
duke@435 692 const char* printable_name_at(int which) PRODUCT_RETURN0;
duke@435 693
jrose@1920 694 #ifdef ASSERT
jrose@1920 695 enum { CPCACHE_INDEX_TAG = 0x10000 }; // helps keep CP cache indices distinct from CP indices
jrose@1957 696 #else
jrose@1957 697 enum { CPCACHE_INDEX_TAG = 0 }; // in product mode, this zero value is a no-op
jrose@1920 698 #endif //ASSERT
jrose@1920 699
duke@435 700 private:
duke@435 701
coleenp@2497 702 Symbol* impl_name_ref_at(int which, bool uncached);
coleenp@2497 703 Symbol* impl_signature_ref_at(int which, bool uncached);
jrose@1161 704 int impl_klass_ref_index_at(int which, bool uncached);
jrose@1161 705 int impl_name_and_type_ref_index_at(int which, bool uncached);
jrose@1161 706
jrose@1920 707 int remap_instruction_operand_from_cache(int operand); // operand must be biased by CPCACHE_INDEX_TAG
duke@435 708
duke@435 709 // Used while constructing constant pool (only by ClassFileParser)
duke@435 710 jint klass_index_at(int which) {
duke@435 711 assert(tag_at(which).is_klass_index(), "Corrupted constant pool");
duke@435 712 return *int_at_addr(which);
duke@435 713 }
duke@435 714
duke@435 715 jint string_index_at(int which) {
duke@435 716 assert(tag_at(which).is_string_index(), "Corrupted constant pool");
duke@435 717 return *int_at_addr(which);
duke@435 718 }
duke@435 719
duke@435 720 // Performs the LinkResolver checks
duke@435 721 static void verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle klass, TRAPS);
duke@435 722
duke@435 723 // Implementation of methods that needs an exposed 'this' pointer, in order to
duke@435 724 // handle GC while executing the method
duke@435 725 static klassOop klass_at_impl(constantPoolHandle this_oop, int which, TRAPS);
duke@435 726 static oop string_at_impl(constantPoolHandle this_oop, int which, TRAPS);
duke@435 727
duke@435 728 // Resolve string constants (to prevent allocation during compilation)
duke@435 729 static void resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS);
duke@435 730
jrose@1957 731 static oop resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS);
jrose@1957 732
duke@435 733 public:
duke@435 734 // Merging constantPoolOop support:
duke@435 735 bool compare_entry_to(int index1, constantPoolHandle cp2, int index2, TRAPS);
jrose@2353 736 void copy_cp_to(int start_i, int end_i, constantPoolHandle to_cp, int to_i, TRAPS) {
jrose@2353 737 constantPoolHandle h_this(THREAD, this);
jrose@2353 738 copy_cp_to_impl(h_this, start_i, end_i, to_cp, to_i, THREAD);
jrose@2353 739 }
jrose@2353 740 static void copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i, constantPoolHandle to_cp, int to_i, TRAPS);
jrose@2353 741 static void copy_entry_to(constantPoolHandle from_cp, int from_i, constantPoolHandle to_cp, int to_i, TRAPS);
duke@435 742 int find_matching_entry(int pattern_i, constantPoolHandle search_cp, TRAPS);
duke@435 743 int orig_length() const { return _orig_length; }
duke@435 744 void set_orig_length(int orig_length) { _orig_length = orig_length; }
duke@435 745
coleenp@2497 746 // Decrease ref counts of symbols that are in the constant pool
coleenp@2497 747 // when the holder class is unloaded
coleenp@2497 748 void unreference_symbols();
duke@435 749
duke@435 750 // JVMTI accesss - GetConstantPool, RetransformClasses, ...
duke@435 751 friend class JvmtiConstantPoolReconstituter;
duke@435 752
duke@435 753 private:
duke@435 754 jint cpool_entry_size(jint idx);
duke@435 755 jint hash_entries_to(SymbolHashMap *symmap, SymbolHashMap *classmap);
duke@435 756
duke@435 757 // Copy cpool bytes into byte array.
duke@435 758 // Returns:
duke@435 759 // int > 0, count of the raw cpool bytes that have been copied
duke@435 760 // 0, OutOfMemory error
duke@435 761 // -1, Internal error
duke@435 762 int copy_cpool_bytes(int cpool_size,
duke@435 763 SymbolHashMap* tbl,
duke@435 764 unsigned char *bytes);
duke@435 765 };
duke@435 766
duke@435 767 class SymbolHashMapEntry : public CHeapObj {
duke@435 768 private:
duke@435 769 unsigned int _hash; // 32-bit hash for item
duke@435 770 SymbolHashMapEntry* _next; // Next element in the linked list for this bucket
coleenp@2497 771 Symbol* _symbol; // 1-st part of the mapping: symbol => value
duke@435 772 u2 _value; // 2-nd part of the mapping: symbol => value
duke@435 773
duke@435 774 public:
duke@435 775 unsigned int hash() const { return _hash; }
duke@435 776 void set_hash(unsigned int hash) { _hash = hash; }
duke@435 777
duke@435 778 SymbolHashMapEntry* next() const { return _next; }
duke@435 779 void set_next(SymbolHashMapEntry* next) { _next = next; }
duke@435 780
coleenp@2497 781 Symbol* symbol() const { return _symbol; }
coleenp@2497 782 void set_symbol(Symbol* sym) { _symbol = sym; }
duke@435 783
duke@435 784 u2 value() const { return _value; }
duke@435 785 void set_value(u2 value) { _value = value; }
duke@435 786
coleenp@2497 787 SymbolHashMapEntry(unsigned int hash, Symbol* symbol, u2 value)
duke@435 788 : _hash(hash), _symbol(symbol), _value(value), _next(NULL) {}
duke@435 789
duke@435 790 }; // End SymbolHashMapEntry class
duke@435 791
duke@435 792
duke@435 793 class SymbolHashMapBucket : public CHeapObj {
duke@435 794
duke@435 795 private:
duke@435 796 SymbolHashMapEntry* _entry;
duke@435 797
duke@435 798 public:
duke@435 799 SymbolHashMapEntry* entry() const { return _entry; }
duke@435 800 void set_entry(SymbolHashMapEntry* entry) { _entry = entry; }
duke@435 801 void clear() { _entry = NULL; }
duke@435 802
duke@435 803 }; // End SymbolHashMapBucket class
duke@435 804
duke@435 805
duke@435 806 class SymbolHashMap: public CHeapObj {
duke@435 807
duke@435 808 private:
duke@435 809 // Default number of entries in the table
duke@435 810 enum SymbolHashMap_Constants {
duke@435 811 _Def_HashMap_Size = 256
duke@435 812 };
duke@435 813
duke@435 814 int _table_size;
duke@435 815 SymbolHashMapBucket* _buckets;
duke@435 816
duke@435 817 void initialize_table(int table_size) {
duke@435 818 _table_size = table_size;
duke@435 819 _buckets = NEW_C_HEAP_ARRAY(SymbolHashMapBucket, table_size);
duke@435 820 for (int index = 0; index < table_size; index++) {
duke@435 821 _buckets[index].clear();
duke@435 822 }
duke@435 823 }
duke@435 824
duke@435 825 public:
duke@435 826
duke@435 827 int table_size() const { return _table_size; }
duke@435 828
duke@435 829 SymbolHashMap() { initialize_table(_Def_HashMap_Size); }
duke@435 830 SymbolHashMap(int table_size) { initialize_table(table_size); }
duke@435 831
duke@435 832 // hash P(31) from Kernighan & Ritchie
duke@435 833 static unsigned int compute_hash(const char* str, int len) {
duke@435 834 unsigned int hash = 0;
duke@435 835 while (len-- > 0) {
duke@435 836 hash = 31*hash + (unsigned) *str;
duke@435 837 str++;
duke@435 838 }
duke@435 839 return hash;
duke@435 840 }
duke@435 841
duke@435 842 SymbolHashMapEntry* bucket(int i) {
duke@435 843 return _buckets[i].entry();
duke@435 844 }
duke@435 845
coleenp@2497 846 void add_entry(Symbol* sym, u2 value);
coleenp@2497 847 SymbolHashMapEntry* find_entry(Symbol* sym);
duke@435 848
coleenp@2497 849 u2 symbol_to_value(Symbol* sym) {
duke@435 850 SymbolHashMapEntry *entry = find_entry(sym);
duke@435 851 return (entry == NULL) ? 0 : entry->value();
duke@435 852 }
duke@435 853
duke@435 854 ~SymbolHashMap() {
duke@435 855 SymbolHashMapEntry* next;
duke@435 856 for (int i = 0; i < _table_size; i++) {
duke@435 857 for (SymbolHashMapEntry* cur = bucket(i); cur != NULL; cur = next) {
duke@435 858 next = cur->next();
duke@435 859 delete(cur);
duke@435 860 }
duke@435 861 }
duke@435 862 delete _buckets;
duke@435 863 }
duke@435 864 }; // End SymbolHashMap class
stefank@2314 865
stefank@2314 866 #endif // SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP

mercurial