Mon, 26 Jan 2009 12:47:21 -0800
6786503: Overflow list performance can be improved
Summary: Avoid overflow list walk in CMS & ParNew when it is unnecessary. Fix a couple of correctness issues, including a C-heap leak, in ParNew at the intersection of promotion failure, work queue overflow and object array chunking. Add stress testing option and related assertion checking.
Reviewed-by: jmasa
duke@435 | 1 | /* |
xdono@631 | 2 | * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_dump.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | // Closure to set up the fingerprint field for all methods. |
duke@435 | 30 | |
duke@435 | 31 | class FingerprintMethodsClosure: public ObjectClosure { |
duke@435 | 32 | public: |
duke@435 | 33 | void do_object(oop obj) { |
duke@435 | 34 | if (obj->is_method()) { |
duke@435 | 35 | methodOop mobj = (methodOop)obj; |
duke@435 | 36 | ResourceMark rm; |
duke@435 | 37 | (new Fingerprinter(mobj))->fingerprint(); |
duke@435 | 38 | } |
duke@435 | 39 | } |
duke@435 | 40 | }; |
duke@435 | 41 | |
duke@435 | 42 | |
duke@435 | 43 | |
duke@435 | 44 | // Closure to set the hash value (String.hash field) in all of the |
duke@435 | 45 | // String objects in the heap. Setting the hash value is not required. |
duke@435 | 46 | // However, setting the value in advance prevents the value from being |
duke@435 | 47 | // written later, increasing the likelihood that the shared page contain |
duke@435 | 48 | // the hash can be shared. |
duke@435 | 49 | // |
duke@435 | 50 | // NOTE THAT the algorithm in StringTable::hash_string() MUST MATCH the |
duke@435 | 51 | // algorithm in java.lang.String.hashCode(). |
duke@435 | 52 | |
duke@435 | 53 | class StringHashCodeClosure: public OopClosure { |
duke@435 | 54 | private: |
duke@435 | 55 | Thread* THREAD; |
duke@435 | 56 | int hash_offset; |
duke@435 | 57 | public: |
duke@435 | 58 | StringHashCodeClosure(Thread* t) { |
duke@435 | 59 | THREAD = t; |
duke@435 | 60 | hash_offset = java_lang_String::hash_offset_in_bytes(); |
duke@435 | 61 | } |
duke@435 | 62 | |
coleenp@548 | 63 | void do_oop(oop* p) { |
coleenp@548 | 64 | if (p != NULL) { |
coleenp@548 | 65 | oop obj = *p; |
duke@435 | 66 | if (obj->klass() == SystemDictionary::string_klass()) { |
duke@435 | 67 | |
duke@435 | 68 | int hash; |
duke@435 | 69 | typeArrayOop value = java_lang_String::value(obj); |
duke@435 | 70 | int length = java_lang_String::length(obj); |
duke@435 | 71 | if (length == 0) { |
duke@435 | 72 | hash = 0; |
duke@435 | 73 | } else { |
duke@435 | 74 | int offset = java_lang_String::offset(obj); |
duke@435 | 75 | jchar* s = value->char_at_addr(offset); |
duke@435 | 76 | hash = StringTable::hash_string(s, length); |
duke@435 | 77 | } |
duke@435 | 78 | obj->int_field_put(hash_offset, hash); |
duke@435 | 79 | } |
duke@435 | 80 | } |
duke@435 | 81 | } |
coleenp@548 | 82 | void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
duke@435 | 83 | }; |
duke@435 | 84 | |
duke@435 | 85 | |
duke@435 | 86 | // Remove data from objects which should not appear in the shared file |
duke@435 | 87 | // (as it pertains only to the current JVM). |
duke@435 | 88 | |
duke@435 | 89 | class RemoveUnshareableInfoClosure : public ObjectClosure { |
duke@435 | 90 | public: |
duke@435 | 91 | void do_object(oop obj) { |
duke@435 | 92 | // Zap data from the objects which is pertains only to this JVM. We |
duke@435 | 93 | // want that data recreated in new JVMs when the shared file is used. |
duke@435 | 94 | if (obj->is_method()) { |
duke@435 | 95 | ((methodOop)obj)->remove_unshareable_info(); |
duke@435 | 96 | } |
duke@435 | 97 | else if (obj->is_klass()) { |
duke@435 | 98 | Klass::cast((klassOop)obj)->remove_unshareable_info(); |
duke@435 | 99 | } |
duke@435 | 100 | |
duke@435 | 101 | // Don't save compiler related special oops (shouldn't be any yet). |
duke@435 | 102 | if (obj->is_methodData() || obj->is_compiledICHolder()) { |
duke@435 | 103 | ShouldNotReachHere(); |
duke@435 | 104 | } |
duke@435 | 105 | } |
duke@435 | 106 | }; |
duke@435 | 107 | |
duke@435 | 108 | |
duke@435 | 109 | static bool mark_object(oop obj) { |
duke@435 | 110 | if (obj != NULL && |
duke@435 | 111 | !obj->is_shared() && |
duke@435 | 112 | !obj->is_forwarded() && |
duke@435 | 113 | !obj->is_gc_marked()) { |
duke@435 | 114 | obj->set_mark(markOopDesc::prototype()->set_marked()); |
duke@435 | 115 | return true; |
duke@435 | 116 | } |
duke@435 | 117 | |
duke@435 | 118 | return false; |
duke@435 | 119 | } |
duke@435 | 120 | |
duke@435 | 121 | // Closure: mark objects closure. |
duke@435 | 122 | |
duke@435 | 123 | class MarkObjectsOopClosure : public OopClosure { |
duke@435 | 124 | public: |
coleenp@548 | 125 | void do_oop(oop* p) { mark_object(*p); } |
coleenp@548 | 126 | void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
duke@435 | 127 | }; |
duke@435 | 128 | |
duke@435 | 129 | |
duke@435 | 130 | class MarkObjectsSkippingKlassesOopClosure : public OopClosure { |
duke@435 | 131 | public: |
duke@435 | 132 | void do_oop(oop* pobj) { |
duke@435 | 133 | oop obj = *pobj; |
duke@435 | 134 | if (obj != NULL && |
duke@435 | 135 | !obj->is_klass()) { |
duke@435 | 136 | mark_object(obj); |
duke@435 | 137 | } |
duke@435 | 138 | } |
coleenp@548 | 139 | void do_oop(narrowOop* pobj) { ShouldNotReachHere(); } |
duke@435 | 140 | }; |
duke@435 | 141 | |
duke@435 | 142 | |
duke@435 | 143 | static void mark_object_recursive_skipping_klasses(oop obj) { |
duke@435 | 144 | mark_object(obj); |
duke@435 | 145 | if (obj != NULL) { |
duke@435 | 146 | MarkObjectsSkippingKlassesOopClosure mark_all; |
duke@435 | 147 | obj->oop_iterate(&mark_all); |
duke@435 | 148 | } |
duke@435 | 149 | } |
duke@435 | 150 | |
duke@435 | 151 | |
duke@435 | 152 | // Closure: mark common read-only objects, excluding symbols |
duke@435 | 153 | |
duke@435 | 154 | class MarkCommonReadOnly : public ObjectClosure { |
duke@435 | 155 | private: |
duke@435 | 156 | MarkObjectsOopClosure mark_all; |
duke@435 | 157 | public: |
duke@435 | 158 | void do_object(oop obj) { |
duke@435 | 159 | |
duke@435 | 160 | // Mark all constMethod objects. |
duke@435 | 161 | |
duke@435 | 162 | if (obj->is_constMethod()) { |
duke@435 | 163 | mark_object(obj); |
duke@435 | 164 | mark_object(constMethodOop(obj)->stackmap_data()); |
duke@435 | 165 | // Exception tables are needed by ci code during compilation. |
duke@435 | 166 | mark_object(constMethodOop(obj)->exception_table()); |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | // Mark objects referenced by klass objects which are read-only. |
duke@435 | 170 | |
duke@435 | 171 | else if (obj->is_klass()) { |
duke@435 | 172 | Klass* k = Klass::cast((klassOop)obj); |
duke@435 | 173 | mark_object(k->secondary_supers()); |
duke@435 | 174 | |
duke@435 | 175 | // The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though |
duke@435 | 176 | // it is never modified. Otherwise, they will be pre-marked; the |
duke@435 | 177 | // GC marking phase will skip them; and by skipping them will fail |
duke@435 | 178 | // to mark the methods objects referenced by the array. |
duke@435 | 179 | |
duke@435 | 180 | if (obj->blueprint()->oop_is_instanceKlass()) { |
duke@435 | 181 | instanceKlass* ik = instanceKlass::cast((klassOop)obj); |
duke@435 | 182 | mark_object(ik->method_ordering()); |
duke@435 | 183 | mark_object(ik->local_interfaces()); |
duke@435 | 184 | mark_object(ik->transitive_interfaces()); |
duke@435 | 185 | mark_object(ik->fields()); |
duke@435 | 186 | |
duke@435 | 187 | mark_object(ik->class_annotations()); |
duke@435 | 188 | |
duke@435 | 189 | mark_object_recursive_skipping_klasses(ik->fields_annotations()); |
duke@435 | 190 | mark_object_recursive_skipping_klasses(ik->methods_annotations()); |
duke@435 | 191 | mark_object_recursive_skipping_klasses(ik->methods_parameter_annotations()); |
duke@435 | 192 | mark_object_recursive_skipping_klasses(ik->methods_default_annotations()); |
duke@435 | 193 | |
duke@435 | 194 | typeArrayOop inner_classes = ik->inner_classes(); |
duke@435 | 195 | if (inner_classes != NULL) { |
duke@435 | 196 | mark_object(inner_classes); |
duke@435 | 197 | } |
duke@435 | 198 | } |
duke@435 | 199 | } |
duke@435 | 200 | } |
duke@435 | 201 | }; |
duke@435 | 202 | |
duke@435 | 203 | |
duke@435 | 204 | // Closure: mark common symbols |
duke@435 | 205 | |
duke@435 | 206 | class MarkCommonSymbols : public ObjectClosure { |
duke@435 | 207 | private: |
duke@435 | 208 | MarkObjectsOopClosure mark_all; |
duke@435 | 209 | public: |
duke@435 | 210 | void do_object(oop obj) { |
duke@435 | 211 | |
duke@435 | 212 | // Mark symbols refered to by method objects. |
duke@435 | 213 | |
duke@435 | 214 | if (obj->is_method()) { |
duke@435 | 215 | methodOop m = methodOop(obj); |
duke@435 | 216 | mark_object(m->name()); |
duke@435 | 217 | mark_object(m->signature()); |
duke@435 | 218 | } |
duke@435 | 219 | |
duke@435 | 220 | // Mark symbols referenced by klass objects which are read-only. |
duke@435 | 221 | |
duke@435 | 222 | else if (obj->is_klass()) { |
duke@435 | 223 | |
duke@435 | 224 | if (obj->blueprint()->oop_is_instanceKlass()) { |
duke@435 | 225 | instanceKlass* ik = instanceKlass::cast((klassOop)obj); |
duke@435 | 226 | mark_object(ik->name()); |
duke@435 | 227 | mark_object(ik->generic_signature()); |
duke@435 | 228 | mark_object(ik->source_file_name()); |
duke@435 | 229 | mark_object(ik->source_debug_extension()); |
duke@435 | 230 | |
duke@435 | 231 | typeArrayOop inner_classes = ik->inner_classes(); |
duke@435 | 232 | if (inner_classes != NULL) { |
duke@435 | 233 | int length = inner_classes->length(); |
duke@435 | 234 | for (int i = 0; |
duke@435 | 235 | i < length; |
duke@435 | 236 | i += instanceKlass::inner_class_next_offset) { |
duke@435 | 237 | int ioff = i + instanceKlass::inner_class_inner_name_offset; |
duke@435 | 238 | int index = inner_classes->ushort_at(ioff); |
duke@435 | 239 | if (index != 0) { |
duke@435 | 240 | mark_object(ik->constants()->symbol_at(index)); |
duke@435 | 241 | } |
duke@435 | 242 | } |
duke@435 | 243 | } |
duke@435 | 244 | ik->field_names_and_sigs_iterate(&mark_all); |
duke@435 | 245 | } |
duke@435 | 246 | } |
duke@435 | 247 | |
duke@435 | 248 | // Mark symbols referenced by other constantpool entries. |
duke@435 | 249 | |
duke@435 | 250 | if (obj->is_constantPool()) { |
duke@435 | 251 | constantPoolOop(obj)->shared_symbols_iterate(&mark_all); |
duke@435 | 252 | } |
duke@435 | 253 | } |
duke@435 | 254 | }; |
duke@435 | 255 | |
duke@435 | 256 | |
duke@435 | 257 | // Closure: mark char arrays used by strings |
duke@435 | 258 | |
duke@435 | 259 | class MarkStringValues : public ObjectClosure { |
duke@435 | 260 | private: |
duke@435 | 261 | MarkObjectsOopClosure mark_all; |
duke@435 | 262 | public: |
duke@435 | 263 | void do_object(oop obj) { |
duke@435 | 264 | |
duke@435 | 265 | // Character arrays referenced by String objects are read-only. |
duke@435 | 266 | |
duke@435 | 267 | if (java_lang_String::is_instance(obj)) { |
duke@435 | 268 | mark_object(java_lang_String::value(obj)); |
duke@435 | 269 | } |
duke@435 | 270 | } |
duke@435 | 271 | }; |
duke@435 | 272 | |
duke@435 | 273 | |
duke@435 | 274 | #ifdef DEBUG |
duke@435 | 275 | // Closure: Check for objects left in the heap which have not been moved. |
duke@435 | 276 | |
duke@435 | 277 | class CheckRemainingObjects : public ObjectClosure { |
duke@435 | 278 | private: |
duke@435 | 279 | int count; |
duke@435 | 280 | |
duke@435 | 281 | public: |
duke@435 | 282 | CheckRemainingObjects() { |
duke@435 | 283 | count = 0; |
duke@435 | 284 | } |
duke@435 | 285 | |
duke@435 | 286 | void do_object(oop obj) { |
duke@435 | 287 | if (!obj->is_shared() && |
duke@435 | 288 | !obj->is_forwarded()) { |
duke@435 | 289 | ++count; |
duke@435 | 290 | if (Verbose) { |
duke@435 | 291 | tty->print("Unreferenced object: "); |
duke@435 | 292 | obj->print_on(tty); |
duke@435 | 293 | } |
duke@435 | 294 | } |
duke@435 | 295 | } |
duke@435 | 296 | |
duke@435 | 297 | void status() { |
duke@435 | 298 | tty->print_cr("%d objects no longer referenced, not shared.", count); |
duke@435 | 299 | } |
duke@435 | 300 | }; |
duke@435 | 301 | #endif |
duke@435 | 302 | |
duke@435 | 303 | |
duke@435 | 304 | // Closure: Mark remaining objects read-write, except Strings. |
duke@435 | 305 | |
duke@435 | 306 | class MarkReadWriteObjects : public ObjectClosure { |
duke@435 | 307 | private: |
duke@435 | 308 | MarkObjectsOopClosure mark_objects; |
duke@435 | 309 | public: |
duke@435 | 310 | void do_object(oop obj) { |
duke@435 | 311 | |
duke@435 | 312 | // The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though |
duke@435 | 313 | // it is never modified. Otherwise, they will be pre-marked; the |
duke@435 | 314 | // GC marking phase will skip them; and by skipping them will fail |
duke@435 | 315 | // to mark the methods objects referenced by the array. |
duke@435 | 316 | |
duke@435 | 317 | if (obj->is_klass()) { |
duke@435 | 318 | mark_object(obj); |
duke@435 | 319 | Klass* k = klassOop(obj)->klass_part(); |
duke@435 | 320 | mark_object(k->java_mirror()); |
duke@435 | 321 | if (obj->blueprint()->oop_is_instanceKlass()) { |
duke@435 | 322 | instanceKlass* ik = (instanceKlass*)k; |
duke@435 | 323 | mark_object(ik->methods()); |
duke@435 | 324 | mark_object(ik->constants()); |
duke@435 | 325 | } |
duke@435 | 326 | if (obj->blueprint()->oop_is_javaArray()) { |
duke@435 | 327 | arrayKlass* ak = (arrayKlass*)k; |
duke@435 | 328 | mark_object(ak->component_mirror()); |
duke@435 | 329 | } |
duke@435 | 330 | return; |
duke@435 | 331 | } |
duke@435 | 332 | |
duke@435 | 333 | // Mark constantPool tags and the constantPoolCache. |
duke@435 | 334 | |
duke@435 | 335 | else if (obj->is_constantPool()) { |
duke@435 | 336 | constantPoolOop pool = constantPoolOop(obj); |
duke@435 | 337 | mark_object(pool->cache()); |
duke@435 | 338 | pool->shared_tags_iterate(&mark_objects); |
duke@435 | 339 | return; |
duke@435 | 340 | } |
duke@435 | 341 | |
duke@435 | 342 | // Mark all method objects. |
duke@435 | 343 | |
duke@435 | 344 | if (obj->is_method()) { |
duke@435 | 345 | mark_object(obj); |
duke@435 | 346 | } |
duke@435 | 347 | } |
duke@435 | 348 | }; |
duke@435 | 349 | |
duke@435 | 350 | |
duke@435 | 351 | // Closure: Mark String objects read-write. |
duke@435 | 352 | |
duke@435 | 353 | class MarkStringObjects : public ObjectClosure { |
duke@435 | 354 | private: |
duke@435 | 355 | MarkObjectsOopClosure mark_objects; |
duke@435 | 356 | public: |
duke@435 | 357 | void do_object(oop obj) { |
duke@435 | 358 | |
duke@435 | 359 | // Mark String objects referenced by constant pool entries. |
duke@435 | 360 | |
duke@435 | 361 | if (obj->is_constantPool()) { |
duke@435 | 362 | constantPoolOop pool = constantPoolOop(obj); |
duke@435 | 363 | pool->shared_strings_iterate(&mark_objects); |
duke@435 | 364 | return; |
duke@435 | 365 | } |
duke@435 | 366 | } |
duke@435 | 367 | }; |
duke@435 | 368 | |
duke@435 | 369 | |
duke@435 | 370 | // Move objects matching specified type (ie. lock_bits) to the specified |
duke@435 | 371 | // space. |
duke@435 | 372 | |
duke@435 | 373 | class MoveMarkedObjects : public ObjectClosure { |
duke@435 | 374 | private: |
duke@435 | 375 | OffsetTableContigSpace* _space; |
duke@435 | 376 | bool _read_only; |
duke@435 | 377 | |
duke@435 | 378 | public: |
duke@435 | 379 | MoveMarkedObjects(OffsetTableContigSpace* space, bool read_only) { |
duke@435 | 380 | _space = space; |
duke@435 | 381 | _read_only = read_only; |
duke@435 | 382 | } |
duke@435 | 383 | |
duke@435 | 384 | void do_object(oop obj) { |
duke@435 | 385 | if (obj->is_shared()) { |
duke@435 | 386 | return; |
duke@435 | 387 | } |
duke@435 | 388 | if (obj->is_gc_marked() && obj->forwardee() == NULL) { |
duke@435 | 389 | int s = obj->size(); |
duke@435 | 390 | oop sh_obj = (oop)_space->allocate(s); |
duke@435 | 391 | if (sh_obj == NULL) { |
duke@435 | 392 | if (_read_only) { |
duke@435 | 393 | warning("\nThe permanent generation read only space is not large " |
duke@435 | 394 | "enough to \npreload requested classes. Use " |
duke@435 | 395 | "-XX:SharedReadOnlySize= to increase \nthe initial " |
duke@435 | 396 | "size of the read only space.\n"); |
duke@435 | 397 | } else { |
duke@435 | 398 | warning("\nThe permanent generation read write space is not large " |
duke@435 | 399 | "enough to \npreload requested classes. Use " |
duke@435 | 400 | "-XX:SharedReadWriteSize= to increase \nthe initial " |
duke@435 | 401 | "size of the read write space.\n"); |
duke@435 | 402 | } |
duke@435 | 403 | exit(2); |
duke@435 | 404 | } |
duke@435 | 405 | if (PrintSharedSpaces && Verbose && WizardMode) { |
duke@435 | 406 | tty->print_cr("\nMoveMarkedObjects: " PTR_FORMAT " -> " PTR_FORMAT " %s", obj, sh_obj, |
duke@435 | 407 | (_read_only ? "ro" : "rw")); |
duke@435 | 408 | } |
duke@435 | 409 | Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)sh_obj, s); |
duke@435 | 410 | obj->forward_to(sh_obj); |
duke@435 | 411 | if (_read_only) { |
duke@435 | 412 | // Readonly objects: set hash value to self pointer and make gc_marked. |
duke@435 | 413 | sh_obj->forward_to(sh_obj); |
duke@435 | 414 | } else { |
duke@435 | 415 | sh_obj->init_mark(); |
duke@435 | 416 | } |
duke@435 | 417 | } |
duke@435 | 418 | } |
duke@435 | 419 | }; |
duke@435 | 420 | |
duke@435 | 421 | static void mark_and_move(oop obj, MoveMarkedObjects* move) { |
duke@435 | 422 | if (mark_object(obj)) move->do_object(obj); |
duke@435 | 423 | } |
duke@435 | 424 | |
duke@435 | 425 | enum order_policy { |
duke@435 | 426 | OP_favor_startup = 0, |
duke@435 | 427 | OP_balanced = 1, |
duke@435 | 428 | OP_favor_runtime = 2 |
duke@435 | 429 | }; |
duke@435 | 430 | |
duke@435 | 431 | static void mark_and_move_for_policy(order_policy policy, oop obj, MoveMarkedObjects* move) { |
duke@435 | 432 | if (SharedOptimizeColdStartPolicy >= policy) mark_and_move(obj, move); |
duke@435 | 433 | } |
duke@435 | 434 | |
duke@435 | 435 | class MarkAndMoveOrderedReadOnly : public ObjectClosure { |
duke@435 | 436 | private: |
duke@435 | 437 | MoveMarkedObjects *_move_ro; |
duke@435 | 438 | |
duke@435 | 439 | public: |
duke@435 | 440 | MarkAndMoveOrderedReadOnly(MoveMarkedObjects *move_ro) : _move_ro(move_ro) {} |
duke@435 | 441 | |
duke@435 | 442 | void do_object(oop obj) { |
duke@435 | 443 | if (obj->is_klass() && obj->blueprint()->oop_is_instanceKlass()) { |
duke@435 | 444 | instanceKlass* ik = instanceKlass::cast((klassOop)obj); |
duke@435 | 445 | int i; |
duke@435 | 446 | |
duke@435 | 447 | mark_and_move_for_policy(OP_favor_startup, ik->name(), _move_ro); |
duke@435 | 448 | |
duke@435 | 449 | if (ik->super() != NULL) { |
duke@435 | 450 | do_object(ik->super()); |
duke@435 | 451 | } |
duke@435 | 452 | |
duke@435 | 453 | objArrayOop interfaces = ik->local_interfaces(); |
duke@435 | 454 | mark_and_move_for_policy(OP_favor_startup, interfaces, _move_ro); |
duke@435 | 455 | for(i = 0; i < interfaces->length(); i++) { |
duke@435 | 456 | klassOop k = klassOop(interfaces->obj_at(i)); |
duke@435 | 457 | mark_and_move_for_policy(OP_favor_startup, k->klass_part()->name(), _move_ro); |
duke@435 | 458 | do_object(k); |
duke@435 | 459 | } |
duke@435 | 460 | |
duke@435 | 461 | objArrayOop methods = ik->methods(); |
duke@435 | 462 | for(i = 0; i < methods->length(); i++) { |
duke@435 | 463 | methodOop m = methodOop(methods->obj_at(i)); |
duke@435 | 464 | mark_and_move_for_policy(OP_favor_startup, m->constMethod(), _move_ro); |
duke@435 | 465 | mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->exception_table(), _move_ro); |
duke@435 | 466 | mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->stackmap_data(), _move_ro); |
duke@435 | 467 | |
duke@435 | 468 | // We don't move the name symbolOop here because it may invalidate |
duke@435 | 469 | // method ordering, which is dependent on the address of the name |
duke@435 | 470 | // symbolOop. It will get promoted later with the other symbols. |
duke@435 | 471 | // Method name is rarely accessed during classloading anyway. |
duke@435 | 472 | // mark_and_move_for_policy(OP_balanced, m->name(), _move_ro); |
duke@435 | 473 | |
duke@435 | 474 | mark_and_move_for_policy(OP_favor_startup, m->signature(), _move_ro); |
duke@435 | 475 | } |
duke@435 | 476 | |
duke@435 | 477 | mark_and_move_for_policy(OP_favor_startup, ik->transitive_interfaces(), _move_ro); |
duke@435 | 478 | mark_and_move_for_policy(OP_favor_startup, ik->fields(), _move_ro); |
duke@435 | 479 | |
duke@435 | 480 | mark_and_move_for_policy(OP_favor_runtime, ik->secondary_supers(), _move_ro); |
duke@435 | 481 | mark_and_move_for_policy(OP_favor_runtime, ik->method_ordering(), _move_ro); |
duke@435 | 482 | mark_and_move_for_policy(OP_favor_runtime, ik->class_annotations(), _move_ro); |
duke@435 | 483 | mark_and_move_for_policy(OP_favor_runtime, ik->fields_annotations(), _move_ro); |
duke@435 | 484 | mark_and_move_for_policy(OP_favor_runtime, ik->methods_annotations(), _move_ro); |
duke@435 | 485 | mark_and_move_for_policy(OP_favor_runtime, ik->methods_parameter_annotations(), _move_ro); |
duke@435 | 486 | mark_and_move_for_policy(OP_favor_runtime, ik->methods_default_annotations(), _move_ro); |
duke@435 | 487 | mark_and_move_for_policy(OP_favor_runtime, ik->inner_classes(), _move_ro); |
duke@435 | 488 | mark_and_move_for_policy(OP_favor_runtime, ik->secondary_supers(), _move_ro); |
duke@435 | 489 | } |
duke@435 | 490 | } |
duke@435 | 491 | }; |
duke@435 | 492 | |
duke@435 | 493 | class MarkAndMoveOrderedReadWrite: public ObjectClosure { |
duke@435 | 494 | private: |
duke@435 | 495 | MoveMarkedObjects *_move_rw; |
duke@435 | 496 | |
duke@435 | 497 | public: |
duke@435 | 498 | MarkAndMoveOrderedReadWrite(MoveMarkedObjects *move_rw) : _move_rw(move_rw) {} |
duke@435 | 499 | |
duke@435 | 500 | void do_object(oop obj) { |
duke@435 | 501 | if (obj->is_klass() && obj->blueprint()->oop_is_instanceKlass()) { |
duke@435 | 502 | instanceKlass* ik = instanceKlass::cast((klassOop)obj); |
duke@435 | 503 | int i; |
duke@435 | 504 | |
duke@435 | 505 | mark_and_move_for_policy(OP_favor_startup, ik->as_klassOop(), _move_rw); |
duke@435 | 506 | |
duke@435 | 507 | if (ik->super() != NULL) { |
duke@435 | 508 | do_object(ik->super()); |
duke@435 | 509 | } |
duke@435 | 510 | |
duke@435 | 511 | objArrayOop interfaces = ik->local_interfaces(); |
duke@435 | 512 | for(i = 0; i < interfaces->length(); i++) { |
duke@435 | 513 | klassOop k = klassOop(interfaces->obj_at(i)); |
duke@435 | 514 | mark_and_move_for_policy(OP_favor_startup, k, _move_rw); |
duke@435 | 515 | do_object(k); |
duke@435 | 516 | } |
duke@435 | 517 | |
duke@435 | 518 | objArrayOop methods = ik->methods(); |
duke@435 | 519 | mark_and_move_for_policy(OP_favor_startup, methods, _move_rw); |
duke@435 | 520 | for(i = 0; i < methods->length(); i++) { |
duke@435 | 521 | methodOop m = methodOop(methods->obj_at(i)); |
duke@435 | 522 | mark_and_move_for_policy(OP_favor_startup, m, _move_rw); |
duke@435 | 523 | mark_and_move_for_policy(OP_favor_startup, ik->constants(), _move_rw); // idempotent |
duke@435 | 524 | mark_and_move_for_policy(OP_balanced, ik->constants()->cache(), _move_rw); // idempotent |
duke@435 | 525 | mark_and_move_for_policy(OP_balanced, ik->constants()->tags(), _move_rw); // idempotent |
duke@435 | 526 | } |
duke@435 | 527 | |
duke@435 | 528 | mark_and_move_for_policy(OP_favor_startup, ik->as_klassOop()->klass(), _move_rw); |
duke@435 | 529 | mark_and_move_for_policy(OP_favor_startup, ik->constants()->klass(), _move_rw); |
duke@435 | 530 | |
duke@435 | 531 | // Although Java mirrors are marked in MarkReadWriteObjects, |
duke@435 | 532 | // apparently they were never moved into shared spaces since |
duke@435 | 533 | // MoveMarkedObjects skips marked instance oops. This may |
duke@435 | 534 | // be a bug in the original implementation or simply the vestige |
duke@435 | 535 | // of an abandoned experiment. Nevertheless we leave a hint |
duke@435 | 536 | // here in case this capability is ever correctly implemented. |
duke@435 | 537 | // |
duke@435 | 538 | // mark_and_move_for_policy(OP_favor_runtime, ik->java_mirror(), _move_rw); |
duke@435 | 539 | } |
duke@435 | 540 | } |
duke@435 | 541 | |
duke@435 | 542 | }; |
duke@435 | 543 | |
duke@435 | 544 | // Adjust references in oops to refer to shared spaces. |
duke@435 | 545 | |
duke@435 | 546 | class ResolveForwardingClosure: public OopClosure { |
duke@435 | 547 | public: |
duke@435 | 548 | void do_oop(oop* p) { |
duke@435 | 549 | oop obj = *p; |
duke@435 | 550 | if (!obj->is_shared()) { |
duke@435 | 551 | if (obj != NULL) { |
duke@435 | 552 | oop f = obj->forwardee(); |
duke@435 | 553 | guarantee(f->is_shared(), "Oop doesn't refer to shared space."); |
duke@435 | 554 | *p = f; |
duke@435 | 555 | } |
duke@435 | 556 | } |
duke@435 | 557 | } |
coleenp@548 | 558 | void do_oop(narrowOop* pobj) { ShouldNotReachHere(); } |
duke@435 | 559 | }; |
duke@435 | 560 | |
duke@435 | 561 | |
duke@435 | 562 | void sort_methods(instanceKlass* ik, TRAPS) { |
duke@435 | 563 | klassOop super = ik->super(); |
duke@435 | 564 | if (super != NULL) { |
duke@435 | 565 | sort_methods(instanceKlass::cast(super), THREAD); |
duke@435 | 566 | } |
duke@435 | 567 | |
duke@435 | 568 | // The methods array must be ordered by symbolOop address. (See |
duke@435 | 569 | // classFileParser.cpp where methods in a class are originally |
duke@435 | 570 | // sorted.) Since objects have just be reordered, this must be |
duke@435 | 571 | // corrected. |
duke@435 | 572 | methodOopDesc::sort_methods(ik->methods(), |
duke@435 | 573 | ik->methods_annotations(), |
duke@435 | 574 | ik->methods_parameter_annotations(), |
duke@435 | 575 | ik->methods_default_annotations(), |
duke@435 | 576 | true /* idempotent, slow */); |
duke@435 | 577 | |
duke@435 | 578 | // Itable indices are calculated based on methods array order |
duke@435 | 579 | // (see klassItable::compute_itable_index()). Must reinitialize. |
duke@435 | 580 | // We assume that since checkconstraints is false, this method |
duke@435 | 581 | // cannot throw an exception. An exception here would be |
duke@435 | 582 | // problematic since this is the VMThread, not a JavaThread. |
duke@435 | 583 | ik->itable()->initialize_itable(false, THREAD); |
duke@435 | 584 | } |
duke@435 | 585 | |
duke@435 | 586 | // Sort methods if the oop is an instanceKlass. |
duke@435 | 587 | |
duke@435 | 588 | class SortMethodsClosure: public ObjectClosure { |
duke@435 | 589 | private: |
duke@435 | 590 | Thread* _thread; |
duke@435 | 591 | |
duke@435 | 592 | public: |
duke@435 | 593 | SortMethodsClosure(Thread* thread) : _thread(thread) {} |
duke@435 | 594 | |
duke@435 | 595 | void do_object(oop obj) { |
duke@435 | 596 | // instanceKlass objects need some adjustment. |
duke@435 | 597 | if (obj->blueprint()->oop_is_instanceKlass()) { |
duke@435 | 598 | instanceKlass* ik = instanceKlass::cast((klassOop)obj); |
duke@435 | 599 | |
duke@435 | 600 | sort_methods(ik, _thread); |
duke@435 | 601 | } |
duke@435 | 602 | } |
duke@435 | 603 | }; |
duke@435 | 604 | |
duke@435 | 605 | |
duke@435 | 606 | // Adjust references in oops to refer to shared spaces. |
duke@435 | 607 | |
duke@435 | 608 | class PatchOopsClosure: public ObjectClosure { |
duke@435 | 609 | private: |
duke@435 | 610 | Thread* _thread; |
duke@435 | 611 | ResolveForwardingClosure resolve; |
duke@435 | 612 | |
duke@435 | 613 | public: |
duke@435 | 614 | PatchOopsClosure(Thread* thread) : _thread(thread) {} |
duke@435 | 615 | |
duke@435 | 616 | void do_object(oop obj) { |
duke@435 | 617 | obj->oop_iterate_header(&resolve); |
duke@435 | 618 | obj->oop_iterate(&resolve); |
duke@435 | 619 | |
duke@435 | 620 | assert(obj->klass()->is_shared(), "Klass not pointing into shared space."); |
duke@435 | 621 | |
duke@435 | 622 | // If the object is a Java object or class which might (in the |
duke@435 | 623 | // future) contain a reference to a young gen object, add it to the |
duke@435 | 624 | // list. |
duke@435 | 625 | |
duke@435 | 626 | if (obj->is_klass() || obj->is_instance()) { |
duke@435 | 627 | if (obj->is_klass() || |
duke@435 | 628 | obj->is_a(SystemDictionary::class_klass()) || |
duke@435 | 629 | obj->is_a(SystemDictionary::throwable_klass())) { |
duke@435 | 630 | // Do nothing |
duke@435 | 631 | } |
duke@435 | 632 | else if (obj->is_a(SystemDictionary::string_klass())) { |
duke@435 | 633 | // immutable objects. |
duke@435 | 634 | } else { |
duke@435 | 635 | // someone added an object we hadn't accounted for. |
duke@435 | 636 | ShouldNotReachHere(); |
duke@435 | 637 | } |
duke@435 | 638 | } |
duke@435 | 639 | } |
duke@435 | 640 | }; |
duke@435 | 641 | |
duke@435 | 642 | |
duke@435 | 643 | // Empty the young and old generations. |
duke@435 | 644 | |
duke@435 | 645 | class ClearSpaceClosure : public SpaceClosure { |
duke@435 | 646 | public: |
duke@435 | 647 | void do_space(Space* s) { |
jmasa@698 | 648 | s->clear(SpaceDecorator::Mangle); |
duke@435 | 649 | } |
duke@435 | 650 | }; |
duke@435 | 651 | |
duke@435 | 652 | |
duke@435 | 653 | // Closure for serializing initialization data out to a data area to be |
duke@435 | 654 | // written to the shared file. |
duke@435 | 655 | |
duke@435 | 656 | class WriteClosure : public SerializeOopClosure { |
duke@435 | 657 | private: |
duke@435 | 658 | oop* top; |
duke@435 | 659 | char* end; |
duke@435 | 660 | |
duke@435 | 661 | void out_of_space() { |
duke@435 | 662 | warning("\nThe shared miscellaneous data space is not large " |
duke@435 | 663 | "enough to \npreload requested classes. Use " |
duke@435 | 664 | "-XX:SharedMiscDataSize= to increase \nthe initial " |
duke@435 | 665 | "size of the miscellaneous data space.\n"); |
duke@435 | 666 | exit(2); |
duke@435 | 667 | } |
duke@435 | 668 | |
duke@435 | 669 | |
duke@435 | 670 | inline void check_space() { |
duke@435 | 671 | if ((char*)top + sizeof(oop) > end) { |
duke@435 | 672 | out_of_space(); |
duke@435 | 673 | } |
duke@435 | 674 | } |
duke@435 | 675 | |
duke@435 | 676 | |
duke@435 | 677 | public: |
duke@435 | 678 | WriteClosure(char* md_top, char* md_end) { |
duke@435 | 679 | top = (oop*)md_top; |
duke@435 | 680 | end = md_end; |
duke@435 | 681 | } |
duke@435 | 682 | |
duke@435 | 683 | char* get_top() { return (char*)top; } |
duke@435 | 684 | |
duke@435 | 685 | void do_oop(oop* p) { |
duke@435 | 686 | check_space(); |
duke@435 | 687 | oop obj = *p; |
duke@435 | 688 | assert(obj->is_oop_or_null(), "invalid oop"); |
duke@435 | 689 | assert(obj == NULL || obj->is_shared(), |
duke@435 | 690 | "Oop in shared space not pointing into shared space."); |
duke@435 | 691 | *top = obj; |
duke@435 | 692 | ++top; |
duke@435 | 693 | } |
duke@435 | 694 | |
coleenp@548 | 695 | void do_oop(narrowOop* pobj) { ShouldNotReachHere(); } |
coleenp@548 | 696 | |
duke@435 | 697 | void do_int(int* p) { |
duke@435 | 698 | check_space(); |
duke@435 | 699 | *top = (oop)(intptr_t)*p; |
duke@435 | 700 | ++top; |
duke@435 | 701 | } |
duke@435 | 702 | |
duke@435 | 703 | void do_size_t(size_t* p) { |
duke@435 | 704 | check_space(); |
duke@435 | 705 | *top = (oop)(intptr_t)*p; |
duke@435 | 706 | ++top; |
duke@435 | 707 | } |
duke@435 | 708 | |
duke@435 | 709 | void do_ptr(void** p) { |
duke@435 | 710 | check_space(); |
duke@435 | 711 | *top = (oop)*p; |
duke@435 | 712 | ++top; |
duke@435 | 713 | } |
duke@435 | 714 | |
duke@435 | 715 | void do_ptr(HeapWord** p) { do_ptr((void **) p); } |
duke@435 | 716 | |
duke@435 | 717 | void do_tag(int tag) { |
duke@435 | 718 | check_space(); |
duke@435 | 719 | *top = (oop)(intptr_t)tag; |
duke@435 | 720 | ++top; |
duke@435 | 721 | } |
duke@435 | 722 | |
duke@435 | 723 | void do_region(u_char* start, size_t size) { |
duke@435 | 724 | if ((char*)top + size > end) { |
duke@435 | 725 | out_of_space(); |
duke@435 | 726 | } |
duke@435 | 727 | assert((intptr_t)start % sizeof(oop) == 0, "bad alignment"); |
duke@435 | 728 | assert(size % sizeof(oop) == 0, "bad size"); |
duke@435 | 729 | do_tag((int)size); |
duke@435 | 730 | while (size > 0) { |
duke@435 | 731 | *top = *(oop*)start; |
duke@435 | 732 | ++top; |
duke@435 | 733 | start += sizeof(oop); |
duke@435 | 734 | size -= sizeof(oop); |
duke@435 | 735 | } |
duke@435 | 736 | } |
duke@435 | 737 | |
duke@435 | 738 | bool reading() const { return false; } |
duke@435 | 739 | }; |
duke@435 | 740 | |
duke@435 | 741 | |
duke@435 | 742 | class ResolveConstantPoolsClosure : public ObjectClosure { |
duke@435 | 743 | private: |
duke@435 | 744 | TRAPS; |
duke@435 | 745 | public: |
duke@435 | 746 | ResolveConstantPoolsClosure(Thread *t) { |
duke@435 | 747 | __the_thread__ = t; |
duke@435 | 748 | } |
duke@435 | 749 | void do_object(oop obj) { |
duke@435 | 750 | if (obj->is_constantPool()) { |
duke@435 | 751 | constantPoolOop cpool = (constantPoolOop)obj; |
duke@435 | 752 | int unresolved = cpool->pre_resolve_shared_klasses(THREAD); |
duke@435 | 753 | } |
duke@435 | 754 | } |
duke@435 | 755 | }; |
duke@435 | 756 | |
duke@435 | 757 | |
duke@435 | 758 | // Print a summary of the contents of the read/write spaces to help |
duke@435 | 759 | // identify objects which might be able to be made read-only. At this |
duke@435 | 760 | // point, the objects have been written, and we can trash them as |
duke@435 | 761 | // needed. |
duke@435 | 762 | |
duke@435 | 763 | static void print_contents() { |
duke@435 | 764 | if (PrintSharedSpaces) { |
duke@435 | 765 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 766 | CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen(); |
duke@435 | 767 | |
duke@435 | 768 | // High level summary of the read-only space: |
duke@435 | 769 | |
duke@435 | 770 | ClassifyObjectClosure coc; |
duke@435 | 771 | tty->cr(); tty->print_cr("ReadOnly space:"); |
duke@435 | 772 | gen->ro_space()->object_iterate(&coc); |
duke@435 | 773 | coc.print(); |
duke@435 | 774 | |
duke@435 | 775 | // High level summary of the read-write space: |
duke@435 | 776 | |
duke@435 | 777 | coc.reset(); |
duke@435 | 778 | tty->cr(); tty->print_cr("ReadWrite space:"); |
duke@435 | 779 | gen->rw_space()->object_iterate(&coc); |
duke@435 | 780 | coc.print(); |
duke@435 | 781 | |
duke@435 | 782 | // Reset counters |
duke@435 | 783 | |
duke@435 | 784 | ClearAllocCountClosure cacc; |
duke@435 | 785 | gen->ro_space()->object_iterate(&cacc); |
duke@435 | 786 | gen->rw_space()->object_iterate(&cacc); |
duke@435 | 787 | coc.reset(); |
duke@435 | 788 | |
duke@435 | 789 | // Lower level summary of the read-only space: |
duke@435 | 790 | |
duke@435 | 791 | gen->ro_space()->object_iterate(&coc); |
duke@435 | 792 | tty->cr(); tty->print_cr("ReadOnly space:"); |
duke@435 | 793 | ClassifyInstanceKlassClosure cikc; |
duke@435 | 794 | gen->rw_space()->object_iterate(&cikc); |
duke@435 | 795 | cikc.print(); |
duke@435 | 796 | |
duke@435 | 797 | // Reset counters |
duke@435 | 798 | |
duke@435 | 799 | gen->ro_space()->object_iterate(&cacc); |
duke@435 | 800 | gen->rw_space()->object_iterate(&cacc); |
duke@435 | 801 | coc.reset(); |
duke@435 | 802 | |
duke@435 | 803 | // Lower level summary of the read-write space: |
duke@435 | 804 | |
duke@435 | 805 | gen->rw_space()->object_iterate(&coc); |
duke@435 | 806 | cikc.reset(); |
duke@435 | 807 | tty->cr(); tty->print_cr("ReadWrite space:"); |
duke@435 | 808 | gen->rw_space()->object_iterate(&cikc); |
duke@435 | 809 | cikc.print(); |
duke@435 | 810 | } |
duke@435 | 811 | } |
duke@435 | 812 | |
duke@435 | 813 | |
duke@435 | 814 | // Patch C++ vtable pointer in klass oops. |
duke@435 | 815 | |
duke@435 | 816 | // Klass objects contain references to c++ vtables in the JVM library. |
duke@435 | 817 | // Fix them to point to our constructed vtables. However, don't iterate |
duke@435 | 818 | // across the space while doing this, as that causes the vtables to be |
duke@435 | 819 | // patched, undoing our useful work. Instead, iterate to make a list, |
duke@435 | 820 | // then use the list to do the fixing. |
acorn@843 | 821 | // |
acorn@843 | 822 | // Our constructed vtables: |
acorn@843 | 823 | // Dump time: |
acorn@843 | 824 | // 1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs |
acorn@843 | 825 | // 2. generate_vtable_methods: create jump table, appended to above vtbl_list |
acorn@843 | 826 | // 3. PatchKlassVtables: for Klass list, patch the vtable entry to point to jump table |
acorn@843 | 827 | // rather than to current vtbl |
acorn@843 | 828 | // Table layout: NOTE FIXED SIZE |
acorn@843 | 829 | // 1. vtbl pointers |
acorn@843 | 830 | // 2. #Klass X #virtual methods per Klass |
acorn@843 | 831 | // 1 entry for each, in the order: |
acorn@843 | 832 | // Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry |
acorn@843 | 833 | // Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry |
acorn@843 | 834 | // ... |
acorn@843 | 835 | // Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry, |
acorn@843 | 836 | // ... Klass<vtbl_list_size>:method<num_virtuals> entry |
acorn@843 | 837 | // Sample entry: (Sparc): |
acorn@843 | 838 | // save(sp, -256, sp) |
acorn@843 | 839 | // ba,pt common_code |
acorn@843 | 840 | // mov XXX, %L0 %L0 gets: Klass index <<8 + method index (note: max method index 255) |
acorn@843 | 841 | // |
acorn@843 | 842 | // Restore time: |
acorn@843 | 843 | // 1. initialize_oops: reserve space for table |
acorn@843 | 844 | // 2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text |
acorn@843 | 845 | // |
acorn@843 | 846 | // Execution time: |
acorn@843 | 847 | // First virtual method call for any object of these Klass types: |
acorn@843 | 848 | // 1. object->klass->klass_part |
acorn@843 | 849 | // 2. vtable entry for that klass_part points to the jump table entries |
acorn@843 | 850 | // 3. branches to common_code with %O0/klass_part, %L0: Klass index <<8 + method index |
acorn@843 | 851 | // 4. common_code: |
acorn@843 | 852 | // Get address of new vtbl pointer for this Klass from updated table |
acorn@843 | 853 | // Update new vtbl pointer in the Klass: future virtual calls go direct |
acorn@843 | 854 | // Jump to method, using new vtbl pointer and method index |
duke@435 | 855 | |
duke@435 | 856 | class PatchKlassVtables: public ObjectClosure { |
duke@435 | 857 | private: |
duke@435 | 858 | void* _vtbl_ptr; |
duke@435 | 859 | VirtualSpace* _md_vs; |
duke@435 | 860 | GrowableArray<klassOop>* _klass_objects; |
duke@435 | 861 | |
duke@435 | 862 | public: |
duke@435 | 863 | |
duke@435 | 864 | PatchKlassVtables(void* vtbl_ptr, VirtualSpace* md_vs) { |
duke@435 | 865 | _vtbl_ptr = vtbl_ptr; |
duke@435 | 866 | _md_vs = md_vs; |
duke@435 | 867 | _klass_objects = new GrowableArray<klassOop>(); |
duke@435 | 868 | } |
duke@435 | 869 | |
duke@435 | 870 | |
duke@435 | 871 | void do_object(oop obj) { |
duke@435 | 872 | if (obj->is_klass()) { |
duke@435 | 873 | _klass_objects->append(klassOop(obj)); |
duke@435 | 874 | } |
duke@435 | 875 | } |
duke@435 | 876 | |
duke@435 | 877 | |
duke@435 | 878 | void patch(void** vtbl_list, int vtbl_list_size) { |
duke@435 | 879 | for (int i = 0; i < _klass_objects->length(); ++i) { |
duke@435 | 880 | klassOop obj = (klassOop)_klass_objects->at(i); |
duke@435 | 881 | Klass* k = obj->klass_part(); |
duke@435 | 882 | void* v = *(void**)k; |
duke@435 | 883 | |
duke@435 | 884 | int n; |
duke@435 | 885 | for (n = 0; n < vtbl_list_size; ++n) { |
duke@435 | 886 | *(void**)k = NULL; |
duke@435 | 887 | if (vtbl_list[n] == v) { |
duke@435 | 888 | *(void**)k = (void**)_vtbl_ptr + |
duke@435 | 889 | (n * CompactingPermGenGen::num_virtuals); |
duke@435 | 890 | break; |
duke@435 | 891 | } |
duke@435 | 892 | } |
duke@435 | 893 | guarantee(n < vtbl_list_size, "unable to find matching vtbl pointer"); |
duke@435 | 894 | } |
duke@435 | 895 | } |
duke@435 | 896 | }; |
duke@435 | 897 | |
duke@435 | 898 | |
duke@435 | 899 | // Populate the shared space. |
duke@435 | 900 | |
duke@435 | 901 | class VM_PopulateDumpSharedSpace: public VM_Operation { |
duke@435 | 902 | private: |
duke@435 | 903 | GrowableArray<oop> *_class_promote_order; |
duke@435 | 904 | OffsetTableContigSpace* _ro_space; |
duke@435 | 905 | OffsetTableContigSpace* _rw_space; |
duke@435 | 906 | VirtualSpace* _md_vs; |
duke@435 | 907 | VirtualSpace* _mc_vs; |
duke@435 | 908 | |
duke@435 | 909 | public: |
duke@435 | 910 | VM_PopulateDumpSharedSpace(GrowableArray<oop> *class_promote_order, |
duke@435 | 911 | OffsetTableContigSpace* ro_space, |
duke@435 | 912 | OffsetTableContigSpace* rw_space, |
duke@435 | 913 | VirtualSpace* md_vs, VirtualSpace* mc_vs) { |
duke@435 | 914 | _class_promote_order = class_promote_order; |
duke@435 | 915 | _ro_space = ro_space; |
duke@435 | 916 | _rw_space = rw_space; |
duke@435 | 917 | _md_vs = md_vs; |
duke@435 | 918 | _mc_vs = mc_vs; |
duke@435 | 919 | } |
duke@435 | 920 | |
duke@435 | 921 | VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; } |
duke@435 | 922 | void doit() { |
duke@435 | 923 | Thread* THREAD = VMThread::vm_thread(); |
duke@435 | 924 | NOT_PRODUCT(SystemDictionary::verify();) |
duke@435 | 925 | // The following guarantee is meant to ensure that no loader constraints |
duke@435 | 926 | // exist yet, since the constraints table is not shared. This becomes |
duke@435 | 927 | // more important now that we don't re-initialize vtables/itables for |
duke@435 | 928 | // shared classes at runtime, where constraints were previously created. |
duke@435 | 929 | guarantee(SystemDictionary::constraints()->number_of_entries() == 0, |
duke@435 | 930 | "loader constraints are not saved"); |
duke@435 | 931 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 932 | |
duke@435 | 933 | // At this point, many classes have been loaded. |
duke@435 | 934 | |
duke@435 | 935 | // Update all the fingerprints in the shared methods. |
duke@435 | 936 | |
duke@435 | 937 | tty->print("Calculating fingerprints ... "); |
duke@435 | 938 | FingerprintMethodsClosure fpmc; |
duke@435 | 939 | gch->object_iterate(&fpmc); |
duke@435 | 940 | tty->print_cr("done. "); |
duke@435 | 941 | |
duke@435 | 942 | // Remove all references outside the heap. |
duke@435 | 943 | |
duke@435 | 944 | tty->print("Removing unshareable information ... "); |
duke@435 | 945 | RemoveUnshareableInfoClosure ruic; |
duke@435 | 946 | gch->object_iterate(&ruic); |
duke@435 | 947 | tty->print_cr("done. "); |
duke@435 | 948 | |
duke@435 | 949 | // Move the objects in three passes. |
duke@435 | 950 | |
duke@435 | 951 | MarkObjectsOopClosure mark_all; |
duke@435 | 952 | MarkCommonReadOnly mark_common_ro; |
duke@435 | 953 | MarkCommonSymbols mark_common_symbols; |
duke@435 | 954 | MarkStringValues mark_string_values; |
duke@435 | 955 | MarkReadWriteObjects mark_rw; |
duke@435 | 956 | MarkStringObjects mark_strings; |
duke@435 | 957 | MoveMarkedObjects move_ro(_ro_space, true); |
duke@435 | 958 | MoveMarkedObjects move_rw(_rw_space, false); |
duke@435 | 959 | |
duke@435 | 960 | // The SharedOptimizeColdStart VM option governs the new layout |
duke@435 | 961 | // algorithm for promoting classes into the shared archive. |
duke@435 | 962 | // The general idea is to minimize cold start time by laying |
duke@435 | 963 | // out the objects in the order they are accessed at startup time. |
duke@435 | 964 | // By doing this we are trying to eliminate out-of-order accesses |
duke@435 | 965 | // in the shared archive. This benefits cold startup time by making |
duke@435 | 966 | // disk reads as sequential as possible during class loading and |
duke@435 | 967 | // bootstrapping activities. There may also be a small secondary |
duke@435 | 968 | // effect of better "packing" of more commonly used data on a smaller |
duke@435 | 969 | // number of pages, although no direct benefit has been measured from |
duke@435 | 970 | // this effect. |
duke@435 | 971 | // |
duke@435 | 972 | // At the class level of granularity, the promotion order is dictated |
duke@435 | 973 | // by the classlist file whose generation is discussed elsewhere. |
duke@435 | 974 | // |
duke@435 | 975 | // At smaller granularity, optimal ordering was determined by an |
duke@435 | 976 | // offline analysis of object access order in the shared archive. |
duke@435 | 977 | // The dbx watchpoint facility, combined with SA post-processing, |
duke@435 | 978 | // was used to observe common access patterns primarily during |
duke@435 | 979 | // classloading. This information was used to craft the promotion |
duke@435 | 980 | // order seen in the following closures. |
duke@435 | 981 | // |
duke@435 | 982 | // The observed access order is mostly governed by what happens |
duke@435 | 983 | // in SystemDictionary::load_shared_class(). NOTE WELL - care |
duke@435 | 984 | // should be taken when making changes to this method, because it |
duke@435 | 985 | // may invalidate assumptions made about access order! |
duke@435 | 986 | // |
duke@435 | 987 | // (Ideally, there would be a better way to manage changes to |
duke@435 | 988 | // the access order. Unfortunately a generic in-VM solution for |
duke@435 | 989 | // dynamically observing access order and optimizing shared |
duke@435 | 990 | // archive layout is pretty difficult. We go with the static |
duke@435 | 991 | // analysis because the code is fairly mature at this point |
duke@435 | 992 | // and we're betting that the access order won't change much.) |
duke@435 | 993 | |
duke@435 | 994 | MarkAndMoveOrderedReadOnly mark_and_move_ordered_ro(&move_ro); |
duke@435 | 995 | MarkAndMoveOrderedReadWrite mark_and_move_ordered_rw(&move_rw); |
duke@435 | 996 | |
duke@435 | 997 | // Phase 1a: move commonly used read-only objects to the read-only space. |
duke@435 | 998 | |
duke@435 | 999 | if (SharedOptimizeColdStart) { |
duke@435 | 1000 | tty->print("Moving pre-ordered read-only objects to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1001 | _ro_space->top()); |
duke@435 | 1002 | for (int i = 0; i < _class_promote_order->length(); i++) { |
duke@435 | 1003 | oop obj = _class_promote_order->at(i); |
duke@435 | 1004 | mark_and_move_ordered_ro.do_object(obj); |
duke@435 | 1005 | } |
duke@435 | 1006 | tty->print_cr("done. "); |
duke@435 | 1007 | } |
duke@435 | 1008 | |
duke@435 | 1009 | tty->print("Moving read-only objects to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1010 | _ro_space->top()); |
duke@435 | 1011 | gch->object_iterate(&mark_common_ro); |
duke@435 | 1012 | gch->object_iterate(&move_ro); |
duke@435 | 1013 | tty->print_cr("done. "); |
duke@435 | 1014 | |
duke@435 | 1015 | // Phase 1b: move commonly used symbols to the read-only space. |
duke@435 | 1016 | |
duke@435 | 1017 | tty->print("Moving common symbols to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1018 | _ro_space->top()); |
duke@435 | 1019 | gch->object_iterate(&mark_common_symbols); |
duke@435 | 1020 | gch->object_iterate(&move_ro); |
duke@435 | 1021 | tty->print_cr("done. "); |
duke@435 | 1022 | |
duke@435 | 1023 | // Phase 1c: move remaining symbols to the read-only space |
duke@435 | 1024 | // (e.g. String initializers). |
duke@435 | 1025 | |
duke@435 | 1026 | tty->print("Moving remaining symbols to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1027 | _ro_space->top()); |
duke@435 | 1028 | vmSymbols::oops_do(&mark_all, true); |
duke@435 | 1029 | gch->object_iterate(&move_ro); |
duke@435 | 1030 | tty->print_cr("done. "); |
duke@435 | 1031 | |
duke@435 | 1032 | // Phase 1d: move String character arrays to the read-only space. |
duke@435 | 1033 | |
duke@435 | 1034 | tty->print("Moving string char arrays to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1035 | _ro_space->top()); |
duke@435 | 1036 | gch->object_iterate(&mark_string_values); |
duke@435 | 1037 | gch->object_iterate(&move_ro); |
duke@435 | 1038 | tty->print_cr("done. "); |
duke@435 | 1039 | |
duke@435 | 1040 | // Phase 2: move all remaining symbols to the read-only space. The |
duke@435 | 1041 | // remaining symbols are assumed to be string initializers no longer |
duke@435 | 1042 | // referenced. |
duke@435 | 1043 | |
duke@435 | 1044 | void* extra_symbols = _ro_space->top(); |
duke@435 | 1045 | tty->print("Moving additional symbols to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1046 | _ro_space->top()); |
duke@435 | 1047 | SymbolTable::oops_do(&mark_all); |
duke@435 | 1048 | gch->object_iterate(&move_ro); |
duke@435 | 1049 | tty->print_cr("done. "); |
duke@435 | 1050 | tty->print_cr("Read-only space ends at " PTR_FORMAT ", %d bytes.", |
duke@435 | 1051 | _ro_space->top(), _ro_space->used()); |
duke@435 | 1052 | |
duke@435 | 1053 | // Phase 3: move read-write objects to the read-write space, except |
duke@435 | 1054 | // Strings. |
duke@435 | 1055 | |
duke@435 | 1056 | if (SharedOptimizeColdStart) { |
duke@435 | 1057 | tty->print("Moving pre-ordered read-write objects to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1058 | _rw_space->top()); |
duke@435 | 1059 | for (int i = 0; i < _class_promote_order->length(); i++) { |
duke@435 | 1060 | oop obj = _class_promote_order->at(i); |
duke@435 | 1061 | mark_and_move_ordered_rw.do_object(obj); |
duke@435 | 1062 | } |
duke@435 | 1063 | tty->print_cr("done. "); |
duke@435 | 1064 | } |
duke@435 | 1065 | tty->print("Moving read-write objects to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1066 | _rw_space->top()); |
duke@435 | 1067 | Universe::oops_do(&mark_all, true); |
duke@435 | 1068 | SystemDictionary::oops_do(&mark_all); |
duke@435 | 1069 | oop tmp = Universe::arithmetic_exception_instance(); |
duke@435 | 1070 | mark_object(java_lang_Throwable::message(tmp)); |
duke@435 | 1071 | gch->object_iterate(&mark_rw); |
duke@435 | 1072 | gch->object_iterate(&move_rw); |
duke@435 | 1073 | tty->print_cr("done. "); |
duke@435 | 1074 | |
duke@435 | 1075 | // Phase 4: move String objects to the read-write space. |
duke@435 | 1076 | |
duke@435 | 1077 | tty->print("Moving String objects to shared space at " PTR_FORMAT " ... ", |
duke@435 | 1078 | _rw_space->top()); |
duke@435 | 1079 | StringTable::oops_do(&mark_all); |
duke@435 | 1080 | gch->object_iterate(&mark_strings); |
duke@435 | 1081 | gch->object_iterate(&move_rw); |
duke@435 | 1082 | tty->print_cr("done. "); |
duke@435 | 1083 | tty->print_cr("Read-write space ends at " PTR_FORMAT ", %d bytes.", |
duke@435 | 1084 | _rw_space->top(), _rw_space->used()); |
duke@435 | 1085 | |
duke@435 | 1086 | #ifdef DEBUG |
duke@435 | 1087 | // Check: scan for objects which were not moved. |
duke@435 | 1088 | |
duke@435 | 1089 | CheckRemainingObjects check_objects; |
duke@435 | 1090 | gch->object_iterate(&check_objects); |
duke@435 | 1091 | check_objects.status(); |
duke@435 | 1092 | #endif |
duke@435 | 1093 | |
duke@435 | 1094 | // Resolve forwarding in objects and saved C++ structures |
duke@435 | 1095 | tty->print("Updating references to shared objects ... "); |
duke@435 | 1096 | ResolveForwardingClosure resolve; |
duke@435 | 1097 | Universe::oops_do(&resolve); |
duke@435 | 1098 | SystemDictionary::oops_do(&resolve); |
duke@435 | 1099 | StringTable::oops_do(&resolve); |
duke@435 | 1100 | SymbolTable::oops_do(&resolve); |
duke@435 | 1101 | vmSymbols::oops_do(&resolve); |
duke@435 | 1102 | |
duke@435 | 1103 | // Set up the share data and shared code segments. |
duke@435 | 1104 | |
duke@435 | 1105 | char* md_top = _md_vs->low(); |
duke@435 | 1106 | char* md_end = _md_vs->high(); |
duke@435 | 1107 | char* mc_top = _mc_vs->low(); |
duke@435 | 1108 | char* mc_end = _mc_vs->high(); |
duke@435 | 1109 | |
duke@435 | 1110 | // Reserve space for the list of klassOops whose vtables are used |
duke@435 | 1111 | // for patching others as needed. |
duke@435 | 1112 | |
duke@435 | 1113 | void** vtbl_list = (void**)md_top; |
duke@435 | 1114 | int vtbl_list_size = CompactingPermGenGen::vtbl_list_size; |
duke@435 | 1115 | Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size); |
duke@435 | 1116 | |
duke@435 | 1117 | md_top += vtbl_list_size * sizeof(void*); |
duke@435 | 1118 | void* vtable = md_top; |
duke@435 | 1119 | |
duke@435 | 1120 | // Reserve space for a new dummy vtable for klass objects in the |
duke@435 | 1121 | // heap. Generate self-patching vtable entries. |
duke@435 | 1122 | |
duke@435 | 1123 | CompactingPermGenGen::generate_vtable_methods(vtbl_list, |
duke@435 | 1124 | &vtable, |
duke@435 | 1125 | &md_top, md_end, |
duke@435 | 1126 | &mc_top, mc_end); |
duke@435 | 1127 | |
duke@435 | 1128 | // Fix (forward) all of the references in these shared objects (which |
duke@435 | 1129 | // are required to point ONLY to objects in the shared spaces). |
duke@435 | 1130 | // Also, create a list of all objects which might later contain a |
duke@435 | 1131 | // reference to a younger generation object. |
duke@435 | 1132 | |
duke@435 | 1133 | CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen(); |
duke@435 | 1134 | PatchOopsClosure patch(THREAD); |
duke@435 | 1135 | gen->ro_space()->object_iterate(&patch); |
duke@435 | 1136 | gen->rw_space()->object_iterate(&patch); |
duke@435 | 1137 | |
duke@435 | 1138 | // Previously method sorting was done concurrently with forwarding |
duke@435 | 1139 | // pointer resolution in the shared spaces. This imposed an ordering |
duke@435 | 1140 | // restriction in that methods were required to be promoted/patched |
duke@435 | 1141 | // before their holder classes. (Because constant pool pointers in |
duke@435 | 1142 | // methodKlasses are required to be resolved before their holder class |
duke@435 | 1143 | // is visited for sorting, otherwise methods are sorted by incorrect, |
duke@435 | 1144 | // pre-forwarding addresses.) |
duke@435 | 1145 | // |
duke@435 | 1146 | // Now, we reorder methods as a separate step after ALL forwarding |
duke@435 | 1147 | // pointer resolution, so that methods can be promoted in any order |
duke@435 | 1148 | // with respect to their holder classes. |
duke@435 | 1149 | |
duke@435 | 1150 | SortMethodsClosure sort(THREAD); |
duke@435 | 1151 | gen->ro_space()->object_iterate(&sort); |
duke@435 | 1152 | gen->rw_space()->object_iterate(&sort); |
duke@435 | 1153 | tty->print_cr("done. "); |
duke@435 | 1154 | tty->cr(); |
duke@435 | 1155 | |
duke@435 | 1156 | // Reorder the system dictionary. (Moving the symbols opps affects |
duke@435 | 1157 | // how the hash table indices are calculated.) |
duke@435 | 1158 | |
duke@435 | 1159 | SystemDictionary::reorder_dictionary(); |
duke@435 | 1160 | |
duke@435 | 1161 | // Empty the non-shared heap (because most of the objects were |
duke@435 | 1162 | // copied out, and the remainder cannot be considered valid oops). |
duke@435 | 1163 | |
duke@435 | 1164 | ClearSpaceClosure csc; |
duke@435 | 1165 | for (int i = 0; i < gch->n_gens(); ++i) { |
duke@435 | 1166 | gch->get_gen(i)->space_iterate(&csc); |
duke@435 | 1167 | } |
duke@435 | 1168 | csc.do_space(gen->the_space()); |
duke@435 | 1169 | NOT_PRODUCT(SystemDictionary::verify();) |
duke@435 | 1170 | |
duke@435 | 1171 | // Copy the String table, the symbol table, and the system |
duke@435 | 1172 | // dictionary to the shared space in usable form. Copy the hastable |
duke@435 | 1173 | // buckets first [read-write], then copy the linked lists of entries |
duke@435 | 1174 | // [read-only]. |
duke@435 | 1175 | |
duke@435 | 1176 | SymbolTable::reverse(extra_symbols); |
duke@435 | 1177 | NOT_PRODUCT(SymbolTable::verify()); |
duke@435 | 1178 | SymbolTable::copy_buckets(&md_top, md_end); |
duke@435 | 1179 | |
duke@435 | 1180 | StringTable::reverse(); |
duke@435 | 1181 | NOT_PRODUCT(StringTable::verify()); |
duke@435 | 1182 | StringTable::copy_buckets(&md_top, md_end); |
duke@435 | 1183 | |
duke@435 | 1184 | SystemDictionary::reverse(); |
duke@435 | 1185 | SystemDictionary::copy_buckets(&md_top, md_end); |
duke@435 | 1186 | |
duke@435 | 1187 | ClassLoader::verify(); |
duke@435 | 1188 | ClassLoader::copy_package_info_buckets(&md_top, md_end); |
duke@435 | 1189 | ClassLoader::verify(); |
duke@435 | 1190 | |
duke@435 | 1191 | SymbolTable::copy_table(&md_top, md_end); |
duke@435 | 1192 | StringTable::copy_table(&md_top, md_end); |
duke@435 | 1193 | SystemDictionary::copy_table(&md_top, md_end); |
duke@435 | 1194 | ClassLoader::verify(); |
duke@435 | 1195 | ClassLoader::copy_package_info_table(&md_top, md_end); |
duke@435 | 1196 | ClassLoader::verify(); |
duke@435 | 1197 | |
duke@435 | 1198 | // Print debug data. |
duke@435 | 1199 | |
duke@435 | 1200 | if (PrintSharedSpaces) { |
duke@435 | 1201 | const char* fmt = "%s space: " PTR_FORMAT " out of " PTR_FORMAT " bytes allocated at " PTR_FORMAT "."; |
duke@435 | 1202 | tty->print_cr(fmt, "ro", _ro_space->used(), _ro_space->capacity(), |
duke@435 | 1203 | _ro_space->bottom()); |
duke@435 | 1204 | tty->print_cr(fmt, "rw", _rw_space->used(), _rw_space->capacity(), |
duke@435 | 1205 | _rw_space->bottom()); |
duke@435 | 1206 | } |
duke@435 | 1207 | |
duke@435 | 1208 | // Write the oop data to the output array. |
duke@435 | 1209 | |
duke@435 | 1210 | WriteClosure wc(md_top, md_end); |
duke@435 | 1211 | CompactingPermGenGen::serialize_oops(&wc); |
duke@435 | 1212 | md_top = wc.get_top(); |
duke@435 | 1213 | |
duke@435 | 1214 | // Update the vtable pointers in all of the Klass objects in the |
duke@435 | 1215 | // heap. They should point to newly generated vtable. |
duke@435 | 1216 | |
duke@435 | 1217 | PatchKlassVtables pkvt(vtable, _md_vs); |
duke@435 | 1218 | _rw_space->object_iterate(&pkvt); |
duke@435 | 1219 | pkvt.patch(vtbl_list, vtbl_list_size); |
duke@435 | 1220 | |
duke@435 | 1221 | char* saved_vtbl = (char*)malloc(vtbl_list_size * sizeof(void*)); |
duke@435 | 1222 | memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*)); |
duke@435 | 1223 | memset(vtbl_list, 0, vtbl_list_size * sizeof(void*)); |
duke@435 | 1224 | |
duke@435 | 1225 | // Create and write the archive file that maps the shared spaces. |
duke@435 | 1226 | |
duke@435 | 1227 | FileMapInfo* mapinfo = new FileMapInfo(); |
duke@435 | 1228 | mapinfo->populate_header(gch->gen_policy()->max_alignment()); |
duke@435 | 1229 | |
duke@435 | 1230 | // Pass 1 - update file offsets in header. |
duke@435 | 1231 | mapinfo->write_header(); |
duke@435 | 1232 | mapinfo->write_space(CompactingPermGenGen::ro, _ro_space, true); |
duke@435 | 1233 | _ro_space->set_saved_mark(); |
duke@435 | 1234 | mapinfo->write_space(CompactingPermGenGen::rw, _rw_space, false); |
duke@435 | 1235 | _rw_space->set_saved_mark(); |
duke@435 | 1236 | mapinfo->write_region(CompactingPermGenGen::md, _md_vs->low(), |
xlu@722 | 1237 | pointer_delta(md_top, _md_vs->low(), sizeof(char)), |
xlu@722 | 1238 | SharedMiscDataSize, |
duke@435 | 1239 | false, false); |
duke@435 | 1240 | mapinfo->write_region(CompactingPermGenGen::mc, _mc_vs->low(), |
xlu@722 | 1241 | pointer_delta(mc_top, _mc_vs->low(), sizeof(char)), |
xlu@722 | 1242 | SharedMiscCodeSize, |
duke@435 | 1243 | true, true); |
duke@435 | 1244 | |
duke@435 | 1245 | // Pass 2 - write data. |
duke@435 | 1246 | mapinfo->open_for_write(); |
duke@435 | 1247 | mapinfo->write_header(); |
duke@435 | 1248 | mapinfo->write_space(CompactingPermGenGen::ro, _ro_space, true); |
duke@435 | 1249 | mapinfo->write_space(CompactingPermGenGen::rw, _rw_space, false); |
duke@435 | 1250 | mapinfo->write_region(CompactingPermGenGen::md, _md_vs->low(), |
xlu@722 | 1251 | pointer_delta(md_top, _md_vs->low(), sizeof(char)), |
xlu@722 | 1252 | SharedMiscDataSize, |
duke@435 | 1253 | false, false); |
duke@435 | 1254 | mapinfo->write_region(CompactingPermGenGen::mc, _mc_vs->low(), |
xlu@722 | 1255 | pointer_delta(mc_top, _mc_vs->low(), sizeof(char)), |
xlu@722 | 1256 | SharedMiscCodeSize, |
duke@435 | 1257 | true, true); |
duke@435 | 1258 | mapinfo->close(); |
duke@435 | 1259 | |
duke@435 | 1260 | // Summarize heap. |
duke@435 | 1261 | memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*)); |
duke@435 | 1262 | print_contents(); |
duke@435 | 1263 | } |
duke@435 | 1264 | }; // class VM_PopulateDumpSharedSpace |
duke@435 | 1265 | |
duke@435 | 1266 | |
duke@435 | 1267 | // Populate the shared spaces and dump to a file. |
duke@435 | 1268 | |
duke@435 | 1269 | jint CompactingPermGenGen::dump_shared(GrowableArray<oop>* class_promote_order, TRAPS) { |
duke@435 | 1270 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 1271 | |
duke@435 | 1272 | // Calculate hash values for all of the (interned) strings to avoid |
duke@435 | 1273 | // writes to shared pages in the future. |
duke@435 | 1274 | |
duke@435 | 1275 | tty->print("Calculating hash values for String objects .. "); |
duke@435 | 1276 | StringHashCodeClosure shcc(THREAD); |
duke@435 | 1277 | StringTable::oops_do(&shcc); |
duke@435 | 1278 | tty->print_cr("done. "); |
duke@435 | 1279 | |
duke@435 | 1280 | CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen(); |
duke@435 | 1281 | VM_PopulateDumpSharedSpace op(class_promote_order, |
duke@435 | 1282 | gen->ro_space(), gen->rw_space(), |
duke@435 | 1283 | gen->md_space(), gen->mc_space()); |
duke@435 | 1284 | VMThread::execute(&op); |
duke@435 | 1285 | return JNI_OK; |
duke@435 | 1286 | } |
duke@435 | 1287 | |
duke@435 | 1288 | |
duke@435 | 1289 | class LinkClassesClosure : public ObjectClosure { |
duke@435 | 1290 | private: |
duke@435 | 1291 | Thread* THREAD; |
duke@435 | 1292 | |
duke@435 | 1293 | public: |
duke@435 | 1294 | LinkClassesClosure(Thread* thread) : THREAD(thread) {} |
duke@435 | 1295 | |
duke@435 | 1296 | void do_object(oop obj) { |
duke@435 | 1297 | if (obj->is_klass()) { |
duke@435 | 1298 | Klass* k = Klass::cast((klassOop) obj); |
duke@435 | 1299 | if (k->oop_is_instance()) { |
duke@435 | 1300 | instanceKlass* ik = (instanceKlass*) k; |
duke@435 | 1301 | // Link the class to cause the bytecodes to be rewritten and the |
duke@435 | 1302 | // cpcache to be created. |
duke@435 | 1303 | if (ik->get_init_state() < instanceKlass::linked) { |
duke@435 | 1304 | ik->link_class(THREAD); |
duke@435 | 1305 | guarantee(!HAS_PENDING_EXCEPTION, "exception in class rewriting"); |
duke@435 | 1306 | } |
duke@435 | 1307 | |
duke@435 | 1308 | // Create String objects from string initializer symbols. |
duke@435 | 1309 | ik->constants()->resolve_string_constants(THREAD); |
duke@435 | 1310 | guarantee(!HAS_PENDING_EXCEPTION, "exception resolving string constants"); |
duke@435 | 1311 | } |
duke@435 | 1312 | } |
duke@435 | 1313 | } |
duke@435 | 1314 | }; |
duke@435 | 1315 | |
duke@435 | 1316 | |
duke@435 | 1317 | // Support for a simple checksum of the contents of the class list |
duke@435 | 1318 | // file to prevent trivial tampering. The algorithm matches that in |
duke@435 | 1319 | // the MakeClassList program used by the J2SE build process. |
duke@435 | 1320 | #define JSUM_SEED ((jlong)CONST64(0xcafebabebabecafe)) |
duke@435 | 1321 | static jlong |
duke@435 | 1322 | jsum(jlong start, const char *buf, const int len) |
duke@435 | 1323 | { |
duke@435 | 1324 | jlong h = start; |
duke@435 | 1325 | char *p = (char *)buf, *e = p + len; |
duke@435 | 1326 | while (p < e) { |
duke@435 | 1327 | char c = *p++; |
duke@435 | 1328 | if (c <= ' ') { |
duke@435 | 1329 | /* Skip spaces and control characters */ |
duke@435 | 1330 | continue; |
duke@435 | 1331 | } |
duke@435 | 1332 | h = 31 * h + c; |
duke@435 | 1333 | } |
duke@435 | 1334 | return h; |
duke@435 | 1335 | } |
duke@435 | 1336 | |
duke@435 | 1337 | |
duke@435 | 1338 | |
duke@435 | 1339 | |
duke@435 | 1340 | |
duke@435 | 1341 | // Preload classes from a list, populate the shared spaces and dump to a |
duke@435 | 1342 | // file. |
duke@435 | 1343 | |
duke@435 | 1344 | void GenCollectedHeap::preload_and_dump(TRAPS) { |
duke@435 | 1345 | TraceTime timer("Dump Shared Spaces", TraceStartupTime); |
duke@435 | 1346 | ResourceMark rm; |
duke@435 | 1347 | |
duke@435 | 1348 | // Preload classes to be shared. |
duke@435 | 1349 | // Should use some hpi:: method rather than fopen() here. aB. |
duke@435 | 1350 | // Construct the path to the class list (in jre/lib) |
duke@435 | 1351 | // Walk up two directories from the location of the VM and |
duke@435 | 1352 | // optionally tack on "lib" (depending on platform) |
duke@435 | 1353 | char class_list_path[JVM_MAXPATHLEN]; |
duke@435 | 1354 | os::jvm_path(class_list_path, sizeof(class_list_path)); |
duke@435 | 1355 | for (int i = 0; i < 3; i++) { |
duke@435 | 1356 | char *end = strrchr(class_list_path, *os::file_separator()); |
duke@435 | 1357 | if (end != NULL) *end = '\0'; |
duke@435 | 1358 | } |
duke@435 | 1359 | int class_list_path_len = (int)strlen(class_list_path); |
duke@435 | 1360 | if (class_list_path_len >= 3) { |
duke@435 | 1361 | if (strcmp(class_list_path + class_list_path_len - 3, "lib") != 0) { |
duke@435 | 1362 | strcat(class_list_path, os::file_separator()); |
duke@435 | 1363 | strcat(class_list_path, "lib"); |
duke@435 | 1364 | } |
duke@435 | 1365 | } |
duke@435 | 1366 | strcat(class_list_path, os::file_separator()); |
duke@435 | 1367 | strcat(class_list_path, "classlist"); |
duke@435 | 1368 | |
duke@435 | 1369 | FILE* file = fopen(class_list_path, "r"); |
duke@435 | 1370 | if (file != NULL) { |
duke@435 | 1371 | jlong computed_jsum = JSUM_SEED; |
duke@435 | 1372 | jlong file_jsum = 0; |
duke@435 | 1373 | |
duke@435 | 1374 | char class_name[256]; |
duke@435 | 1375 | int class_count = 0; |
duke@435 | 1376 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 1377 | gch->_preloading_shared_classes = true; |
duke@435 | 1378 | GrowableArray<oop>* class_promote_order = new GrowableArray<oop>(); |
duke@435 | 1379 | |
duke@435 | 1380 | // Preload (and intern) strings which will be used later. |
duke@435 | 1381 | |
duke@435 | 1382 | StringTable::intern("main", THREAD); |
duke@435 | 1383 | StringTable::intern("([Ljava/lang/String;)V", THREAD); |
duke@435 | 1384 | StringTable::intern("Ljava/lang/Class;", THREAD); |
duke@435 | 1385 | |
duke@435 | 1386 | StringTable::intern("I", THREAD); // Needed for StringBuffer persistence? |
duke@435 | 1387 | StringTable::intern("Z", THREAD); // Needed for StringBuffer persistence? |
duke@435 | 1388 | |
duke@435 | 1389 | // sun.io.Converters |
duke@435 | 1390 | static const char obj_array_sig[] = "[[Ljava/lang/Object;"; |
duke@435 | 1391 | SymbolTable::lookup(obj_array_sig, (int)strlen(obj_array_sig), THREAD); |
duke@435 | 1392 | |
duke@435 | 1393 | // java.util.HashMap |
duke@435 | 1394 | static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;"; |
duke@435 | 1395 | SymbolTable::lookup(map_entry_array_sig, (int)strlen(map_entry_array_sig), |
duke@435 | 1396 | THREAD); |
duke@435 | 1397 | |
duke@435 | 1398 | tty->print("Loading classes to share ... "); |
duke@435 | 1399 | while ((fgets(class_name, sizeof class_name, file)) != NULL) { |
duke@435 | 1400 | if (*class_name == '#') { |
duke@435 | 1401 | jint fsh, fsl; |
duke@435 | 1402 | if (sscanf(class_name, "# %8x%8x\n", &fsh, &fsl) == 2) { |
duke@435 | 1403 | file_jsum = ((jlong)(fsh) << 32) | (fsl & 0xffffffff); |
duke@435 | 1404 | } |
duke@435 | 1405 | |
duke@435 | 1406 | continue; |
duke@435 | 1407 | } |
duke@435 | 1408 | // Remove trailing newline |
duke@435 | 1409 | size_t name_len = strlen(class_name); |
duke@435 | 1410 | class_name[name_len-1] = '\0'; |
duke@435 | 1411 | |
duke@435 | 1412 | computed_jsum = jsum(computed_jsum, class_name, (const int)name_len - 1); |
duke@435 | 1413 | |
duke@435 | 1414 | // Got a class name - load it. |
duke@435 | 1415 | symbolHandle class_name_symbol = oopFactory::new_symbol(class_name, |
duke@435 | 1416 | THREAD); |
duke@435 | 1417 | guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); |
duke@435 | 1418 | klassOop klass = SystemDictionary::resolve_or_null(class_name_symbol, |
duke@435 | 1419 | THREAD); |
duke@435 | 1420 | guarantee(!HAS_PENDING_EXCEPTION, "Exception resolving a class."); |
duke@435 | 1421 | if (klass != NULL) { |
duke@435 | 1422 | if (PrintSharedSpaces) { |
duke@435 | 1423 | tty->print_cr("Shared spaces preloaded: %s", class_name); |
duke@435 | 1424 | } |
duke@435 | 1425 | |
duke@435 | 1426 | |
duke@435 | 1427 | instanceKlass* ik = instanceKlass::cast(klass); |
duke@435 | 1428 | |
duke@435 | 1429 | // Should be class load order as per -XX:+TraceClassLoadingPreorder |
duke@435 | 1430 | class_promote_order->append(ik->as_klassOop()); |
duke@435 | 1431 | |
duke@435 | 1432 | // Link the class to cause the bytecodes to be rewritten and the |
duke@435 | 1433 | // cpcache to be created. The linking is done as soon as classes |
duke@435 | 1434 | // are loaded in order that the related data structures (klass, |
duke@435 | 1435 | // cpCache, Sting constants) are located together. |
duke@435 | 1436 | |
duke@435 | 1437 | if (ik->get_init_state() < instanceKlass::linked) { |
duke@435 | 1438 | ik->link_class(THREAD); |
duke@435 | 1439 | guarantee(!(HAS_PENDING_EXCEPTION), "exception in class rewriting"); |
duke@435 | 1440 | } |
duke@435 | 1441 | |
duke@435 | 1442 | // Create String objects from string initializer symbols. |
duke@435 | 1443 | |
duke@435 | 1444 | ik->constants()->resolve_string_constants(THREAD); |
duke@435 | 1445 | |
duke@435 | 1446 | class_count++; |
duke@435 | 1447 | } else { |
duke@435 | 1448 | if (PrintSharedSpaces) { |
duke@435 | 1449 | tty->cr(); |
duke@435 | 1450 | tty->print_cr(" Preload failed: %s", class_name); |
duke@435 | 1451 | } |
duke@435 | 1452 | } |
duke@435 | 1453 | file_jsum = 0; // Checksum must be on last line of file |
duke@435 | 1454 | } |
duke@435 | 1455 | if (computed_jsum != file_jsum) { |
duke@435 | 1456 | tty->cr(); |
duke@435 | 1457 | tty->print_cr("Preload failed: checksum of class list was incorrect."); |
duke@435 | 1458 | exit(1); |
duke@435 | 1459 | } |
duke@435 | 1460 | |
duke@435 | 1461 | tty->print_cr("done. "); |
duke@435 | 1462 | |
duke@435 | 1463 | if (PrintSharedSpaces) { |
duke@435 | 1464 | tty->print_cr("Shared spaces: preloaded %d classes", class_count); |
duke@435 | 1465 | } |
duke@435 | 1466 | |
duke@435 | 1467 | // Rewrite and unlink classes. |
duke@435 | 1468 | tty->print("Rewriting and unlinking classes ... "); |
duke@435 | 1469 | // Make heap parsable |
duke@435 | 1470 | ensure_parsability(false); // arg is actually don't care |
duke@435 | 1471 | |
duke@435 | 1472 | // Link any classes which got missed. (It's not quite clear why |
duke@435 | 1473 | // they got missed.) This iteration would be unsafe if we weren't |
duke@435 | 1474 | // single-threaded at this point; however we can't do it on the VM |
duke@435 | 1475 | // thread because it requires object allocation. |
duke@435 | 1476 | LinkClassesClosure lcc(Thread::current()); |
duke@435 | 1477 | object_iterate(&lcc); |
duke@435 | 1478 | tty->print_cr("done. "); |
duke@435 | 1479 | |
duke@435 | 1480 | // Create and dump the shared spaces. |
duke@435 | 1481 | jint err = CompactingPermGenGen::dump_shared(class_promote_order, THREAD); |
duke@435 | 1482 | if (err != JNI_OK) { |
duke@435 | 1483 | fatal("Dumping shared spaces failed."); |
duke@435 | 1484 | } |
duke@435 | 1485 | |
duke@435 | 1486 | } else { |
duke@435 | 1487 | char errmsg[JVM_MAXPATHLEN]; |
duke@435 | 1488 | hpi::lasterror(errmsg, JVM_MAXPATHLEN); |
duke@435 | 1489 | tty->print_cr("Loading classlist failed: %s", errmsg); |
duke@435 | 1490 | exit(1); |
duke@435 | 1491 | } |
duke@435 | 1492 | |
duke@435 | 1493 | // Since various initialization steps have been undone by this process, |
duke@435 | 1494 | // it is not reasonable to continue running a java process. |
duke@435 | 1495 | exit(0); |
duke@435 | 1496 | } |