src/share/vm/memory/metaspaceShared.cpp

Fri, 07 Sep 2012 12:04:16 -0400

author
coleenp
date
Fri, 07 Sep 2012 12:04:16 -0400
changeset 4047
aed758eda82a
parent 4045
fa6e618671d7
child 4165
fb19af007ffc
permissions
-rw-r--r--

7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
Summary: Simple renaming to be consistent with instanceKlass->InstanceKlass renaming
Reviewed-by: stefank, jmasa

coleenp@4037 1 /*
coleenp@4037 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
coleenp@4037 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@4037 4 *
coleenp@4037 5 * This code is free software; you can redistribute it and/or modify it
coleenp@4037 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@4037 7 * published by the Free Software Foundation.
coleenp@4037 8 *
coleenp@4037 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@4037 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
coleenp@4037 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@4037 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@4037 13 * accompanied this code).
coleenp@4037 14 *
coleenp@4037 15 * You should have received a copy of the GNU General Public License version
coleenp@4037 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@4037 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@4037 18 *
coleenp@4037 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@4037 20 * or visit www.oracle.com if you need additional information or have any
coleenp@4037 21 * questions.
coleenp@4037 22 *
coleenp@4037 23 */
coleenp@4037 24
coleenp@4037 25 #include "precompiled.hpp"
coleenp@4037 26 #include "classfile/dictionary.hpp"
coleenp@4037 27 #include "classfile/loaderConstraints.hpp"
coleenp@4037 28 #include "classfile/placeholders.hpp"
coleenp@4037 29 #include "classfile/symbolTable.hpp"
coleenp@4037 30 #include "classfile/systemDictionary.hpp"
coleenp@4037 31 #include "code/codeCache.hpp"
coleenp@4037 32 #include "memory/filemap.hpp"
coleenp@4037 33 #include "memory/gcLocker.hpp"
coleenp@4037 34 #include "memory/metaspace.hpp"
coleenp@4037 35 #include "memory/metaspaceShared.hpp"
coleenp@4037 36 #include "oops/objArrayOop.hpp"
coleenp@4037 37 #include "oops/oop.inline.hpp"
coleenp@4037 38 #include "runtime/signature.hpp"
coleenp@4037 39 #include "runtime/vm_operations.hpp"
coleenp@4037 40 #include "runtime/vmThread.hpp"
coleenp@4037 41 #include "utilities/hashtable.inline.hpp"
coleenp@4037 42
coleenp@4037 43
coleenp@4037 44 int MetaspaceShared::_max_alignment = 0;
coleenp@4037 45 int MetaspaceShared::max_alignment() { return _max_alignment; }
coleenp@4037 46 void MetaspaceShared::set_max_alignment(int alignment) { _max_alignment = alignment; }
coleenp@4037 47
coleenp@4037 48 // Accessor functions to save shared space created for metadata, which has
coleenp@4037 49 // extra space allocated at the end for miscellaneous data and code.
coleenp@4037 50 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
coleenp@4037 51 ReservedSpace* MetaspaceShared::shared_rs() { return _shared_rs; }
coleenp@4037 52 void MetaspaceShared::set_shared_rs(ReservedSpace* rs) { _shared_rs = rs; }
coleenp@4037 53
coleenp@4037 54 // Read/write a data stream for restoring/preserving metadata pointers and
coleenp@4037 55 // miscellaneous data from/to the shared archive file.
coleenp@4037 56
coleenp@4037 57 void MetaspaceShared::serialize(SerializeClosure* soc) {
coleenp@4037 58 int tag = 0;
coleenp@4037 59 soc->do_tag(--tag);
coleenp@4037 60
coleenp@4037 61 assert(!UseCompressedOops, "UseCompressedOops doesn't work with shared archive");
coleenp@4037 62 // Verify the sizes of various metadata in the system.
coleenp@4037 63 soc->do_tag(sizeof(Method));
coleenp@4037 64 soc->do_tag(sizeof(ConstMethod));
coleenp@4037 65 soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
coleenp@4037 66 soc->do_tag(sizeof(ConstantPool));
coleenp@4037 67 soc->do_tag(sizeof(ConstantPoolCache));
coleenp@4037 68 soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
coleenp@4037 69 soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
coleenp@4037 70 soc->do_tag(sizeof(Symbol));
coleenp@4037 71
coleenp@4037 72 // Dump/restore miscellaneous metadata.
coleenp@4037 73 Universe::serialize(soc, true);
coleenp@4037 74 soc->do_tag(--tag);
coleenp@4037 75
coleenp@4037 76 // Dump/restore references to commonly used names and signatures.
coleenp@4037 77 vmSymbols::serialize(soc);
coleenp@4037 78 soc->do_tag(--tag);
coleenp@4037 79
coleenp@4037 80 soc->do_tag(666);
coleenp@4037 81 }
coleenp@4037 82
coleenp@4037 83
coleenp@4037 84 // CDS code for dumping shared archive.
coleenp@4037 85
coleenp@4037 86 // Global object for holding classes that have been loaded. Since this
coleenp@4037 87 // is run at a safepoint just before exit, this is the entire set of classes.
coleenp@4037 88 static GrowableArray<Klass*>* _global_klass_objects;
coleenp@4037 89 static void collect_classes(Klass* k) {
coleenp@4037 90 _global_klass_objects->append_if_missing(k);
coleenp@4037 91 if (k->oop_is_instance()) {
coleenp@4037 92 // Add in the array classes too
coleenp@4037 93 InstanceKlass* ik = InstanceKlass::cast(k);
coleenp@4037 94 ik->array_klasses_do(collect_classes);
coleenp@4037 95 }
coleenp@4037 96 }
coleenp@4037 97
coleenp@4037 98 static void remove_unshareable_in_classes() {
coleenp@4037 99 for (int i = 0; i < _global_klass_objects->length(); i++) {
coleenp@4037 100 Klass* k = _global_klass_objects->at(i);
coleenp@4037 101 k->remove_unshareable_info();
coleenp@4037 102 }
coleenp@4037 103 }
coleenp@4037 104
coleenp@4037 105 // Walk all methods in the class list and assign a fingerprint.
coleenp@4037 106 // so that this part of the ConstMethod* is read only.
coleenp@4037 107 static void calculate_fingerprints() {
coleenp@4037 108 for (int i = 0; i < _global_klass_objects->length(); i++) {
coleenp@4037 109 Klass* k = _global_klass_objects->at(i);
coleenp@4037 110 if (k->oop_is_instance()) {
coleenp@4037 111 InstanceKlass* ik = InstanceKlass::cast(k);
coleenp@4037 112 for (int i = 0; i < ik->methods()->length(); i++) {
coleenp@4037 113 ResourceMark rm;
coleenp@4037 114 Method* m = ik->methods()->at(i);
coleenp@4037 115 (new Fingerprinter(m))->fingerprint();
coleenp@4037 116 }
coleenp@4037 117 }
coleenp@4037 118 }
coleenp@4037 119 }
coleenp@4037 120
coleenp@4037 121 // Patch C++ vtable pointer in metadata.
coleenp@4037 122
coleenp@4037 123 // Klass and other metadata objects contain references to c++ vtables in the
coleenp@4037 124 // JVM library.
coleenp@4037 125 // Fix them to point to our constructed vtables. However, don't iterate
coleenp@4037 126 // across the space while doing this, as that causes the vtables to be
coleenp@4037 127 // patched, undoing our useful work. Instead, iterate to make a list,
coleenp@4037 128 // then use the list to do the fixing.
coleenp@4037 129 //
coleenp@4037 130 // Our constructed vtables:
coleenp@4037 131 // Dump time:
coleenp@4037 132 // 1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs
coleenp@4037 133 // 2. generate_vtable_methods: create jump table, appended to above vtbl_list
coleenp@4037 134 // 3. patch_klass_vtables: for Klass list, patch the vtable entry in klass and
coleenp@4037 135 // associated metadata to point to jump table rather than to current vtbl
coleenp@4037 136 // Table layout: NOTE FIXED SIZE
coleenp@4037 137 // 1. vtbl pointers
coleenp@4037 138 // 2. #Klass X #virtual methods per Klass
coleenp@4037 139 // 1 entry for each, in the order:
coleenp@4037 140 // Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry
coleenp@4037 141 // Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry
coleenp@4037 142 // ...
coleenp@4037 143 // Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry,
coleenp@4037 144 // ... Klass<vtbl_list_size>:method<num_virtuals> entry
coleenp@4037 145 // Sample entry: (Sparc):
coleenp@4037 146 // save(sp, -256, sp)
coleenp@4037 147 // ba,pt common_code
coleenp@4037 148 // mov XXX, %L0 %L0 gets: Klass index <<8 + method index (note: max method index 255)
coleenp@4037 149 //
coleenp@4037 150 // Restore time:
coleenp@4037 151 // 1. initialize_shared_space: reserve space for table
coleenp@4037 152 // 2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text
coleenp@4037 153 //
coleenp@4037 154 // Execution time:
coleenp@4037 155 // First virtual method call for any object of these metadata types:
coleenp@4045 156 // 1. object->klass
coleenp@4045 157 // 2. vtable entry for that klass points to the jump table entries
coleenp@4045 158 // 3. branches to common_code with %O0/klass, %L0: Klass index <<8 + method index
coleenp@4037 159 // 4. common_code:
coleenp@4037 160 // Get address of new vtbl pointer for this Klass from updated table
coleenp@4037 161 // Update new vtbl pointer in the Klass: future virtual calls go direct
coleenp@4037 162 // Jump to method, using new vtbl pointer and method index
coleenp@4037 163
coleenp@4037 164
coleenp@4037 165 static void* find_matching_vtbl_ptr(void** vtbl_list, void* new_vtable_start, void* obj) {
coleenp@4037 166 void* old_vtbl_ptr = *(void**)obj;
coleenp@4037 167 for (int i = 0; i < MetaspaceShared::vtbl_list_size; i++) {
coleenp@4037 168 if (vtbl_list[i] == old_vtbl_ptr) {
coleenp@4037 169 return (void**)new_vtable_start + i * MetaspaceShared::num_virtuals;
coleenp@4037 170 }
coleenp@4037 171 }
coleenp@4037 172 ShouldNotReachHere();
coleenp@4037 173 return NULL;
coleenp@4037 174 }
coleenp@4037 175
coleenp@4037 176 // Assumes the vtable is in first slot in object.
coleenp@4037 177 static void patch_klass_vtables(void** vtbl_list, void* new_vtable_start) {
coleenp@4037 178 int n = _global_klass_objects->length();
coleenp@4037 179 for (int i = 0; i < n; i++) {
coleenp@4037 180 Klass* obj = _global_klass_objects->at(i);
coleenp@4037 181 // Note oop_is_instance() is a virtual call. After patching vtables
coleenp@4037 182 // all virtual calls on the dummy vtables will restore the original!
coleenp@4037 183 if (obj->oop_is_instance()) {
coleenp@4037 184 InstanceKlass* ik = InstanceKlass::cast(obj);
coleenp@4037 185 *(void**)ik = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, ik);
coleenp@4037 186 ConstantPool* cp = ik->constants();
coleenp@4037 187 *(void**)cp = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, cp);
coleenp@4037 188 for (int j = 0; j < ik->methods()->length(); j++) {
coleenp@4037 189 Method* m = ik->methods()->at(j);
coleenp@4037 190 *(void**)m = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, m);
coleenp@4037 191 }
coleenp@4037 192 } else {
coleenp@4037 193 // Array klasses
coleenp@4037 194 Klass* k = obj;
coleenp@4037 195 *(void**)k = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, k);
coleenp@4037 196 }
coleenp@4037 197 }
coleenp@4037 198 }
coleenp@4037 199
coleenp@4037 200 // Closure for serializing initialization data out to a data area to be
coleenp@4037 201 // written to the shared file.
coleenp@4037 202
coleenp@4037 203 class WriteClosure : public SerializeClosure {
coleenp@4037 204 private:
coleenp@4037 205 intptr_t* top;
coleenp@4037 206 char* end;
coleenp@4037 207
coleenp@4037 208 inline void check_space() {
coleenp@4037 209 if ((char*)top + sizeof(intptr_t) > end) {
coleenp@4037 210 report_out_of_shared_space(SharedMiscData);
coleenp@4037 211 }
coleenp@4037 212 }
coleenp@4037 213
coleenp@4037 214 public:
coleenp@4037 215 WriteClosure(char* md_top, char* md_end) {
coleenp@4037 216 top = (intptr_t*)md_top;
coleenp@4037 217 end = md_end;
coleenp@4037 218 }
coleenp@4037 219
coleenp@4037 220 char* get_top() { return (char*)top; }
coleenp@4037 221
coleenp@4037 222 void do_ptr(void** p) {
coleenp@4037 223 check_space();
coleenp@4037 224 *top = (intptr_t)*p;
coleenp@4037 225 ++top;
coleenp@4037 226 }
coleenp@4037 227
coleenp@4037 228 void do_tag(int tag) {
coleenp@4037 229 check_space();
coleenp@4037 230 *top = (intptr_t)tag;
coleenp@4037 231 ++top;
coleenp@4037 232 }
coleenp@4037 233
coleenp@4037 234 void do_region(u_char* start, size_t size) {
coleenp@4037 235 if ((char*)top + size > end) {
coleenp@4037 236 report_out_of_shared_space(SharedMiscData);
coleenp@4037 237 }
coleenp@4037 238 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
coleenp@4037 239 assert(size % sizeof(intptr_t) == 0, "bad size");
coleenp@4037 240 do_tag((int)size);
coleenp@4037 241 while (size > 0) {
coleenp@4037 242 *top = *(intptr_t*)start;
coleenp@4037 243 ++top;
coleenp@4037 244 start += sizeof(intptr_t);
coleenp@4037 245 size -= sizeof(intptr_t);
coleenp@4037 246 }
coleenp@4037 247 }
coleenp@4037 248
coleenp@4037 249 bool reading() const { return false; }
coleenp@4037 250 };
coleenp@4037 251
coleenp@4037 252
coleenp@4037 253 // Populate the shared space.
coleenp@4037 254
coleenp@4037 255 class VM_PopulateDumpSharedSpace: public VM_Operation {
coleenp@4037 256 private:
coleenp@4037 257 ClassLoaderData* _loader_data;
coleenp@4037 258 GrowableArray<Klass*> *_class_promote_order;
coleenp@4037 259 VirtualSpace _md_vs;
coleenp@4037 260 VirtualSpace _mc_vs;
coleenp@4037 261
coleenp@4037 262 public:
coleenp@4037 263 VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
coleenp@4037 264 GrowableArray<Klass*> *class_promote_order) :
coleenp@4037 265 _loader_data(loader_data) {
coleenp@4037 266
coleenp@4037 267 // Split up and initialize the misc code and data spaces
coleenp@4037 268 ReservedSpace* shared_rs = MetaspaceShared::shared_rs();
coleenp@4037 269 int metadata_size = SharedReadOnlySize+SharedReadWriteSize;
coleenp@4037 270 ReservedSpace shared_ro_rw = shared_rs->first_part(metadata_size);
coleenp@4037 271 ReservedSpace misc_section = shared_rs->last_part(metadata_size);
coleenp@4037 272
coleenp@4037 273 // Now split into misc sections.
coleenp@4037 274 ReservedSpace md_rs = misc_section.first_part(SharedMiscDataSize);
coleenp@4037 275 ReservedSpace mc_rs = misc_section.last_part(SharedMiscDataSize);
coleenp@4037 276 _md_vs.initialize(md_rs, SharedMiscDataSize);
coleenp@4037 277 _mc_vs.initialize(mc_rs, SharedMiscCodeSize);
coleenp@4037 278 _class_promote_order = class_promote_order;
coleenp@4037 279 }
coleenp@4037 280
coleenp@4037 281 VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
coleenp@4037 282 void doit(); // outline because gdb sucks
coleenp@4037 283 }; // class VM_PopulateDumpSharedSpace
coleenp@4037 284
coleenp@4037 285
coleenp@4037 286 void VM_PopulateDumpSharedSpace::doit() {
coleenp@4037 287 Thread* THREAD = VMThread::vm_thread();
coleenp@4037 288 NOT_PRODUCT(SystemDictionary::verify();)
coleenp@4037 289 // The following guarantee is meant to ensure that no loader constraints
coleenp@4037 290 // exist yet, since the constraints table is not shared. This becomes
coleenp@4037 291 // more important now that we don't re-initialize vtables/itables for
coleenp@4037 292 // shared classes at runtime, where constraints were previously created.
coleenp@4037 293 guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
coleenp@4037 294 "loader constraints are not saved");
coleenp@4037 295 guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
coleenp@4037 296 "placeholders are not saved");
coleenp@4037 297 // Revisit and implement this if we prelink method handle call sites:
coleenp@4037 298 guarantee(SystemDictionary::invoke_method_table() == NULL ||
coleenp@4037 299 SystemDictionary::invoke_method_table()->number_of_entries() == 0,
coleenp@4037 300 "invoke method table is not saved");
coleenp@4037 301
coleenp@4037 302 // At this point, many classes have been loaded.
coleenp@4037 303 // Gather systemDictionary classes in a global array and do everything to
coleenp@4037 304 // that so we don't have to walk the SystemDictionary again.
coleenp@4037 305 _global_klass_objects = new GrowableArray<Klass*>(1000);
coleenp@4037 306 Universe::basic_type_classes_do(collect_classes);
coleenp@4037 307 SystemDictionary::classes_do(collect_classes);
coleenp@4037 308
coleenp@4037 309 tty->print_cr("Number of classes %d", _global_klass_objects->length());
coleenp@4037 310
coleenp@4037 311 // Update all the fingerprints in the shared methods.
coleenp@4037 312 tty->print("Calculating fingerprints ... ");
coleenp@4037 313 calculate_fingerprints();
coleenp@4037 314 tty->print_cr("done. ");
coleenp@4037 315
coleenp@4037 316 // Remove all references outside the metadata
coleenp@4037 317 tty->print("Removing unshareable information ... ");
coleenp@4037 318 remove_unshareable_in_classes();
coleenp@4037 319 tty->print_cr("done. ");
coleenp@4037 320
coleenp@4037 321 // Set up the share data and shared code segments.
coleenp@4037 322 char* md_low = _md_vs.low();
coleenp@4037 323 char* md_top = md_low;
coleenp@4037 324 char* md_end = _md_vs.high();
coleenp@4037 325 char* mc_low = _mc_vs.low();
coleenp@4037 326 char* mc_top = mc_low;
coleenp@4037 327 char* mc_end = _mc_vs.high();
coleenp@4037 328
coleenp@4037 329 // Reserve space for the list of Klass*s whose vtables are used
coleenp@4037 330 // for patching others as needed.
coleenp@4037 331
coleenp@4037 332 void** vtbl_list = (void**)md_top;
coleenp@4037 333 int vtbl_list_size = MetaspaceShared::vtbl_list_size;
coleenp@4037 334 Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
coleenp@4037 335
coleenp@4037 336 md_top += vtbl_list_size * sizeof(void*);
coleenp@4037 337 void* vtable = md_top;
coleenp@4037 338
coleenp@4037 339 // Reserve space for a new dummy vtable for klass objects in the
coleenp@4037 340 // heap. Generate self-patching vtable entries.
coleenp@4037 341
coleenp@4037 342 MetaspaceShared::generate_vtable_methods(vtbl_list, &vtable,
coleenp@4037 343 &md_top, md_end,
coleenp@4037 344 &mc_top, mc_end);
coleenp@4037 345
coleenp@4037 346 // Reorder the system dictionary. (Moving the symbols affects
coleenp@4037 347 // how the hash table indices are calculated.)
coleenp@4037 348 // Not doing this either.
coleenp@4037 349
coleenp@4037 350 SystemDictionary::reorder_dictionary();
coleenp@4037 351
coleenp@4037 352 NOT_PRODUCT(SystemDictionary::verify();)
coleenp@4037 353
coleenp@4037 354 // Copy the the symbol table, and the system dictionary to the shared
coleenp@4037 355 // space in usable form. Copy the hastable
coleenp@4037 356 // buckets first [read-write], then copy the linked lists of entries
coleenp@4037 357 // [read-only].
coleenp@4037 358
coleenp@4037 359 SymbolTable::reverse(md_top);
coleenp@4037 360 NOT_PRODUCT(SymbolTable::verify());
coleenp@4037 361 SymbolTable::copy_buckets(&md_top, md_end);
coleenp@4037 362
coleenp@4037 363 SystemDictionary::reverse();
coleenp@4037 364 SystemDictionary::copy_buckets(&md_top, md_end);
coleenp@4037 365
coleenp@4037 366 ClassLoader::verify();
coleenp@4037 367 ClassLoader::copy_package_info_buckets(&md_top, md_end);
coleenp@4037 368 ClassLoader::verify();
coleenp@4037 369
coleenp@4037 370 SymbolTable::copy_table(&md_top, md_end);
coleenp@4037 371 SystemDictionary::copy_table(&md_top, md_end);
coleenp@4037 372 ClassLoader::verify();
coleenp@4037 373 ClassLoader::copy_package_info_table(&md_top, md_end);
coleenp@4037 374 ClassLoader::verify();
coleenp@4037 375
coleenp@4037 376 // Write the other data to the output array.
coleenp@4037 377 WriteClosure wc(md_top, md_end);
coleenp@4037 378 MetaspaceShared::serialize(&wc);
coleenp@4037 379 md_top = wc.get_top();
coleenp@4037 380
coleenp@4037 381 // Print shared spaces all the time
coleenp@4037 382 const char* fmt = "%s space: " PTR_FORMAT " out of " PTR_FORMAT " words allocated at " PTR_FORMAT ".";
coleenp@4037 383 Metaspace* ro_space = _loader_data->ro_metaspace();
coleenp@4037 384 Metaspace* rw_space = _loader_data->rw_metaspace();
coleenp@4037 385 tty->print_cr(fmt, "ro", ro_space->used_words(Metaspace::NonClassType),
coleenp@4037 386 ro_space->capacity_words(Metaspace::NonClassType),
coleenp@4037 387 ro_space->bottom());
coleenp@4037 388 tty->print_cr(fmt, "rw", rw_space->used_words(Metaspace::NonClassType),
coleenp@4037 389 rw_space->capacity_words(Metaspace::NonClassType),
coleenp@4037 390 rw_space->bottom());
coleenp@4037 391 tty->print_cr(fmt, "md", md_top - md_low, md_end-md_low, md_low);
coleenp@4037 392 tty->print_cr(fmt, "mc", mc_top - mc_low, mc_end-mc_low, mc_low);
coleenp@4037 393
coleenp@4037 394 // Update the vtable pointers in all of the Klass objects in the
coleenp@4037 395 // heap. They should point to newly generated vtable.
coleenp@4037 396 patch_klass_vtables(vtbl_list, vtable);
coleenp@4037 397
coleenp@4037 398 // dunno what this is for.
coleenp@4037 399 char* saved_vtbl = (char*)os::malloc(vtbl_list_size * sizeof(void*), mtClass);
coleenp@4037 400 memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
coleenp@4037 401 memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
coleenp@4037 402
coleenp@4037 403 // Create and write the archive file that maps the shared spaces.
coleenp@4037 404
coleenp@4037 405 FileMapInfo* mapinfo = new FileMapInfo();
coleenp@4037 406 mapinfo->populate_header(MetaspaceShared::max_alignment());
coleenp@4037 407
coleenp@4037 408 // Pass 1 - update file offsets in header.
coleenp@4037 409 mapinfo->write_header();
coleenp@4037 410 mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
coleenp@4037 411 mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
coleenp@4037 412 mapinfo->write_region(MetaspaceShared::md, _md_vs.low(),
coleenp@4037 413 pointer_delta(md_top, _md_vs.low(), sizeof(char)),
coleenp@4037 414 SharedMiscDataSize,
coleenp@4037 415 false, false);
coleenp@4037 416 mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
coleenp@4037 417 pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
coleenp@4037 418 SharedMiscCodeSize,
coleenp@4037 419 true, true);
coleenp@4037 420
coleenp@4037 421 // Pass 2 - write data.
coleenp@4037 422 mapinfo->open_for_write();
coleenp@4037 423 mapinfo->write_header();
coleenp@4037 424 mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
coleenp@4037 425 mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
coleenp@4037 426 mapinfo->write_region(MetaspaceShared::md, _md_vs.low(),
coleenp@4037 427 pointer_delta(md_top, _md_vs.low(), sizeof(char)),
coleenp@4037 428 SharedMiscDataSize,
coleenp@4037 429 false, false);
coleenp@4037 430 mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
coleenp@4037 431 pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
coleenp@4037 432 SharedMiscCodeSize,
coleenp@4037 433 true, true);
coleenp@4037 434 mapinfo->close();
coleenp@4037 435
coleenp@4037 436 memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
coleenp@4037 437 }
coleenp@4037 438
coleenp@4037 439 static void link_shared_classes(Klass* obj, TRAPS) {
coleenp@4037 440 Klass* k = Klass::cast(obj);
coleenp@4037 441 if (k->oop_is_instance()) {
coleenp@4037 442 InstanceKlass* ik = (InstanceKlass*) k;
coleenp@4037 443 // Link the class to cause the bytecodes to be rewritten and the
coleenp@4037 444 // cpcache to be created.
coleenp@4037 445 if (ik->init_state() < InstanceKlass::linked) {
coleenp@4037 446 ik->link_class(THREAD);
coleenp@4037 447 guarantee(!HAS_PENDING_EXCEPTION, "exception in class rewriting");
coleenp@4037 448 }
coleenp@4037 449 }
coleenp@4037 450 }
coleenp@4037 451
coleenp@4037 452
coleenp@4037 453 // Support for a simple checksum of the contents of the class list
coleenp@4037 454 // file to prevent trivial tampering. The algorithm matches that in
coleenp@4037 455 // the MakeClassList program used by the J2SE build process.
coleenp@4037 456 #define JSUM_SEED ((jlong)CONST64(0xcafebabebabecafe))
coleenp@4037 457 static jlong
coleenp@4037 458 jsum(jlong start, const char *buf, const int len)
coleenp@4037 459 {
coleenp@4037 460 jlong h = start;
coleenp@4037 461 char *p = (char *)buf, *e = p + len;
coleenp@4037 462 while (p < e) {
coleenp@4037 463 char c = *p++;
coleenp@4037 464 if (c <= ' ') {
coleenp@4037 465 /* Skip spaces and control characters */
coleenp@4037 466 continue;
coleenp@4037 467 }
coleenp@4037 468 h = 31 * h + c;
coleenp@4037 469 }
coleenp@4037 470 return h;
coleenp@4037 471 }
coleenp@4037 472
coleenp@4037 473 // Preload classes from a list, populate the shared spaces and dump to a
coleenp@4037 474 // file.
coleenp@4037 475 void MetaspaceShared::preload_and_dump(TRAPS) {
coleenp@4037 476 TraceTime timer("Dump Shared Spaces", TraceStartupTime);
coleenp@4037 477 ResourceMark rm;
coleenp@4037 478
coleenp@4037 479 // Lock out GC - is it necessary? I don't think we care.
coleenp@4037 480 No_GC_Verifier no_gc;
coleenp@4037 481
coleenp@4037 482 // Preload classes to be shared.
coleenp@4037 483 // Should use some os:: method rather than fopen() here. aB.
coleenp@4037 484 // Construct the path to the class list (in jre/lib)
coleenp@4037 485 // Walk up two directories from the location of the VM and
coleenp@4037 486 // optionally tack on "lib" (depending on platform)
coleenp@4037 487 char class_list_path[JVM_MAXPATHLEN];
coleenp@4037 488 os::jvm_path(class_list_path, sizeof(class_list_path));
coleenp@4037 489 for (int i = 0; i < 3; i++) {
coleenp@4037 490 char *end = strrchr(class_list_path, *os::file_separator());
coleenp@4037 491 if (end != NULL) *end = '\0';
coleenp@4037 492 }
coleenp@4037 493 int class_list_path_len = (int)strlen(class_list_path);
coleenp@4037 494 if (class_list_path_len >= 3) {
coleenp@4037 495 if (strcmp(class_list_path + class_list_path_len - 3, "lib") != 0) {
coleenp@4037 496 strcat(class_list_path, os::file_separator());
coleenp@4037 497 strcat(class_list_path, "lib");
coleenp@4037 498 }
coleenp@4037 499 }
coleenp@4037 500 strcat(class_list_path, os::file_separator());
coleenp@4037 501 strcat(class_list_path, "classlist");
coleenp@4037 502
coleenp@4037 503 FILE* file = fopen(class_list_path, "r");
coleenp@4037 504 if (file != NULL) {
coleenp@4037 505 jlong computed_jsum = JSUM_SEED;
coleenp@4037 506 jlong file_jsum = 0;
coleenp@4037 507
coleenp@4037 508 char class_name[256];
coleenp@4037 509 int class_count = 0;
coleenp@4037 510 GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
coleenp@4037 511
coleenp@4037 512 // sun.io.Converters
coleenp@4037 513 static const char obj_array_sig[] = "[[Ljava/lang/Object;";
coleenp@4037 514 SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
coleenp@4037 515
coleenp@4037 516 // java.util.HashMap
coleenp@4037 517 static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
coleenp@4037 518 SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
coleenp@4037 519
coleenp@4037 520 tty->print("Loading classes to share ... ");
coleenp@4037 521 while ((fgets(class_name, sizeof class_name, file)) != NULL) {
coleenp@4037 522 if (*class_name == '#') {
coleenp@4037 523 jint fsh, fsl;
coleenp@4037 524 if (sscanf(class_name, "# %8x%8x\n", &fsh, &fsl) == 2) {
coleenp@4037 525 file_jsum = ((jlong)(fsh) << 32) | (fsl & 0xffffffff);
coleenp@4037 526 }
coleenp@4037 527
coleenp@4037 528 continue;
coleenp@4037 529 }
coleenp@4037 530 // Remove trailing newline
coleenp@4037 531 size_t name_len = strlen(class_name);
coleenp@4037 532 class_name[name_len-1] = '\0';
coleenp@4037 533
coleenp@4037 534 computed_jsum = jsum(computed_jsum, class_name, (const int)name_len - 1);
coleenp@4037 535
coleenp@4037 536 // Got a class name - load it.
coleenp@4037 537 TempNewSymbol class_name_symbol = SymbolTable::new_permanent_symbol(class_name, THREAD);
coleenp@4037 538 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol.");
coleenp@4037 539 Klass* klass = SystemDictionary::resolve_or_null(class_name_symbol,
coleenp@4037 540 THREAD);
coleenp@4037 541 guarantee(!HAS_PENDING_EXCEPTION, "Exception resolving a class.");
coleenp@4037 542 if (klass != NULL) {
coleenp@4037 543 if (PrintSharedSpaces && Verbose && WizardMode) {
coleenp@4037 544 tty->print_cr("Shared spaces preloaded: %s", class_name);
coleenp@4037 545 }
coleenp@4037 546
coleenp@4037 547
coleenp@4037 548 InstanceKlass* ik = InstanceKlass::cast(klass);
coleenp@4037 549
coleenp@4037 550 // Should be class load order as per -XX:+TraceClassLoadingPreorder
coleenp@4037 551 class_promote_order->append(ik);
coleenp@4037 552
coleenp@4037 553 // Link the class to cause the bytecodes to be rewritten and the
coleenp@4037 554 // cpcache to be created. The linking is done as soon as classes
coleenp@4037 555 // are loaded in order that the related data structures (klass and
coleenp@4037 556 // cpCache) are located together.
coleenp@4037 557
coleenp@4037 558 if (ik->init_state() < InstanceKlass::linked) {
coleenp@4037 559 ik->link_class(THREAD);
coleenp@4037 560 guarantee(!(HAS_PENDING_EXCEPTION), "exception in class rewriting");
coleenp@4037 561 }
coleenp@4037 562
coleenp@4037 563 // TODO: Resolve klasses in constant pool
coleenp@4037 564 ik->constants()->resolve_class_constants(THREAD);
coleenp@4037 565
coleenp@4037 566 class_count++;
coleenp@4037 567 } else {
coleenp@4037 568 if (PrintSharedSpaces && Verbose && WizardMode) {
coleenp@4037 569 tty->cr();
coleenp@4037 570 tty->print_cr(" Preload failed: %s", class_name);
coleenp@4037 571 }
coleenp@4037 572 }
coleenp@4037 573 file_jsum = 0; // Checksum must be on last line of file
coleenp@4037 574 }
coleenp@4037 575 if (computed_jsum != file_jsum) {
coleenp@4037 576 tty->cr();
coleenp@4037 577 tty->print_cr("Preload failed: checksum of class list was incorrect.");
coleenp@4037 578 exit(1);
coleenp@4037 579 }
coleenp@4037 580
coleenp@4037 581 tty->print_cr("done. ");
coleenp@4037 582
coleenp@4037 583 if (PrintSharedSpaces) {
coleenp@4037 584 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
coleenp@4037 585 }
coleenp@4037 586
coleenp@4037 587 // Rewrite and unlink classes.
coleenp@4037 588 tty->print("Rewriting and linking classes ... ");
coleenp@4037 589
coleenp@4037 590 // Link any classes which got missed. (It's not quite clear why
coleenp@4037 591 // they got missed.) This iteration would be unsafe if we weren't
coleenp@4037 592 // single-threaded at this point; however we can't do it on the VM
coleenp@4037 593 // thread because it requires object allocation.
coleenp@4037 594 SystemDictionary::classes_do(link_shared_classes, CATCH);
coleenp@4037 595 tty->print_cr("done. ");
coleenp@4037 596
coleenp@4037 597 // Create and dump the shared spaces. Everything so far is loaded
coleenp@4037 598 // with the null class loader.
coleenp@4037 599 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
coleenp@4037 600 VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
coleenp@4037 601 VMThread::execute(&op);
coleenp@4037 602
coleenp@4037 603 } else {
coleenp@4037 604 char errmsg[JVM_MAXPATHLEN];
coleenp@4037 605 os::lasterror(errmsg, JVM_MAXPATHLEN);
coleenp@4037 606 tty->print_cr("Loading classlist failed: %s", errmsg);
coleenp@4037 607 exit(1);
coleenp@4037 608 }
coleenp@4037 609
coleenp@4037 610 // Since various initialization steps have been undone by this process,
coleenp@4037 611 // it is not reasonable to continue running a java process.
coleenp@4037 612 exit(0);
coleenp@4037 613 }
coleenp@4037 614
coleenp@4037 615
coleenp@4037 616 // Closure for serializing initialization data in from a data area
coleenp@4037 617 // (ptr_array) read from the shared file.
coleenp@4037 618
coleenp@4037 619 class ReadClosure : public SerializeClosure {
coleenp@4037 620 private:
coleenp@4037 621 intptr_t** _ptr_array;
coleenp@4037 622
coleenp@4037 623 inline intptr_t nextPtr() {
coleenp@4037 624 return *(*_ptr_array)++;
coleenp@4037 625 }
coleenp@4037 626
coleenp@4037 627 public:
coleenp@4037 628 ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; }
coleenp@4037 629
coleenp@4037 630 void do_ptr(void** p) {
coleenp@4037 631 assert(*p == NULL, "initializing previous initialized pointer.");
coleenp@4037 632 intptr_t obj = nextPtr();
coleenp@4037 633 assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
coleenp@4037 634 "hit tag while initializing ptrs.");
coleenp@4037 635 *p = (void*)obj;
coleenp@4037 636 }
coleenp@4037 637
coleenp@4037 638 void do_tag(int tag) {
coleenp@4037 639 int old_tag;
coleenp@4037 640 old_tag = (int)(intptr_t)nextPtr();
coleenp@4037 641 // do_int(&old_tag);
coleenp@4037 642 assert(tag == old_tag, "old tag doesn't match");
coleenp@4037 643 FileMapInfo::assert_mark(tag == old_tag);
coleenp@4037 644 }
coleenp@4037 645
coleenp@4037 646 void do_region(u_char* start, size_t size) {
coleenp@4037 647 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
coleenp@4037 648 assert(size % sizeof(intptr_t) == 0, "bad size");
coleenp@4037 649 do_tag((int)size);
coleenp@4037 650 while (size > 0) {
coleenp@4037 651 *(intptr_t*)start = nextPtr();
coleenp@4037 652 start += sizeof(intptr_t);
coleenp@4037 653 size -= sizeof(intptr_t);
coleenp@4037 654 }
coleenp@4037 655 }
coleenp@4037 656
coleenp@4037 657 bool reading() const { return true; }
coleenp@4037 658 };
coleenp@4037 659
coleenp@4037 660
coleenp@4037 661 // Save bounds of shared spaces mapped in.
coleenp@4037 662 static char* _ro_base = NULL;
coleenp@4037 663 static char* _rw_base = NULL;
coleenp@4037 664 static char* _md_base = NULL;
coleenp@4037 665 static char* _mc_base = NULL;
coleenp@4037 666
coleenp@4037 667 // Return true if given address is in the mapped shared space.
coleenp@4037 668 bool MetaspaceShared::is_in_shared_space(const void* p) {
coleenp@4037 669 if (_ro_base == NULL || _rw_base == NULL) {
coleenp@4037 670 return false;
coleenp@4037 671 } else {
coleenp@4037 672 return ((p > _ro_base && p < (_ro_base + SharedReadOnlySize)) ||
coleenp@4037 673 (p > _rw_base && p < (_rw_base + SharedReadWriteSize)));
coleenp@4037 674 }
coleenp@4037 675 }
coleenp@4037 676
coleenp@4037 677 void MetaspaceShared::print_shared_spaces() {
coleenp@4037 678 gclog_or_tty->print_cr("Shared Spaces:");
coleenp@4037 679 gclog_or_tty->print(" read-only " INTPTR_FORMAT "-" INTPTR_FORMAT,
coleenp@4037 680 _ro_base, _ro_base + SharedReadOnlySize);
coleenp@4037 681 gclog_or_tty->print(" read-write " INTPTR_FORMAT "-" INTPTR_FORMAT,
coleenp@4037 682 _rw_base, _rw_base + SharedReadWriteSize);
coleenp@4037 683 gclog_or_tty->cr();
coleenp@4037 684 gclog_or_tty->print(" misc-data " INTPTR_FORMAT "-" INTPTR_FORMAT,
coleenp@4037 685 _md_base, _md_base + SharedMiscDataSize);
coleenp@4037 686 gclog_or_tty->print(" misc-code " INTPTR_FORMAT "-" INTPTR_FORMAT,
coleenp@4037 687 _mc_base, _mc_base + SharedMiscCodeSize);
coleenp@4037 688 gclog_or_tty->cr();
coleenp@4037 689 }
coleenp@4037 690
coleenp@4037 691
coleenp@4037 692 // Map shared spaces at requested addresses and return if succeeded.
coleenp@4037 693 // Need to keep the bounds of the ro and rw space for the Metaspace::contains
coleenp@4037 694 // call, or is_in_shared_space.
coleenp@4037 695 bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
coleenp@4037 696 size_t image_alignment = mapinfo->alignment();
coleenp@4037 697
coleenp@4037 698 // Map in the shared memory and then map the regions on top of it
coleenp@4037 699 ReservedSpace shared_rs = mapinfo->reserve_shared_memory();
coleenp@4037 700 if (!shared_rs.is_reserved()) return false;
coleenp@4037 701
coleenp@4037 702 // Split reserved memory into pieces (windows needs this)
coleenp@4037 703 ReservedSpace ro_rs = shared_rs.first_part(SharedReadOnlySize);
coleenp@4037 704 ReservedSpace tmp_rs1 = shared_rs.last_part(SharedReadOnlySize);
coleenp@4037 705 ReservedSpace rw_rs = tmp_rs1.first_part(SharedReadWriteSize);
coleenp@4037 706 ReservedSpace tmp_rs2 = tmp_rs1.last_part(SharedReadWriteSize);
coleenp@4037 707 ReservedSpace md_rs = tmp_rs2.first_part(SharedMiscDataSize);
coleenp@4037 708 ReservedSpace mc_rs = tmp_rs2.last_part(SharedMiscDataSize);
coleenp@4037 709
coleenp@4037 710 // Map each shared region
coleenp@4037 711 if ((_ro_base = mapinfo->map_region(ro)) != NULL &&
coleenp@4037 712 (_rw_base = mapinfo->map_region(rw)) != NULL &&
coleenp@4037 713 (_md_base = mapinfo->map_region(md)) != NULL &&
coleenp@4037 714 (_mc_base = mapinfo->map_region(mc)) != NULL &&
coleenp@4037 715 (image_alignment == (size_t)max_alignment())) {
coleenp@4037 716 // Success (no need to do anything)
coleenp@4037 717 return true;
coleenp@4037 718 } else {
coleenp@4037 719 // If there was a failure in mapping any of the spaces, unmap the ones
coleenp@4037 720 // that succeeded
coleenp@4037 721 if (_ro_base != NULL) mapinfo->unmap_region(ro);
coleenp@4037 722 if (_rw_base != NULL) mapinfo->unmap_region(rw);
coleenp@4037 723 if (_md_base != NULL) mapinfo->unmap_region(md);
coleenp@4037 724 if (_mc_base != NULL) mapinfo->unmap_region(mc);
coleenp@4037 725 // Release the entire mapped region
coleenp@4037 726 shared_rs.release();
coleenp@4037 727 // If -Xshare:on is specified, print out the error message and exit VM,
coleenp@4037 728 // otherwise, set UseSharedSpaces to false and continue.
coleenp@4037 729 if (RequireSharedSpaces) {
coleenp@4037 730 vm_exit_during_initialization("Unable to use shared archive.", NULL);
coleenp@4037 731 } else {
coleenp@4037 732 FLAG_SET_DEFAULT(UseSharedSpaces, false);
coleenp@4037 733 }
coleenp@4037 734 return false;
coleenp@4037 735 }
coleenp@4037 736 }
coleenp@4037 737
coleenp@4037 738 // Read the miscellaneous data from the shared file, and
coleenp@4037 739 // serialize it out to its various destinations.
coleenp@4037 740
coleenp@4037 741 void MetaspaceShared::initialize_shared_spaces() {
coleenp@4037 742 FileMapInfo *mapinfo = FileMapInfo::current_info();
coleenp@4037 743
coleenp@4037 744 char* buffer = mapinfo->region_base(md);
coleenp@4037 745
coleenp@4037 746 // Skip over (reserve space for) a list of addresses of C++ vtables
coleenp@4037 747 // for Klass objects. They get filled in later.
coleenp@4037 748
coleenp@4037 749 void** vtbl_list = (void**)buffer;
coleenp@4037 750 buffer += MetaspaceShared::vtbl_list_size * sizeof(void*);
coleenp@4037 751 Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
coleenp@4037 752
coleenp@4037 753 // Skip over (reserve space for) dummy C++ vtables Klass objects.
coleenp@4037 754 // They are used as is.
coleenp@4037 755
coleenp@4037 756 intptr_t vtable_size = *(intptr_t*)buffer;
coleenp@4037 757 buffer += sizeof(intptr_t);
coleenp@4037 758 buffer += vtable_size;
coleenp@4037 759
coleenp@4037 760 // Create the symbol table using the bucket array at this spot in the
coleenp@4037 761 // misc data space. Since the symbol table is often modified, this
coleenp@4037 762 // region (of mapped pages) will be copy-on-write.
coleenp@4037 763
coleenp@4037 764 int symbolTableLen = *(intptr_t*)buffer;
coleenp@4037 765 buffer += sizeof(intptr_t);
coleenp@4037 766 int number_of_entries = *(intptr_t*)buffer;
coleenp@4037 767 buffer += sizeof(intptr_t);
coleenp@4037 768 SymbolTable::create_table((HashtableBucket<mtSymbol>*)buffer, symbolTableLen,
coleenp@4037 769 number_of_entries);
coleenp@4037 770 buffer += symbolTableLen;
coleenp@4037 771
coleenp@4037 772 // Create the shared dictionary using the bucket array at this spot in
coleenp@4037 773 // the misc data space. Since the shared dictionary table is never
coleenp@4037 774 // modified, this region (of mapped pages) will be (effectively, if
coleenp@4037 775 // not explicitly) read-only.
coleenp@4037 776
coleenp@4037 777 int sharedDictionaryLen = *(intptr_t*)buffer;
coleenp@4037 778 buffer += sizeof(intptr_t);
coleenp@4037 779 number_of_entries = *(intptr_t*)buffer;
coleenp@4037 780 buffer += sizeof(intptr_t);
coleenp@4037 781 SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer,
coleenp@4037 782 sharedDictionaryLen,
coleenp@4037 783 number_of_entries);
coleenp@4037 784 buffer += sharedDictionaryLen;
coleenp@4037 785
coleenp@4037 786 // Create the package info table using the bucket array at this spot in
coleenp@4037 787 // the misc data space. Since the package info table is never
coleenp@4037 788 // modified, this region (of mapped pages) will be (effectively, if
coleenp@4037 789 // not explicitly) read-only.
coleenp@4037 790
coleenp@4037 791 int pkgInfoLen = *(intptr_t*)buffer;
coleenp@4037 792 buffer += sizeof(intptr_t);
coleenp@4037 793 number_of_entries = *(intptr_t*)buffer;
coleenp@4037 794 buffer += sizeof(intptr_t);
coleenp@4037 795 ClassLoader::create_package_info_table((HashtableBucket<mtClass>*)buffer, pkgInfoLen,
coleenp@4037 796 number_of_entries);
coleenp@4037 797 buffer += pkgInfoLen;
coleenp@4037 798 ClassLoader::verify();
coleenp@4037 799
coleenp@4037 800 // The following data in the shared misc data region are the linked
coleenp@4037 801 // list elements (HashtableEntry objects) for the symbol table, string
coleenp@4037 802 // table, and shared dictionary. The heap objects refered to by the
coleenp@4037 803 // symbol table, string table, and shared dictionary are permanent and
coleenp@4037 804 // unmovable. Since new entries added to the string and symbol tables
coleenp@4037 805 // are always added at the beginning of the linked lists, THESE LINKED
coleenp@4037 806 // LIST ELEMENTS ARE READ-ONLY.
coleenp@4037 807
coleenp@4037 808 int len = *(intptr_t*)buffer; // skip over symbol table entries
coleenp@4037 809 buffer += sizeof(intptr_t);
coleenp@4037 810 buffer += len;
coleenp@4037 811
coleenp@4037 812 len = *(intptr_t*)buffer; // skip over shared dictionary entries
coleenp@4037 813 buffer += sizeof(intptr_t);
coleenp@4037 814 buffer += len;
coleenp@4037 815
coleenp@4037 816 len = *(intptr_t*)buffer; // skip over package info table entries
coleenp@4037 817 buffer += sizeof(intptr_t);
coleenp@4037 818 buffer += len;
coleenp@4037 819
coleenp@4037 820 len = *(intptr_t*)buffer; // skip over package info table char[] arrays.
coleenp@4037 821 buffer += sizeof(intptr_t);
coleenp@4037 822 buffer += len;
coleenp@4037 823
coleenp@4037 824 intptr_t* array = (intptr_t*)buffer;
coleenp@4037 825 ReadClosure rc(&array);
coleenp@4037 826 serialize(&rc);
coleenp@4037 827
coleenp@4037 828 // Close the mapinfo file
coleenp@4037 829 mapinfo->close();
coleenp@4037 830 }
coleenp@4037 831
coleenp@4037 832 // JVM/TI RedefineClasses() support:
coleenp@4037 833 bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
coleenp@4037 834 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
coleenp@4037 835
coleenp@4037 836 if (UseSharedSpaces) {
coleenp@4037 837 // remap the shared readonly space to shared readwrite, private
coleenp@4037 838 FileMapInfo* mapinfo = FileMapInfo::current_info();
coleenp@4037 839 if (!mapinfo->remap_shared_readonly_as_readwrite()) {
coleenp@4037 840 return false;
coleenp@4037 841 }
coleenp@4037 842 }
coleenp@4037 843 return true;
coleenp@4037 844 }

mercurial