1.1 --- a/src/share/vm/memory/dump.cpp Thu Jan 27 13:42:28 2011 -0800 1.2 +++ b/src/share/vm/memory/dump.cpp Thu Jan 27 16:11:27 2011 -0800 1.3 @@ -133,6 +133,69 @@ 1.4 return false; 1.5 } 1.6 1.7 + 1.8 +class MoveSymbols : public SymbolClosure { 1.9 +private: 1.10 + char* _start; 1.11 + char* _end; 1.12 + char* _top; 1.13 + int _count; 1.14 + 1.15 + bool in_shared_space(Symbol* sym) const { 1.16 + return (char*)sym >= _start && (char*)sym < _end; 1.17 + } 1.18 + 1.19 + Symbol* get_shared_copy(Symbol* sym) { 1.20 + return sym->refcount() > 0 ? NULL : (Symbol*)(_start - sym->refcount()); 1.21 + } 1.22 + 1.23 + Symbol* make_shared_copy(Symbol* sym) { 1.24 + Symbol* new_sym = (Symbol*)_top; 1.25 + int size = sym->object_size(); 1.26 + _top += size * HeapWordSize; 1.27 + if (_top <= _end) { 1.28 + Copy::disjoint_words((HeapWord*)sym, (HeapWord*)new_sym, size); 1.29 + // Encode a reference to the copy as a negative distance from _start 1.30 + // When a symbol is being copied to a shared space 1.31 + // during CDS archive creation, the original symbol is marked 1.32 + // as relocated by putting a negative value to its _refcount field, 1.33 + // This value is also used to find where exactly the shared copy is 1.34 + // (see MoveSymbols::get_shared_copy), so that the other references 1.35 + // to this symbol could be changed to point to the shared copy. 1.36 + sym->_refcount = (int)(_start - (char*)new_sym); 1.37 + // Mark the symbol in the shared archive as immortal so it is read only 1.38 + // and not refcounted. 1.39 + new_sym->_refcount = -1; 1.40 + _count++; 1.41 + } else { 1.42 + report_out_of_shared_space(SharedMiscData); 1.43 + } 1.44 + return new_sym; 1.45 + } 1.46 + 1.47 +public: 1.48 + MoveSymbols(char* top, char* end) : 1.49 + _start(top), _end(end), _top(top), _count(0) { } 1.50 + 1.51 + char* get_top() const { return _top; } 1.52 + int count() const { return _count; } 1.53 + 1.54 + void do_symbol(Symbol** p) { 1.55 + Symbol* sym = load_symbol(p); 1.56 + if (sym != NULL && !in_shared_space(sym)) { 1.57 + Symbol* new_sym = get_shared_copy(sym); 1.58 + if (new_sym == NULL) { 1.59 + // The symbol has not been relocated yet; copy it to _top address 1.60 + assert(sym->refcount() > 0, "should have positive reference count"); 1.61 + new_sym = make_shared_copy(sym); 1.62 + } 1.63 + // Make the reference point to the shared copy of the symbol 1.64 + store_symbol(p, new_sym); 1.65 + } 1.66 + } 1.67 +}; 1.68 + 1.69 + 1.70 // Closure: mark objects closure. 1.71 1.72 class MarkObjectsOopClosure : public OopClosure { 1.73 @@ -164,7 +227,7 @@ 1.74 } 1.75 1.76 1.77 -// Closure: mark common read-only objects, excluding symbols 1.78 +// Closure: mark common read-only objects 1.79 1.80 class MarkCommonReadOnly : public ObjectClosure { 1.81 private: 1.82 @@ -216,54 +279,52 @@ 1.83 }; 1.84 1.85 1.86 -// Closure: mark common symbols 1.87 +// Closure: find symbol references in Java Heap objects 1.88 1.89 -class MarkCommonSymbols : public ObjectClosure { 1.90 +class CommonSymbolsClosure : public ObjectClosure { 1.91 private: 1.92 - MarkObjectsOopClosure mark_all; 1.93 + SymbolClosure* _closure; 1.94 public: 1.95 + CommonSymbolsClosure(SymbolClosure* closure) : _closure(closure) { } 1.96 + 1.97 void do_object(oop obj) { 1.98 1.99 - // Mark symbols refered to by method objects. 1.100 + // Traverse symbols referenced by method objects. 1.101 1.102 if (obj->is_method()) { 1.103 methodOop m = methodOop(obj); 1.104 - mark_object(m->name()); 1.105 - mark_object(m->signature()); 1.106 + constantPoolOop constants = m->constants(); 1.107 + _closure->do_symbol(constants->symbol_at_addr(m->name_index())); 1.108 + _closure->do_symbol(constants->symbol_at_addr(m->signature_index())); 1.109 } 1.110 1.111 - // Mark symbols referenced by klass objects which are read-only. 1.112 + // Traverse symbols referenced by klass objects which are read-only. 1.113 1.114 else if (obj->is_klass()) { 1.115 + Klass* k = Klass::cast((klassOop)obj); 1.116 + k->shared_symbols_iterate(_closure); 1.117 1.118 if (obj->blueprint()->oop_is_instanceKlass()) { 1.119 instanceKlass* ik = instanceKlass::cast((klassOop)obj); 1.120 - mark_object(ik->name()); 1.121 - mark_object(ik->generic_signature()); 1.122 - mark_object(ik->source_file_name()); 1.123 - mark_object(ik->source_debug_extension()); 1.124 - 1.125 typeArrayOop inner_classes = ik->inner_classes(); 1.126 if (inner_classes != NULL) { 1.127 - int length = inner_classes->length(); 1.128 - for (int i = 0; 1.129 - i < length; 1.130 - i += instanceKlass::inner_class_next_offset) { 1.131 + constantPoolOop constants = ik->constants(); 1.132 + int n = inner_classes->length(); 1.133 + for (int i = 0; i < n; i += instanceKlass::inner_class_next_offset) { 1.134 int ioff = i + instanceKlass::inner_class_inner_name_offset; 1.135 int index = inner_classes->ushort_at(ioff); 1.136 if (index != 0) { 1.137 - mark_object(ik->constants()->symbol_at(index)); 1.138 + _closure->do_symbol(constants->symbol_at_addr(index)); 1.139 } 1.140 } 1.141 } 1.142 - ik->field_names_and_sigs_iterate(&mark_all); 1.143 } 1.144 } 1.145 1.146 - // Mark symbols referenced by other constantpool entries. 1.147 + // Traverse symbols referenced by other constantpool entries. 1.148 1.149 - if (obj->is_constantPool()) { 1.150 - constantPoolOop(obj)->shared_symbols_iterate(&mark_all); 1.151 + else if (obj->is_constantPool()) { 1.152 + constantPoolOop(obj)->shared_symbols_iterate(_closure); 1.153 } 1.154 } 1.155 }; 1.156 @@ -404,18 +465,7 @@ 1.157 int s = obj->size(); 1.158 oop sh_obj = (oop)_space->allocate(s); 1.159 if (sh_obj == NULL) { 1.160 - if (_read_only) { 1.161 - warning("\nThe permanent generation read only space is not large " 1.162 - "enough to \npreload requested classes. Use " 1.163 - "-XX:SharedReadOnlySize= to increase \nthe initial " 1.164 - "size of the read only space.\n"); 1.165 - } else { 1.166 - warning("\nThe permanent generation read write space is not large " 1.167 - "enough to \npreload requested classes. Use " 1.168 - "-XX:SharedReadWriteSize= to increase \nthe initial " 1.169 - "size of the read write space.\n"); 1.170 - } 1.171 - exit(2); 1.172 + report_out_of_shared_space(_read_only ? SharedReadOnly : SharedReadWrite); 1.173 } 1.174 if (PrintSharedSpaces && Verbose && WizardMode) { 1.175 tty->print_cr("\nMoveMarkedObjects: " PTR_FORMAT " -> " PTR_FORMAT " %s", obj, sh_obj, 1.176 @@ -459,8 +509,6 @@ 1.177 instanceKlass* ik = instanceKlass::cast((klassOop)obj); 1.178 int i; 1.179 1.180 - mark_and_move_for_policy(OP_favor_startup, ik->name(), _move_ro); 1.181 - 1.182 if (ik->super() != NULL) { 1.183 do_object(ik->super()); 1.184 } 1.185 @@ -469,7 +517,6 @@ 1.186 mark_and_move_for_policy(OP_favor_startup, interfaces, _move_ro); 1.187 for(i = 0; i < interfaces->length(); i++) { 1.188 klassOop k = klassOop(interfaces->obj_at(i)); 1.189 - mark_and_move_for_policy(OP_favor_startup, k->klass_part()->name(), _move_ro); 1.190 do_object(k); 1.191 } 1.192 1.193 @@ -479,14 +526,6 @@ 1.194 mark_and_move_for_policy(OP_favor_startup, m->constMethod(), _move_ro); 1.195 mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->exception_table(), _move_ro); 1.196 mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->stackmap_data(), _move_ro); 1.197 - 1.198 - // We don't move the name symbolOop here because it may invalidate 1.199 - // method ordering, which is dependent on the address of the name 1.200 - // symbolOop. It will get promoted later with the other symbols. 1.201 - // Method name is rarely accessed during classloading anyway. 1.202 - // mark_and_move_for_policy(OP_balanced, m->name(), _move_ro); 1.203 - 1.204 - mark_and_move_for_policy(OP_favor_startup, m->signature(), _move_ro); 1.205 } 1.206 1.207 mark_and_move_for_policy(OP_favor_startup, ik->transitive_interfaces(), _move_ro); 1.208 @@ -574,45 +613,43 @@ 1.209 }; 1.210 1.211 1.212 -void sort_methods(instanceKlass* ik, TRAPS) { 1.213 - klassOop super = ik->super(); 1.214 - if (super != NULL) { 1.215 - sort_methods(instanceKlass::cast(super), THREAD); 1.216 - } 1.217 - 1.218 - // The methods array must be ordered by symbolOop address. (See 1.219 - // classFileParser.cpp where methods in a class are originally 1.220 - // sorted.) Since objects have just be reordered, this must be 1.221 - // corrected. 1.222 - methodOopDesc::sort_methods(ik->methods(), 1.223 - ik->methods_annotations(), 1.224 - ik->methods_parameter_annotations(), 1.225 - ik->methods_default_annotations(), 1.226 - true /* idempotent, slow */); 1.227 - 1.228 - // Itable indices are calculated based on methods array order 1.229 - // (see klassItable::compute_itable_index()). Must reinitialize. 1.230 - // We assume that since checkconstraints is false, this method 1.231 - // cannot throw an exception. An exception here would be 1.232 - // problematic since this is the VMThread, not a JavaThread. 1.233 - ik->itable()->initialize_itable(false, THREAD); 1.234 -} 1.235 - 1.236 -// Sort methods if the oop is an instanceKlass. 1.237 +// The methods array must be reordered by Symbol* address. 1.238 +// (See classFileParser.cpp where methods in a class are originally 1.239 +// sorted). The addresses of symbols have been changed as a result 1.240 +// of moving to the shared space. 1.241 1.242 class SortMethodsClosure: public ObjectClosure { 1.243 +public: 1.244 + void do_object(oop obj) { 1.245 + if (obj->blueprint()->oop_is_instanceKlass()) { 1.246 + instanceKlass* ik = instanceKlass::cast((klassOop)obj); 1.247 + methodOopDesc::sort_methods(ik->methods(), 1.248 + ik->methods_annotations(), 1.249 + ik->methods_parameter_annotations(), 1.250 + ik->methods_default_annotations(), 1.251 + true /* idempotent, slow */); 1.252 + } 1.253 + } 1.254 +}; 1.255 + 1.256 +// Itable indices are calculated based on methods array order 1.257 +// (see klassItable::compute_itable_index()). Must reinitialize 1.258 +// after ALL methods of ALL classes have been reordered. 1.259 +// We assume that since checkconstraints is false, this method 1.260 +// cannot throw an exception. An exception here would be 1.261 +// problematic since this is the VMThread, not a JavaThread. 1.262 + 1.263 +class ReinitializeItables: public ObjectClosure { 1.264 private: 1.265 Thread* _thread; 1.266 1.267 public: 1.268 - SortMethodsClosure(Thread* thread) : _thread(thread) {} 1.269 + ReinitializeItables(Thread* thread) : _thread(thread) {} 1.270 1.271 void do_object(oop obj) { 1.272 - // instanceKlass objects need some adjustment. 1.273 if (obj->blueprint()->oop_is_instanceKlass()) { 1.274 instanceKlass* ik = instanceKlass::cast((klassOop)obj); 1.275 - 1.276 - sort_methods(ik, _thread); 1.277 + ik->itable()->initialize_itable(false, _thread); 1.278 } 1.279 } 1.280 }; 1.281 @@ -673,18 +710,9 @@ 1.282 oop* top; 1.283 char* end; 1.284 1.285 - void out_of_space() { 1.286 - warning("\nThe shared miscellaneous data space is not large " 1.287 - "enough to \npreload requested classes. Use " 1.288 - "-XX:SharedMiscDataSize= to increase \nthe initial " 1.289 - "size of the miscellaneous data space.\n"); 1.290 - exit(2); 1.291 - } 1.292 - 1.293 - 1.294 inline void check_space() { 1.295 if ((char*)top + sizeof(oop) > end) { 1.296 - out_of_space(); 1.297 + report_out_of_shared_space(SharedMiscData); 1.298 } 1.299 } 1.300 1.301 @@ -737,7 +765,7 @@ 1.302 1.303 void do_region(u_char* start, size_t size) { 1.304 if ((char*)top + size > end) { 1.305 - out_of_space(); 1.306 + report_out_of_shared_space(SharedMiscData); 1.307 } 1.308 assert((intptr_t)start % sizeof(oop) == 0, "bad alignment"); 1.309 assert(size % sizeof(oop) == 0, "bad size"); 1.310 @@ -870,46 +898,53 @@ 1.311 1.312 class PatchKlassVtables: public ObjectClosure { 1.313 private: 1.314 - void* _vtbl_ptr; 1.315 - VirtualSpace* _md_vs; 1.316 GrowableArray<klassOop>* _klass_objects; 1.317 1.318 public: 1.319 - 1.320 - PatchKlassVtables(void* vtbl_ptr, VirtualSpace* md_vs) { 1.321 - _vtbl_ptr = vtbl_ptr; 1.322 - _md_vs = md_vs; 1.323 + PatchKlassVtables() { 1.324 _klass_objects = new GrowableArray<klassOop>(); 1.325 } 1.326 1.327 - 1.328 void do_object(oop obj) { 1.329 if (obj->is_klass()) { 1.330 _klass_objects->append(klassOop(obj)); 1.331 } 1.332 } 1.333 1.334 - 1.335 - void patch(void** vtbl_list, int vtbl_list_size) { 1.336 - for (int i = 0; i < _klass_objects->length(); ++i) { 1.337 + void patch(void** vtbl_list, void* new_vtable_start) { 1.338 + int n = _klass_objects->length(); 1.339 + for (int i = 0; i < n; i++) { 1.340 klassOop obj = (klassOop)_klass_objects->at(i); 1.341 Klass* k = obj->klass_part(); 1.342 - void* v = *(void**)k; 1.343 - 1.344 - int n; 1.345 - for (n = 0; n < vtbl_list_size; ++n) { 1.346 - *(void**)k = NULL; 1.347 - if (vtbl_list[n] == v) { 1.348 - *(void**)k = (void**)_vtbl_ptr + 1.349 - (n * CompactingPermGenGen::num_virtuals); 1.350 - break; 1.351 - } 1.352 - } 1.353 - guarantee(n < vtbl_list_size, "unable to find matching vtbl pointer"); 1.354 + *(void**)k = CompactingPermGenGen::find_matching_vtbl_ptr( 1.355 + vtbl_list, new_vtable_start, k); 1.356 } 1.357 } 1.358 }; 1.359 1.360 +// Walk through all symbols and patch their vtable pointers. 1.361 +// Note that symbols have vtable pointers only in non-product builds 1.362 +// (see allocation.hpp). 1.363 + 1.364 +#ifndef PRODUCT 1.365 +class PatchSymbolVtables: public SymbolClosure { 1.366 +private: 1.367 + void* _new_vtbl_ptr; 1.368 + 1.369 +public: 1.370 + PatchSymbolVtables(void** vtbl_list, void* new_vtable_start) { 1.371 + Symbol s; 1.372 + _new_vtbl_ptr = CompactingPermGenGen::find_matching_vtbl_ptr( 1.373 + vtbl_list, new_vtable_start, &s); 1.374 + } 1.375 + 1.376 + void do_symbol(Symbol** p) { 1.377 + Symbol* sym = load_symbol(p); 1.378 + *(void**)sym = _new_vtbl_ptr; 1.379 + } 1.380 +}; 1.381 +#endif 1.382 + 1.383 1.384 // Populate the shared space. 1.385 1.386 @@ -969,7 +1004,6 @@ 1.387 1.388 MarkObjectsOopClosure mark_all; 1.389 MarkCommonReadOnly mark_common_ro; 1.390 - MarkCommonSymbols mark_common_symbols; 1.391 MarkStringValues mark_string_values; 1.392 MarkReadWriteObjects mark_rw; 1.393 MarkStringObjects mark_strings; 1.394 @@ -1013,112 +1047,6 @@ 1.395 MarkAndMoveOrderedReadOnly mark_and_move_ordered_ro(&move_ro); 1.396 MarkAndMoveOrderedReadWrite mark_and_move_ordered_rw(&move_rw); 1.397 1.398 - // Phase 1a: move commonly used read-only objects to the read-only space. 1.399 - 1.400 - if (SharedOptimizeColdStart) { 1.401 - tty->print("Moving pre-ordered read-only objects to shared space at " PTR_FORMAT " ... ", 1.402 - _ro_space->top()); 1.403 - for (int i = 0; i < _class_promote_order->length(); i++) { 1.404 - oop obj = _class_promote_order->at(i); 1.405 - mark_and_move_ordered_ro.do_object(obj); 1.406 - } 1.407 - tty->print_cr("done. "); 1.408 - } 1.409 - 1.410 - tty->print("Moving read-only objects to shared space at " PTR_FORMAT " ... ", 1.411 - _ro_space->top()); 1.412 - gch->object_iterate(&mark_common_ro); 1.413 - gch->object_iterate(&move_ro); 1.414 - tty->print_cr("done. "); 1.415 - 1.416 - // Phase 1b: move commonly used symbols to the read-only space. 1.417 - 1.418 - tty->print("Moving common symbols to shared space at " PTR_FORMAT " ... ", 1.419 - _ro_space->top()); 1.420 - gch->object_iterate(&mark_common_symbols); 1.421 - gch->object_iterate(&move_ro); 1.422 - tty->print_cr("done. "); 1.423 - 1.424 - // Phase 1c: move remaining symbols to the read-only space 1.425 - // (e.g. String initializers). 1.426 - 1.427 - tty->print("Moving remaining symbols to shared space at " PTR_FORMAT " ... ", 1.428 - _ro_space->top()); 1.429 - vmSymbols::oops_do(&mark_all, true); 1.430 - gch->object_iterate(&move_ro); 1.431 - tty->print_cr("done. "); 1.432 - 1.433 - // Phase 1d: move String character arrays to the read-only space. 1.434 - 1.435 - tty->print("Moving string char arrays to shared space at " PTR_FORMAT " ... ", 1.436 - _ro_space->top()); 1.437 - gch->object_iterate(&mark_string_values); 1.438 - gch->object_iterate(&move_ro); 1.439 - tty->print_cr("done. "); 1.440 - 1.441 - // Phase 2: move all remaining symbols to the read-only space. The 1.442 - // remaining symbols are assumed to be string initializers no longer 1.443 - // referenced. 1.444 - 1.445 - void* extra_symbols = _ro_space->top(); 1.446 - tty->print("Moving additional symbols to shared space at " PTR_FORMAT " ... ", 1.447 - _ro_space->top()); 1.448 - SymbolTable::oops_do(&mark_all); 1.449 - gch->object_iterate(&move_ro); 1.450 - tty->print_cr("done. "); 1.451 - tty->print_cr("Read-only space ends at " PTR_FORMAT ", %d bytes.", 1.452 - _ro_space->top(), _ro_space->used()); 1.453 - 1.454 - // Phase 3: move read-write objects to the read-write space, except 1.455 - // Strings. 1.456 - 1.457 - if (SharedOptimizeColdStart) { 1.458 - tty->print("Moving pre-ordered read-write objects to shared space at " PTR_FORMAT " ... ", 1.459 - _rw_space->top()); 1.460 - for (int i = 0; i < _class_promote_order->length(); i++) { 1.461 - oop obj = _class_promote_order->at(i); 1.462 - mark_and_move_ordered_rw.do_object(obj); 1.463 - } 1.464 - tty->print_cr("done. "); 1.465 - } 1.466 - tty->print("Moving read-write objects to shared space at " PTR_FORMAT " ... ", 1.467 - _rw_space->top()); 1.468 - Universe::oops_do(&mark_all, true); 1.469 - SystemDictionary::oops_do(&mark_all); 1.470 - oop tmp = Universe::arithmetic_exception_instance(); 1.471 - mark_object(java_lang_Throwable::message(tmp)); 1.472 - gch->object_iterate(&mark_rw); 1.473 - gch->object_iterate(&move_rw); 1.474 - tty->print_cr("done. "); 1.475 - 1.476 - // Phase 4: move String objects to the read-write space. 1.477 - 1.478 - tty->print("Moving String objects to shared space at " PTR_FORMAT " ... ", 1.479 - _rw_space->top()); 1.480 - StringTable::oops_do(&mark_all); 1.481 - gch->object_iterate(&mark_strings); 1.482 - gch->object_iterate(&move_rw); 1.483 - tty->print_cr("done. "); 1.484 - tty->print_cr("Read-write space ends at " PTR_FORMAT ", %d bytes.", 1.485 - _rw_space->top(), _rw_space->used()); 1.486 - 1.487 -#ifdef DEBUG 1.488 - // Check: scan for objects which were not moved. 1.489 - 1.490 - CheckRemainingObjects check_objects; 1.491 - gch->object_iterate(&check_objects); 1.492 - check_objects.status(); 1.493 -#endif 1.494 - 1.495 - // Resolve forwarding in objects and saved C++ structures 1.496 - tty->print("Updating references to shared objects ... "); 1.497 - ResolveForwardingClosure resolve; 1.498 - Universe::oops_do(&resolve); 1.499 - SystemDictionary::oops_do(&resolve); 1.500 - StringTable::oops_do(&resolve); 1.501 - SymbolTable::oops_do(&resolve); 1.502 - vmSymbols::oops_do(&resolve); 1.503 - 1.504 // Set up the share data and shared code segments. 1.505 1.506 char* md_top = _md_vs->low(); 1.507 @@ -1144,6 +1072,122 @@ 1.508 &md_top, md_end, 1.509 &mc_top, mc_end); 1.510 1.511 + // Reserve space for the total size and the number of stored symbols. 1.512 + 1.513 + md_top += sizeof(intptr_t) * 2; 1.514 + 1.515 + MoveSymbols move_symbols(md_top, md_end); 1.516 + CommonSymbolsClosure traverse_common_symbols(&move_symbols); 1.517 + 1.518 + // Phase 1a: remove symbols with _refcount == 0 1.519 + 1.520 + SymbolTable::unlink(); 1.521 + 1.522 + // Phase 1b: move commonly used symbols referenced by oop fields. 1.523 + 1.524 + tty->print("Moving common symbols to metadata section at " PTR_FORMAT " ... ", 1.525 + move_symbols.get_top()); 1.526 + gch->object_iterate(&traverse_common_symbols); 1.527 + tty->print_cr("done. "); 1.528 + 1.529 + // Phase 1c: move known names and signatures. 1.530 + 1.531 + tty->print("Moving vmSymbols to metadata section at " PTR_FORMAT " ... ", 1.532 + move_symbols.get_top()); 1.533 + vmSymbols::symbols_do(&move_symbols); 1.534 + tty->print_cr("done. "); 1.535 + 1.536 + // Phase 1d: move the remaining symbols by scanning the whole SymbolTable. 1.537 + 1.538 + void* extra_symbols = move_symbols.get_top(); 1.539 + tty->print("Moving the remaining symbols to metadata section at " PTR_FORMAT " ... ", 1.540 + move_symbols.get_top()); 1.541 + SymbolTable::symbols_do(&move_symbols); 1.542 + tty->print_cr("done. "); 1.543 + 1.544 + // Record the total length of all symbols at the beginning of the block. 1.545 + ((intptr_t*)md_top)[-2] = move_symbols.get_top() - md_top; 1.546 + ((intptr_t*)md_top)[-1] = move_symbols.count(); 1.547 + tty->print_cr("Moved %d symbols, %d bytes.", 1.548 + move_symbols.count(), move_symbols.get_top() - md_top); 1.549 + // Advance the pointer to the end of symbol store. 1.550 + md_top = move_symbols.get_top(); 1.551 + 1.552 + 1.553 + // Phase 2: move commonly used read-only objects to the read-only space. 1.554 + 1.555 + if (SharedOptimizeColdStart) { 1.556 + tty->print("Moving pre-ordered read-only objects to shared space at " PTR_FORMAT " ... ", 1.557 + _ro_space->top()); 1.558 + for (int i = 0; i < _class_promote_order->length(); i++) { 1.559 + oop obj = _class_promote_order->at(i); 1.560 + mark_and_move_ordered_ro.do_object(obj); 1.561 + } 1.562 + tty->print_cr("done. "); 1.563 + } 1.564 + 1.565 + tty->print("Moving read-only objects to shared space at " PTR_FORMAT " ... ", 1.566 + _ro_space->top()); 1.567 + gch->object_iterate(&mark_common_ro); 1.568 + gch->object_iterate(&move_ro); 1.569 + tty->print_cr("done. "); 1.570 + 1.571 + // Phase 3: move String character arrays to the read-only space. 1.572 + 1.573 + tty->print("Moving string char arrays to shared space at " PTR_FORMAT " ... ", 1.574 + _ro_space->top()); 1.575 + gch->object_iterate(&mark_string_values); 1.576 + gch->object_iterate(&move_ro); 1.577 + tty->print_cr("done. "); 1.578 + 1.579 + // Phase 4: move read-write objects to the read-write space, except 1.580 + // Strings. 1.581 + 1.582 + if (SharedOptimizeColdStart) { 1.583 + tty->print("Moving pre-ordered read-write objects to shared space at " PTR_FORMAT " ... ", 1.584 + _rw_space->top()); 1.585 + for (int i = 0; i < _class_promote_order->length(); i++) { 1.586 + oop obj = _class_promote_order->at(i); 1.587 + mark_and_move_ordered_rw.do_object(obj); 1.588 + } 1.589 + tty->print_cr("done. "); 1.590 + } 1.591 + tty->print("Moving read-write objects to shared space at " PTR_FORMAT " ... ", 1.592 + _rw_space->top()); 1.593 + Universe::oops_do(&mark_all, true); 1.594 + SystemDictionary::oops_do(&mark_all); 1.595 + oop tmp = Universe::arithmetic_exception_instance(); 1.596 + mark_object(java_lang_Throwable::message(tmp)); 1.597 + gch->object_iterate(&mark_rw); 1.598 + gch->object_iterate(&move_rw); 1.599 + tty->print_cr("done. "); 1.600 + 1.601 + // Phase 5: move String objects to the read-write space. 1.602 + 1.603 + tty->print("Moving String objects to shared space at " PTR_FORMAT " ... ", 1.604 + _rw_space->top()); 1.605 + StringTable::oops_do(&mark_all); 1.606 + gch->object_iterate(&mark_strings); 1.607 + gch->object_iterate(&move_rw); 1.608 + tty->print_cr("done. "); 1.609 + tty->print_cr("Read-write space ends at " PTR_FORMAT ", %d bytes.", 1.610 + _rw_space->top(), _rw_space->used()); 1.611 + 1.612 +#ifdef DEBUG 1.613 + // Check: scan for objects which were not moved. 1.614 + 1.615 + CheckRemainingObjects check_objects; 1.616 + gch->object_iterate(&check_objects); 1.617 + check_objects.status(); 1.618 +#endif 1.619 + 1.620 + // Resolve forwarding in objects and saved C++ structures 1.621 + tty->print("Updating references to shared objects ... "); 1.622 + ResolveForwardingClosure resolve; 1.623 + Universe::oops_do(&resolve); 1.624 + SystemDictionary::oops_do(&resolve); 1.625 + StringTable::oops_do(&resolve); 1.626 + 1.627 // Fix (forward) all of the references in these shared objects (which 1.628 // are required to point ONLY to objects in the shared spaces). 1.629 // Also, create a list of all objects which might later contain a 1.630 @@ -1166,9 +1210,13 @@ 1.631 // pointer resolution, so that methods can be promoted in any order 1.632 // with respect to their holder classes. 1.633 1.634 - SortMethodsClosure sort(THREAD); 1.635 + SortMethodsClosure sort; 1.636 gen->ro_space()->object_iterate(&sort); 1.637 gen->rw_space()->object_iterate(&sort); 1.638 + 1.639 + ReinitializeItables reinit_itables(THREAD); 1.640 + gen->ro_space()->object_iterate(&reinit_itables); 1.641 + gen->rw_space()->object_iterate(&reinit_itables); 1.642 tty->print_cr("done. "); 1.643 tty->cr(); 1.644 1.645 @@ -1233,9 +1281,16 @@ 1.646 // Update the vtable pointers in all of the Klass objects in the 1.647 // heap. They should point to newly generated vtable. 1.648 1.649 - PatchKlassVtables pkvt(vtable, _md_vs); 1.650 + PatchKlassVtables pkvt; 1.651 _rw_space->object_iterate(&pkvt); 1.652 - pkvt.patch(vtbl_list, vtbl_list_size); 1.653 + pkvt.patch(vtbl_list, vtable); 1.654 + 1.655 +#ifndef PRODUCT 1.656 + // Update the vtable pointers in all symbols, 1.657 + // but only in non-product builds where symbols DO have virtual methods. 1.658 + PatchSymbolVtables psvt(vtbl_list, vtable); 1.659 + SymbolTable::symbols_do(&psvt); 1.660 +#endif 1.661 1.662 char* saved_vtbl = (char*)malloc(vtbl_list_size * sizeof(void*)); 1.663 memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*)); 1.664 @@ -1304,6 +1359,19 @@ 1.665 return JNI_OK; 1.666 } 1.667 1.668 +void* CompactingPermGenGen::find_matching_vtbl_ptr(void** vtbl_list, 1.669 + void* new_vtable_start, 1.670 + void* obj) { 1.671 + void* old_vtbl_ptr = *(void**)obj; 1.672 + for (int i = 0; i < vtbl_list_size; i++) { 1.673 + if (vtbl_list[i] == old_vtbl_ptr) { 1.674 + return (void**)new_vtable_start + i * num_virtuals; 1.675 + } 1.676 + } 1.677 + ShouldNotReachHere(); 1.678 + return NULL; 1.679 +} 1.680 + 1.681 1.682 class LinkClassesClosure : public ObjectClosure { 1.683 private: 1.684 @@ -1431,8 +1499,7 @@ 1.685 computed_jsum = jsum(computed_jsum, class_name, (const int)name_len - 1); 1.686 1.687 // Got a class name - load it. 1.688 - symbolHandle class_name_symbol = oopFactory::new_symbol(class_name, 1.689 - THREAD); 1.690 + TempNewSymbol class_name_symbol = SymbolTable::new_symbol(class_name, THREAD); 1.691 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); 1.692 klassOop klass = SystemDictionary::resolve_or_null(class_name_symbol, 1.693 THREAD);