comparison src/share/vm/oops/constantPoolOop.cpp @ 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 fbbeec6dad2d
comparison
equal deleted inserted replaced
2176:27e4ea99855d 2177:3582bf76420e
50 assert(false, "failed to cmpxchg flags"); 50 assert(false, "failed to cmpxchg flags");
51 _flags |= (1 << (int)fb); // better than nothing 51 _flags |= (1 << (int)fb); // better than nothing
52 } 52 }
53 53
54 klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) { 54 klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
55 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop. 55 // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*.
56 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and 56 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
57 // tag is not updated atomicly. 57 // tag is not updated atomicly.
58 oop entry = *(this_oop->obj_at_addr(which)); 58 CPSlot entry = this_oop->slot_at(which);
59 if (entry->is_klass()) { 59 if (entry.is_oop()) {
60 assert(entry.get_oop()->is_klass(), "must be");
60 // Already resolved - return entry. 61 // Already resolved - return entry.
61 return (klassOop)entry; 62 return (klassOop)entry.get_oop();
62 } 63 }
63 64
64 // Acquire lock on constant oop while doing update. After we get the lock, we check if another object 65 // Acquire lock on constant oop while doing update. After we get the lock, we check if another object
65 // already has updated the object 66 // already has updated the object
66 assert(THREAD->is_Java_thread(), "must be a Java thread"); 67 assert(THREAD->is_Java_thread(), "must be a Java thread");
67 bool do_resolve = false; 68 bool do_resolve = false;
68 bool in_error = false; 69 bool in_error = false;
69 70
70 symbolHandle name; 71 Symbol* name = NULL;
71 Handle loader; 72 Handle loader;
72 { ObjectLocker ol(this_oop, THREAD); 73 { ObjectLocker ol(this_oop, THREAD);
73 74
74 if (this_oop->tag_at(which).is_unresolved_klass()) { 75 if (this_oop->tag_at(which).is_unresolved_klass()) {
75 if (this_oop->tag_at(which).is_unresolved_klass_in_error()) { 76 if (this_oop->tag_at(which).is_unresolved_klass_in_error()) {
76 in_error = true; 77 in_error = true;
77 } else { 78 } else {
78 do_resolve = true; 79 do_resolve = true;
79 name = symbolHandle(THREAD, this_oop->unresolved_klass_at(which)); 80 name = this_oop->unresolved_klass_at(which);
80 loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader()); 81 loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader());
81 } 82 }
82 } 83 }
83 } // unlocking constantPool 84 } // unlocking constantPool
84 85
85 86
86 // The original attempt to resolve this constant pool entry failed so find the 87 // The original attempt to resolve this constant pool entry failed so find the
87 // original error and throw it again (JVMS 5.4.3). 88 // original error and throw it again (JVMS 5.4.3).
88 if (in_error) { 89 if (in_error) {
89 symbolOop error = SystemDictionary::find_resolution_error(this_oop, which); 90 Symbol* error = SystemDictionary::find_resolution_error(this_oop, which);
90 guarantee(error != (symbolOop)NULL, "tag mismatch with resolution error table"); 91 guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table");
91 ResourceMark rm; 92 ResourceMark rm;
92 // exception text will be the class name 93 // exception text will be the class name
93 const char* className = this_oop->unresolved_klass_at(which)->as_C_string(); 94 const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
94 THROW_MSG_0(error, className); 95 THROW_MSG_0(error, className);
95 } 96 }
108 109
109 // Failed to resolve class. We must record the errors so that subsequent attempts 110 // Failed to resolve class. We must record the errors so that subsequent attempts
110 // to resolve this constant pool entry fail with the same error (JVMS 5.4.3). 111 // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
111 if (HAS_PENDING_EXCEPTION) { 112 if (HAS_PENDING_EXCEPTION) {
112 ResourceMark rm; 113 ResourceMark rm;
113 symbolHandle error(PENDING_EXCEPTION->klass()->klass_part()->name()); 114 Symbol* error = PENDING_EXCEPTION->klass()->klass_part()->name();
114 115
115 bool throw_orig_error = false; 116 bool throw_orig_error = false;
116 { 117 {
117 ObjectLocker ol (this_oop, THREAD); 118 ObjectLocker ol (this_oop, THREAD);
118 119
119 // some other thread has beaten us and has resolved the class. 120 // some other thread has beaten us and has resolved the class.
120 if (this_oop->tag_at(which).is_klass()) { 121 if (this_oop->tag_at(which).is_klass()) {
121 CLEAR_PENDING_EXCEPTION; 122 CLEAR_PENDING_EXCEPTION;
122 entry = this_oop->resolved_klass_at(which); 123 entry = this_oop->resolved_klass_at(which);
123 return (klassOop)entry; 124 return (klassOop)entry.get_oop();
124 } 125 }
125 126
126 if (!PENDING_EXCEPTION-> 127 if (!PENDING_EXCEPTION->
127 is_a(SystemDictionary::LinkageError_klass())) { 128 is_a(SystemDictionary::LinkageError_klass())) {
128 // Just throw the exception and don't prevent these classes from 129 // Just throw the exception and don't prevent these classes from
133 else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) { 134 else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) {
134 SystemDictionary::add_resolution_error(this_oop, which, error); 135 SystemDictionary::add_resolution_error(this_oop, which, error);
135 this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError); 136 this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError);
136 } else { 137 } else {
137 // some other thread has put the class in error state. 138 // some other thread has put the class in error state.
138 error = symbolHandle(SystemDictionary::find_resolution_error(this_oop, which)); 139 error = SystemDictionary::find_resolution_error(this_oop, which);
139 assert(!error.is_null(), "checking"); 140 assert(error != NULL, "checking");
140 throw_orig_error = true; 141 throw_orig_error = true;
141 } 142 }
142 } // unlocked 143 } // unlocked
143 144
144 if (throw_orig_error) { 145 if (throw_orig_error) {
160 if (JavaThread::current()->has_last_Java_frame()) { 161 if (JavaThread::current()->has_last_Java_frame()) {
161 // try to identify the method which called this function. 162 // try to identify the method which called this function.
162 vframeStream vfst(JavaThread::current()); 163 vframeStream vfst(JavaThread::current());
163 if (!vfst.at_end()) { 164 if (!vfst.at_end()) {
164 line_number = vfst.method()->line_number_from_bci(vfst.bci()); 165 line_number = vfst.method()->line_number_from_bci(vfst.bci());
165 symbolOop s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name(); 166 Symbol* s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name();
166 if (s != NULL) { 167 if (s != NULL) {
167 source_file = s->as_C_string(); 168 source_file = s->as_C_string();
168 } 169 }
169 } 170 }
170 } 171 }
190 } 191 }
191 } 192 }
192 } 193 }
193 194
194 entry = this_oop->resolved_klass_at(which); 195 entry = this_oop->resolved_klass_at(which);
195 assert(entry->is_klass(), "must be resolved at this point"); 196 assert(entry.is_oop() && entry.get_oop()->is_klass(), "must be resolved at this point");
196 return (klassOop)entry; 197 return (klassOop)entry.get_oop();
197 } 198 }
198 199
199 200
200 // Does not update constantPoolOop - to avoid any exception throwing. Used 201 // Does not update constantPoolOop - to avoid any exception throwing. Used
201 // by compiler and exception handling. Also used to avoid classloads for 202 // by compiler and exception handling. Also used to avoid classloads for
202 // instanceof operations. Returns NULL if the class has not been loaded or 203 // instanceof operations. Returns NULL if the class has not been loaded or
203 // if the verification of constant pool failed 204 // if the verification of constant pool failed
204 klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) { 205 klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) {
205 oop entry = *this_oop->obj_at_addr(which); 206 CPSlot entry = this_oop->slot_at(which);
206 if (entry->is_klass()) { 207 if (entry.is_oop()) {
207 return (klassOop)entry; 208 assert(entry.get_oop()->is_klass(), "must be");
209 return (klassOop)entry.get_oop();
208 } else { 210 } else {
209 assert(entry->is_symbol(), "must be either symbol or klass"); 211 assert(entry.is_metadata(), "must be either symbol or klass");
210 Thread *thread = Thread::current(); 212 Thread *thread = Thread::current();
211 symbolHandle name (thread, (symbolOop)entry); 213 Symbol* name = entry.get_symbol();
212 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); 214 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
213 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); 215 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
214 Handle h_prot (thread, protection_domain); 216 Handle h_prot (thread, protection_domain);
215 Handle h_loader (thread, loader); 217 Handle h_loader (thread, loader);
216 klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread); 218 klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread);
242 // in the constant pool - but still performs the validations tests. Must be used 244 // in the constant pool - but still performs the validations tests. Must be used
243 // in a pre-parse of the compiler - to determine what it can do and not do. 245 // in a pre-parse of the compiler - to determine what it can do and not do.
244 // Note: We cannot update the ConstantPool from the vm_thread. 246 // Note: We cannot update the ConstantPool from the vm_thread.
245 klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) { 247 klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) {
246 int which = this_oop->klass_ref_index_at(index); 248 int which = this_oop->klass_ref_index_at(index);
247 oop entry = *this_oop->obj_at_addr(which); 249 CPSlot entry = this_oop->slot_at(which);
248 if (entry->is_klass()) { 250 if (entry.is_oop()) {
249 return (klassOop)entry; 251 assert(entry.get_oop()->is_klass(), "must be");
252 return (klassOop)entry.get_oop();
250 } else { 253 } else {
251 assert(entry->is_symbol(), "must be either symbol or klass"); 254 assert(entry.is_metadata(), "must be either symbol or klass");
252 symbolHandle name (THREAD, (symbolOop)entry); 255 Symbol* name = entry.get_symbol();
253 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader(); 256 oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
254 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain(); 257 oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
255 Handle h_loader(THREAD, loader); 258 Handle h_loader(THREAD, loader);
256 Handle h_prot (THREAD, protection_domain); 259 Handle h_prot (THREAD, protection_domain);
257 KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD)); 260 KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD));
261 return k(); 264 return k();
262 } 265 }
263 } 266 }
264 267
265 268
266 symbolOop constantPoolOopDesc::impl_name_ref_at(int which, bool uncached) { 269 Symbol* constantPoolOopDesc::impl_name_ref_at(int which, bool uncached) {
267 int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); 270 int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
268 return symbol_at(name_index); 271 return symbol_at(name_index);
269 } 272 }
270 273
271 274
272 symbolOop constantPoolOopDesc::impl_signature_ref_at(int which, bool uncached) { 275 Symbol* constantPoolOopDesc::impl_signature_ref_at(int which, bool uncached) {
273 int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached)); 276 int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
274 return symbol_at(signature_index); 277 return symbol_at(signature_index);
275 } 278 }
276 279
277 280
359 klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) { 362 klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) {
360 return klass_at(klass_ref_index_at(which), CHECK_NULL); 363 return klass_at(klass_ref_index_at(which), CHECK_NULL);
361 } 364 }
362 365
363 366
364 symbolOop constantPoolOopDesc::klass_name_at(int which) { 367 Symbol* constantPoolOopDesc::klass_name_at(int which) {
365 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(), 368 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(),
366 "Corrupted constant pool"); 369 "Corrupted constant pool");
367 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop. 370 // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*.
368 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and 371 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
369 // tag is not updated atomicly. 372 // tag is not updated atomicly.
370 oop entry = *(obj_at_addr(which)); 373 CPSlot entry = slot_at(which);
371 if (entry->is_klass()) { 374 if (entry.is_oop()) {
372 // Already resolved - return entry's name. 375 // Already resolved - return entry's name.
373 return klassOop(entry)->klass_part()->name(); 376 assert(entry.get_oop()->is_klass(), "must be");
377 return klassOop(entry.get_oop())->klass_part()->name();
374 } else { 378 } else {
375 assert(entry->is_symbol(), "must be either symbol or klass"); 379 assert(entry.is_metadata(), "must be either symbol or klass");
376 return (symbolOop)entry; 380 return entry.get_symbol();
377 } 381 }
378 } 382 }
379 383
380 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) { 384 Symbol* constantPoolOopDesc::klass_ref_at_noresolve(int which) {
381 jint ref_index = klass_ref_index_at(which); 385 jint ref_index = klass_ref_index_at(which);
382 return klass_at_noresolve(ref_index); 386 return klass_at_noresolve(ref_index);
383 } 387 }
384 388
385 symbolOop constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) { 389 Symbol* constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) {
386 jint ref_index = uncached_klass_ref_index_at(which); 390 jint ref_index = uncached_klass_ref_index_at(which);
387 return klass_at_noresolve(ref_index); 391 return klass_at_noresolve(ref_index);
388 } 392 }
389 393
390 char* constantPoolOopDesc::string_at_noresolve(int which) { 394 char* constantPoolOopDesc::string_at_noresolve(int which) {
391 // Test entry type in case string is resolved while in here. 395 // Test entry type in case string is resolved while in here.
392 oop entry = *(obj_at_addr(which)); 396 CPSlot entry = slot_at(which);
393 if (entry->is_symbol()) { 397 if (entry.is_metadata()) {
394 return ((symbolOop)entry)->as_C_string(); 398 return (entry.get_symbol())->as_C_string();
395 } else if (java_lang_String::is_instance(entry)) { 399 } else if (java_lang_String::is_instance(entry.get_oop())) {
396 return java_lang_String::as_utf8_string(entry); 400 return java_lang_String::as_utf8_string(entry.get_oop());
397 } else { 401 } else {
398 return (char*)"<pseudo-string>"; 402 return (char*)"<pseudo-string>";
399 } 403 }
400 } 404 }
401 405
496 500
497 case JVM_CONSTANT_MethodHandle: 501 case JVM_CONSTANT_MethodHandle:
498 { 502 {
499 int ref_kind = this_oop->method_handle_ref_kind_at(index); 503 int ref_kind = this_oop->method_handle_ref_kind_at(index);
500 int callee_index = this_oop->method_handle_klass_index_at(index); 504 int callee_index = this_oop->method_handle_klass_index_at(index);
501 symbolHandle name(THREAD, this_oop->method_handle_name_ref_at(index)); 505 Symbol* name = this_oop->method_handle_name_ref_at(index);
502 symbolHandle signature(THREAD, this_oop->method_handle_signature_ref_at(index)); 506 Symbol* signature = this_oop->method_handle_signature_ref_at(index);
503 if (PrintMiscellaneous) 507 if (PrintMiscellaneous)
504 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s", 508 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
505 ref_kind, index, this_oop->method_handle_index_at(index), 509 ref_kind, index, this_oop->method_handle_index_at(index),
506 callee_index, name->as_C_string(), signature->as_C_string()); 510 callee_index, name->as_C_string(), signature->as_C_string());
507 KlassHandle callee; 511 KlassHandle callee;
522 break; 526 break;
523 } 527 }
524 528
525 case JVM_CONSTANT_MethodType: 529 case JVM_CONSTANT_MethodType:
526 { 530 {
527 symbolHandle signature(THREAD, this_oop->method_type_signature_at(index)); 531 Symbol* signature = this_oop->method_type_signature_at(index);
528 if (PrintMiscellaneous) 532 if (PrintMiscellaneous)
529 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s", 533 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
530 index, this_oop->method_type_index_at(index), 534 index, this_oop->method_type_index_at(index),
531 signature->as_C_string()); 535 signature->as_C_string());
532 KlassHandle klass(THREAD, this_oop->pool_holder()); 536 KlassHandle klass(THREAD, this_oop->pool_holder());
603 return result_oop; 607 return result_oop;
604 } 608 }
605 } 609 }
606 610
607 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) { 611 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
608 oop entry = *(this_oop->obj_at_addr(which)); 612 oop str = NULL;
609 if (entry->is_symbol()) { 613 CPSlot entry = this_oop->slot_at(which);
614 if (entry.is_metadata()) {
610 ObjectLocker ol(this_oop, THREAD); 615 ObjectLocker ol(this_oop, THREAD);
611 if (this_oop->tag_at(which).is_unresolved_string()) { 616 if (this_oop->tag_at(which).is_unresolved_string()) {
612 // Intern string 617 // Intern string
613 symbolOop sym = this_oop->unresolved_string_at(which); 618 Symbol* sym = this_oop->unresolved_string_at(which);
614 entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL))); 619 str = StringTable::intern(sym, CHECK_(constantPoolOop(NULL)));
615 this_oop->string_at_put(which, entry); 620 this_oop->string_at_put(which, str);
616 } else { 621 } else {
617 // Another thread beat us and interned string, read string from constant pool 622 // Another thread beat us and interned string, read string from constant pool
618 entry = this_oop->resolved_string_at(which); 623 str = this_oop->resolved_string_at(which);
619 } 624 }
620 } 625 } else {
621 assert(java_lang_String::is_instance(entry), "must be string"); 626 str = entry.get_oop();
622 return entry; 627 }
628 assert(java_lang_String::is_instance(str), "must be string");
629 return str;
623 } 630 }
624 631
625 632
626 bool constantPoolOopDesc::is_pseudo_string_at(int which) { 633 bool constantPoolOopDesc::is_pseudo_string_at(int which) {
627 oop entry = *(obj_at_addr(which)); 634 CPSlot entry = slot_at(which);
628 if (entry->is_symbol()) 635 if (entry.is_metadata())
629 // Not yet resolved, but it will resolve to a string. 636 // Not yet resolved, but it will resolve to a string.
630 return false; 637 return false;
631 else if (java_lang_String::is_instance(entry)) 638 else if (java_lang_String::is_instance(entry.get_oop()))
632 return false; // actually, it might be a non-interned or non-perm string 639 return false; // actually, it might be a non-interned or non-perm string
633 else 640 else
634 // truly pseudo 641 // truly pseudo
635 return true; 642 return true;
636 } 643 }
637 644
638 645
639 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k, 646 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k,
640 int which) { 647 int which) {
641 // Names are interned, so we can compare symbolOops directly 648 // Names are interned, so we can compare Symbol*s directly
642 symbolOop cp_name = klass_name_at(which); 649 Symbol* cp_name = klass_name_at(which);
643 return (cp_name == k->name()); 650 return (cp_name == k->name());
644 } 651 }
645 652
646 653
647 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) { 654 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) {
648 ResourceMark rm; 655 ResourceMark rm;
649 int count = 0; 656 int count = 0;
650 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused 657 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused
651 if (tag_at(index).is_unresolved_string()) { 658 if (tag_at(index).is_unresolved_string()) {
652 // Intern string 659 // Intern string
653 symbolOop sym = unresolved_string_at(index); 660 Symbol* sym = unresolved_string_at(index);
654 oop entry = StringTable::intern(sym, CHECK_(-1)); 661 oop entry = StringTable::intern(sym, CHECK_(-1));
655 string_at_put(index, entry); 662 string_at_put(index, entry);
656 } 663 }
657 } 664 }
658 return count; 665 return count;
659 } 666 }
660 667
668 // Iterate over symbols and decrement ones which are Symbol*s.
669 // This is done during GC so do not need to lock constantPool unless we
670 // have per-thread safepoints.
671 // Only decrement the UTF8 symbols. Unresolved classes and strings point to
672 // these symbols but didn't increment the reference count.
673 void constantPoolOopDesc::unreference_symbols() {
674 for (int index = 1; index < length(); index++) { // Index 0 is unused
675 constantTag tag = tag_at(index);
676 if (tag.is_symbol()) {
677 symbol_at(index)->decrement_refcount();
678 }
679 }
680 }
661 681
662 // Iterate over symbols which are used as class, field, method names and 682 // Iterate over symbols which are used as class, field, method names and
663 // signatures (in preparation for writing to the shared archive). 683 // signatures (in preparation for writing to the shared archive).
664 684
665 void constantPoolOopDesc::shared_symbols_iterate(OopClosure* closure) { 685 void constantPoolOopDesc::shared_symbols_iterate(SymbolClosure* closure) {
666 for (int index = 1; index < length(); index++) { // Index 0 is unused 686 for (int index = 1; index < length(); index++) { // Index 0 is unused
667 switch (tag_at(index).value()) { 687 switch (tag_at(index).value()) {
668 688
669 case JVM_CONSTANT_UnresolvedClass: 689 case JVM_CONSTANT_UnresolvedClass:
670 closure->do_oop(obj_at_addr(index)); 690 case JVM_CONSTANT_UnresolvedString:
691 case JVM_CONSTANT_Utf8:
692 assert(slot_at(index).is_metadata(), "must be symbol");
693 closure->do_symbol(symbol_at_addr(index));
671 break; 694 break;
672 695
673 case JVM_CONSTANT_NameAndType: 696 case JVM_CONSTANT_NameAndType:
674 { 697 {
675 int i = *int_at_addr(index); 698 int i = *int_at_addr(index);
676 closure->do_oop(obj_at_addr((unsigned)i >> 16)); 699 closure->do_symbol(symbol_at_addr((unsigned)i >> 16));
677 closure->do_oop(obj_at_addr((unsigned)i & 0xffff)); 700 closure->do_symbol(symbol_at_addr((unsigned)i & 0xffff));
678 } 701 }
679 break; 702 break;
680 703
681 case JVM_CONSTANT_Class: 704 case JVM_CONSTANT_Class:
682 case JVM_CONSTANT_InterfaceMethodref: 705 case JVM_CONSTANT_InterfaceMethodref:
690 713
691 case JVM_CONSTANT_String: 714 case JVM_CONSTANT_String:
692 // Do nothing! Not a symbol. 715 // Do nothing! Not a symbol.
693 break; 716 break;
694 717
695 case JVM_CONSTANT_UnresolvedString:
696 case JVM_CONSTANT_Utf8:
697 // These constants are symbols, but unless these symbols are
698 // actually to be used for something, we don't want to mark them.
699 break;
700
701 case JVM_CONSTANT_Long: 718 case JVM_CONSTANT_Long:
702 case JVM_CONSTANT_Double: 719 case JVM_CONSTANT_Double:
703 // Do nothing! Not an oop. (But takes two pool entries.) 720 // Do nothing! Not an oop. (But takes two pool entries.)
704 ++index; 721 ++index;
705 break; 722 break;
742 // Do nothing! Not an oop. 759 // Do nothing! Not an oop.
743 // These constant types do not reference symbols at this point. 760 // These constant types do not reference symbols at this point.
744 break; 761 break;
745 762
746 case JVM_CONSTANT_String: 763 case JVM_CONSTANT_String:
747 closure->do_oop(obj_at_addr(index)); 764 closure->do_oop(obj_at_addr_raw(index));
748 break; 765 break;
749 766
750 case JVM_CONSTANT_UnresolvedString: 767 case JVM_CONSTANT_UnresolvedString:
751 case JVM_CONSTANT_Utf8: 768 case JVM_CONSTANT_Utf8:
752 // These constants are symbols, but unless these symbols are 769 // These constants are symbols, but unless these symbols are
902 } 919 }
903 } break; 920 } break;
904 921
905 case JVM_CONSTANT_UnresolvedClass: 922 case JVM_CONSTANT_UnresolvedClass:
906 { 923 {
907 symbolOop k1 = unresolved_klass_at(index1); 924 Symbol* k1 = unresolved_klass_at(index1);
908 symbolOop k2 = cp2->unresolved_klass_at(index2); 925 Symbol* k2 = cp2->unresolved_klass_at(index2);
909 if (k1 == k2) { 926 if (k1 == k2) {
910 return true; 927 return true;
911 } 928 }
912 } break; 929 } break;
913 930
958 } 975 }
959 } break; 976 } break;
960 977
961 case JVM_CONSTANT_UnresolvedString: 978 case JVM_CONSTANT_UnresolvedString:
962 { 979 {
963 symbolOop s1 = unresolved_string_at(index1); 980 Symbol* s1 = unresolved_string_at(index1);
964 symbolOop s2 = cp2->unresolved_string_at(index2); 981 Symbol* s2 = cp2->unresolved_string_at(index2);
965 if (s1 == s2) { 982 if (s1 == s2) {
966 return true; 983 return true;
967 } 984 }
968 } break; 985 } break;
969 986
970 case JVM_CONSTANT_Utf8: 987 case JVM_CONSTANT_Utf8:
971 { 988 {
972 symbolOop s1 = symbol_at(index1); 989 Symbol* s1 = symbol_at(index1);
973 symbolOop s2 = cp2->symbol_at(index2); 990 Symbol* s2 = cp2->symbol_at(index2);
974 if (s1 == s2) { 991 if (s1 == s2) {
975 return true; 992 return true;
976 } 993 }
977 } break; 994 } break;
978 995
1156 to_cp->string_index_at_put(to_i, si); 1173 to_cp->string_index_at_put(to_i, si);
1157 } break; 1174 } break;
1158 1175
1159 case JVM_CONSTANT_UnresolvedClass: 1176 case JVM_CONSTANT_UnresolvedClass:
1160 { 1177 {
1161 symbolOop k = from_cp->unresolved_klass_at(from_i); 1178 Symbol* k = from_cp->unresolved_klass_at(from_i);
1162 to_cp->unresolved_klass_at_put(to_i, k); 1179 to_cp->unresolved_klass_at_put(to_i, k);
1163 } break; 1180 } break;
1164 1181
1165 case JVM_CONSTANT_UnresolvedClassInError: 1182 case JVM_CONSTANT_UnresolvedClassInError:
1166 { 1183 {
1167 symbolOop k = from_cp->unresolved_klass_at(from_i); 1184 Symbol* k = from_cp->unresolved_klass_at(from_i);
1168 to_cp->unresolved_klass_at_put(to_i, k); 1185 to_cp->unresolved_klass_at_put(to_i, k);
1169 to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError); 1186 to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError);
1170 } break; 1187 } break;
1171 1188
1172 1189
1173 case JVM_CONSTANT_UnresolvedString: 1190 case JVM_CONSTANT_UnresolvedString:
1174 { 1191 {
1175 symbolOop s = from_cp->unresolved_string_at(from_i); 1192 Symbol* s = from_cp->unresolved_string_at(from_i);
1176 to_cp->unresolved_string_at_put(to_i, s); 1193 to_cp->unresolved_string_at_put(to_i, s);
1177 } break; 1194 } break;
1178 1195
1179 case JVM_CONSTANT_Utf8: 1196 case JVM_CONSTANT_Utf8:
1180 { 1197 {
1181 symbolOop s = from_cp->symbol_at(from_i); 1198 Symbol* s = from_cp->symbol_at(from_i);
1182 to_cp->symbol_at_put(to_i, s); 1199 to_cp->symbol_at_put(to_i, s);
1200 // This constantPool has the same lifetime as the original, so don't
1201 // increase reference counts for the copy.
1183 } break; 1202 } break;
1184 1203
1185 case JVM_CONSTANT_MethodType: 1204 case JVM_CONSTANT_MethodType:
1186 { 1205 {
1187 jint k = from_cp->method_type_index_at(from_i); 1206 jint k = from_cp->method_type_index_at(from_i);
1451 u2 tag = tag_at(idx).value(); 1470 u2 tag = tag_at(idx).value();
1452 size += cpool_entry_size(idx); 1471 size += cpool_entry_size(idx);
1453 1472
1454 switch(tag) { 1473 switch(tag) {
1455 case JVM_CONSTANT_Utf8: { 1474 case JVM_CONSTANT_Utf8: {
1456 symbolOop sym = symbol_at(idx); 1475 Symbol* sym = symbol_at(idx);
1457 symmap->add_entry(sym, idx); 1476 symmap->add_entry(sym, idx);
1458 DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx)); 1477 DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx));
1459 break; 1478 break;
1460 } 1479 }
1461 case JVM_CONSTANT_Class: 1480 case JVM_CONSTANT_Class:
1462 case JVM_CONSTANT_UnresolvedClass: 1481 case JVM_CONSTANT_UnresolvedClass:
1463 case JVM_CONSTANT_UnresolvedClassInError: { 1482 case JVM_CONSTANT_UnresolvedClassInError: {
1464 symbolOop sym = klass_name_at(idx); 1483 Symbol* sym = klass_name_at(idx);
1465 classmap->add_entry(sym, idx); 1484 classmap->add_entry(sym, idx);
1466 DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx)); 1485 DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx));
1467 break; 1486 break;
1468 } 1487 }
1469 case JVM_CONSTANT_Long: 1488 case JVM_CONSTANT_Long:
1507 assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode"); 1526 assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode");
1508 DBG(printf("JVM_CONSTANT_Unicode")); 1527 DBG(printf("JVM_CONSTANT_Unicode"));
1509 break; 1528 break;
1510 } 1529 }
1511 case JVM_CONSTANT_Utf8: { 1530 case JVM_CONSTANT_Utf8: {
1512 symbolOop sym = symbol_at(idx); 1531 Symbol* sym = symbol_at(idx);
1513 char* str = sym->as_utf8(); 1532 char* str = sym->as_utf8();
1514 // Warning! It's crashing on x86 with len = sym->utf8_length() 1533 // Warning! It's crashing on x86 with len = sym->utf8_length()
1515 int len = (int) strlen(str); 1534 int len = (int) strlen(str);
1516 Bytes::put_Java_u2((address) (bytes+1), (u2) len); 1535 Bytes::put_Java_u2((address) (bytes+1), (u2) len);
1517 for (int i = 0; i < len; i++) { 1536 for (int i = 0; i < len; i++) {
1544 } 1563 }
1545 case JVM_CONSTANT_Class: 1564 case JVM_CONSTANT_Class:
1546 case JVM_CONSTANT_UnresolvedClass: 1565 case JVM_CONSTANT_UnresolvedClass:
1547 case JVM_CONSTANT_UnresolvedClassInError: { 1566 case JVM_CONSTANT_UnresolvedClassInError: {
1548 *bytes = JVM_CONSTANT_Class; 1567 *bytes = JVM_CONSTANT_Class;
1549 symbolOop sym = klass_name_at(idx); 1568 Symbol* sym = klass_name_at(idx);
1550 idx1 = tbl->symbol_to_value(sym); 1569 idx1 = tbl->symbol_to_value(sym);
1551 assert(idx1 != 0, "Have not found a hashtable entry"); 1570 assert(idx1 != 0, "Have not found a hashtable entry");
1552 Bytes::put_Java_u2((address) (bytes+1), idx1); 1571 Bytes::put_Java_u2((address) (bytes+1), idx1);
1553 DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8())); 1572 DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
1554 break; 1573 break;
1555 } 1574 }
1556 case JVM_CONSTANT_String: { 1575 case JVM_CONSTANT_String: {
1557 unsigned int hash; 1576 unsigned int hash;
1558 char *str = string_at_noresolve(idx); 1577 char *str = string_at_noresolve(idx);
1559 symbolOop sym = SymbolTable::lookup_only(str, (int) strlen(str), hash); 1578 TempNewSymbol sym = SymbolTable::lookup_only(str, (int) strlen(str), hash);
1560 if (sym == NULL) { 1579 if (sym == NULL) {
1561 // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8 1580 // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8
1562 // this can happen with JVM TI; see CR 6839599 for more details 1581 // this can happen with JVM TI; see CR 6839599 for more details
1563 oop string = *(obj_at_addr(idx)); 1582 oop string = *(obj_at_addr_raw(idx));
1564 assert(java_lang_String::is_instance(string),"Not a String"); 1583 assert(java_lang_String::is_instance(string),"Not a String");
1565 DBG(printf("Error #%03hd tag=%03hd\n", idx, tag)); 1584 DBG(printf("Error #%03hd tag=%03hd\n", idx, tag));
1566 idx1 = 0; 1585 idx1 = 0;
1567 for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) { 1586 for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) {
1568 for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) { 1587 for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) {
1569 int length; 1588 int length;
1570 sym = cur->symbol(); 1589 Symbol* s = cur->symbol();
1571 jchar* chars = sym->as_unicode(length); 1590 jchar* chars = s->as_unicode(length);
1572 if (java_lang_String::equals(string, chars, length)) { 1591 if (java_lang_String::equals(string, chars, length)) {
1573 idx1 = cur->value(); 1592 idx1 = cur->value();
1574 DBG(printf("Index found: %d\n",idx1)); 1593 DBG(printf("Index found: %d\n",idx1));
1575 break; 1594 break;
1576 } 1595 }
1584 DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str)); 1603 DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str));
1585 break; 1604 break;
1586 } 1605 }
1587 case JVM_CONSTANT_UnresolvedString: { 1606 case JVM_CONSTANT_UnresolvedString: {
1588 *bytes = JVM_CONSTANT_String; 1607 *bytes = JVM_CONSTANT_String;
1589 symbolOop sym = unresolved_string_at(idx); 1608 Symbol* sym = unresolved_string_at(idx);
1590 idx1 = tbl->symbol_to_value(sym); 1609 idx1 = tbl->symbol_to_value(sym);
1591 assert(idx1 != 0, "Have not found a hashtable entry"); 1610 assert(idx1 != 0, "Have not found a hashtable entry");
1592 Bytes::put_Java_u2((address) (bytes+1), idx1); 1611 Bytes::put_Java_u2((address) (bytes+1), idx1);
1593 DBG(char *str = sym->as_utf8()); 1612 DBG(char *str = sym->as_utf8());
1594 DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str)); 1613 DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str));
1664 DBG(print_cpool_bytes(cnt, start_bytes)); 1683 DBG(print_cpool_bytes(cnt, start_bytes));
1665 return (int)(bytes - start_bytes); 1684 return (int)(bytes - start_bytes);
1666 } /* end copy_cpool_bytes */ 1685 } /* end copy_cpool_bytes */
1667 1686
1668 1687
1669 void SymbolHashMap::add_entry(symbolOop sym, u2 value) { 1688 void SymbolHashMap::add_entry(Symbol* sym, u2 value) {
1670 char *str = sym->as_utf8(); 1689 char *str = sym->as_utf8();
1671 unsigned int hash = compute_hash(str, sym->utf8_length()); 1690 unsigned int hash = compute_hash(str, sym->utf8_length());
1672 unsigned int index = hash % table_size(); 1691 unsigned int index = hash % table_size();
1673 1692
1674 // check if already in map 1693 // check if already in map
1685 entry->set_next(bucket(index)); 1704 entry->set_next(bucket(index));
1686 _buckets[index].set_entry(entry); 1705 _buckets[index].set_entry(entry);
1687 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); 1706 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
1688 } 1707 }
1689 1708
1690 SymbolHashMapEntry* SymbolHashMap::find_entry(symbolOop sym) { 1709 SymbolHashMapEntry* SymbolHashMap::find_entry(Symbol* sym) {
1691 assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL"); 1710 assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
1692 char *str = sym->as_utf8(); 1711 char *str = sym->as_utf8();
1693 int len = sym->utf8_length(); 1712 int len = sym->utf8_length();
1694 unsigned int hash = SymbolHashMap::compute_hash(str, len); 1713 unsigned int hash = SymbolHashMap::compute_hash(str, len);
1695 unsigned int index = hash % table_size(); 1714 unsigned int index = hash % table_size();