Thu, 13 Jun 2013 22:02:40 -0700
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
Reviewed-by: dholmes, coleenp
Contributed-by: jeremymanson@google.com, calvin.cheung@oracle.com
coleenp@4037 | 1 | /* |
coleenp@4434 | 2 | * Copyright (c) 2012, 2013, 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 | |
coleenp@4037 | 46 | ReservedSpace* MetaspaceShared::_shared_rs = NULL; |
coleenp@4037 | 47 | |
coleenp@4037 | 48 | // Read/write a data stream for restoring/preserving metadata pointers and |
coleenp@4037 | 49 | // miscellaneous data from/to the shared archive file. |
coleenp@4037 | 50 | |
coleenp@4037 | 51 | void MetaspaceShared::serialize(SerializeClosure* soc) { |
coleenp@4037 | 52 | int tag = 0; |
coleenp@4037 | 53 | soc->do_tag(--tag); |
coleenp@4037 | 54 | |
coleenp@4037 | 55 | assert(!UseCompressedOops, "UseCompressedOops doesn't work with shared archive"); |
coleenp@4037 | 56 | // Verify the sizes of various metadata in the system. |
coleenp@4037 | 57 | soc->do_tag(sizeof(Method)); |
coleenp@4037 | 58 | soc->do_tag(sizeof(ConstMethod)); |
coleenp@4037 | 59 | soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE)); |
coleenp@4037 | 60 | soc->do_tag(sizeof(ConstantPool)); |
coleenp@4037 | 61 | soc->do_tag(sizeof(ConstantPoolCache)); |
coleenp@4037 | 62 | soc->do_tag(objArrayOopDesc::base_offset_in_bytes()); |
coleenp@4037 | 63 | soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE)); |
coleenp@4037 | 64 | soc->do_tag(sizeof(Symbol)); |
coleenp@4037 | 65 | |
coleenp@4037 | 66 | // Dump/restore miscellaneous metadata. |
coleenp@4037 | 67 | Universe::serialize(soc, true); |
coleenp@4037 | 68 | soc->do_tag(--tag); |
coleenp@4037 | 69 | |
coleenp@4037 | 70 | // Dump/restore references to commonly used names and signatures. |
coleenp@4037 | 71 | vmSymbols::serialize(soc); |
coleenp@4037 | 72 | soc->do_tag(--tag); |
coleenp@4037 | 73 | |
coleenp@4037 | 74 | soc->do_tag(666); |
coleenp@4037 | 75 | } |
coleenp@4037 | 76 | |
coleenp@4037 | 77 | |
coleenp@4037 | 78 | // CDS code for dumping shared archive. |
coleenp@4037 | 79 | |
coleenp@4037 | 80 | // Global object for holding classes that have been loaded. Since this |
coleenp@4037 | 81 | // is run at a safepoint just before exit, this is the entire set of classes. |
coleenp@4037 | 82 | static GrowableArray<Klass*>* _global_klass_objects; |
coleenp@4037 | 83 | static void collect_classes(Klass* k) { |
coleenp@4037 | 84 | _global_klass_objects->append_if_missing(k); |
coleenp@4037 | 85 | if (k->oop_is_instance()) { |
coleenp@4037 | 86 | // Add in the array classes too |
coleenp@4037 | 87 | InstanceKlass* ik = InstanceKlass::cast(k); |
coleenp@4037 | 88 | ik->array_klasses_do(collect_classes); |
coleenp@4037 | 89 | } |
coleenp@4037 | 90 | } |
coleenp@4037 | 91 | |
coleenp@4037 | 92 | static void remove_unshareable_in_classes() { |
coleenp@4037 | 93 | for (int i = 0; i < _global_klass_objects->length(); i++) { |
coleenp@4037 | 94 | Klass* k = _global_klass_objects->at(i); |
coleenp@4037 | 95 | k->remove_unshareable_info(); |
coleenp@4037 | 96 | } |
coleenp@4037 | 97 | } |
coleenp@4037 | 98 | |
coleenp@4037 | 99 | // Walk all methods in the class list and assign a fingerprint. |
coleenp@4037 | 100 | // so that this part of the ConstMethod* is read only. |
coleenp@4037 | 101 | static void calculate_fingerprints() { |
coleenp@4037 | 102 | for (int i = 0; i < _global_klass_objects->length(); i++) { |
coleenp@4037 | 103 | Klass* k = _global_klass_objects->at(i); |
coleenp@4037 | 104 | if (k->oop_is_instance()) { |
coleenp@4037 | 105 | InstanceKlass* ik = InstanceKlass::cast(k); |
coleenp@4037 | 106 | for (int i = 0; i < ik->methods()->length(); i++) { |
coleenp@4037 | 107 | ResourceMark rm; |
coleenp@4037 | 108 | Method* m = ik->methods()->at(i); |
coleenp@4037 | 109 | (new Fingerprinter(m))->fingerprint(); |
coleenp@4037 | 110 | } |
coleenp@4037 | 111 | } |
coleenp@4037 | 112 | } |
coleenp@4037 | 113 | } |
coleenp@4037 | 114 | |
coleenp@4037 | 115 | // Patch C++ vtable pointer in metadata. |
coleenp@4037 | 116 | |
coleenp@4037 | 117 | // Klass and other metadata objects contain references to c++ vtables in the |
coleenp@4037 | 118 | // JVM library. |
coleenp@4037 | 119 | // Fix them to point to our constructed vtables. However, don't iterate |
coleenp@4037 | 120 | // across the space while doing this, as that causes the vtables to be |
coleenp@4037 | 121 | // patched, undoing our useful work. Instead, iterate to make a list, |
coleenp@4037 | 122 | // then use the list to do the fixing. |
coleenp@4037 | 123 | // |
coleenp@4037 | 124 | // Our constructed vtables: |
coleenp@4037 | 125 | // Dump time: |
coleenp@4037 | 126 | // 1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs |
coleenp@4037 | 127 | // 2. generate_vtable_methods: create jump table, appended to above vtbl_list |
coleenp@4037 | 128 | // 3. patch_klass_vtables: for Klass list, patch the vtable entry in klass and |
coleenp@4037 | 129 | // associated metadata to point to jump table rather than to current vtbl |
coleenp@4037 | 130 | // Table layout: NOTE FIXED SIZE |
coleenp@4037 | 131 | // 1. vtbl pointers |
coleenp@4037 | 132 | // 2. #Klass X #virtual methods per Klass |
coleenp@4037 | 133 | // 1 entry for each, in the order: |
coleenp@4037 | 134 | // Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry |
coleenp@4037 | 135 | // Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry |
coleenp@4037 | 136 | // ... |
coleenp@4037 | 137 | // Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry, |
coleenp@4037 | 138 | // ... Klass<vtbl_list_size>:method<num_virtuals> entry |
coleenp@4037 | 139 | // Sample entry: (Sparc): |
coleenp@4037 | 140 | // save(sp, -256, sp) |
coleenp@4037 | 141 | // ba,pt common_code |
coleenp@4037 | 142 | // mov XXX, %L0 %L0 gets: Klass index <<8 + method index (note: max method index 255) |
coleenp@4037 | 143 | // |
coleenp@4037 | 144 | // Restore time: |
coleenp@4037 | 145 | // 1. initialize_shared_space: reserve space for table |
coleenp@4037 | 146 | // 2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text |
coleenp@4037 | 147 | // |
coleenp@4037 | 148 | // Execution time: |
coleenp@4037 | 149 | // First virtual method call for any object of these metadata types: |
coleenp@4045 | 150 | // 1. object->klass |
coleenp@4045 | 151 | // 2. vtable entry for that klass points to the jump table entries |
coleenp@4045 | 152 | // 3. branches to common_code with %O0/klass, %L0: Klass index <<8 + method index |
coleenp@4037 | 153 | // 4. common_code: |
coleenp@4037 | 154 | // Get address of new vtbl pointer for this Klass from updated table |
coleenp@4037 | 155 | // Update new vtbl pointer in the Klass: future virtual calls go direct |
coleenp@4037 | 156 | // Jump to method, using new vtbl pointer and method index |
coleenp@4037 | 157 | |
coleenp@4037 | 158 | |
coleenp@4037 | 159 | static void* find_matching_vtbl_ptr(void** vtbl_list, void* new_vtable_start, void* obj) { |
coleenp@4037 | 160 | void* old_vtbl_ptr = *(void**)obj; |
coleenp@4037 | 161 | for (int i = 0; i < MetaspaceShared::vtbl_list_size; i++) { |
coleenp@4037 | 162 | if (vtbl_list[i] == old_vtbl_ptr) { |
coleenp@4037 | 163 | return (void**)new_vtable_start + i * MetaspaceShared::num_virtuals; |
coleenp@4037 | 164 | } |
coleenp@4037 | 165 | } |
coleenp@4037 | 166 | ShouldNotReachHere(); |
coleenp@4037 | 167 | return NULL; |
coleenp@4037 | 168 | } |
coleenp@4037 | 169 | |
coleenp@4037 | 170 | // Assumes the vtable is in first slot in object. |
coleenp@4037 | 171 | static void patch_klass_vtables(void** vtbl_list, void* new_vtable_start) { |
coleenp@4037 | 172 | int n = _global_klass_objects->length(); |
coleenp@4037 | 173 | for (int i = 0; i < n; i++) { |
coleenp@4037 | 174 | Klass* obj = _global_klass_objects->at(i); |
coleenp@4037 | 175 | // Note oop_is_instance() is a virtual call. After patching vtables |
coleenp@4037 | 176 | // all virtual calls on the dummy vtables will restore the original! |
coleenp@4037 | 177 | if (obj->oop_is_instance()) { |
coleenp@4037 | 178 | InstanceKlass* ik = InstanceKlass::cast(obj); |
coleenp@4037 | 179 | *(void**)ik = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, ik); |
coleenp@4037 | 180 | ConstantPool* cp = ik->constants(); |
coleenp@4037 | 181 | *(void**)cp = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, cp); |
coleenp@4037 | 182 | for (int j = 0; j < ik->methods()->length(); j++) { |
coleenp@4037 | 183 | Method* m = ik->methods()->at(j); |
coleenp@4037 | 184 | *(void**)m = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, m); |
coleenp@4037 | 185 | } |
coleenp@4037 | 186 | } else { |
coleenp@4037 | 187 | // Array klasses |
coleenp@4037 | 188 | Klass* k = obj; |
coleenp@4037 | 189 | *(void**)k = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, k); |
coleenp@4037 | 190 | } |
coleenp@4037 | 191 | } |
coleenp@4037 | 192 | } |
coleenp@4037 | 193 | |
coleenp@4037 | 194 | // Closure for serializing initialization data out to a data area to be |
coleenp@4037 | 195 | // written to the shared file. |
coleenp@4037 | 196 | |
coleenp@4037 | 197 | class WriteClosure : public SerializeClosure { |
coleenp@4037 | 198 | private: |
coleenp@4037 | 199 | intptr_t* top; |
coleenp@4037 | 200 | char* end; |
coleenp@4037 | 201 | |
coleenp@4037 | 202 | inline void check_space() { |
coleenp@4037 | 203 | if ((char*)top + sizeof(intptr_t) > end) { |
coleenp@4037 | 204 | report_out_of_shared_space(SharedMiscData); |
coleenp@4037 | 205 | } |
coleenp@4037 | 206 | } |
coleenp@4037 | 207 | |
coleenp@4037 | 208 | public: |
coleenp@4037 | 209 | WriteClosure(char* md_top, char* md_end) { |
coleenp@4037 | 210 | top = (intptr_t*)md_top; |
coleenp@4037 | 211 | end = md_end; |
coleenp@4037 | 212 | } |
coleenp@4037 | 213 | |
coleenp@4037 | 214 | char* get_top() { return (char*)top; } |
coleenp@4037 | 215 | |
coleenp@4037 | 216 | void do_ptr(void** p) { |
coleenp@4037 | 217 | check_space(); |
coleenp@4037 | 218 | *top = (intptr_t)*p; |
coleenp@4037 | 219 | ++top; |
coleenp@4037 | 220 | } |
coleenp@4037 | 221 | |
coleenp@4037 | 222 | void do_tag(int tag) { |
coleenp@4037 | 223 | check_space(); |
coleenp@4037 | 224 | *top = (intptr_t)tag; |
coleenp@4037 | 225 | ++top; |
coleenp@4037 | 226 | } |
coleenp@4037 | 227 | |
coleenp@4037 | 228 | void do_region(u_char* start, size_t size) { |
coleenp@4037 | 229 | if ((char*)top + size > end) { |
coleenp@4037 | 230 | report_out_of_shared_space(SharedMiscData); |
coleenp@4037 | 231 | } |
coleenp@4037 | 232 | assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment"); |
coleenp@4037 | 233 | assert(size % sizeof(intptr_t) == 0, "bad size"); |
coleenp@4037 | 234 | do_tag((int)size); |
coleenp@4037 | 235 | while (size > 0) { |
coleenp@4037 | 236 | *top = *(intptr_t*)start; |
coleenp@4037 | 237 | ++top; |
coleenp@4037 | 238 | start += sizeof(intptr_t); |
coleenp@4037 | 239 | size -= sizeof(intptr_t); |
coleenp@4037 | 240 | } |
coleenp@4037 | 241 | } |
coleenp@4037 | 242 | |
coleenp@4037 | 243 | bool reading() const { return false; } |
coleenp@4037 | 244 | }; |
coleenp@4037 | 245 | |
iklam@5208 | 246 | // This is for dumping detailed statistics for the allocations |
iklam@5208 | 247 | // in the shared spaces. |
iklam@5208 | 248 | class DumpAllocClosure : public Metaspace::AllocRecordClosure { |
iklam@5208 | 249 | public: |
iklam@5208 | 250 | |
iklam@5208 | 251 | // Here's poor man's enum inheritance |
iklam@5208 | 252 | #define SHAREDSPACE_OBJ_TYPES_DO(f) \ |
iklam@5208 | 253 | METASPACE_OBJ_TYPES_DO(f) \ |
iklam@5208 | 254 | f(SymbolHashentry) \ |
iklam@5208 | 255 | f(SymbolBuckets) \ |
iklam@5208 | 256 | f(Other) |
iklam@5208 | 257 | |
iklam@5208 | 258 | #define SHAREDSPACE_OBJ_TYPE_DECLARE(name) name ## Type, |
iklam@5208 | 259 | #define SHAREDSPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name; |
iklam@5208 | 260 | |
iklam@5208 | 261 | enum Type { |
iklam@5208 | 262 | // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc |
iklam@5208 | 263 | SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_DECLARE) |
iklam@5208 | 264 | _number_of_types |
iklam@5208 | 265 | }; |
iklam@5208 | 266 | |
iklam@5208 | 267 | static const char * type_name(Type type) { |
iklam@5208 | 268 | switch(type) { |
iklam@5208 | 269 | SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_NAME_CASE) |
iklam@5208 | 270 | default: |
iklam@5208 | 271 | ShouldNotReachHere(); |
iklam@5208 | 272 | return NULL; |
iklam@5208 | 273 | } |
iklam@5208 | 274 | } |
iklam@5208 | 275 | |
iklam@5208 | 276 | public: |
iklam@5208 | 277 | enum { |
iklam@5208 | 278 | RO = 0, |
iklam@5208 | 279 | RW = 1 |
iklam@5208 | 280 | }; |
iklam@5208 | 281 | |
iklam@5208 | 282 | int _counts[2][_number_of_types]; |
iklam@5208 | 283 | int _bytes [2][_number_of_types]; |
iklam@5208 | 284 | int _which; |
iklam@5208 | 285 | |
iklam@5208 | 286 | DumpAllocClosure() { |
iklam@5208 | 287 | memset(_counts, 0, sizeof(_counts)); |
iklam@5208 | 288 | memset(_bytes, 0, sizeof(_bytes)); |
iklam@5208 | 289 | }; |
iklam@5208 | 290 | |
iklam@5208 | 291 | void iterate_metaspace(Metaspace* space, int which) { |
iklam@5208 | 292 | assert(which == RO || which == RW, "sanity"); |
iklam@5208 | 293 | _which = which; |
iklam@5208 | 294 | space->iterate(this); |
iklam@5208 | 295 | } |
iklam@5208 | 296 | |
iklam@5208 | 297 | virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) { |
iklam@5208 | 298 | assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity"); |
iklam@5208 | 299 | _counts[_which][type] ++; |
iklam@5208 | 300 | _bytes [_which][type] += byte_size; |
iklam@5208 | 301 | } |
iklam@5208 | 302 | |
iklam@5208 | 303 | void dump_stats(int ro_all, int rw_all, int md_all, int mc_all); |
iklam@5208 | 304 | }; |
iklam@5208 | 305 | |
iklam@5208 | 306 | void DumpAllocClosure::dump_stats(int ro_all, int rw_all, int md_all, int mc_all) { |
iklam@5208 | 307 | rw_all += (md_all + mc_all); // md and mc are all mapped Read/Write |
iklam@5208 | 308 | int other_bytes = md_all + mc_all; |
iklam@5208 | 309 | |
iklam@5208 | 310 | // Calculate size of data that was not allocated by Metaspace::allocate() |
iklam@5208 | 311 | int symbol_count = _counts[RO][MetaspaceObj::SymbolType]; |
iklam@5208 | 312 | int symhash_bytes = symbol_count * sizeof (HashtableEntry<Symbol*, mtSymbol>); |
iklam@5208 | 313 | int symbuck_count = SymbolTable::the_table()->table_size(); |
iklam@5208 | 314 | int symbuck_bytes = symbuck_count * sizeof(HashtableBucket<mtSymbol>); |
iklam@5208 | 315 | |
iklam@5208 | 316 | _counts[RW][SymbolHashentryType] = symbol_count; |
iklam@5208 | 317 | _bytes [RW][SymbolHashentryType] = symhash_bytes; |
iklam@5208 | 318 | other_bytes -= symhash_bytes; |
iklam@5208 | 319 | |
iklam@5208 | 320 | _counts[RW][SymbolBucketsType] = symbuck_count; |
iklam@5208 | 321 | _bytes [RW][SymbolBucketsType] = symbuck_bytes; |
iklam@5208 | 322 | other_bytes -= symbuck_bytes; |
iklam@5208 | 323 | |
iklam@5208 | 324 | // TODO: count things like dictionary, vtable, etc |
iklam@5208 | 325 | _bytes[RW][OtherType] = other_bytes; |
iklam@5208 | 326 | |
iklam@5208 | 327 | // prevent divide-by-zero |
iklam@5208 | 328 | if (ro_all < 1) { |
iklam@5208 | 329 | ro_all = 1; |
iklam@5208 | 330 | } |
iklam@5208 | 331 | if (rw_all < 1) { |
iklam@5208 | 332 | rw_all = 1; |
iklam@5208 | 333 | } |
iklam@5208 | 334 | |
iklam@5208 | 335 | int all_ro_count = 0; |
iklam@5208 | 336 | int all_ro_bytes = 0; |
iklam@5208 | 337 | int all_rw_count = 0; |
iklam@5208 | 338 | int all_rw_bytes = 0; |
iklam@5208 | 339 | |
iklam@5208 | 340 | const char *fmt = "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f"; |
iklam@5208 | 341 | const char *sep = "--------------------+---------------------------+---------------------------+--------------------------"; |
iklam@5208 | 342 | const char *hdr = " ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %"; |
iklam@5208 | 343 | |
iklam@5208 | 344 | tty->print_cr("Detailed metadata info (rw includes md and mc):"); |
iklam@5208 | 345 | tty->print_cr(hdr); |
iklam@5208 | 346 | tty->print_cr(sep); |
iklam@5208 | 347 | for (int type = 0; type < int(_number_of_types); type ++) { |
iklam@5208 | 348 | const char *name = type_name((Type)type); |
iklam@5208 | 349 | int ro_count = _counts[RO][type]; |
iklam@5208 | 350 | int ro_bytes = _bytes [RO][type]; |
iklam@5208 | 351 | int rw_count = _counts[RW][type]; |
iklam@5208 | 352 | int rw_bytes = _bytes [RW][type]; |
iklam@5208 | 353 | int count = ro_count + rw_count; |
iklam@5208 | 354 | int bytes = ro_bytes + rw_bytes; |
iklam@5208 | 355 | |
iklam@5208 | 356 | double ro_perc = 100.0 * double(ro_bytes) / double(ro_all); |
iklam@5208 | 357 | double rw_perc = 100.0 * double(rw_bytes) / double(rw_all); |
iklam@5208 | 358 | double perc = 100.0 * double(bytes) / double(ro_all + rw_all); |
iklam@5208 | 359 | |
iklam@5208 | 360 | tty->print_cr(fmt, name, |
iklam@5208 | 361 | ro_count, ro_bytes, ro_perc, |
iklam@5208 | 362 | rw_count, rw_bytes, rw_perc, |
iklam@5208 | 363 | count, bytes, perc); |
iklam@5208 | 364 | |
iklam@5208 | 365 | all_ro_count += ro_count; |
iklam@5208 | 366 | all_ro_bytes += ro_bytes; |
iklam@5208 | 367 | all_rw_count += rw_count; |
iklam@5208 | 368 | all_rw_bytes += rw_bytes; |
iklam@5208 | 369 | } |
iklam@5208 | 370 | |
iklam@5208 | 371 | int all_count = all_ro_count + all_rw_count; |
iklam@5208 | 372 | int all_bytes = all_ro_bytes + all_rw_bytes; |
iklam@5208 | 373 | |
iklam@5208 | 374 | double all_ro_perc = 100.0 * double(all_ro_bytes) / double(ro_all); |
iklam@5208 | 375 | double all_rw_perc = 100.0 * double(all_rw_bytes) / double(rw_all); |
iklam@5208 | 376 | double all_perc = 100.0 * double(all_bytes) / double(ro_all + rw_all); |
iklam@5208 | 377 | |
iklam@5208 | 378 | tty->print_cr(sep); |
iklam@5208 | 379 | tty->print_cr(fmt, "Total", |
iklam@5208 | 380 | all_ro_count, all_ro_bytes, all_ro_perc, |
iklam@5208 | 381 | all_rw_count, all_rw_bytes, all_rw_perc, |
iklam@5208 | 382 | all_count, all_bytes, all_perc); |
iklam@5208 | 383 | |
iklam@5208 | 384 | assert(all_ro_bytes == ro_all, "everything should have been counted"); |
iklam@5208 | 385 | assert(all_rw_bytes == rw_all, "everything should have been counted"); |
iklam@5208 | 386 | } |
coleenp@4037 | 387 | |
coleenp@4037 | 388 | // Populate the shared space. |
coleenp@4037 | 389 | |
coleenp@4037 | 390 | class VM_PopulateDumpSharedSpace: public VM_Operation { |
coleenp@4037 | 391 | private: |
coleenp@4037 | 392 | ClassLoaderData* _loader_data; |
coleenp@4037 | 393 | GrowableArray<Klass*> *_class_promote_order; |
coleenp@4037 | 394 | VirtualSpace _md_vs; |
coleenp@4037 | 395 | VirtualSpace _mc_vs; |
coleenp@4037 | 396 | |
coleenp@4037 | 397 | public: |
coleenp@4037 | 398 | VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data, |
coleenp@4037 | 399 | GrowableArray<Klass*> *class_promote_order) : |
coleenp@4037 | 400 | _loader_data(loader_data) { |
coleenp@4037 | 401 | |
coleenp@4037 | 402 | // Split up and initialize the misc code and data spaces |
coleenp@4037 | 403 | ReservedSpace* shared_rs = MetaspaceShared::shared_rs(); |
coleenp@4037 | 404 | int metadata_size = SharedReadOnlySize+SharedReadWriteSize; |
coleenp@4037 | 405 | ReservedSpace shared_ro_rw = shared_rs->first_part(metadata_size); |
coleenp@4037 | 406 | ReservedSpace misc_section = shared_rs->last_part(metadata_size); |
coleenp@4037 | 407 | |
coleenp@4037 | 408 | // Now split into misc sections. |
coleenp@4037 | 409 | ReservedSpace md_rs = misc_section.first_part(SharedMiscDataSize); |
coleenp@4037 | 410 | ReservedSpace mc_rs = misc_section.last_part(SharedMiscDataSize); |
coleenp@4037 | 411 | _md_vs.initialize(md_rs, SharedMiscDataSize); |
coleenp@4037 | 412 | _mc_vs.initialize(mc_rs, SharedMiscCodeSize); |
coleenp@4037 | 413 | _class_promote_order = class_promote_order; |
coleenp@4037 | 414 | } |
coleenp@4037 | 415 | |
coleenp@4037 | 416 | VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; } |
coleenp@4037 | 417 | void doit(); // outline because gdb sucks |
coleenp@4037 | 418 | }; // class VM_PopulateDumpSharedSpace |
coleenp@4037 | 419 | |
coleenp@4037 | 420 | |
coleenp@4037 | 421 | void VM_PopulateDumpSharedSpace::doit() { |
coleenp@4037 | 422 | Thread* THREAD = VMThread::vm_thread(); |
coleenp@4037 | 423 | NOT_PRODUCT(SystemDictionary::verify();) |
coleenp@4037 | 424 | // The following guarantee is meant to ensure that no loader constraints |
coleenp@4037 | 425 | // exist yet, since the constraints table is not shared. This becomes |
coleenp@4037 | 426 | // more important now that we don't re-initialize vtables/itables for |
coleenp@4037 | 427 | // shared classes at runtime, where constraints were previously created. |
coleenp@4037 | 428 | guarantee(SystemDictionary::constraints()->number_of_entries() == 0, |
coleenp@4037 | 429 | "loader constraints are not saved"); |
coleenp@4037 | 430 | guarantee(SystemDictionary::placeholders()->number_of_entries() == 0, |
coleenp@4037 | 431 | "placeholders are not saved"); |
coleenp@4037 | 432 | // Revisit and implement this if we prelink method handle call sites: |
coleenp@4037 | 433 | guarantee(SystemDictionary::invoke_method_table() == NULL || |
coleenp@4037 | 434 | SystemDictionary::invoke_method_table()->number_of_entries() == 0, |
coleenp@4037 | 435 | "invoke method table is not saved"); |
coleenp@4037 | 436 | |
coleenp@4037 | 437 | // At this point, many classes have been loaded. |
coleenp@4037 | 438 | // Gather systemDictionary classes in a global array and do everything to |
coleenp@4037 | 439 | // that so we don't have to walk the SystemDictionary again. |
coleenp@4037 | 440 | _global_klass_objects = new GrowableArray<Klass*>(1000); |
coleenp@4037 | 441 | Universe::basic_type_classes_do(collect_classes); |
coleenp@4037 | 442 | SystemDictionary::classes_do(collect_classes); |
coleenp@4037 | 443 | |
coleenp@4037 | 444 | tty->print_cr("Number of classes %d", _global_klass_objects->length()); |
coleenp@4037 | 445 | |
coleenp@4037 | 446 | // Update all the fingerprints in the shared methods. |
coleenp@4037 | 447 | tty->print("Calculating fingerprints ... "); |
coleenp@4037 | 448 | calculate_fingerprints(); |
coleenp@4037 | 449 | tty->print_cr("done. "); |
coleenp@4037 | 450 | |
coleenp@4037 | 451 | // Remove all references outside the metadata |
coleenp@4037 | 452 | tty->print("Removing unshareable information ... "); |
coleenp@4037 | 453 | remove_unshareable_in_classes(); |
coleenp@4037 | 454 | tty->print_cr("done. "); |
coleenp@4037 | 455 | |
coleenp@4037 | 456 | // Set up the share data and shared code segments. |
coleenp@4037 | 457 | char* md_low = _md_vs.low(); |
coleenp@4037 | 458 | char* md_top = md_low; |
coleenp@4037 | 459 | char* md_end = _md_vs.high(); |
coleenp@4037 | 460 | char* mc_low = _mc_vs.low(); |
coleenp@4037 | 461 | char* mc_top = mc_low; |
coleenp@4037 | 462 | char* mc_end = _mc_vs.high(); |
coleenp@4037 | 463 | |
coleenp@4037 | 464 | // Reserve space for the list of Klass*s whose vtables are used |
coleenp@4037 | 465 | // for patching others as needed. |
coleenp@4037 | 466 | |
coleenp@4037 | 467 | void** vtbl_list = (void**)md_top; |
coleenp@4037 | 468 | int vtbl_list_size = MetaspaceShared::vtbl_list_size; |
coleenp@4037 | 469 | Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size); |
coleenp@4037 | 470 | |
coleenp@4037 | 471 | md_top += vtbl_list_size * sizeof(void*); |
coleenp@4037 | 472 | void* vtable = md_top; |
coleenp@4037 | 473 | |
coleenp@4037 | 474 | // Reserve space for a new dummy vtable for klass objects in the |
coleenp@4037 | 475 | // heap. Generate self-patching vtable entries. |
coleenp@4037 | 476 | |
coleenp@4037 | 477 | MetaspaceShared::generate_vtable_methods(vtbl_list, &vtable, |
coleenp@4037 | 478 | &md_top, md_end, |
coleenp@4037 | 479 | &mc_top, mc_end); |
coleenp@4037 | 480 | |
coleenp@4037 | 481 | // Reorder the system dictionary. (Moving the symbols affects |
coleenp@4037 | 482 | // how the hash table indices are calculated.) |
coleenp@4037 | 483 | // Not doing this either. |
coleenp@4037 | 484 | |
coleenp@4037 | 485 | SystemDictionary::reorder_dictionary(); |
coleenp@4037 | 486 | |
coleenp@4037 | 487 | NOT_PRODUCT(SystemDictionary::verify();) |
coleenp@4037 | 488 | |
coleenp@4037 | 489 | // Copy the the symbol table, and the system dictionary to the shared |
coleenp@4037 | 490 | // space in usable form. Copy the hastable |
coleenp@4037 | 491 | // buckets first [read-write], then copy the linked lists of entries |
coleenp@4037 | 492 | // [read-only]. |
coleenp@4037 | 493 | |
coleenp@4037 | 494 | SymbolTable::reverse(md_top); |
coleenp@4037 | 495 | NOT_PRODUCT(SymbolTable::verify()); |
coleenp@4037 | 496 | SymbolTable::copy_buckets(&md_top, md_end); |
coleenp@4037 | 497 | |
coleenp@4037 | 498 | SystemDictionary::reverse(); |
coleenp@4037 | 499 | SystemDictionary::copy_buckets(&md_top, md_end); |
coleenp@4037 | 500 | |
coleenp@4037 | 501 | ClassLoader::verify(); |
coleenp@4037 | 502 | ClassLoader::copy_package_info_buckets(&md_top, md_end); |
coleenp@4037 | 503 | ClassLoader::verify(); |
coleenp@4037 | 504 | |
coleenp@4037 | 505 | SymbolTable::copy_table(&md_top, md_end); |
coleenp@4037 | 506 | SystemDictionary::copy_table(&md_top, md_end); |
coleenp@4037 | 507 | ClassLoader::verify(); |
coleenp@4037 | 508 | ClassLoader::copy_package_info_table(&md_top, md_end); |
coleenp@4037 | 509 | ClassLoader::verify(); |
coleenp@4037 | 510 | |
coleenp@4037 | 511 | // Write the other data to the output array. |
coleenp@4037 | 512 | WriteClosure wc(md_top, md_end); |
coleenp@4037 | 513 | MetaspaceShared::serialize(&wc); |
coleenp@4037 | 514 | md_top = wc.get_top(); |
coleenp@4037 | 515 | |
coleenp@4037 | 516 | // Print shared spaces all the time |
coleenp@4434 | 517 | const char* fmt = "%s space: %9d [ %4.1f%% of total] out of %9d bytes [%4.1f%% used] at " PTR_FORMAT; |
coleenp@4037 | 518 | Metaspace* ro_space = _loader_data->ro_metaspace(); |
coleenp@4037 | 519 | Metaspace* rw_space = _loader_data->rw_metaspace(); |
coleenp@4434 | 520 | |
coleenp@4434 | 521 | // Allocated size of each space (may not be all occupied) |
jmasa@5015 | 522 | const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType); |
jmasa@5015 | 523 | const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType); |
coleenp@4434 | 524 | const size_t md_alloced = md_end-md_low; |
coleenp@4434 | 525 | const size_t mc_alloced = mc_end-mc_low; |
coleenp@4434 | 526 | const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced; |
coleenp@4434 | 527 | |
coleenp@4434 | 528 | // Occupied size of each space. |
jmasa@5015 | 529 | const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType); |
jmasa@5015 | 530 | const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType); |
coleenp@4434 | 531 | const size_t md_bytes = size_t(md_top - md_low); |
coleenp@4434 | 532 | const size_t mc_bytes = size_t(mc_top - mc_low); |
coleenp@4434 | 533 | |
coleenp@4434 | 534 | // Percent of total size |
coleenp@4434 | 535 | const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes; |
coleenp@4434 | 536 | const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0; |
coleenp@4434 | 537 | const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0; |
coleenp@4434 | 538 | const double md_t_perc = md_bytes / double(total_bytes) * 100.0; |
coleenp@4434 | 539 | const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0; |
coleenp@4434 | 540 | |
coleenp@4434 | 541 | // Percent of fullness of each space |
coleenp@4434 | 542 | const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0; |
coleenp@4434 | 543 | const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0; |
coleenp@4434 | 544 | const double md_u_perc = md_bytes / double(md_alloced) * 100.0; |
coleenp@4434 | 545 | const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0; |
coleenp@4434 | 546 | const double total_u_perc = total_bytes / double(total_alloced) * 100.0; |
coleenp@4434 | 547 | |
coleenp@4434 | 548 | tty->print_cr(fmt, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, ro_space->bottom()); |
coleenp@4434 | 549 | tty->print_cr(fmt, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, rw_space->bottom()); |
coleenp@4434 | 550 | tty->print_cr(fmt, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, md_low); |
coleenp@4434 | 551 | tty->print_cr(fmt, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, mc_low); |
coleenp@4434 | 552 | tty->print_cr("total : %9d [100.0%% of total] out of %9d bytes [%4.1f%% used]", |
coleenp@4434 | 553 | total_bytes, total_alloced, total_u_perc); |
coleenp@4037 | 554 | |
coleenp@4037 | 555 | // Update the vtable pointers in all of the Klass objects in the |
coleenp@4037 | 556 | // heap. They should point to newly generated vtable. |
coleenp@4037 | 557 | patch_klass_vtables(vtbl_list, vtable); |
coleenp@4037 | 558 | |
coleenp@4037 | 559 | // dunno what this is for. |
coleenp@4037 | 560 | char* saved_vtbl = (char*)os::malloc(vtbl_list_size * sizeof(void*), mtClass); |
coleenp@4037 | 561 | memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*)); |
coleenp@4037 | 562 | memset(vtbl_list, 0, vtbl_list_size * sizeof(void*)); |
coleenp@4037 | 563 | |
coleenp@4037 | 564 | // Create and write the archive file that maps the shared spaces. |
coleenp@4037 | 565 | |
coleenp@4037 | 566 | FileMapInfo* mapinfo = new FileMapInfo(); |
coleenp@4037 | 567 | mapinfo->populate_header(MetaspaceShared::max_alignment()); |
coleenp@4037 | 568 | |
coleenp@4037 | 569 | // Pass 1 - update file offsets in header. |
coleenp@4037 | 570 | mapinfo->write_header(); |
coleenp@4037 | 571 | mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true); |
coleenp@4037 | 572 | mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false); |
coleenp@4037 | 573 | mapinfo->write_region(MetaspaceShared::md, _md_vs.low(), |
coleenp@4037 | 574 | pointer_delta(md_top, _md_vs.low(), sizeof(char)), |
coleenp@4037 | 575 | SharedMiscDataSize, |
coleenp@4037 | 576 | false, false); |
coleenp@4037 | 577 | mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(), |
coleenp@4037 | 578 | pointer_delta(mc_top, _mc_vs.low(), sizeof(char)), |
coleenp@4037 | 579 | SharedMiscCodeSize, |
coleenp@4037 | 580 | true, true); |
coleenp@4037 | 581 | |
coleenp@4037 | 582 | // Pass 2 - write data. |
coleenp@4037 | 583 | mapinfo->open_for_write(); |
coleenp@4037 | 584 | mapinfo->write_header(); |
coleenp@4037 | 585 | mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true); |
coleenp@4037 | 586 | mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false); |
coleenp@4037 | 587 | mapinfo->write_region(MetaspaceShared::md, _md_vs.low(), |
coleenp@4037 | 588 | pointer_delta(md_top, _md_vs.low(), sizeof(char)), |
coleenp@4037 | 589 | SharedMiscDataSize, |
coleenp@4037 | 590 | false, false); |
coleenp@4037 | 591 | mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(), |
coleenp@4037 | 592 | pointer_delta(mc_top, _mc_vs.low(), sizeof(char)), |
coleenp@4037 | 593 | SharedMiscCodeSize, |
coleenp@4037 | 594 | true, true); |
coleenp@4037 | 595 | mapinfo->close(); |
coleenp@4037 | 596 | |
coleenp@4037 | 597 | memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*)); |
iklam@5208 | 598 | |
iklam@5208 | 599 | if (PrintSharedSpaces) { |
iklam@5208 | 600 | DumpAllocClosure dac; |
iklam@5208 | 601 | dac.iterate_metaspace(_loader_data->ro_metaspace(), DumpAllocClosure::RO); |
iklam@5208 | 602 | dac.iterate_metaspace(_loader_data->rw_metaspace(), DumpAllocClosure::RW); |
iklam@5208 | 603 | |
iklam@5208 | 604 | dac.dump_stats(int(ro_bytes), int(rw_bytes), int(md_bytes), int(mc_bytes)); |
iklam@5208 | 605 | } |
coleenp@4037 | 606 | } |
coleenp@4037 | 607 | |
coleenp@4037 | 608 | static void link_shared_classes(Klass* obj, TRAPS) { |
hseigel@4278 | 609 | Klass* k = obj; |
coleenp@4037 | 610 | if (k->oop_is_instance()) { |
coleenp@4037 | 611 | InstanceKlass* ik = (InstanceKlass*) k; |
coleenp@4037 | 612 | // Link the class to cause the bytecodes to be rewritten and the |
coleenp@4037 | 613 | // cpcache to be created. |
coleenp@4037 | 614 | if (ik->init_state() < InstanceKlass::linked) { |
coleenp@4037 | 615 | ik->link_class(THREAD); |
coleenp@4037 | 616 | guarantee(!HAS_PENDING_EXCEPTION, "exception in class rewriting"); |
coleenp@4037 | 617 | } |
coleenp@4037 | 618 | } |
coleenp@4037 | 619 | } |
coleenp@4037 | 620 | |
coleenp@4037 | 621 | |
coleenp@4037 | 622 | // Support for a simple checksum of the contents of the class list |
coleenp@4037 | 623 | // file to prevent trivial tampering. The algorithm matches that in |
coleenp@4037 | 624 | // the MakeClassList program used by the J2SE build process. |
coleenp@4037 | 625 | #define JSUM_SEED ((jlong)CONST64(0xcafebabebabecafe)) |
coleenp@4037 | 626 | static jlong |
coleenp@4037 | 627 | jsum(jlong start, const char *buf, const int len) |
coleenp@4037 | 628 | { |
coleenp@4037 | 629 | jlong h = start; |
coleenp@4037 | 630 | char *p = (char *)buf, *e = p + len; |
coleenp@4037 | 631 | while (p < e) { |
coleenp@4037 | 632 | char c = *p++; |
coleenp@4037 | 633 | if (c <= ' ') { |
coleenp@4037 | 634 | /* Skip spaces and control characters */ |
coleenp@4037 | 635 | continue; |
coleenp@4037 | 636 | } |
coleenp@4037 | 637 | h = 31 * h + c; |
coleenp@4037 | 638 | } |
coleenp@4037 | 639 | return h; |
coleenp@4037 | 640 | } |
coleenp@4037 | 641 | |
coleenp@4037 | 642 | // Preload classes from a list, populate the shared spaces and dump to a |
coleenp@4037 | 643 | // file. |
coleenp@4037 | 644 | void MetaspaceShared::preload_and_dump(TRAPS) { |
coleenp@4037 | 645 | TraceTime timer("Dump Shared Spaces", TraceStartupTime); |
coleenp@4037 | 646 | ResourceMark rm; |
coleenp@4037 | 647 | |
coleenp@4037 | 648 | // Lock out GC - is it necessary? I don't think we care. |
coleenp@4037 | 649 | No_GC_Verifier no_gc; |
coleenp@4037 | 650 | |
coleenp@4037 | 651 | // Preload classes to be shared. |
coleenp@4037 | 652 | // Should use some os:: method rather than fopen() here. aB. |
coleenp@4037 | 653 | // Construct the path to the class list (in jre/lib) |
coleenp@4037 | 654 | // Walk up two directories from the location of the VM and |
coleenp@4037 | 655 | // optionally tack on "lib" (depending on platform) |
coleenp@4037 | 656 | char class_list_path[JVM_MAXPATHLEN]; |
coleenp@4037 | 657 | os::jvm_path(class_list_path, sizeof(class_list_path)); |
coleenp@4037 | 658 | for (int i = 0; i < 3; i++) { |
coleenp@4037 | 659 | char *end = strrchr(class_list_path, *os::file_separator()); |
coleenp@4037 | 660 | if (end != NULL) *end = '\0'; |
coleenp@4037 | 661 | } |
coleenp@4037 | 662 | int class_list_path_len = (int)strlen(class_list_path); |
coleenp@4037 | 663 | if (class_list_path_len >= 3) { |
coleenp@4037 | 664 | if (strcmp(class_list_path + class_list_path_len - 3, "lib") != 0) { |
coleenp@4037 | 665 | strcat(class_list_path, os::file_separator()); |
coleenp@4037 | 666 | strcat(class_list_path, "lib"); |
coleenp@4037 | 667 | } |
coleenp@4037 | 668 | } |
coleenp@4037 | 669 | strcat(class_list_path, os::file_separator()); |
coleenp@4037 | 670 | strcat(class_list_path, "classlist"); |
coleenp@4037 | 671 | |
coleenp@4037 | 672 | FILE* file = fopen(class_list_path, "r"); |
coleenp@4037 | 673 | if (file != NULL) { |
coleenp@4037 | 674 | jlong computed_jsum = JSUM_SEED; |
coleenp@4037 | 675 | jlong file_jsum = 0; |
coleenp@4037 | 676 | |
coleenp@4037 | 677 | char class_name[256]; |
coleenp@4037 | 678 | int class_count = 0; |
coleenp@4037 | 679 | GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>(); |
coleenp@4037 | 680 | |
coleenp@4037 | 681 | // sun.io.Converters |
coleenp@4037 | 682 | static const char obj_array_sig[] = "[[Ljava/lang/Object;"; |
coleenp@4037 | 683 | SymbolTable::new_permanent_symbol(obj_array_sig, THREAD); |
coleenp@4037 | 684 | |
coleenp@4037 | 685 | // java.util.HashMap |
coleenp@4037 | 686 | static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;"; |
coleenp@4037 | 687 | SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD); |
coleenp@4037 | 688 | |
coleenp@4037 | 689 | tty->print("Loading classes to share ... "); |
coleenp@4037 | 690 | while ((fgets(class_name, sizeof class_name, file)) != NULL) { |
coleenp@4037 | 691 | if (*class_name == '#') { |
coleenp@4037 | 692 | jint fsh, fsl; |
coleenp@4037 | 693 | if (sscanf(class_name, "# %8x%8x\n", &fsh, &fsl) == 2) { |
coleenp@4037 | 694 | file_jsum = ((jlong)(fsh) << 32) | (fsl & 0xffffffff); |
coleenp@4037 | 695 | } |
coleenp@4037 | 696 | |
coleenp@4037 | 697 | continue; |
coleenp@4037 | 698 | } |
coleenp@4037 | 699 | // Remove trailing newline |
coleenp@4037 | 700 | size_t name_len = strlen(class_name); |
coleenp@4037 | 701 | class_name[name_len-1] = '\0'; |
coleenp@4037 | 702 | |
coleenp@4037 | 703 | computed_jsum = jsum(computed_jsum, class_name, (const int)name_len - 1); |
coleenp@4037 | 704 | |
coleenp@4037 | 705 | // Got a class name - load it. |
coleenp@4037 | 706 | TempNewSymbol class_name_symbol = SymbolTable::new_permanent_symbol(class_name, THREAD); |
coleenp@4037 | 707 | guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); |
coleenp@4037 | 708 | Klass* klass = SystemDictionary::resolve_or_null(class_name_symbol, |
coleenp@4037 | 709 | THREAD); |
coleenp@4037 | 710 | guarantee(!HAS_PENDING_EXCEPTION, "Exception resolving a class."); |
coleenp@4037 | 711 | if (klass != NULL) { |
coleenp@4037 | 712 | if (PrintSharedSpaces && Verbose && WizardMode) { |
coleenp@4037 | 713 | tty->print_cr("Shared spaces preloaded: %s", class_name); |
coleenp@4037 | 714 | } |
coleenp@4037 | 715 | |
coleenp@4037 | 716 | |
coleenp@4037 | 717 | InstanceKlass* ik = InstanceKlass::cast(klass); |
coleenp@4037 | 718 | |
coleenp@4037 | 719 | // Should be class load order as per -XX:+TraceClassLoadingPreorder |
coleenp@4037 | 720 | class_promote_order->append(ik); |
coleenp@4037 | 721 | |
coleenp@4037 | 722 | // Link the class to cause the bytecodes to be rewritten and the |
coleenp@4037 | 723 | // cpcache to be created. The linking is done as soon as classes |
coleenp@4037 | 724 | // are loaded in order that the related data structures (klass and |
coleenp@4037 | 725 | // cpCache) are located together. |
coleenp@4037 | 726 | |
coleenp@4037 | 727 | if (ik->init_state() < InstanceKlass::linked) { |
coleenp@4037 | 728 | ik->link_class(THREAD); |
coleenp@4037 | 729 | guarantee(!(HAS_PENDING_EXCEPTION), "exception in class rewriting"); |
coleenp@4037 | 730 | } |
coleenp@4037 | 731 | |
coleenp@4037 | 732 | // TODO: Resolve klasses in constant pool |
coleenp@4037 | 733 | ik->constants()->resolve_class_constants(THREAD); |
coleenp@4037 | 734 | |
coleenp@4037 | 735 | class_count++; |
coleenp@4037 | 736 | } else { |
coleenp@4037 | 737 | if (PrintSharedSpaces && Verbose && WizardMode) { |
coleenp@4037 | 738 | tty->cr(); |
coleenp@4037 | 739 | tty->print_cr(" Preload failed: %s", class_name); |
coleenp@4037 | 740 | } |
coleenp@4037 | 741 | } |
coleenp@4037 | 742 | file_jsum = 0; // Checksum must be on last line of file |
coleenp@4037 | 743 | } |
coleenp@4037 | 744 | if (computed_jsum != file_jsum) { |
coleenp@4037 | 745 | tty->cr(); |
coleenp@4037 | 746 | tty->print_cr("Preload failed: checksum of class list was incorrect."); |
coleenp@4037 | 747 | exit(1); |
coleenp@4037 | 748 | } |
coleenp@4037 | 749 | |
coleenp@4037 | 750 | tty->print_cr("done. "); |
coleenp@4037 | 751 | |
coleenp@4037 | 752 | if (PrintSharedSpaces) { |
coleenp@4037 | 753 | tty->print_cr("Shared spaces: preloaded %d classes", class_count); |
coleenp@4037 | 754 | } |
coleenp@4037 | 755 | |
coleenp@4037 | 756 | // Rewrite and unlink classes. |
coleenp@4037 | 757 | tty->print("Rewriting and linking classes ... "); |
coleenp@4037 | 758 | |
coleenp@4037 | 759 | // Link any classes which got missed. (It's not quite clear why |
coleenp@4037 | 760 | // they got missed.) This iteration would be unsafe if we weren't |
coleenp@4037 | 761 | // single-threaded at this point; however we can't do it on the VM |
coleenp@4037 | 762 | // thread because it requires object allocation. |
coleenp@4037 | 763 | SystemDictionary::classes_do(link_shared_classes, CATCH); |
coleenp@4037 | 764 | tty->print_cr("done. "); |
coleenp@4037 | 765 | |
coleenp@4037 | 766 | // Create and dump the shared spaces. Everything so far is loaded |
coleenp@4037 | 767 | // with the null class loader. |
coleenp@4037 | 768 | ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); |
coleenp@4037 | 769 | VM_PopulateDumpSharedSpace op(loader_data, class_promote_order); |
coleenp@4037 | 770 | VMThread::execute(&op); |
coleenp@4037 | 771 | |
coleenp@4037 | 772 | } else { |
coleenp@4037 | 773 | char errmsg[JVM_MAXPATHLEN]; |
coleenp@4037 | 774 | os::lasterror(errmsg, JVM_MAXPATHLEN); |
coleenp@4037 | 775 | tty->print_cr("Loading classlist failed: %s", errmsg); |
coleenp@4037 | 776 | exit(1); |
coleenp@4037 | 777 | } |
coleenp@4037 | 778 | |
coleenp@4037 | 779 | // Since various initialization steps have been undone by this process, |
coleenp@4037 | 780 | // it is not reasonable to continue running a java process. |
coleenp@4037 | 781 | exit(0); |
coleenp@4037 | 782 | } |
coleenp@4037 | 783 | |
coleenp@4037 | 784 | |
coleenp@4037 | 785 | // Closure for serializing initialization data in from a data area |
coleenp@4037 | 786 | // (ptr_array) read from the shared file. |
coleenp@4037 | 787 | |
coleenp@4037 | 788 | class ReadClosure : public SerializeClosure { |
coleenp@4037 | 789 | private: |
coleenp@4037 | 790 | intptr_t** _ptr_array; |
coleenp@4037 | 791 | |
coleenp@4037 | 792 | inline intptr_t nextPtr() { |
coleenp@4037 | 793 | return *(*_ptr_array)++; |
coleenp@4037 | 794 | } |
coleenp@4037 | 795 | |
coleenp@4037 | 796 | public: |
coleenp@4037 | 797 | ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; } |
coleenp@4037 | 798 | |
coleenp@4037 | 799 | void do_ptr(void** p) { |
coleenp@4037 | 800 | assert(*p == NULL, "initializing previous initialized pointer."); |
coleenp@4037 | 801 | intptr_t obj = nextPtr(); |
coleenp@4037 | 802 | assert((intptr_t)obj >= 0 || (intptr_t)obj < -100, |
coleenp@4037 | 803 | "hit tag while initializing ptrs."); |
coleenp@4037 | 804 | *p = (void*)obj; |
coleenp@4037 | 805 | } |
coleenp@4037 | 806 | |
coleenp@4037 | 807 | void do_tag(int tag) { |
coleenp@4037 | 808 | int old_tag; |
coleenp@4037 | 809 | old_tag = (int)(intptr_t)nextPtr(); |
coleenp@4037 | 810 | // do_int(&old_tag); |
coleenp@4037 | 811 | assert(tag == old_tag, "old tag doesn't match"); |
coleenp@4037 | 812 | FileMapInfo::assert_mark(tag == old_tag); |
coleenp@4037 | 813 | } |
coleenp@4037 | 814 | |
coleenp@4037 | 815 | void do_region(u_char* start, size_t size) { |
coleenp@4037 | 816 | assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment"); |
coleenp@4037 | 817 | assert(size % sizeof(intptr_t) == 0, "bad size"); |
coleenp@4037 | 818 | do_tag((int)size); |
coleenp@4037 | 819 | while (size > 0) { |
coleenp@4037 | 820 | *(intptr_t*)start = nextPtr(); |
coleenp@4037 | 821 | start += sizeof(intptr_t); |
coleenp@4037 | 822 | size -= sizeof(intptr_t); |
coleenp@4037 | 823 | } |
coleenp@4037 | 824 | } |
coleenp@4037 | 825 | |
coleenp@4037 | 826 | bool reading() const { return true; } |
coleenp@4037 | 827 | }; |
coleenp@4037 | 828 | |
coleenp@4037 | 829 | |
coleenp@4037 | 830 | // Save bounds of shared spaces mapped in. |
coleenp@4037 | 831 | static char* _ro_base = NULL; |
coleenp@4037 | 832 | static char* _rw_base = NULL; |
coleenp@4037 | 833 | static char* _md_base = NULL; |
coleenp@4037 | 834 | static char* _mc_base = NULL; |
coleenp@4037 | 835 | |
coleenp@4037 | 836 | // Return true if given address is in the mapped shared space. |
coleenp@4037 | 837 | bool MetaspaceShared::is_in_shared_space(const void* p) { |
coleenp@4037 | 838 | if (_ro_base == NULL || _rw_base == NULL) { |
coleenp@4037 | 839 | return false; |
coleenp@4037 | 840 | } else { |
zgu@4193 | 841 | return ((p >= _ro_base && p < (_ro_base + SharedReadOnlySize)) || |
zgu@4193 | 842 | (p >= _rw_base && p < (_rw_base + SharedReadWriteSize))); |
coleenp@4037 | 843 | } |
coleenp@4037 | 844 | } |
coleenp@4037 | 845 | |
coleenp@4037 | 846 | void MetaspaceShared::print_shared_spaces() { |
coleenp@4037 | 847 | gclog_or_tty->print_cr("Shared Spaces:"); |
coleenp@4037 | 848 | gclog_or_tty->print(" read-only " INTPTR_FORMAT "-" INTPTR_FORMAT, |
coleenp@4037 | 849 | _ro_base, _ro_base + SharedReadOnlySize); |
coleenp@4037 | 850 | gclog_or_tty->print(" read-write " INTPTR_FORMAT "-" INTPTR_FORMAT, |
coleenp@4037 | 851 | _rw_base, _rw_base + SharedReadWriteSize); |
coleenp@4037 | 852 | gclog_or_tty->cr(); |
coleenp@4037 | 853 | gclog_or_tty->print(" misc-data " INTPTR_FORMAT "-" INTPTR_FORMAT, |
coleenp@4037 | 854 | _md_base, _md_base + SharedMiscDataSize); |
coleenp@4037 | 855 | gclog_or_tty->print(" misc-code " INTPTR_FORMAT "-" INTPTR_FORMAT, |
coleenp@4037 | 856 | _mc_base, _mc_base + SharedMiscCodeSize); |
coleenp@4037 | 857 | gclog_or_tty->cr(); |
coleenp@4037 | 858 | } |
coleenp@4037 | 859 | |
coleenp@4037 | 860 | |
coleenp@4037 | 861 | // Map shared spaces at requested addresses and return if succeeded. |
coleenp@4037 | 862 | // Need to keep the bounds of the ro and rw space for the Metaspace::contains |
coleenp@4037 | 863 | // call, or is_in_shared_space. |
coleenp@4037 | 864 | bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) { |
coleenp@4037 | 865 | size_t image_alignment = mapinfo->alignment(); |
coleenp@4037 | 866 | |
hseigel@4396 | 867 | #ifndef _WINDOWS |
hseigel@4396 | 868 | // Map in the shared memory and then map the regions on top of it. |
hseigel@4396 | 869 | // On Windows, don't map the memory here because it will cause the |
hseigel@4396 | 870 | // mappings of the regions to fail. |
coleenp@4037 | 871 | ReservedSpace shared_rs = mapinfo->reserve_shared_memory(); |
coleenp@4037 | 872 | if (!shared_rs.is_reserved()) return false; |
hseigel@4396 | 873 | #endif |
hseigel@4396 | 874 | |
hseigel@4396 | 875 | assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces"); |
coleenp@4037 | 876 | |
coleenp@4037 | 877 | // Map each shared region |
coleenp@4037 | 878 | if ((_ro_base = mapinfo->map_region(ro)) != NULL && |
coleenp@4037 | 879 | (_rw_base = mapinfo->map_region(rw)) != NULL && |
coleenp@4037 | 880 | (_md_base = mapinfo->map_region(md)) != NULL && |
coleenp@4037 | 881 | (_mc_base = mapinfo->map_region(mc)) != NULL && |
coleenp@4037 | 882 | (image_alignment == (size_t)max_alignment())) { |
coleenp@4037 | 883 | // Success (no need to do anything) |
coleenp@4037 | 884 | return true; |
coleenp@4037 | 885 | } else { |
coleenp@4037 | 886 | // If there was a failure in mapping any of the spaces, unmap the ones |
coleenp@4037 | 887 | // that succeeded |
coleenp@4037 | 888 | if (_ro_base != NULL) mapinfo->unmap_region(ro); |
coleenp@4037 | 889 | if (_rw_base != NULL) mapinfo->unmap_region(rw); |
coleenp@4037 | 890 | if (_md_base != NULL) mapinfo->unmap_region(md); |
coleenp@4037 | 891 | if (_mc_base != NULL) mapinfo->unmap_region(mc); |
hseigel@4396 | 892 | #ifndef _WINDOWS |
coleenp@4037 | 893 | // Release the entire mapped region |
coleenp@4037 | 894 | shared_rs.release(); |
hseigel@4396 | 895 | #endif |
coleenp@4037 | 896 | // If -Xshare:on is specified, print out the error message and exit VM, |
coleenp@4037 | 897 | // otherwise, set UseSharedSpaces to false and continue. |
coleenp@4037 | 898 | if (RequireSharedSpaces) { |
coleenp@4037 | 899 | vm_exit_during_initialization("Unable to use shared archive.", NULL); |
coleenp@4037 | 900 | } else { |
coleenp@4037 | 901 | FLAG_SET_DEFAULT(UseSharedSpaces, false); |
coleenp@4037 | 902 | } |
coleenp@4037 | 903 | return false; |
coleenp@4037 | 904 | } |
coleenp@4037 | 905 | } |
coleenp@4037 | 906 | |
coleenp@4037 | 907 | // Read the miscellaneous data from the shared file, and |
coleenp@4037 | 908 | // serialize it out to its various destinations. |
coleenp@4037 | 909 | |
coleenp@4037 | 910 | void MetaspaceShared::initialize_shared_spaces() { |
coleenp@4037 | 911 | FileMapInfo *mapinfo = FileMapInfo::current_info(); |
coleenp@4037 | 912 | |
coleenp@4037 | 913 | char* buffer = mapinfo->region_base(md); |
coleenp@4037 | 914 | |
coleenp@4037 | 915 | // Skip over (reserve space for) a list of addresses of C++ vtables |
coleenp@4037 | 916 | // for Klass objects. They get filled in later. |
coleenp@4037 | 917 | |
coleenp@4037 | 918 | void** vtbl_list = (void**)buffer; |
coleenp@4037 | 919 | buffer += MetaspaceShared::vtbl_list_size * sizeof(void*); |
coleenp@4037 | 920 | Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size); |
coleenp@4037 | 921 | |
coleenp@4037 | 922 | // Skip over (reserve space for) dummy C++ vtables Klass objects. |
coleenp@4037 | 923 | // They are used as is. |
coleenp@4037 | 924 | |
coleenp@4037 | 925 | intptr_t vtable_size = *(intptr_t*)buffer; |
coleenp@4037 | 926 | buffer += sizeof(intptr_t); |
coleenp@4037 | 927 | buffer += vtable_size; |
coleenp@4037 | 928 | |
coleenp@4037 | 929 | // Create the symbol table using the bucket array at this spot in the |
coleenp@4037 | 930 | // misc data space. Since the symbol table is often modified, this |
coleenp@4037 | 931 | // region (of mapped pages) will be copy-on-write. |
coleenp@4037 | 932 | |
coleenp@4037 | 933 | int symbolTableLen = *(intptr_t*)buffer; |
coleenp@4037 | 934 | buffer += sizeof(intptr_t); |
coleenp@4037 | 935 | int number_of_entries = *(intptr_t*)buffer; |
coleenp@4037 | 936 | buffer += sizeof(intptr_t); |
coleenp@4037 | 937 | SymbolTable::create_table((HashtableBucket<mtSymbol>*)buffer, symbolTableLen, |
coleenp@4037 | 938 | number_of_entries); |
coleenp@4037 | 939 | buffer += symbolTableLen; |
coleenp@4037 | 940 | |
coleenp@4037 | 941 | // Create the shared dictionary using the bucket array at this spot in |
coleenp@4037 | 942 | // the misc data space. Since the shared dictionary table is never |
coleenp@4037 | 943 | // modified, this region (of mapped pages) will be (effectively, if |
coleenp@4037 | 944 | // not explicitly) read-only. |
coleenp@4037 | 945 | |
coleenp@4037 | 946 | int sharedDictionaryLen = *(intptr_t*)buffer; |
coleenp@4037 | 947 | buffer += sizeof(intptr_t); |
coleenp@4037 | 948 | number_of_entries = *(intptr_t*)buffer; |
coleenp@4037 | 949 | buffer += sizeof(intptr_t); |
coleenp@4037 | 950 | SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer, |
coleenp@4037 | 951 | sharedDictionaryLen, |
coleenp@4037 | 952 | number_of_entries); |
coleenp@4037 | 953 | buffer += sharedDictionaryLen; |
coleenp@4037 | 954 | |
coleenp@4037 | 955 | // Create the package info table using the bucket array at this spot in |
coleenp@4037 | 956 | // the misc data space. Since the package info table is never |
coleenp@4037 | 957 | // modified, this region (of mapped pages) will be (effectively, if |
coleenp@4037 | 958 | // not explicitly) read-only. |
coleenp@4037 | 959 | |
coleenp@4037 | 960 | int pkgInfoLen = *(intptr_t*)buffer; |
coleenp@4037 | 961 | buffer += sizeof(intptr_t); |
coleenp@4037 | 962 | number_of_entries = *(intptr_t*)buffer; |
coleenp@4037 | 963 | buffer += sizeof(intptr_t); |
coleenp@4037 | 964 | ClassLoader::create_package_info_table((HashtableBucket<mtClass>*)buffer, pkgInfoLen, |
coleenp@4037 | 965 | number_of_entries); |
coleenp@4037 | 966 | buffer += pkgInfoLen; |
coleenp@4037 | 967 | ClassLoader::verify(); |
coleenp@4037 | 968 | |
coleenp@4037 | 969 | // The following data in the shared misc data region are the linked |
coleenp@4037 | 970 | // list elements (HashtableEntry objects) for the symbol table, string |
coleenp@4037 | 971 | // table, and shared dictionary. The heap objects refered to by the |
coleenp@4037 | 972 | // symbol table, string table, and shared dictionary are permanent and |
coleenp@4037 | 973 | // unmovable. Since new entries added to the string and symbol tables |
coleenp@4037 | 974 | // are always added at the beginning of the linked lists, THESE LINKED |
coleenp@4037 | 975 | // LIST ELEMENTS ARE READ-ONLY. |
coleenp@4037 | 976 | |
coleenp@4037 | 977 | int len = *(intptr_t*)buffer; // skip over symbol table entries |
coleenp@4037 | 978 | buffer += sizeof(intptr_t); |
coleenp@4037 | 979 | buffer += len; |
coleenp@4037 | 980 | |
coleenp@4037 | 981 | len = *(intptr_t*)buffer; // skip over shared dictionary entries |
coleenp@4037 | 982 | buffer += sizeof(intptr_t); |
coleenp@4037 | 983 | buffer += len; |
coleenp@4037 | 984 | |
coleenp@4037 | 985 | len = *(intptr_t*)buffer; // skip over package info table entries |
coleenp@4037 | 986 | buffer += sizeof(intptr_t); |
coleenp@4037 | 987 | buffer += len; |
coleenp@4037 | 988 | |
coleenp@4037 | 989 | len = *(intptr_t*)buffer; // skip over package info table char[] arrays. |
coleenp@4037 | 990 | buffer += sizeof(intptr_t); |
coleenp@4037 | 991 | buffer += len; |
coleenp@4037 | 992 | |
coleenp@4037 | 993 | intptr_t* array = (intptr_t*)buffer; |
coleenp@4037 | 994 | ReadClosure rc(&array); |
coleenp@4037 | 995 | serialize(&rc); |
coleenp@4037 | 996 | |
coleenp@4037 | 997 | // Close the mapinfo file |
coleenp@4037 | 998 | mapinfo->close(); |
coleenp@4037 | 999 | } |
coleenp@4037 | 1000 | |
coleenp@4037 | 1001 | // JVM/TI RedefineClasses() support: |
coleenp@4037 | 1002 | bool MetaspaceShared::remap_shared_readonly_as_readwrite() { |
coleenp@4037 | 1003 | assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
coleenp@4037 | 1004 | |
coleenp@4037 | 1005 | if (UseSharedSpaces) { |
coleenp@4037 | 1006 | // remap the shared readonly space to shared readwrite, private |
coleenp@4037 | 1007 | FileMapInfo* mapinfo = FileMapInfo::current_info(); |
coleenp@4037 | 1008 | if (!mapinfo->remap_shared_readonly_as_readwrite()) { |
coleenp@4037 | 1009 | return false; |
coleenp@4037 | 1010 | } |
coleenp@4037 | 1011 | } |
coleenp@4037 | 1012 | return true; |
coleenp@4037 | 1013 | } |