comparison src/share/vm/oops/constantPoolOop.hpp @ 2177:3582bf76420e

6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
author coleenp
date Thu, 27 Jan 2011 16:11:27 -0800
parents dad31fc330cd
children b92c45f2bc75
comparison
equal deleted inserted replaced
2176:27e4ea99855d 2177:3582bf76420e
25 #ifndef SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP 25 #ifndef SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP
26 #define SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP 26 #define SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP
27 27
28 #include "oops/arrayOop.hpp" 28 #include "oops/arrayOop.hpp"
29 #include "oops/cpCacheOop.hpp" 29 #include "oops/cpCacheOop.hpp"
30 #include "oops/symbol.hpp"
30 #include "oops/typeArrayOop.hpp" 31 #include "oops/typeArrayOop.hpp"
31 #include "utilities/constantTag.hpp" 32 #include "utilities/constantTag.hpp"
32 #ifdef TARGET_ARCH_x86 33 #ifdef TARGET_ARCH_x86
33 # include "bytes_x86.hpp" 34 # include "bytes_x86.hpp"
34 #endif 35 #endif
45 // Most of the constant pool entries are written during class parsing, which 46 // Most of the constant pool entries are written during class parsing, which
46 // is safe. For klass and string types, the constant pool entry is 47 // is safe. For klass and string types, the constant pool entry is
47 // modified when the entry is resolved. If a klass or string constant pool 48 // modified when the entry is resolved. If a klass or string constant pool
48 // entry is read without a lock, only the resolved state guarantees that 49 // entry is read without a lock, only the resolved state guarantees that
49 // the entry in the constant pool is a klass or String object and 50 // the entry in the constant pool is a klass or String object and
50 // not a symbolOop. 51 // not a Symbol*.
51 52
52 class SymbolHashMap; 53 class SymbolHashMap;
54
55 class CPSlot VALUE_OBJ_CLASS_SPEC {
56 intptr_t _ptr;
57 public:
58 CPSlot(intptr_t ptr): _ptr(ptr) {}
59 CPSlot(void* ptr): _ptr((intptr_t)ptr) {}
60 CPSlot(oop ptr): _ptr((intptr_t)ptr) {}
61 CPSlot(Symbol* ptr): _ptr((intptr_t)ptr | 1) {}
62
63 intptr_t value() { return _ptr; }
64 bool is_oop() { return (_ptr & 1) == 0; }
65 bool is_metadata() { return (_ptr & 1) == 1; }
66
67 oop get_oop() {
68 assert(is_oop(), "bad call");
69 return oop(_ptr);
70 }
71 Symbol* get_symbol() {
72 assert(is_metadata(), "bad call");
73 return (Symbol*)(_ptr & ~1);
74 }
75 };
53 76
54 class constantPoolOopDesc : public oopDesc { 77 class constantPoolOopDesc : public oopDesc {
55 friend class VMStructs; 78 friend class VMStructs;
56 friend class BytecodeInterpreter; // Directly extracts an oop in the pool for fast instanceof/checkcast 79 friend class BytecodeInterpreter; // Directly extracts an oop in the pool for fast instanceof/checkcast
57 private: 80 private:
87 intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(constantPoolOopDesc)); } 110 intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(constantPoolOopDesc)); }
88 oop* tags_addr() { return (oop*)&_tags; } 111 oop* tags_addr() { return (oop*)&_tags; }
89 oop* cache_addr() { return (oop*)&_cache; } 112 oop* cache_addr() { return (oop*)&_cache; }
90 oop* operands_addr() { return (oop*)&_operands; } 113 oop* operands_addr() { return (oop*)&_operands; }
91 114
92 oop* obj_at_addr(int which) const { 115 CPSlot slot_at(int which) {
116 assert(is_within_bounds(which), "index out of bounds");
117 // There's a transitional value of zero when converting from
118 // Symbol->0->Klass for G1 when resolving classes and strings.
119 // wait for the value to be non-zero (this is temporary)
120 volatile intptr_t adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which));
121 if (adr == 0 && which != 0) {
122 constantTag t = tag_at(which);
123 if (t.is_unresolved_klass() || t.is_klass() ||
124 t.is_unresolved_string() || t.is_string()) {
125 while ((adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))) == 0);
126 }
127 }
128 return CPSlot(adr);
129 }
130
131 void slot_at_put(int which, CPSlot s) const {
132 assert(is_within_bounds(which), "index out of bounds");
133 *(intptr_t*)&base()[which] = s.value();
134 }
135 oop* obj_at_addr_raw(int which) const {
93 assert(is_within_bounds(which), "index out of bounds"); 136 assert(is_within_bounds(which), "index out of bounds");
94 return (oop*) &base()[which]; 137 return (oop*) &base()[which];
138 }
139
140 void obj_at_put_without_check(int which, oop o) {
141 assert(is_within_bounds(which), "index out of bounds");
142 oop_store_without_check((volatile oop *)obj_at_addr_raw(which), o);
143 }
144
145 void obj_at_put(int which, oop o) const {
146 assert(is_within_bounds(which), "index out of bounds");
147 oop_store((volatile oop*)obj_at_addr_raw(which), o);
95 } 148 }
96 149
97 jint* int_at_addr(int which) const { 150 jint* int_at_addr(int which) const {
98 assert(is_within_bounds(which), "index out of bounds"); 151 assert(is_within_bounds(which), "index out of bounds");
99 return (jint*) &base()[which]; 152 return (jint*) &base()[which];
139 static int pool_holder_offset_in_bytes() { return offset_of(constantPoolOopDesc, _pool_holder); } 192 static int pool_holder_offset_in_bytes() { return offset_of(constantPoolOopDesc, _pool_holder); }
140 193
141 // Storing constants 194 // Storing constants
142 195
143 void klass_at_put(int which, klassOop k) { 196 void klass_at_put(int which, klassOop k) {
144 oop_store_without_check((volatile oop *)obj_at_addr(which), oop(k)); 197 // Overwrite the old index with a GC friendly value so
198 // that if G1 looks during the transition during oop_store it won't
199 // assert the symbol is not an oop.
200 *obj_at_addr_raw(which) = NULL;
201 assert(k != NULL, "resolved class shouldn't be null");
202 obj_at_put_without_check(which, k);
145 // The interpreter assumes when the tag is stored, the klass is resolved 203 // The interpreter assumes when the tag is stored, the klass is resolved
146 // and the klassOop is a klass rather than a symbolOop, so we need 204 // and the klassOop is a klass rather than a Symbol*, so we need
147 // hardware store ordering here. 205 // hardware store ordering here.
148 release_tag_at_put(which, JVM_CONSTANT_Class); 206 release_tag_at_put(which, JVM_CONSTANT_Class);
149 if (UseConcMarkSweepGC) { 207 if (UseConcMarkSweepGC) {
150 // In case the earlier card-mark was consumed by a concurrent 208 // In case the earlier card-mark was consumed by a concurrent
151 // marking thread before the tag was updated, redirty the card. 209 // marking thread before the tag was updated, redirty the card.
152 oop_store_without_check((volatile oop *)obj_at_addr(which), oop(k)); 210 obj_at_put_without_check(which, k);
153 } 211 }
154 } 212 }
155 213
156 // For temporary use while constructing constant pool 214 // For temporary use while constructing constant pool
157 void klass_index_at_put(int which, int name_index) { 215 void klass_index_at_put(int which, int name_index) {
158 tag_at_put(which, JVM_CONSTANT_ClassIndex); 216 tag_at_put(which, JVM_CONSTANT_ClassIndex);
159 *int_at_addr(which) = name_index; 217 *int_at_addr(which) = name_index;
160 } 218 }
161 219
162 // Temporary until actual use 220 // Temporary until actual use
163 void unresolved_klass_at_put(int which, symbolOop s) { 221 void unresolved_klass_at_put(int which, Symbol* s) {
164 // Overwrite the old index with a GC friendly value so
165 // that if GC looks during the transition it won't try
166 // to treat a small integer as oop.
167 *obj_at_addr(which) = NULL;
168 release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass); 222 release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass);
169 oop_store_without_check(obj_at_addr(which), oop(s)); 223 slot_at_put(which, s);
170 } 224 }
171 225
172 void method_handle_index_at_put(int which, int ref_kind, int ref_index) { 226 void method_handle_index_at_put(int which, int ref_kind, int ref_index) {
173 tag_at_put(which, JVM_CONSTANT_MethodHandle); 227 tag_at_put(which, JVM_CONSTANT_MethodHandle);
174 *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind; 228 *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind;
189 *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_method_index; 243 *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_method_index;
190 assert(AllowTransitionalJSR292, ""); 244 assert(AllowTransitionalJSR292, "");
191 } 245 }
192 246
193 // Temporary until actual use 247 // Temporary until actual use
194 void unresolved_string_at_put(int which, symbolOop s) { 248 void unresolved_string_at_put(int which, Symbol* s) {
195 *obj_at_addr(which) = NULL;
196 release_tag_at_put(which, JVM_CONSTANT_UnresolvedString); 249 release_tag_at_put(which, JVM_CONSTANT_UnresolvedString);
197 oop_store_without_check(obj_at_addr(which), oop(s)); 250 slot_at_put(which, s);
198 } 251 }
199 252
200 void int_at_put(int which, jint i) { 253 void int_at_put(int which, jint i) {
201 tag_at_put(which, JVM_CONSTANT_Integer); 254 tag_at_put(which, JVM_CONSTANT_Integer);
202 *int_at_addr(which) = i; 255 *int_at_addr(which) = i;
218 // *double_at_addr(which) = d; 271 // *double_at_addr(which) = d;
219 // u8 temp = *(u8*) &d; 272 // u8 temp = *(u8*) &d;
220 Bytes::put_native_u8((address) double_at_addr(which), *((u8*) &d)); 273 Bytes::put_native_u8((address) double_at_addr(which), *((u8*) &d));
221 } 274 }
222 275
223 void symbol_at_put(int which, symbolOop s) { 276 Symbol** symbol_at_addr(int which) const {
277 assert(is_within_bounds(which), "index out of bounds");
278 return (Symbol**) &base()[which];
279 }
280
281 void symbol_at_put(int which, Symbol* s) {
282 assert(s->refcount() != 0, "should have nonzero refcount");
224 tag_at_put(which, JVM_CONSTANT_Utf8); 283 tag_at_put(which, JVM_CONSTANT_Utf8);
225 oop_store_without_check(obj_at_addr(which), oop(s)); 284 slot_at_put(which, s);
226 } 285 }
227 286
228 void string_at_put(int which, oop str) { 287 void string_at_put(int which, oop str) {
229 oop_store((volatile oop*)obj_at_addr(which), str); 288 // Overwrite the old index with a GC friendly value so
289 // that if G1 looks during the transition during oop_store it won't
290 // assert the symbol is not an oop.
291 *obj_at_addr_raw(which) = NULL;
292 assert(str != NULL, "resolved string shouldn't be null");
293 obj_at_put(which, str);
230 release_tag_at_put(which, JVM_CONSTANT_String); 294 release_tag_at_put(which, JVM_CONSTANT_String);
231 if (UseConcMarkSweepGC) { 295 if (UseConcMarkSweepGC) {
232 // In case the earlier card-mark was consumed by a concurrent 296 // In case the earlier card-mark was consumed by a concurrent
233 // marking thread before the tag was updated, redirty the card. 297 // marking thread before the tag was updated, redirty the card.
234 oop_store_without_check((volatile oop *)obj_at_addr(which), str); 298 obj_at_put_without_check(which, str);
235 } 299 }
236 } 300 }
237 301
238 void object_at_put(int which, oop str) { 302 void object_at_put(int which, oop str) {
239 oop_store((volatile oop*) obj_at_addr(which), str); 303 obj_at_put(which, str);
240 release_tag_at_put(which, JVM_CONSTANT_Object); 304 release_tag_at_put(which, JVM_CONSTANT_Object);
241 if (UseConcMarkSweepGC) { 305 if (UseConcMarkSweepGC) {
242 // In case the earlier card-mark was consumed by a concurrent 306 // In case the earlier card-mark was consumed by a concurrent
243 // marking thread before the tag was updated, redirty the card. 307 // marking thread before the tag was updated, redirty the card.
244 oop_store_without_check((volatile oop*) obj_at_addr(which), str); 308 obj_at_put_without_check(which, str);
245 } 309 }
246 } 310 }
247 311
248 // For temporary use while constructing constant pool 312 // For temporary use while constructing constant pool
249 void string_index_at_put(int which, int string_index) { 313 void string_index_at_put(int which, int string_index) {
277 341
278 // Whether the entry is a pointer that must be GC'd. 342 // Whether the entry is a pointer that must be GC'd.
279 bool is_pointer_entry(int which) { 343 bool is_pointer_entry(int which) {
280 constantTag tag = tag_at(which); 344 constantTag tag = tag_at(which);
281 return tag.is_klass() || 345 return tag.is_klass() ||
282 tag.is_unresolved_klass() ||
283 tag.is_symbol() ||
284 tag.is_unresolved_string() ||
285 tag.is_string() || 346 tag.is_string() ||
286 tag.is_object(); 347 tag.is_object();
348 }
349
350 // Whether the entry points to an object for ldc (resolved or not)
351 bool is_object_entry(int which) {
352 constantTag tag = tag_at(which);
353 return is_pointer_entry(which) ||
354 tag.is_unresolved_klass() ||
355 tag.is_unresolved_string() ||
356 tag.is_symbol();
287 } 357 }
288 358
289 // Fetching constants 359 // Fetching constants
290 360
291 klassOop klass_at(int which, TRAPS) { 361 klassOop klass_at(int which, TRAPS) {
292 constantPoolHandle h_this(THREAD, this); 362 constantPoolHandle h_this(THREAD, this);
293 return klass_at_impl(h_this, which, CHECK_NULL); 363 return klass_at_impl(h_this, which, CHECK_NULL);
294 } 364 }
295 365
296 symbolOop klass_name_at(int which); // Returns the name, w/o resolving. 366 Symbol* klass_name_at(int which); // Returns the name, w/o resolving.
297 367
298 klassOop resolved_klass_at(int which) { // Used by Compiler 368 klassOop resolved_klass_at(int which) { // Used by Compiler
299 guarantee(tag_at(which).is_klass(), "Corrupted constant pool"); 369 guarantee(tag_at(which).is_klass(), "Corrupted constant pool");
300 // Must do an acquire here in case another thread resolved the klass 370 // Must do an acquire here in case another thread resolved the klass
301 // behind our back, lest we later load stale values thru the oop. 371 // behind our back, lest we later load stale values thru the oop.
302 return klassOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); 372 return klassOop(CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_oop());
303 } 373 }
304 374
305 // This method should only be used with a cpool lock or during parsing or gc 375 // This method should only be used with a cpool lock or during parsing or gc
306 symbolOop unresolved_klass_at(int which) { // Temporary until actual use 376 Symbol* unresolved_klass_at(int which) { // Temporary until actual use
307 symbolOop s = symbolOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); 377 Symbol* s = CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_symbol();
308 // check that the klass is still unresolved. 378 // check that the klass is still unresolved.
309 assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool"); 379 assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool");
310 return s; 380 return s;
311 } 381 }
312 382
313 // RedefineClasses() API support: 383 // RedefineClasses() API support:
314 symbolOop klass_at_noresolve(int which) { return klass_name_at(which); } 384 Symbol* klass_at_noresolve(int which) { return klass_name_at(which); }
315 385
316 jint int_at(int which) { 386 jint int_at(int which) {
317 assert(tag_at(which).is_int(), "Corrupted constant pool"); 387 assert(tag_at(which).is_int(), "Corrupted constant pool");
318 return *int_at_addr(which); 388 return *int_at_addr(which);
319 } 389 }
334 assert(tag_at(which).is_double(), "Corrupted constant pool"); 404 assert(tag_at(which).is_double(), "Corrupted constant pool");
335 u8 tmp = Bytes::get_native_u8((address)&base()[which]); 405 u8 tmp = Bytes::get_native_u8((address)&base()[which]);
336 return *((jdouble*)&tmp); 406 return *((jdouble*)&tmp);
337 } 407 }
338 408
339 symbolOop symbol_at(int which) { 409 Symbol* symbol_at(int which) {
340 assert(tag_at(which).is_utf8(), "Corrupted constant pool"); 410 assert(tag_at(which).is_utf8(), "Corrupted constant pool");
341 return symbolOop(*obj_at_addr(which)); 411 return slot_at(which).get_symbol();
342 } 412 }
343 413
344 oop string_at(int which, TRAPS) { 414 oop string_at(int which, TRAPS) {
345 constantPoolHandle h_this(THREAD, this); 415 constantPoolHandle h_this(THREAD, this);
346 return string_at_impl(h_this, which, CHECK_NULL); 416 return string_at_impl(h_this, which, CHECK_NULL);
347 } 417 }
348 418
349 oop object_at(int which) { 419 oop object_at(int which) {
350 assert(tag_at(which).is_object(), "Corrupted constant pool"); 420 assert(tag_at(which).is_object(), "Corrupted constant pool");
351 return *obj_at_addr(which); 421 return slot_at(which).get_oop();
352 } 422 }
353 423
354 // A "pseudo-string" is an non-string oop that has found is way into 424 // A "pseudo-string" is an non-string oop that has found is way into
355 // a String entry. 425 // a String entry.
356 // Under AnonymousClasses this can happen if the user patches a live 426 // Under AnonymousClasses this can happen if the user patches a live
360 430
361 bool is_pseudo_string_at(int which); 431 bool is_pseudo_string_at(int which);
362 432
363 oop pseudo_string_at(int which) { 433 oop pseudo_string_at(int which) {
364 assert(tag_at(which).is_string(), "Corrupted constant pool"); 434 assert(tag_at(which).is_string(), "Corrupted constant pool");
365 return *obj_at_addr(which); 435 return slot_at(which).get_oop();
366 } 436 }
367 437
368 void pseudo_string_at_put(int which, oop x) { 438 void pseudo_string_at_put(int which, oop x) {
369 assert(AnonymousClasses, ""); 439 assert(AnonymousClasses, "");
370 set_pseudo_string(); // mark header 440 set_pseudo_string(); // mark header
376 // earlier string_at call. 446 // earlier string_at call.
377 oop resolved_string_at(int which) { 447 oop resolved_string_at(int which) {
378 assert(tag_at(which).is_string(), "Corrupted constant pool"); 448 assert(tag_at(which).is_string(), "Corrupted constant pool");
379 // Must do an acquire here in case another thread resolved the klass 449 // Must do an acquire here in case another thread resolved the klass
380 // behind our back, lest we later load stale values thru the oop. 450 // behind our back, lest we later load stale values thru the oop.
381 return (oop)OrderAccess::load_ptr_acquire(obj_at_addr(which)); 451 return CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_oop();
382 } 452 }
383 453
384 // This method should only be used with a cpool lock or during parsing or gc 454 // This method should only be used with a cpool lock or during parsing or gc
385 symbolOop unresolved_string_at(int which) { // Temporary until actual use 455 Symbol* unresolved_string_at(int which) { // Temporary until actual use
386 symbolOop s = symbolOop((oop)OrderAccess::load_ptr_acquire(obj_at_addr(which))); 456 Symbol* s = CPSlot(OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_symbol();
387 // check that the string is still unresolved. 457 // check that the string is still unresolved.
388 assert(tag_at(which).is_unresolved_string(), "Corrupted constant pool"); 458 assert(tag_at(which).is_unresolved_string(), "Corrupted constant pool");
389 return s; 459 return s;
390 } 460 }
391 461
392 // Returns an UTF8 for a CONSTANT_String entry at a given index. 462 // Returns an UTF8 for a CONSTANT_String entry at a given index.
393 // UTF8 char* representation was chosen to avoid conversion of 463 // UTF8 char* representation was chosen to avoid conversion of
394 // java_lang_Strings at resolved entries into symbolOops 464 // java_lang_Strings at resolved entries into Symbol*s
395 // or vice versa. 465 // or vice versa.
396 // Caller is responsible for checking for pseudo-strings. 466 // Caller is responsible for checking for pseudo-strings.
397 char* string_at_noresolve(int which); 467 char* string_at_noresolve(int which);
398 468
399 jint name_and_type_at(int which) { 469 jint name_and_type_at(int which) {
412 int method_type_index_at(int which) { 482 int method_type_index_at(int which) {
413 assert(tag_at(which).is_method_type(), "Corrupted constant pool"); 483 assert(tag_at(which).is_method_type(), "Corrupted constant pool");
414 return *int_at_addr(which); 484 return *int_at_addr(which);
415 } 485 }
416 // Derived queries: 486 // Derived queries:
417 symbolOop method_handle_name_ref_at(int which) { 487 Symbol* method_handle_name_ref_at(int which) {
418 int member = method_handle_index_at(which); 488 int member = method_handle_index_at(which);
419 return impl_name_ref_at(member, true); 489 return impl_name_ref_at(member, true);
420 } 490 }
421 symbolOop method_handle_signature_ref_at(int which) { 491 Symbol* method_handle_signature_ref_at(int which) {
422 int member = method_handle_index_at(which); 492 int member = method_handle_index_at(which);
423 return impl_signature_ref_at(member, true); 493 return impl_signature_ref_at(member, true);
424 } 494 }
425 int method_handle_klass_index_at(int which) { 495 int method_handle_klass_index_at(int which) {
426 int member = method_handle_index_at(which); 496 int member = method_handle_index_at(which);
427 return impl_klass_ref_index_at(member, true); 497 return impl_klass_ref_index_at(member, true);
428 } 498 }
429 symbolOop method_type_signature_at(int which) { 499 Symbol* method_type_signature_at(int which) {
430 int sym = method_type_index_at(which); 500 int sym = method_type_index_at(which);
431 return symbol_at(sym); 501 return symbol_at(sym);
432 } 502 }
433 503
434 int invoke_dynamic_name_and_type_ref_index_at(int which) { 504 int invoke_dynamic_name_and_type_ref_index_at(int which) {
532 // which are handled by a dynamic check in remap_instruction_operand_from_cache. 602 // which are handled by a dynamic check in remap_instruction_operand_from_cache.
533 // FIXME: Remove the dynamic check, and adjust all callers to specify the correct mode. 603 // FIXME: Remove the dynamic check, and adjust all callers to specify the correct mode.
534 604
535 // Lookup for entries consisting of (klass_index, name_and_type index) 605 // Lookup for entries consisting of (klass_index, name_and_type index)
536 klassOop klass_ref_at(int which, TRAPS); 606 klassOop klass_ref_at(int which, TRAPS);
537 symbolOop klass_ref_at_noresolve(int which); 607 Symbol* klass_ref_at_noresolve(int which);
538 symbolOop name_ref_at(int which) { return impl_name_ref_at(which, false); } 608 Symbol* name_ref_at(int which) { return impl_name_ref_at(which, false); }
539 symbolOop signature_ref_at(int which) { return impl_signature_ref_at(which, false); } 609 Symbol* signature_ref_at(int which) { return impl_signature_ref_at(which, false); }
540 610
541 int klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, false); } 611 int klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, false); }
542 int name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, false); } 612 int name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, false); }
543 613
544 // Lookup for entries consisting of (name_index, signature_index) 614 // Lookup for entries consisting of (name_index, signature_index)
603 static klassOop klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS); 673 static klassOop klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS);
604 674
605 // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the 675 // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the
606 // future by other Java code. These take constant pool indices rather than 676 // future by other Java code. These take constant pool indices rather than
607 // constant pool cache indices as do the peer methods above. 677 // constant pool cache indices as do the peer methods above.
608 symbolOop uncached_klass_ref_at_noresolve(int which); 678 Symbol* uncached_klass_ref_at_noresolve(int which);
609 symbolOop uncached_name_ref_at(int which) { return impl_name_ref_at(which, true); } 679 Symbol* uncached_name_ref_at(int which) { return impl_name_ref_at(which, true); }
610 symbolOop uncached_signature_ref_at(int which) { return impl_signature_ref_at(which, true); } 680 Symbol* uncached_signature_ref_at(int which) { return impl_signature_ref_at(which, true); }
611 int uncached_klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, true); } 681 int uncached_klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, true); }
612 int uncached_name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, true); } 682 int uncached_name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, true); }
613 683
614 // Sharing 684 // Sharing
615 int pre_resolve_shared_klasses(TRAPS); 685 int pre_resolve_shared_klasses(TRAPS);
616 void shared_symbols_iterate(OopClosure* closure0); 686 void shared_symbols_iterate(SymbolClosure* closure0);
617 void shared_tags_iterate(OopClosure* closure0); 687 void shared_tags_iterate(OopClosure* closure0);
618 void shared_strings_iterate(OopClosure* closure0); 688 void shared_strings_iterate(OopClosure* closure0);
619 689
620 // Debugging 690 // Debugging
621 const char* printable_name_at(int which) PRODUCT_RETURN0; 691 const char* printable_name_at(int which) PRODUCT_RETURN0;
626 enum { CPCACHE_INDEX_TAG = 0 }; // in product mode, this zero value is a no-op 696 enum { CPCACHE_INDEX_TAG = 0 }; // in product mode, this zero value is a no-op
627 #endif //ASSERT 697 #endif //ASSERT
628 698
629 private: 699 private:
630 700
631 symbolOop impl_name_ref_at(int which, bool uncached); 701 Symbol* impl_name_ref_at(int which, bool uncached);
632 symbolOop impl_signature_ref_at(int which, bool uncached); 702 Symbol* impl_signature_ref_at(int which, bool uncached);
633 int impl_klass_ref_index_at(int which, bool uncached); 703 int impl_klass_ref_index_at(int which, bool uncached);
634 int impl_name_and_type_ref_index_at(int which, bool uncached); 704 int impl_name_and_type_ref_index_at(int which, bool uncached);
635 705
636 int remap_instruction_operand_from_cache(int operand); // operand must be biased by CPCACHE_INDEX_TAG 706 int remap_instruction_operand_from_cache(int operand); // operand must be biased by CPCACHE_INDEX_TAG
637 707
670 static void copy_entry_to(constantPoolHandle from_cp, int from_i, constantPoolHandle to_cp, int to_i, TRAPS); 740 static void copy_entry_to(constantPoolHandle from_cp, int from_i, constantPoolHandle to_cp, int to_i, TRAPS);
671 int find_matching_entry(int pattern_i, constantPoolHandle search_cp, TRAPS); 741 int find_matching_entry(int pattern_i, constantPoolHandle search_cp, TRAPS);
672 int orig_length() const { return _orig_length; } 742 int orig_length() const { return _orig_length; }
673 void set_orig_length(int orig_length) { _orig_length = orig_length; } 743 void set_orig_length(int orig_length) { _orig_length = orig_length; }
674 744
745 // Decrease ref counts of symbols that are in the constant pool
746 // when the holder class is unloaded
747 void unreference_symbols();
675 748
676 // JVMTI accesss - GetConstantPool, RetransformClasses, ... 749 // JVMTI accesss - GetConstantPool, RetransformClasses, ...
677 friend class JvmtiConstantPoolReconstituter; 750 friend class JvmtiConstantPoolReconstituter;
678 751
679 private: 752 private:
692 765
693 class SymbolHashMapEntry : public CHeapObj { 766 class SymbolHashMapEntry : public CHeapObj {
694 private: 767 private:
695 unsigned int _hash; // 32-bit hash for item 768 unsigned int _hash; // 32-bit hash for item
696 SymbolHashMapEntry* _next; // Next element in the linked list for this bucket 769 SymbolHashMapEntry* _next; // Next element in the linked list for this bucket
697 symbolOop _symbol; // 1-st part of the mapping: symbol => value 770 Symbol* _symbol; // 1-st part of the mapping: symbol => value
698 u2 _value; // 2-nd part of the mapping: symbol => value 771 u2 _value; // 2-nd part of the mapping: symbol => value
699 772
700 public: 773 public:
701 unsigned int hash() const { return _hash; } 774 unsigned int hash() const { return _hash; }
702 void set_hash(unsigned int hash) { _hash = hash; } 775 void set_hash(unsigned int hash) { _hash = hash; }
703 776
704 SymbolHashMapEntry* next() const { return _next; } 777 SymbolHashMapEntry* next() const { return _next; }
705 void set_next(SymbolHashMapEntry* next) { _next = next; } 778 void set_next(SymbolHashMapEntry* next) { _next = next; }
706 779
707 symbolOop symbol() const { return _symbol; } 780 Symbol* symbol() const { return _symbol; }
708 void set_symbol(symbolOop sym) { _symbol = sym; } 781 void set_symbol(Symbol* sym) { _symbol = sym; }
709 782
710 u2 value() const { return _value; } 783 u2 value() const { return _value; }
711 void set_value(u2 value) { _value = value; } 784 void set_value(u2 value) { _value = value; }
712 785
713 SymbolHashMapEntry(unsigned int hash, symbolOop symbol, u2 value) 786 SymbolHashMapEntry(unsigned int hash, Symbol* symbol, u2 value)
714 : _hash(hash), _symbol(symbol), _value(value), _next(NULL) {} 787 : _hash(hash), _symbol(symbol), _value(value), _next(NULL) {}
715 788
716 }; // End SymbolHashMapEntry class 789 }; // End SymbolHashMapEntry class
717 790
718 791
767 840
768 SymbolHashMapEntry* bucket(int i) { 841 SymbolHashMapEntry* bucket(int i) {
769 return _buckets[i].entry(); 842 return _buckets[i].entry();
770 } 843 }
771 844
772 void add_entry(symbolOop sym, u2 value); 845 void add_entry(Symbol* sym, u2 value);
773 SymbolHashMapEntry* find_entry(symbolOop sym); 846 SymbolHashMapEntry* find_entry(Symbol* sym);
774 847
775 u2 symbol_to_value(symbolOop sym) { 848 u2 symbol_to_value(Symbol* sym) {
776 SymbolHashMapEntry *entry = find_entry(sym); 849 SymbolHashMapEntry *entry = find_entry(sym);
777 return (entry == NULL) ? 0 : entry->value(); 850 return (entry == NULL) ? 0 : entry->value();
778 } 851 }
779 852
780 ~SymbolHashMap() { 853 ~SymbolHashMap() {