1 /*
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
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/classListParser.hpp"
27 #include "classfile/classLoaderExt.hpp"
28 #include "classfile/dictionary.hpp"
29 #include "classfile/loaderConstraints.hpp"
30 #include "classfile/placeholders.hpp"
31 #include "classfile/sharedClassUtil.hpp"
32 #include "classfile/symbolTable.hpp"
33 #include "classfile/systemDictionary.hpp"
34 #include "code/codeCache.hpp"
35 #include "gc/shared/gcLocker.hpp"
36 #include "interpreter/bytecodeStream.hpp"
37 #include "interpreter/bytecodes.hpp"
38 #include "memory/filemap.hpp"
39 #include "memory/metaspace.hpp"
40 #include "memory/metaspaceShared.hpp"
41 #include "oops/objArrayOop.hpp"
42 #include "oops/oop.inline.hpp"
43 #include "runtime/os.hpp"
44 #include "runtime/signature.hpp"
45 #include "runtime/vmThread.hpp"
46 #include "runtime/vm_operations.hpp"
47 #include "utilities/defaultStream.hpp"
48 #include "utilities/hashtable.inline.hpp"
49
50 int MetaspaceShared::_max_alignment = 0;
51
52 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
53
54 MetaspaceSharedStats MetaspaceShared::_stats;
55
56 bool MetaspaceShared::_link_classes_made_progress;
57 bool MetaspaceShared::_check_classes_made_progress;
58 bool MetaspaceShared::_has_error_classes;
59 bool MetaspaceShared::_archive_loading_failed = false;
60 SharedMiscRegion MetaspaceShared::_mc;
61 SharedMiscRegion MetaspaceShared::_md;
62
754
755 if (IgnoreUnverifiableClassesDuringDump) {
756 // This is useful when running JCK or SQE tests. You should not
757 // enable this when running real apps.
758 SystemDictionary::remove_classes_in_error_state();
759 } else {
760 tty->print_cr("Please remove the unverifiable classes from your class list and try again");
761 exit(1);
762 }
763 }
764 }
765
766 void MetaspaceShared::prepare_for_dumping() {
767 ClassLoader::initialize_shared_path();
768 FileMapInfo::allocate_classpath_entry_table();
769 }
770
771 // Preload classes from a list, populate the shared spaces and dump to a
772 // file.
773 void MetaspaceShared::preload_and_dump(TRAPS) {
774 TraceTime timer("Dump Shared Spaces", TraceStartupTime);
775 ResourceMark rm;
776 char class_list_path_str[JVM_MAXPATHLEN];
777
778 tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
779 MetaspaceShared::shared_rs()->size(),
780 p2i(MetaspaceShared::shared_rs()->base()));
781
782 // Preload classes to be shared.
783 // Should use some os:: method rather than fopen() here. aB.
784 const char* class_list_path;
785 if (SharedClassListFile == NULL) {
786 // Construct the path to the class list (in jre/lib)
787 // Walk up two directories from the location of the VM and
788 // optionally tack on "lib" (depending on platform)
789 os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
790 for (int i = 0; i < 3; i++) {
791 char *end = strrchr(class_list_path_str, *os::file_separator());
792 if (end != NULL) *end = '\0';
793 }
794 int class_list_path_len = (int)strlen(class_list_path_str);
836 class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
837 THREAD);
838 }
839 tty->print_cr("Loading classes to share: done.");
840
841 if (PrintSharedSpaces) {
842 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
843 }
844
845 // Rewrite and link classes
846 tty->print_cr("Rewriting and linking classes ...");
847
848 // Link any classes which got missed. This would happen if we have loaded classes that
849 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
850 // fails verification, all other interfaces that were not specified in the classlist but
851 // are implemented by K are not verified.
852 link_and_cleanup_shared_classes(CATCH);
853 tty->print_cr("Rewriting and linking classes: done");
854
855 VMThread::execute(&op);
856 // Since various initialization steps have been undone by this process,
857 // it is not reasonable to continue running a java process.
858 exit(0);
859 }
860
861
862 int MetaspaceShared::preload_and_dump(const char* class_list_path,
863 GrowableArray<Klass*>* class_promote_order,
864 TRAPS) {
865 ClassListParser parser(class_list_path);
866 int class_count = 0;
867
868 while (parser.parse_one_line()) {
869 Klass* klass = ClassLoaderExt::load_one_class(&parser, THREAD);
870
871 CLEAR_PENDING_EXCEPTION;
872 if (klass != NULL) {
873 if (PrintSharedSpaces && Verbose && WizardMode) {
874 ResourceMark rm;
875 tty->print_cr("Shared spaces preloaded: %s", klass->external_name());
|
1 /*
2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
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/classListParser.hpp"
27 #include "classfile/classLoaderExt.hpp"
28 #include "classfile/dictionary.hpp"
29 #include "classfile/loaderConstraints.hpp"
30 #include "classfile/placeholders.hpp"
31 #include "classfile/sharedClassUtil.hpp"
32 #include "classfile/symbolTable.hpp"
33 #include "classfile/systemDictionary.hpp"
34 #include "code/codeCache.hpp"
35 #include "gc/shared/gcLocker.hpp"
36 #include "interpreter/bytecodeStream.hpp"
37 #include "interpreter/bytecodes.hpp"
38 #include "memory/filemap.hpp"
39 #include "memory/metaspace.hpp"
40 #include "memory/metaspaceShared.hpp"
41 #include "oops/objArrayOop.hpp"
42 #include "oops/oop.inline.hpp"
43 #include "runtime/logTimer.hpp"
44 #include "runtime/os.hpp"
45 #include "runtime/signature.hpp"
46 #include "runtime/vmThread.hpp"
47 #include "runtime/vm_operations.hpp"
48 #include "utilities/defaultStream.hpp"
49 #include "utilities/hashtable.inline.hpp"
50
51 int MetaspaceShared::_max_alignment = 0;
52
53 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
54
55 MetaspaceSharedStats MetaspaceShared::_stats;
56
57 bool MetaspaceShared::_link_classes_made_progress;
58 bool MetaspaceShared::_check_classes_made_progress;
59 bool MetaspaceShared::_has_error_classes;
60 bool MetaspaceShared::_archive_loading_failed = false;
61 SharedMiscRegion MetaspaceShared::_mc;
62 SharedMiscRegion MetaspaceShared::_md;
63
755
756 if (IgnoreUnverifiableClassesDuringDump) {
757 // This is useful when running JCK or SQE tests. You should not
758 // enable this when running real apps.
759 SystemDictionary::remove_classes_in_error_state();
760 } else {
761 tty->print_cr("Please remove the unverifiable classes from your class list and try again");
762 exit(1);
763 }
764 }
765 }
766
767 void MetaspaceShared::prepare_for_dumping() {
768 ClassLoader::initialize_shared_path();
769 FileMapInfo::allocate_classpath_entry_table();
770 }
771
772 // Preload classes from a list, populate the shared spaces and dump to a
773 // file.
774 void MetaspaceShared::preload_and_dump(TRAPS) {
775 { TraceStartupTime timer("Dump Shared Spaces");
776 ResourceMark rm;
777 char class_list_path_str[JVM_MAXPATHLEN];
778
779 tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
780 MetaspaceShared::shared_rs()->size(),
781 p2i(MetaspaceShared::shared_rs()->base()));
782
783 // Preload classes to be shared.
784 // Should use some os:: method rather than fopen() here. aB.
785 const char* class_list_path;
786 if (SharedClassListFile == NULL) {
787 // Construct the path to the class list (in jre/lib)
788 // Walk up two directories from the location of the VM and
789 // optionally tack on "lib" (depending on platform)
790 os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
791 for (int i = 0; i < 3; i++) {
792 char *end = strrchr(class_list_path_str, *os::file_separator());
793 if (end != NULL) *end = '\0';
794 }
795 int class_list_path_len = (int)strlen(class_list_path_str);
837 class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
838 THREAD);
839 }
840 tty->print_cr("Loading classes to share: done.");
841
842 if (PrintSharedSpaces) {
843 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
844 }
845
846 // Rewrite and link classes
847 tty->print_cr("Rewriting and linking classes ...");
848
849 // Link any classes which got missed. This would happen if we have loaded classes that
850 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
851 // fails verification, all other interfaces that were not specified in the classlist but
852 // are implemented by K are not verified.
853 link_and_cleanup_shared_classes(CATCH);
854 tty->print_cr("Rewriting and linking classes: done");
855
856 VMThread::execute(&op);
857 }
858 // Since various initialization steps have been undone by this process,
859 // it is not reasonable to continue running a java process.
860 exit(0);
861 }
862
863
864 int MetaspaceShared::preload_and_dump(const char* class_list_path,
865 GrowableArray<Klass*>* class_promote_order,
866 TRAPS) {
867 ClassListParser parser(class_list_path);
868 int class_count = 0;
869
870 while (parser.parse_one_line()) {
871 Klass* klass = ClassLoaderExt::load_one_class(&parser, THREAD);
872
873 CLEAR_PENDING_EXCEPTION;
874 if (klass != NULL) {
875 if (PrintSharedSpaces && Verbose && WizardMode) {
876 ResourceMark rm;
877 tty->print_cr("Shared spaces preloaded: %s", klass->external_name());
|