Print this page
rev 6905 : 8064375: Change certain errors to warnings in CDS output.
Summary: Change CDS non-fatal preloading errors to warnings.
Reviewed-by: minqi, mseledtsov, coleenp
Split |
Split |
Close |
Expand all |
Collapse all |
--- old/hotspot/src/share/vm/memory/metaspaceShared.cpp
+++ new/hotspot/src/share/vm/memory/metaspaceShared.cpp
1 1 /*
2 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "classfile/dictionary.hpp"
27 27 #include "classfile/classLoaderExt.hpp"
28 28 #include "classfile/loaderConstraints.hpp"
29 29 #include "classfile/placeholders.hpp"
30 30 #include "classfile/sharedClassUtil.hpp"
31 31 #include "classfile/symbolTable.hpp"
32 32 #include "classfile/systemDictionary.hpp"
33 33 #include "code/codeCache.hpp"
34 34 #include "memory/filemap.hpp"
35 35 #include "memory/gcLocker.hpp"
36 36 #include "memory/metaspace.hpp"
37 37 #include "memory/metaspaceShared.hpp"
38 38 #include "oops/objArrayOop.hpp"
39 39 #include "oops/oop.inline.hpp"
40 40 #include "runtime/signature.hpp"
41 41 #include "runtime/vm_operations.hpp"
42 42 #include "runtime/vmThread.hpp"
43 43 #include "utilities/hashtable.hpp"
44 44 #include "utilities/hashtable.inline.hpp"
45 45
46 46 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
47 47
48 48 int MetaspaceShared::_max_alignment = 0;
49 49
50 50 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
51 51
52 52 bool MetaspaceShared::_link_classes_made_progress;
53 53 bool MetaspaceShared::_check_classes_made_progress;
54 54 bool MetaspaceShared::_has_error_classes;
55 55 bool MetaspaceShared::_archive_loading_failed = false;
56 56 // Read/write a data stream for restoring/preserving metadata pointers and
57 57 // miscellaneous data from/to the shared archive file.
58 58
59 59 void MetaspaceShared::serialize(SerializeClosure* soc) {
60 60 int tag = 0;
61 61 soc->do_tag(--tag);
62 62
63 63 // Verify the sizes of various metadata in the system.
64 64 soc->do_tag(sizeof(Method));
65 65 soc->do_tag(sizeof(ConstMethod));
66 66 soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
67 67 soc->do_tag(sizeof(ConstantPool));
68 68 soc->do_tag(sizeof(ConstantPoolCache));
69 69 soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
70 70 soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
71 71 soc->do_tag(sizeof(Symbol));
72 72
73 73 // Dump/restore miscellaneous metadata.
74 74 Universe::serialize(soc, true);
75 75 soc->do_tag(--tag);
76 76
77 77 // Dump/restore references to commonly used names and signatures.
78 78 vmSymbols::serialize(soc);
79 79 soc->do_tag(--tag);
80 80
81 81 soc->do_tag(666);
82 82 }
83 83
84 84
85 85 // CDS code for dumping shared archive.
86 86
87 87 // Global object for holding classes that have been loaded. Since this
88 88 // is run at a safepoint just before exit, this is the entire set of classes.
89 89 static GrowableArray<Klass*>* _global_klass_objects;
90 90 static void collect_classes(Klass* k) {
91 91 _global_klass_objects->append_if_missing(k);
92 92 if (k->oop_is_instance()) {
93 93 // Add in the array classes too
94 94 InstanceKlass* ik = InstanceKlass::cast(k);
95 95 ik->array_klasses_do(collect_classes);
96 96 }
97 97 }
98 98
99 99 static void remove_unshareable_in_classes() {
100 100 for (int i = 0; i < _global_klass_objects->length(); i++) {
101 101 Klass* k = _global_klass_objects->at(i);
102 102 k->remove_unshareable_info();
103 103 }
104 104 }
105 105
106 106 // Walk all methods in the class list and assign a fingerprint.
107 107 // so that this part of the ConstMethod* is read only.
108 108 static void calculate_fingerprints() {
109 109 for (int i = 0; i < _global_klass_objects->length(); i++) {
110 110 Klass* k = _global_klass_objects->at(i);
111 111 if (k->oop_is_instance()) {
112 112 InstanceKlass* ik = InstanceKlass::cast(k);
113 113 for (int i = 0; i < ik->methods()->length(); i++) {
114 114 Method* m = ik->methods()->at(i);
115 115 Fingerprinter fp(m);
116 116 // The side effect of this call sets method's fingerprint field.
117 117 fp.fingerprint();
118 118 }
119 119 }
120 120 }
121 121 }
122 122
123 123 // Patch C++ vtable pointer in metadata.
124 124
125 125 // Klass and other metadata objects contain references to c++ vtables in the
126 126 // JVM library.
127 127 // Fix them to point to our constructed vtables. However, don't iterate
128 128 // across the space while doing this, as that causes the vtables to be
129 129 // patched, undoing our useful work. Instead, iterate to make a list,
130 130 // then use the list to do the fixing.
131 131 //
132 132 // Our constructed vtables:
133 133 // Dump time:
134 134 // 1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs
135 135 // 2. generate_vtable_methods: create jump table, appended to above vtbl_list
136 136 // 3. patch_klass_vtables: for Klass list, patch the vtable entry in klass and
137 137 // associated metadata to point to jump table rather than to current vtbl
138 138 // Table layout: NOTE FIXED SIZE
139 139 // 1. vtbl pointers
140 140 // 2. #Klass X #virtual methods per Klass
141 141 // 1 entry for each, in the order:
142 142 // Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry
143 143 // Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry
144 144 // ...
145 145 // Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry,
146 146 // ... Klass<vtbl_list_size>:method<num_virtuals> entry
147 147 // Sample entry: (Sparc):
148 148 // save(sp, -256, sp)
149 149 // ba,pt common_code
150 150 // mov XXX, %L0 %L0 gets: Klass index <<8 + method index (note: max method index 255)
151 151 //
152 152 // Restore time:
153 153 // 1. initialize_shared_space: reserve space for table
154 154 // 2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text
155 155 //
156 156 // Execution time:
157 157 // First virtual method call for any object of these metadata types:
158 158 // 1. object->klass
159 159 // 2. vtable entry for that klass points to the jump table entries
160 160 // 3. branches to common_code with %O0/klass, %L0: Klass index <<8 + method index
161 161 // 4. common_code:
162 162 // Get address of new vtbl pointer for this Klass from updated table
163 163 // Update new vtbl pointer in the Klass: future virtual calls go direct
164 164 // Jump to method, using new vtbl pointer and method index
165 165
166 166
167 167 static void* find_matching_vtbl_ptr(void** vtbl_list, void* new_vtable_start, void* obj) {
168 168 void* old_vtbl_ptr = *(void**)obj;
169 169 for (int i = 0; i < MetaspaceShared::vtbl_list_size; i++) {
170 170 if (vtbl_list[i] == old_vtbl_ptr) {
171 171 return (void**)new_vtable_start + i * MetaspaceShared::num_virtuals;
172 172 }
173 173 }
174 174 ShouldNotReachHere();
175 175 return NULL;
176 176 }
177 177
178 178 // Assumes the vtable is in first slot in object.
179 179 static void patch_klass_vtables(void** vtbl_list, void* new_vtable_start) {
180 180 int n = _global_klass_objects->length();
181 181 for (int i = 0; i < n; i++) {
182 182 Klass* obj = _global_klass_objects->at(i);
183 183 // Note oop_is_instance() is a virtual call. After patching vtables
184 184 // all virtual calls on the dummy vtables will restore the original!
185 185 if (obj->oop_is_instance()) {
186 186 InstanceKlass* ik = InstanceKlass::cast(obj);
187 187 *(void**)ik = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, ik);
188 188 ConstantPool* cp = ik->constants();
189 189 *(void**)cp = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, cp);
190 190 for (int j = 0; j < ik->methods()->length(); j++) {
191 191 Method* m = ik->methods()->at(j);
192 192 *(void**)m = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, m);
193 193 }
194 194 } else {
195 195 // Array klasses
196 196 Klass* k = obj;
197 197 *(void**)k = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, k);
198 198 }
199 199 }
200 200 }
201 201
202 202 // Closure for serializing initialization data out to a data area to be
203 203 // written to the shared file.
204 204
205 205 class WriteClosure : public SerializeClosure {
206 206 private:
207 207 intptr_t* top;
208 208 char* end;
209 209
210 210 inline void check_space() {
211 211 if ((char*)top + sizeof(intptr_t) > end) {
212 212 report_out_of_shared_space(SharedMiscData);
213 213 }
214 214 }
215 215
216 216 public:
217 217 WriteClosure(char* md_top, char* md_end) {
218 218 top = (intptr_t*)md_top;
219 219 end = md_end;
220 220 }
221 221
222 222 char* get_top() { return (char*)top; }
223 223
224 224 void do_ptr(void** p) {
225 225 check_space();
226 226 *top = (intptr_t)*p;
227 227 ++top;
228 228 }
229 229
230 230 void do_tag(int tag) {
231 231 check_space();
232 232 *top = (intptr_t)tag;
233 233 ++top;
234 234 }
235 235
236 236 void do_region(u_char* start, size_t size) {
237 237 if ((char*)top + size > end) {
238 238 report_out_of_shared_space(SharedMiscData);
239 239 }
240 240 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
241 241 assert(size % sizeof(intptr_t) == 0, "bad size");
242 242 do_tag((int)size);
243 243 while (size > 0) {
244 244 *top = *(intptr_t*)start;
245 245 ++top;
246 246 start += sizeof(intptr_t);
247 247 size -= sizeof(intptr_t);
248 248 }
249 249 }
250 250
251 251 bool reading() const { return false; }
252 252 };
253 253
254 254 // This is for dumping detailed statistics for the allocations
255 255 // in the shared spaces.
256 256 class DumpAllocClosure : public Metaspace::AllocRecordClosure {
257 257 public:
258 258
259 259 // Here's poor man's enum inheritance
260 260 #define SHAREDSPACE_OBJ_TYPES_DO(f) \
261 261 METASPACE_OBJ_TYPES_DO(f) \
262 262 f(SymbolHashentry) \
263 263 f(SymbolBuckets) \
264 264 f(Other)
265 265
266 266 #define SHAREDSPACE_OBJ_TYPE_DECLARE(name) name ## Type,
267 267 #define SHAREDSPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name;
268 268
269 269 enum Type {
270 270 // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
271 271 SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_DECLARE)
272 272 _number_of_types
273 273 };
274 274
275 275 static const char * type_name(Type type) {
276 276 switch(type) {
277 277 SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_NAME_CASE)
278 278 default:
279 279 ShouldNotReachHere();
280 280 return NULL;
281 281 }
282 282 }
283 283
284 284 public:
285 285 enum {
286 286 RO = 0,
287 287 RW = 1
288 288 };
289 289
290 290 int _counts[2][_number_of_types];
291 291 int _bytes [2][_number_of_types];
292 292 int _which;
293 293
294 294 DumpAllocClosure() {
295 295 memset(_counts, 0, sizeof(_counts));
296 296 memset(_bytes, 0, sizeof(_bytes));
297 297 };
298 298
299 299 void iterate_metaspace(Metaspace* space, int which) {
300 300 assert(which == RO || which == RW, "sanity");
301 301 _which = which;
302 302 space->iterate(this);
303 303 }
304 304
305 305 virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) {
306 306 assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity");
307 307 _counts[_which][type] ++;
308 308 _bytes [_which][type] += byte_size;
309 309 }
310 310
311 311 void dump_stats(int ro_all, int rw_all, int md_all, int mc_all);
312 312 };
313 313
314 314 void DumpAllocClosure::dump_stats(int ro_all, int rw_all, int md_all, int mc_all) {
315 315 rw_all += (md_all + mc_all); // md and mc are all mapped Read/Write
316 316 int other_bytes = md_all + mc_all;
317 317
318 318 // Calculate size of data that was not allocated by Metaspace::allocate()
319 319 int symbol_count = _counts[RO][MetaspaceObj::SymbolType];
320 320 int symhash_bytes = symbol_count * sizeof (HashtableEntry<Symbol*, mtSymbol>);
321 321 int symbuck_count = SymbolTable::the_table()->table_size();
322 322 int symbuck_bytes = symbuck_count * sizeof(HashtableBucket<mtSymbol>);
323 323
324 324 _counts[RW][SymbolHashentryType] = symbol_count;
325 325 _bytes [RW][SymbolHashentryType] = symhash_bytes;
326 326 other_bytes -= symhash_bytes;
327 327
328 328 _counts[RW][SymbolBucketsType] = symbuck_count;
329 329 _bytes [RW][SymbolBucketsType] = symbuck_bytes;
330 330 other_bytes -= symbuck_bytes;
331 331
332 332 // TODO: count things like dictionary, vtable, etc
333 333 _bytes[RW][OtherType] = other_bytes;
334 334
335 335 // prevent divide-by-zero
336 336 if (ro_all < 1) {
337 337 ro_all = 1;
338 338 }
339 339 if (rw_all < 1) {
340 340 rw_all = 1;
341 341 }
342 342
343 343 int all_ro_count = 0;
344 344 int all_ro_bytes = 0;
345 345 int all_rw_count = 0;
346 346 int all_rw_bytes = 0;
347 347
348 348 // To make fmt_stats be a syntactic constant (for format warnings), use #define.
349 349 #define fmt_stats "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f"
350 350 const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
351 351 const char *hdr = " ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %";
352 352
353 353 tty->print_cr("Detailed metadata info (rw includes md and mc):");
354 354 tty->print_cr("%s", hdr);
355 355 tty->print_cr("%s", sep);
356 356 for (int type = 0; type < int(_number_of_types); type ++) {
357 357 const char *name = type_name((Type)type);
358 358 int ro_count = _counts[RO][type];
359 359 int ro_bytes = _bytes [RO][type];
360 360 int rw_count = _counts[RW][type];
361 361 int rw_bytes = _bytes [RW][type];
362 362 int count = ro_count + rw_count;
363 363 int bytes = ro_bytes + rw_bytes;
364 364
365 365 double ro_perc = 100.0 * double(ro_bytes) / double(ro_all);
366 366 double rw_perc = 100.0 * double(rw_bytes) / double(rw_all);
367 367 double perc = 100.0 * double(bytes) / double(ro_all + rw_all);
368 368
369 369 tty->print_cr(fmt_stats, name,
370 370 ro_count, ro_bytes, ro_perc,
371 371 rw_count, rw_bytes, rw_perc,
372 372 count, bytes, perc);
373 373
374 374 all_ro_count += ro_count;
375 375 all_ro_bytes += ro_bytes;
376 376 all_rw_count += rw_count;
377 377 all_rw_bytes += rw_bytes;
378 378 }
379 379
380 380 int all_count = all_ro_count + all_rw_count;
381 381 int all_bytes = all_ro_bytes + all_rw_bytes;
382 382
383 383 double all_ro_perc = 100.0 * double(all_ro_bytes) / double(ro_all);
384 384 double all_rw_perc = 100.0 * double(all_rw_bytes) / double(rw_all);
385 385 double all_perc = 100.0 * double(all_bytes) / double(ro_all + rw_all);
386 386
387 387 tty->print_cr("%s", sep);
388 388 tty->print_cr(fmt_stats, "Total",
389 389 all_ro_count, all_ro_bytes, all_ro_perc,
390 390 all_rw_count, all_rw_bytes, all_rw_perc,
391 391 all_count, all_bytes, all_perc);
392 392
393 393 assert(all_ro_bytes == ro_all, "everything should have been counted");
394 394 assert(all_rw_bytes == rw_all, "everything should have been counted");
395 395 #undef fmt_stats
396 396 }
397 397
398 398 // Populate the shared space.
399 399
400 400 class VM_PopulateDumpSharedSpace: public VM_Operation {
401 401 private:
402 402 ClassLoaderData* _loader_data;
403 403 GrowableArray<Klass*> *_class_promote_order;
404 404 VirtualSpace _md_vs;
405 405 VirtualSpace _mc_vs;
406 406
407 407 public:
408 408 VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
409 409 GrowableArray<Klass*> *class_promote_order) :
410 410 _loader_data(loader_data) {
411 411
412 412 // Split up and initialize the misc code and data spaces
413 413 ReservedSpace* shared_rs = MetaspaceShared::shared_rs();
414 414 int metadata_size = SharedReadOnlySize+SharedReadWriteSize;
415 415 ReservedSpace shared_ro_rw = shared_rs->first_part(metadata_size);
416 416 ReservedSpace misc_section = shared_rs->last_part(metadata_size);
417 417
418 418 // Now split into misc sections.
419 419 ReservedSpace md_rs = misc_section.first_part(SharedMiscDataSize);
420 420 ReservedSpace mc_rs = misc_section.last_part(SharedMiscDataSize);
421 421 _md_vs.initialize(md_rs, SharedMiscDataSize);
422 422 _mc_vs.initialize(mc_rs, SharedMiscCodeSize);
423 423 _class_promote_order = class_promote_order;
424 424 }
425 425
426 426 VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
427 427 void doit(); // outline because gdb sucks
428 428 }; // class VM_PopulateDumpSharedSpace
429 429
430 430
431 431 void VM_PopulateDumpSharedSpace::doit() {
432 432 Thread* THREAD = VMThread::vm_thread();
433 433 NOT_PRODUCT(SystemDictionary::verify();)
434 434 // The following guarantee is meant to ensure that no loader constraints
435 435 // exist yet, since the constraints table is not shared. This becomes
436 436 // more important now that we don't re-initialize vtables/itables for
437 437 // shared classes at runtime, where constraints were previously created.
438 438 guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
439 439 "loader constraints are not saved");
440 440 guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
441 441 "placeholders are not saved");
442 442 // Revisit and implement this if we prelink method handle call sites:
443 443 guarantee(SystemDictionary::invoke_method_table() == NULL ||
444 444 SystemDictionary::invoke_method_table()->number_of_entries() == 0,
445 445 "invoke method table is not saved");
446 446
447 447 // At this point, many classes have been loaded.
448 448 // Gather systemDictionary classes in a global array and do everything to
449 449 // that so we don't have to walk the SystemDictionary again.
450 450 _global_klass_objects = new GrowableArray<Klass*>(1000);
451 451 Universe::basic_type_classes_do(collect_classes);
452 452 SystemDictionary::classes_do(collect_classes);
453 453
454 454 tty->print_cr("Number of classes %d", _global_klass_objects->length());
455 455 {
456 456 int num_type_array = 0, num_obj_array = 0, num_inst = 0;
457 457 for (int i = 0; i < _global_klass_objects->length(); i++) {
458 458 Klass* k = _global_klass_objects->at(i);
459 459 if (k->oop_is_instance()) {
460 460 num_inst ++;
461 461 } else if (k->oop_is_objArray()) {
462 462 num_obj_array ++;
463 463 } else {
464 464 assert(k->oop_is_typeArray(), "sanity");
465 465 num_type_array ++;
466 466 }
467 467 }
468 468 tty->print_cr(" instance classes = %5d", num_inst);
469 469 tty->print_cr(" obj array classes = %5d", num_obj_array);
470 470 tty->print_cr(" type array classes = %5d", num_type_array);
471 471 }
472 472
473 473 // Update all the fingerprints in the shared methods.
474 474 tty->print("Calculating fingerprints ... ");
475 475 calculate_fingerprints();
476 476 tty->print_cr("done. ");
477 477
478 478 // Remove all references outside the metadata
479 479 tty->print("Removing unshareable information ... ");
480 480 remove_unshareable_in_classes();
481 481 tty->print_cr("done. ");
482 482
483 483 // Set up the share data and shared code segments.
484 484 char* md_low = _md_vs.low();
485 485 char* md_top = md_low;
486 486 char* md_end = _md_vs.high();
487 487 char* mc_low = _mc_vs.low();
488 488 char* mc_top = mc_low;
489 489 char* mc_end = _mc_vs.high();
490 490
491 491 // Reserve space for the list of Klass*s whose vtables are used
492 492 // for patching others as needed.
493 493
494 494 void** vtbl_list = (void**)md_top;
495 495 int vtbl_list_size = MetaspaceShared::vtbl_list_size;
496 496 Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
497 497
498 498 md_top += vtbl_list_size * sizeof(void*);
499 499 void* vtable = md_top;
500 500
501 501 // Reserve space for a new dummy vtable for klass objects in the
502 502 // heap. Generate self-patching vtable entries.
503 503
504 504 MetaspaceShared::generate_vtable_methods(vtbl_list, &vtable,
505 505 &md_top, md_end,
506 506 &mc_top, mc_end);
507 507
508 508 // Reorder the system dictionary. (Moving the symbols affects
509 509 // how the hash table indices are calculated.)
510 510 // Not doing this either.
511 511
512 512 SystemDictionary::reorder_dictionary();
513 513
514 514 NOT_PRODUCT(SystemDictionary::verify();)
515 515
516 516 // Copy the the symbol table, and the system dictionary to the shared
517 517 // space in usable form. Copy the hastable
518 518 // buckets first [read-write], then copy the linked lists of entries
519 519 // [read-only].
520 520
521 521 SymbolTable::reverse(md_top);
522 522 NOT_PRODUCT(SymbolTable::verify());
523 523 SymbolTable::copy_buckets(&md_top, md_end);
524 524
525 525 SystemDictionary::reverse();
526 526 SystemDictionary::copy_buckets(&md_top, md_end);
527 527
528 528 ClassLoader::verify();
529 529 ClassLoader::copy_package_info_buckets(&md_top, md_end);
530 530 ClassLoader::verify();
531 531
532 532 SymbolTable::copy_table(&md_top, md_end);
533 533 SystemDictionary::copy_table(&md_top, md_end);
534 534 ClassLoader::verify();
535 535 ClassLoader::copy_package_info_table(&md_top, md_end);
536 536 ClassLoader::verify();
537 537
538 538 ClassLoaderExt::copy_lookup_cache_to_archive(&md_top, md_end);
539 539
540 540 // Write the other data to the output array.
541 541 WriteClosure wc(md_top, md_end);
542 542 MetaspaceShared::serialize(&wc);
543 543 md_top = wc.get_top();
544 544
545 545 // Print shared spaces all the time
546 546 // To make fmt_space be a syntactic constant (for format warnings), use #define.
547 547 #define fmt_space "%s space: %9d [ %4.1f%% of total] out of %9d bytes [%4.1f%% used] at " PTR_FORMAT
548 548 Metaspace* ro_space = _loader_data->ro_metaspace();
549 549 Metaspace* rw_space = _loader_data->rw_metaspace();
550 550
551 551 // Allocated size of each space (may not be all occupied)
552 552 const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
553 553 const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
554 554 const size_t md_alloced = md_end-md_low;
555 555 const size_t mc_alloced = mc_end-mc_low;
556 556 const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced;
557 557
558 558 // Occupied size of each space.
559 559 const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
560 560 const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType);
561 561 const size_t md_bytes = size_t(md_top - md_low);
562 562 const size_t mc_bytes = size_t(mc_top - mc_low);
563 563
564 564 // Percent of total size
565 565 const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes;
566 566 const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0;
567 567 const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0;
568 568 const double md_t_perc = md_bytes / double(total_bytes) * 100.0;
569 569 const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0;
570 570
571 571 // Percent of fullness of each space
572 572 const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0;
573 573 const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0;
574 574 const double md_u_perc = md_bytes / double(md_alloced) * 100.0;
575 575 const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0;
576 576 const double total_u_perc = total_bytes / double(total_alloced) * 100.0;
577 577
578 578 tty->print_cr(fmt_space, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, ro_space->bottom());
579 579 tty->print_cr(fmt_space, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, rw_space->bottom());
580 580 tty->print_cr(fmt_space, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, md_low);
581 581 tty->print_cr(fmt_space, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, mc_low);
582 582 tty->print_cr("total : %9d [100.0%% of total] out of %9d bytes [%4.1f%% used]",
583 583 total_bytes, total_alloced, total_u_perc);
584 584
585 585 // Update the vtable pointers in all of the Klass objects in the
586 586 // heap. They should point to newly generated vtable.
587 587 patch_klass_vtables(vtbl_list, vtable);
588 588
589 589 // dunno what this is for.
590 590 char* saved_vtbl = (char*)os::malloc(vtbl_list_size * sizeof(void*), mtClass);
591 591 memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
592 592 memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
593 593
594 594 // Create and write the archive file that maps the shared spaces.
595 595
596 596 FileMapInfo* mapinfo = new FileMapInfo();
597 597 mapinfo->populate_header(MetaspaceShared::max_alignment());
598 598
599 599 // Pass 1 - update file offsets in header.
600 600 mapinfo->write_header();
601 601 mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
602 602 mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
603 603 mapinfo->write_region(MetaspaceShared::md, _md_vs.low(),
604 604 pointer_delta(md_top, _md_vs.low(), sizeof(char)),
605 605 SharedMiscDataSize,
606 606 false, false);
607 607 mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
608 608 pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
609 609 SharedMiscCodeSize,
610 610 true, true);
611 611
612 612 // Pass 2 - write data.
613 613 mapinfo->open_for_write();
614 614 mapinfo->set_header_crc(mapinfo->compute_header_crc());
615 615 mapinfo->write_header();
616 616 mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
617 617 mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
618 618 mapinfo->write_region(MetaspaceShared::md, _md_vs.low(),
619 619 pointer_delta(md_top, _md_vs.low(), sizeof(char)),
620 620 SharedMiscDataSize,
621 621 false, false);
622 622 mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
623 623 pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
624 624 SharedMiscCodeSize,
625 625 true, true);
626 626 mapinfo->close();
627 627
628 628 memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
629 629
630 630 if (PrintSharedSpaces) {
631 631 DumpAllocClosure dac;
632 632 dac.iterate_metaspace(_loader_data->ro_metaspace(), DumpAllocClosure::RO);
633 633 dac.iterate_metaspace(_loader_data->rw_metaspace(), DumpAllocClosure::RW);
634 634
635 635 dac.dump_stats(int(ro_bytes), int(rw_bytes), int(md_bytes), int(mc_bytes));
636 636 }
637 637 #undef fmt_space
638 638 }
639 639
640 640
641 641 void MetaspaceShared::link_one_shared_class(Klass* obj, TRAPS) {
642 642 Klass* k = obj;
643 643 if (k->oop_is_instance()) {
644 644 InstanceKlass* ik = (InstanceKlass*) k;
645 645 // Link the class to cause the bytecodes to be rewritten and the
646 646 // cpcache to be created. Class verification is done according
647 647 // to -Xverify setting.
648 648 _link_classes_made_progress |= try_link_class(ik, THREAD);
649 649 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
650 650 }
651 651 }
652 652
653 653 void MetaspaceShared::check_one_shared_class(Klass* k) {
654 654 if (k->oop_is_instance() && InstanceKlass::cast(k)->check_sharing_error_state()) {
655 655 _check_classes_made_progress = true;
656 656 }
657 657 }
658 658
659 659 void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
660 660 // We need to iterate because verification may cause additional classes
661 661 // to be loaded.
662 662 do {
663 663 _link_classes_made_progress = false;
664 664 SystemDictionary::classes_do(link_one_shared_class, THREAD);
665 665 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
666 666 } while (_link_classes_made_progress);
667 667
668 668 if (_has_error_classes) {
669 669 // Mark all classes whose super class or interfaces failed verification.
670 670 do {
671 671 // Not completely sure if we need to do this iteratively. Anyway,
672 672 // we should come here only if there are unverifiable classes, which
673 673 // shouldn't happen in normal cases. So better safe than sorry.
674 674 _check_classes_made_progress = false;
675 675 SystemDictionary::classes_do(check_one_shared_class);
676 676 } while (_check_classes_made_progress);
677 677
678 678 if (IgnoreUnverifiableClassesDuringDump) {
679 679 // This is useful when running JCK or SQE tests. You should not
680 680 // enable this when running real apps.
681 681 SystemDictionary::remove_classes_in_error_state();
682 682 } else {
683 683 tty->print_cr("Please remove the unverifiable classes from your class list and try again");
684 684 exit(1);
685 685 }
686 686 }
687 687 }
688 688
689 689 void MetaspaceShared::prepare_for_dumping() {
690 690 ClassLoader::initialize_shared_path();
691 691 FileMapInfo::allocate_classpath_entry_table();
692 692 }
693 693
694 694 // Preload classes from a list, populate the shared spaces and dump to a
695 695 // file.
696 696 void MetaspaceShared::preload_and_dump(TRAPS) {
697 697 TraceTime timer("Dump Shared Spaces", TraceStartupTime);
698 698 ResourceMark rm;
699 699
700 700 tty->print_cr("Allocated shared space: %d bytes at " PTR_FORMAT,
701 701 MetaspaceShared::shared_rs()->size(),
702 702 MetaspaceShared::shared_rs()->base());
703 703
704 704 // Preload classes to be shared.
705 705 // Should use some os:: method rather than fopen() here. aB.
706 706 const char* class_list_path;
707 707 if (SharedClassListFile == NULL) {
708 708 // Construct the path to the class list (in jre/lib)
709 709 // Walk up two directories from the location of the VM and
710 710 // optionally tack on "lib" (depending on platform)
711 711 char class_list_path_str[JVM_MAXPATHLEN];
712 712 os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
713 713 for (int i = 0; i < 3; i++) {
714 714 char *end = strrchr(class_list_path_str, *os::file_separator());
715 715 if (end != NULL) *end = '\0';
716 716 }
717 717 int class_list_path_len = (int)strlen(class_list_path_str);
718 718 if (class_list_path_len >= 3) {
719 719 if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
720 720 strcat(class_list_path_str, os::file_separator());
721 721 strcat(class_list_path_str, "lib");
722 722 }
723 723 }
724 724 strcat(class_list_path_str, os::file_separator());
725 725 strcat(class_list_path_str, "classlist");
726 726 class_list_path = class_list_path_str;
727 727 } else {
728 728 class_list_path = SharedClassListFile;
729 729 }
730 730
731 731 int class_count = 0;
732 732 GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
733 733
734 734 // sun.io.Converters
735 735 static const char obj_array_sig[] = "[[Ljava/lang/Object;";
736 736 SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
737 737
738 738 // java.util.HashMap
739 739 static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
740 740 SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
741 741
742 742 tty->print_cr("Loading classes to share ...");
743 743 _has_error_classes = false;
744 744 class_count += preload_and_dump(class_list_path, class_promote_order,
745 745 THREAD);
746 746 if (ExtraSharedClassListFile) {
747 747 class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
748 748 THREAD);
749 749 }
750 750 tty->print_cr("Loading classes to share: done.");
751 751
752 752 ClassLoaderExt::init_lookup_cache(THREAD);
753 753
754 754 if (PrintSharedSpaces) {
755 755 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
756 756 }
757 757
758 758 // Rewrite and link classes
759 759 tty->print_cr("Rewriting and linking classes ...");
760 760
761 761 // Link any classes which got missed. This would happen if we have loaded classes that
762 762 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
763 763 // fails verification, all other interfaces that were not specified in the classlist but
764 764 // are implemented by K are not verified.
765 765 link_and_cleanup_shared_classes(CATCH);
766 766 tty->print_cr("Rewriting and linking classes: done");
767 767
768 768 // Create and dump the shared spaces. Everything so far is loaded
769 769 // with the null class loader.
770 770 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
771 771 VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
772 772 VMThread::execute(&op);
773 773
774 774 // Since various initialization steps have been undone by this process,
775 775 // it is not reasonable to continue running a java process.
776 776 exit(0);
777 777 }
778 778
779 779 int MetaspaceShared::preload_and_dump(const char * class_list_path,
780 780 GrowableArray<Klass*>* class_promote_order,
781 781 TRAPS) {
782 782 FILE* file = fopen(class_list_path, "r");
783 783 char class_name[256];
784 784 int class_count = 0;
785 785
786 786 if (file != NULL) {
787 787 while ((fgets(class_name, sizeof class_name, file)) != NULL) {
788 788 if (*class_name == '#') { // comment
789 789 continue;
790 790 }
791 791 // Remove trailing newline
792 792 size_t name_len = strlen(class_name);
793 793 if (class_name[name_len-1] == '\n') {
794 794 class_name[name_len-1] = '\0';
795 795 }
796 796
797 797 // Got a class name - load it.
798 798 TempNewSymbol class_name_symbol = SymbolTable::new_permanent_symbol(class_name, THREAD);
799 799 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol.");
800 800 Klass* klass = SystemDictionary::resolve_or_null(class_name_symbol,
801 801 THREAD);
802 802 CLEAR_PENDING_EXCEPTION;
803 803 if (klass != NULL) {
804 804 if (PrintSharedSpaces && Verbose && WizardMode) {
805 805 tty->print_cr("Shared spaces preloaded: %s", class_name);
806 806 }
807 807
808 808 InstanceKlass* ik = InstanceKlass::cast(klass);
809 809
810 810 // Should be class load order as per -XX:+TraceClassLoadingPreorder
811 811 class_promote_order->append(ik);
812 812
813 813 // Link the class to cause the bytecodes to be rewritten and the
814 814 // cpcache to be created. The linking is done as soon as classes
815 815 // are loaded in order that the related data structures (klass and
816 816 // cpCache) are located together.
817 817 try_link_class(ik, THREAD);
818 818 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
819 819
820 820 class_count++;
821 821 } else {
822 822 //tty->print_cr("Preload failed: %s", class_name);
823 823 }
824 824 }
825 825 fclose(file);
826 826 } else {
827 827 char errmsg[JVM_MAXPATHLEN];
828 828 os::lasterror(errmsg, JVM_MAXPATHLEN);
829 829 tty->print_cr("Loading classlist failed: %s", errmsg);
830 830 exit(1);
831 831 }
832 832
833 833 return class_count;
834 834 }
835 835
836 836 // Returns true if the class's status has changed
837 837 bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
838 838 assert(DumpSharedSpaces, "should only be called during dumping");
839 839 if (ik->init_state() < InstanceKlass::linked) {
840 840 bool saved = BytecodeVerificationLocal;
841 841 if (!SharedClassUtil::is_shared_boot_class(ik)) {
842 842 // The verification decision is based on BytecodeVerificationRemote
843 843 // for non-system classes. Since we are using the NULL classloader
↓ open down ↓ |
843 lines elided |
↑ open up ↑ |
844 844 // to load non-system classes during dumping, we need to temporarily
845 845 // change BytecodeVerificationLocal to be the same as
846 846 // BytecodeVerificationRemote. Note this can cause the parent system
847 847 // classes also being verified. The extra overhead is acceptable during
848 848 // dumping.
849 849 BytecodeVerificationLocal = BytecodeVerificationRemote;
850 850 }
851 851 ik->link_class(THREAD);
852 852 if (HAS_PENDING_EXCEPTION) {
853 853 ResourceMark rm;
854 - tty->print_cr("Preload Error: Verification failed for %s",
854 + tty->print_cr("Preload Warning: Verification failed for %s",
855 855 ik->external_name());
856 856 CLEAR_PENDING_EXCEPTION;
857 857 ik->set_in_error_state();
858 858 _has_error_classes = true;
859 859 }
860 860 BytecodeVerificationLocal = saved;
861 861 return true;
862 862 } else {
863 863 return false;
864 864 }
865 865 }
866 866
867 867 // Closure for serializing initialization data in from a data area
868 868 // (ptr_array) read from the shared file.
869 869
870 870 class ReadClosure : public SerializeClosure {
871 871 private:
872 872 intptr_t** _ptr_array;
873 873
874 874 inline intptr_t nextPtr() {
875 875 return *(*_ptr_array)++;
876 876 }
877 877
878 878 public:
879 879 ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; }
880 880
881 881 void do_ptr(void** p) {
882 882 assert(*p == NULL, "initializing previous initialized pointer.");
883 883 intptr_t obj = nextPtr();
884 884 assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
885 885 "hit tag while initializing ptrs.");
886 886 *p = (void*)obj;
887 887 }
888 888
889 889 void do_tag(int tag) {
890 890 int old_tag;
891 891 old_tag = (int)(intptr_t)nextPtr();
892 892 // do_int(&old_tag);
893 893 assert(tag == old_tag, "old tag doesn't match");
894 894 FileMapInfo::assert_mark(tag == old_tag);
895 895 }
896 896
897 897 void do_region(u_char* start, size_t size) {
898 898 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
899 899 assert(size % sizeof(intptr_t) == 0, "bad size");
900 900 do_tag((int)size);
901 901 while (size > 0) {
902 902 *(intptr_t*)start = nextPtr();
903 903 start += sizeof(intptr_t);
904 904 size -= sizeof(intptr_t);
905 905 }
906 906 }
907 907
908 908 bool reading() const { return true; }
909 909 };
910 910
911 911 // Return true if given address is in the mapped shared space.
912 912 bool MetaspaceShared::is_in_shared_space(const void* p) {
913 913 return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_space(p);
914 914 }
915 915
916 916 void MetaspaceShared::print_shared_spaces() {
917 917 if (UseSharedSpaces) {
918 918 FileMapInfo::current_info()->print_shared_spaces();
919 919 }
920 920 }
921 921
922 922
923 923 // Map shared spaces at requested addresses and return if succeeded.
924 924 // Need to keep the bounds of the ro and rw space for the Metaspace::contains
925 925 // call, or is_in_shared_space.
926 926 bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
927 927 size_t image_alignment = mapinfo->alignment();
928 928
929 929 #ifndef _WINDOWS
930 930 // Map in the shared memory and then map the regions on top of it.
931 931 // On Windows, don't map the memory here because it will cause the
932 932 // mappings of the regions to fail.
933 933 ReservedSpace shared_rs = mapinfo->reserve_shared_memory();
934 934 if (!shared_rs.is_reserved()) return false;
935 935 #endif
936 936
937 937 assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
938 938
939 939 char* _ro_base = NULL;
940 940 char* _rw_base = NULL;
941 941 char* _md_base = NULL;
942 942 char* _mc_base = NULL;
943 943
944 944 // Map each shared region
945 945 if ((_ro_base = mapinfo->map_region(ro)) != NULL &&
946 946 mapinfo->verify_region_checksum(ro) &&
947 947 (_rw_base = mapinfo->map_region(rw)) != NULL &&
948 948 mapinfo->verify_region_checksum(rw) &&
949 949 (_md_base = mapinfo->map_region(md)) != NULL &&
950 950 mapinfo->verify_region_checksum(md) &&
951 951 (_mc_base = mapinfo->map_region(mc)) != NULL &&
952 952 mapinfo->verify_region_checksum(mc) &&
953 953 (image_alignment == (size_t)max_alignment()) &&
954 954 mapinfo->validate_classpath_entry_table()) {
955 955 // Success (no need to do anything)
956 956 return true;
957 957 } else {
958 958 // If there was a failure in mapping any of the spaces, unmap the ones
959 959 // that succeeded
960 960 if (_ro_base != NULL) mapinfo->unmap_region(ro);
961 961 if (_rw_base != NULL) mapinfo->unmap_region(rw);
962 962 if (_md_base != NULL) mapinfo->unmap_region(md);
963 963 if (_mc_base != NULL) mapinfo->unmap_region(mc);
964 964 #ifndef _WINDOWS
965 965 // Release the entire mapped region
966 966 shared_rs.release();
967 967 #endif
968 968 // If -Xshare:on is specified, print out the error message and exit VM,
969 969 // otherwise, set UseSharedSpaces to false and continue.
970 970 if (RequireSharedSpaces) {
971 971 vm_exit_during_initialization("Unable to use shared archive.", "Failed map_region for using -Xshare:on.");
972 972 } else {
973 973 FLAG_SET_DEFAULT(UseSharedSpaces, false);
974 974 }
975 975 return false;
976 976 }
977 977 }
978 978
979 979 // Read the miscellaneous data from the shared file, and
980 980 // serialize it out to its various destinations.
981 981
982 982 void MetaspaceShared::initialize_shared_spaces() {
983 983 FileMapInfo *mapinfo = FileMapInfo::current_info();
984 984
985 985 char* buffer = mapinfo->region_base(md);
986 986
987 987 // Skip over (reserve space for) a list of addresses of C++ vtables
988 988 // for Klass objects. They get filled in later.
989 989
990 990 void** vtbl_list = (void**)buffer;
991 991 buffer += MetaspaceShared::vtbl_list_size * sizeof(void*);
992 992 Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
993 993
994 994 // Skip over (reserve space for) dummy C++ vtables Klass objects.
995 995 // They are used as is.
996 996
997 997 intptr_t vtable_size = *(intptr_t*)buffer;
998 998 buffer += sizeof(intptr_t);
999 999 buffer += vtable_size;
1000 1000
1001 1001 // Create the symbol table using the bucket array at this spot in the
1002 1002 // misc data space. Since the symbol table is often modified, this
1003 1003 // region (of mapped pages) will be copy-on-write.
1004 1004
1005 1005 int symbolTableLen = *(intptr_t*)buffer;
1006 1006 buffer += sizeof(intptr_t);
1007 1007 int number_of_entries = *(intptr_t*)buffer;
1008 1008 buffer += sizeof(intptr_t);
1009 1009 SymbolTable::create_table((HashtableBucket<mtSymbol>*)buffer, symbolTableLen,
1010 1010 number_of_entries);
1011 1011 buffer += symbolTableLen;
1012 1012
1013 1013 // Create the shared dictionary using the bucket array at this spot in
1014 1014 // the misc data space. Since the shared dictionary table is never
1015 1015 // modified, this region (of mapped pages) will be (effectively, if
1016 1016 // not explicitly) read-only.
1017 1017
1018 1018 int sharedDictionaryLen = *(intptr_t*)buffer;
1019 1019 buffer += sizeof(intptr_t);
1020 1020 number_of_entries = *(intptr_t*)buffer;
1021 1021 buffer += sizeof(intptr_t);
1022 1022 SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer,
1023 1023 sharedDictionaryLen,
1024 1024 number_of_entries);
1025 1025 buffer += sharedDictionaryLen;
1026 1026
1027 1027 // Create the package info table using the bucket array at this spot in
1028 1028 // the misc data space. Since the package info table is never
1029 1029 // modified, this region (of mapped pages) will be (effectively, if
1030 1030 // not explicitly) read-only.
1031 1031
1032 1032 int pkgInfoLen = *(intptr_t*)buffer;
1033 1033 buffer += sizeof(intptr_t);
1034 1034 number_of_entries = *(intptr_t*)buffer;
1035 1035 buffer += sizeof(intptr_t);
1036 1036 ClassLoader::create_package_info_table((HashtableBucket<mtClass>*)buffer, pkgInfoLen,
1037 1037 number_of_entries);
1038 1038 buffer += pkgInfoLen;
1039 1039 ClassLoader::verify();
1040 1040
1041 1041 // The following data in the shared misc data region are the linked
1042 1042 // list elements (HashtableEntry objects) for the symbol table, string
1043 1043 // table, and shared dictionary. The heap objects refered to by the
1044 1044 // symbol table, string table, and shared dictionary are permanent and
1045 1045 // unmovable. Since new entries added to the string and symbol tables
1046 1046 // are always added at the beginning of the linked lists, THESE LINKED
1047 1047 // LIST ELEMENTS ARE READ-ONLY.
1048 1048
1049 1049 int len = *(intptr_t*)buffer; // skip over symbol table entries
1050 1050 buffer += sizeof(intptr_t);
1051 1051 buffer += len;
1052 1052
1053 1053 len = *(intptr_t*)buffer; // skip over shared dictionary entries
1054 1054 buffer += sizeof(intptr_t);
1055 1055 buffer += len;
1056 1056
1057 1057 len = *(intptr_t*)buffer; // skip over package info table entries
1058 1058 buffer += sizeof(intptr_t);
1059 1059 buffer += len;
1060 1060
1061 1061 len = *(intptr_t*)buffer; // skip over package info table char[] arrays.
1062 1062 buffer += sizeof(intptr_t);
1063 1063 buffer += len;
1064 1064
1065 1065 buffer = ClassLoaderExt::restore_lookup_cache_from_archive(buffer);
1066 1066
1067 1067 intptr_t* array = (intptr_t*)buffer;
1068 1068 ReadClosure rc(&array);
1069 1069 serialize(&rc);
1070 1070
1071 1071 // Close the mapinfo file
1072 1072 mapinfo->close();
1073 1073
1074 1074 if (PrintSharedArchiveAndExit) {
1075 1075 if (PrintSharedDictionary) {
1076 1076 tty->print_cr("\nShared classes:\n");
1077 1077 SystemDictionary::print_shared(false);
1078 1078 }
1079 1079 if (_archive_loading_failed) {
1080 1080 tty->print_cr("archive is invalid");
1081 1081 vm_exit(1);
1082 1082 } else {
1083 1083 tty->print_cr("archive is valid");
1084 1084 vm_exit(0);
1085 1085 }
1086 1086 }
1087 1087 }
1088 1088
1089 1089 // JVM/TI RedefineClasses() support:
1090 1090 bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
1091 1091 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1092 1092
1093 1093 if (UseSharedSpaces) {
1094 1094 // remap the shared readonly space to shared readwrite, private
1095 1095 FileMapInfo* mapinfo = FileMapInfo::current_info();
1096 1096 if (!mapinfo->remap_shared_readonly_as_readwrite()) {
1097 1097 return false;
1098 1098 }
1099 1099 }
1100 1100 return true;
1101 1101 }
1102 1102
1103 1103 int MetaspaceShared::count_class(const char* classlist_file) {
1104 1104 if (classlist_file == NULL) {
1105 1105 return 0;
1106 1106 }
1107 1107 char class_name[256];
1108 1108 int class_count = 0;
1109 1109 FILE* file = fopen(classlist_file, "r");
1110 1110 if (file != NULL) {
1111 1111 while ((fgets(class_name, sizeof class_name, file)) != NULL) {
1112 1112 if (*class_name == '#') { // comment
1113 1113 continue;
1114 1114 }
1115 1115 class_count++;
1116 1116 }
1117 1117 fclose(file);
1118 1118 } else {
1119 1119 char errmsg[JVM_MAXPATHLEN];
1120 1120 os::lasterror(errmsg, JVM_MAXPATHLEN);
1121 1121 tty->print_cr("Loading classlist failed: %s", errmsg);
1122 1122 exit(1);
1123 1123 }
1124 1124
1125 1125 return class_count;
1126 1126 }
1127 1127
1128 1128 // the sizes are good for typical large applications that have a lot of shared
1129 1129 // classes
1130 1130 void MetaspaceShared::estimate_regions_size() {
1131 1131 int class_count = count_class(SharedClassListFile);
1132 1132 class_count += count_class(ExtraSharedClassListFile);
1133 1133
1134 1134 if (class_count > LargeThresholdClassCount) {
1135 1135 if (class_count < HugeThresholdClassCount) {
1136 1136 SET_ESTIMATED_SIZE(Large, ReadOnly);
1137 1137 SET_ESTIMATED_SIZE(Large, ReadWrite);
1138 1138 SET_ESTIMATED_SIZE(Large, MiscData);
1139 1139 SET_ESTIMATED_SIZE(Large, MiscCode);
1140 1140 } else {
1141 1141 SET_ESTIMATED_SIZE(Huge, ReadOnly);
1142 1142 SET_ESTIMATED_SIZE(Huge, ReadWrite);
1143 1143 SET_ESTIMATED_SIZE(Huge, MiscData);
1144 1144 SET_ESTIMATED_SIZE(Huge, MiscCode);
1145 1145 }
1146 1146 }
1147 1147 }
↓ open down ↓ |
283 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX