7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/dictionary.hpp"
27 #include "classfile/loaderConstraints.hpp"
28 #include "classfile/placeholders.hpp"
29 #include "classfile/sharedClassUtil.hpp"
30 #include "classfile/symbolTable.hpp"
31 #include "classfile/systemDictionary.hpp"
32 #include "code/codeCache.hpp"
33 #include "memory/filemap.hpp"
34 #include "memory/gcLocker.hpp"
35 #include "memory/metaspace.hpp"
36 #include "memory/metaspaceShared.hpp"
37 #include "oops/objArrayOop.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/signature.hpp"
40 #include "runtime/vm_operations.hpp"
41 #include "runtime/vmThread.hpp"
42 #include "utilities/hashtable.inline.hpp"
43
44 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
45
46 int MetaspaceShared::_max_alignment = 0;
47
48 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
49
50 bool MetaspaceShared::_link_classes_made_progress;
51 bool MetaspaceShared::_check_classes_made_progress;
52 bool MetaspaceShared::_has_error_classes;
53 bool MetaspaceShared::_archive_loading_failed = false;
54 // Read/write a data stream for restoring/preserving metadata pointers and
55 // miscellaneous data from/to the shared archive file.
56
57 void MetaspaceShared::serialize(SerializeClosure* soc) {
58 int tag = 0;
59 soc->do_tag(--tag);
60
61 // Verify the sizes of various metadata in the system.
516 // buckets first [read-write], then copy the linked lists of entries
517 // [read-only].
518
519 SymbolTable::reverse(md_top);
520 NOT_PRODUCT(SymbolTable::verify());
521 SymbolTable::copy_buckets(&md_top, md_end);
522
523 SystemDictionary::reverse();
524 SystemDictionary::copy_buckets(&md_top, md_end);
525
526 ClassLoader::verify();
527 ClassLoader::copy_package_info_buckets(&md_top, md_end);
528 ClassLoader::verify();
529
530 SymbolTable::copy_table(&md_top, md_end);
531 SystemDictionary::copy_table(&md_top, md_end);
532 ClassLoader::verify();
533 ClassLoader::copy_package_info_table(&md_top, md_end);
534 ClassLoader::verify();
535
536 // Write the other data to the output array.
537 WriteClosure wc(md_top, md_end);
538 MetaspaceShared::serialize(&wc);
539 md_top = wc.get_top();
540
541 // Print shared spaces all the time
542 // To make fmt_space be a syntactic constant (for format warnings), use #define.
543 #define fmt_space "%s space: %9d [ %4.1f%% of total] out of %9d bytes [%4.1f%% used] at " PTR_FORMAT
544 Metaspace* ro_space = _loader_data->ro_metaspace();
545 Metaspace* rw_space = _loader_data->rw_metaspace();
546
547 // Allocated size of each space (may not be all occupied)
548 const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
549 const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
550 const size_t md_alloced = md_end-md_low;
551 const size_t mc_alloced = mc_end-mc_low;
552 const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced;
553
554 // Occupied size of each space.
555 const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
728 GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
729
730 // sun.io.Converters
731 static const char obj_array_sig[] = "[[Ljava/lang/Object;";
732 SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
733
734 // java.util.HashMap
735 static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
736 SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
737
738 tty->print_cr("Loading classes to share ...");
739 _has_error_classes = false;
740 class_count += preload_and_dump(class_list_path, class_promote_order,
741 THREAD);
742 if (ExtraSharedClassListFile) {
743 class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
744 THREAD);
745 }
746 tty->print_cr("Loading classes to share: done.");
747
748 if (PrintSharedSpaces) {
749 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
750 }
751
752 // Rewrite and link classes
753 tty->print_cr("Rewriting and linking classes ...");
754
755 // Link any classes which got missed. This would happen if we have loaded classes that
756 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
757 // fails verification, all other interfaces that were not specified in the classlist but
758 // are implemented by K are not verified.
759 link_and_cleanup_shared_classes(CATCH);
760 tty->print_cr("Rewriting and linking classes: done");
761
762 // Create and dump the shared spaces. Everything so far is loaded
763 // with the null class loader.
764 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
765 VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
766 VMThread::execute(&op);
767
1039 // unmovable. Since new entries added to the string and symbol tables
1040 // are always added at the beginning of the linked lists, THESE LINKED
1041 // LIST ELEMENTS ARE READ-ONLY.
1042
1043 int len = *(intptr_t*)buffer; // skip over symbol table entries
1044 buffer += sizeof(intptr_t);
1045 buffer += len;
1046
1047 len = *(intptr_t*)buffer; // skip over shared dictionary entries
1048 buffer += sizeof(intptr_t);
1049 buffer += len;
1050
1051 len = *(intptr_t*)buffer; // skip over package info table entries
1052 buffer += sizeof(intptr_t);
1053 buffer += len;
1054
1055 len = *(intptr_t*)buffer; // skip over package info table char[] arrays.
1056 buffer += sizeof(intptr_t);
1057 buffer += len;
1058
1059 intptr_t* array = (intptr_t*)buffer;
1060 ReadClosure rc(&array);
1061 serialize(&rc);
1062
1063 // Close the mapinfo file
1064 mapinfo->close();
1065
1066 if (PrintSharedArchiveAndExit) {
1067 if (PrintSharedDictionary) {
1068 tty->print_cr("\nShared classes:\n");
1069 SystemDictionary::print_shared(false);
1070 }
1071 if (_archive_loading_failed) {
1072 tty->print_cr("archive is invalid");
1073 vm_exit(1);
1074 } else {
1075 tty->print_cr("archive is valid");
1076 vm_exit(0);
1077 }
1078 }
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/dictionary.hpp"
27 #include "classfile/classLoaderExt.hpp"
28 #include "classfile/loaderConstraints.hpp"
29 #include "classfile/placeholders.hpp"
30 #include "classfile/sharedClassUtil.hpp"
31 #include "classfile/symbolTable.hpp"
32 #include "classfile/systemDictionary.hpp"
33 #include "code/codeCache.hpp"
34 #include "memory/filemap.hpp"
35 #include "memory/gcLocker.hpp"
36 #include "memory/metaspace.hpp"
37 #include "memory/metaspaceShared.hpp"
38 #include "oops/objArrayOop.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "runtime/signature.hpp"
41 #include "runtime/vm_operations.hpp"
42 #include "runtime/vmThread.hpp"
43 #include "utilities/hashtable.hpp"
44 #include "utilities/hashtable.inline.hpp"
45
46 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
47
48 int MetaspaceShared::_max_alignment = 0;
49
50 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
51
52 bool MetaspaceShared::_link_classes_made_progress;
53 bool MetaspaceShared::_check_classes_made_progress;
54 bool MetaspaceShared::_has_error_classes;
55 bool MetaspaceShared::_archive_loading_failed = false;
56 // Read/write a data stream for restoring/preserving metadata pointers and
57 // miscellaneous data from/to the shared archive file.
58
59 void MetaspaceShared::serialize(SerializeClosure* soc) {
60 int tag = 0;
61 soc->do_tag(--tag);
62
63 // Verify the sizes of various metadata in the system.
518 // buckets first [read-write], then copy the linked lists of entries
519 // [read-only].
520
521 SymbolTable::reverse(md_top);
522 NOT_PRODUCT(SymbolTable::verify());
523 SymbolTable::copy_buckets(&md_top, md_end);
524
525 SystemDictionary::reverse();
526 SystemDictionary::copy_buckets(&md_top, md_end);
527
528 ClassLoader::verify();
529 ClassLoader::copy_package_info_buckets(&md_top, md_end);
530 ClassLoader::verify();
531
532 SymbolTable::copy_table(&md_top, md_end);
533 SystemDictionary::copy_table(&md_top, md_end);
534 ClassLoader::verify();
535 ClassLoader::copy_package_info_table(&md_top, md_end);
536 ClassLoader::verify();
537
538 ClassLoaderExt::copy_lookup_cache_to_archive(&md_top, md_end);
539
540 // Write the other data to the output array.
541 WriteClosure wc(md_top, md_end);
542 MetaspaceShared::serialize(&wc);
543 md_top = wc.get_top();
544
545 // Print shared spaces all the time
546 // To make fmt_space be a syntactic constant (for format warnings), use #define.
547 #define fmt_space "%s space: %9d [ %4.1f%% of total] out of %9d bytes [%4.1f%% used] at " PTR_FORMAT
548 Metaspace* ro_space = _loader_data->ro_metaspace();
549 Metaspace* rw_space = _loader_data->rw_metaspace();
550
551 // Allocated size of each space (may not be all occupied)
552 const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
553 const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
554 const size_t md_alloced = md_end-md_low;
555 const size_t mc_alloced = mc_end-mc_low;
556 const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced;
557
558 // Occupied size of each space.
559 const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
732 GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
733
734 // sun.io.Converters
735 static const char obj_array_sig[] = "[[Ljava/lang/Object;";
736 SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
737
738 // java.util.HashMap
739 static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
740 SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
741
742 tty->print_cr("Loading classes to share ...");
743 _has_error_classes = false;
744 class_count += preload_and_dump(class_list_path, class_promote_order,
745 THREAD);
746 if (ExtraSharedClassListFile) {
747 class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
748 THREAD);
749 }
750 tty->print_cr("Loading classes to share: done.");
751
752 ClassLoaderExt::init_lookup_cache(THREAD);
753
754 if (PrintSharedSpaces) {
755 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
756 }
757
758 // Rewrite and link classes
759 tty->print_cr("Rewriting and linking classes ...");
760
761 // Link any classes which got missed. This would happen if we have loaded classes that
762 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
763 // fails verification, all other interfaces that were not specified in the classlist but
764 // are implemented by K are not verified.
765 link_and_cleanup_shared_classes(CATCH);
766 tty->print_cr("Rewriting and linking classes: done");
767
768 // Create and dump the shared spaces. Everything so far is loaded
769 // with the null class loader.
770 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
771 VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
772 VMThread::execute(&op);
773
1045 // unmovable. Since new entries added to the string and symbol tables
1046 // are always added at the beginning of the linked lists, THESE LINKED
1047 // LIST ELEMENTS ARE READ-ONLY.
1048
1049 int len = *(intptr_t*)buffer; // skip over symbol table entries
1050 buffer += sizeof(intptr_t);
1051 buffer += len;
1052
1053 len = *(intptr_t*)buffer; // skip over shared dictionary entries
1054 buffer += sizeof(intptr_t);
1055 buffer += len;
1056
1057 len = *(intptr_t*)buffer; // skip over package info table entries
1058 buffer += sizeof(intptr_t);
1059 buffer += len;
1060
1061 len = *(intptr_t*)buffer; // skip over package info table char[] arrays.
1062 buffer += sizeof(intptr_t);
1063 buffer += len;
1064
1065 buffer = ClassLoaderExt::restore_lookup_cache_from_archive(buffer);
1066
1067 intptr_t* array = (intptr_t*)buffer;
1068 ReadClosure rc(&array);
1069 serialize(&rc);
1070
1071 // Close the mapinfo file
1072 mapinfo->close();
1073
1074 if (PrintSharedArchiveAndExit) {
1075 if (PrintSharedDictionary) {
1076 tty->print_cr("\nShared classes:\n");
1077 SystemDictionary::print_shared(false);
1078 }
1079 if (_archive_loading_failed) {
1080 tty->print_cr("archive is invalid");
1081 vm_exit(1);
1082 } else {
1083 tty->print_cr("archive is valid");
1084 vm_exit(0);
1085 }
1086 }
|