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 "jvm.h"
27 #include "classfile/classLoaderDataGraph.hpp"
28 #include "classfile/classListParser.hpp"
29 #include "classfile/classLoaderExt.hpp"
30 #include "classfile/dictionary.hpp"
31 #include "classfile/loaderConstraints.hpp"
32 #include "classfile/javaClasses.inline.hpp"
33 #include "classfile/placeholders.hpp"
34 #include "classfile/symbolTable.hpp"
35 #include "classfile/stringTable.hpp"
36 #include "classfile/systemDictionary.hpp"
37 #include "classfile/systemDictionaryShared.hpp"
38 #include "code/codeCache.hpp"
39 #include "gc/shared/softRefPolicy.hpp"
40 #include "interpreter/bytecodeStream.hpp"
41 #include "interpreter/bytecodes.hpp"
42 #include "logging/log.hpp"
43 #include "logging/logMessage.hpp"
44 #include "memory/archiveUtils.inline.hpp"
45 #include "memory/dynamicArchive.hpp"
46 #include "memory/filemap.hpp"
47 #include "memory/heapShared.inline.hpp"
48 #include "memory/metaspace.hpp"
49 #include "memory/metaspaceClosure.hpp"
50 #include "memory/metaspaceShared.hpp"
51 #include "memory/resourceArea.hpp"
52 #include "memory/universe.hpp"
53 #include "oops/compressedOops.inline.hpp"
54 #include "oops/instanceClassLoaderKlass.hpp"
55 #include "oops/instanceMirrorKlass.hpp"
56 #include "oops/instanceRefKlass.hpp"
57 #include "oops/methodData.hpp"
58 #include "oops/objArrayKlass.hpp"
59 #include "oops/objArrayOop.hpp"
60 #include "oops/oop.inline.hpp"
61 #include "oops/typeArrayKlass.hpp"
62 #include "prims/jvmtiRedefineClasses.hpp"
63 #include "runtime/handles.inline.hpp"
64 #include "runtime/os.hpp"
65 #include "runtime/safepointVerifiers.hpp"
66 #include "runtime/signature.hpp"
644 }
645 }
646
647 class CollectClassesClosure : public KlassClosure {
648 void do_klass(Klass* k) {
649 if (k->is_instance_klass() &&
650 SystemDictionaryShared::is_excluded_class(InstanceKlass::cast(k))) {
651 // Don't add to the _global_klass_objects
652 } else {
653 _global_klass_objects->append_if_missing(k);
654 }
655 if (k->is_array_klass()) {
656 // Add in the array classes too
657 ArrayKlass* ak = ArrayKlass::cast(k);
658 Klass* h = ak->higher_dimension();
659 if (h != NULL) {
660 h->array_klasses_do(collect_array_classes);
661 }
662 }
663 }
664 };
665
666 // Global object for holding symbols that created during class loading. See SymbolTable::new_symbol
667 static GrowableArray<Symbol*>* _global_symbol_objects = NULL;
668
669 static int compare_symbols_by_address(Symbol** a, Symbol** b) {
670 if (a[0] < b[0]) {
671 return -1;
672 } else if (a[0] == b[0]) {
673 ResourceMark rm;
674 log_warning(cds)("Duplicated symbol %s unexpected", (*a)->as_C_string());
675 return 0;
676 } else {
677 return 1;
678 }
679 }
680
681 void MetaspaceShared::add_symbol(Symbol* sym) {
682 MutexLocker ml(CDSAddSymbol_lock, Mutex::_no_safepoint_check_flag);
683 if (_global_symbol_objects == NULL) {
1626
1627 FileMapInfo::check_nonempty_dir_in_shared_path_table();
1628
1629 NOT_PRODUCT(SystemDictionary::verify();)
1630 // The following guarantee is meant to ensure that no loader constraints
1631 // exist yet, since the constraints table is not shared. This becomes
1632 // more important now that we don't re-initialize vtables/itables for
1633 // shared classes at runtime, where constraints were previously created.
1634 guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
1635 "loader constraints are not saved");
1636 guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
1637 "placeholders are not saved");
1638
1639 // At this point, many classes have been loaded.
1640 // Gather systemDictionary classes in a global array and do everything to
1641 // that so we don't have to walk the SystemDictionary again.
1642 SystemDictionaryShared::check_excluded_classes();
1643 _global_klass_objects = new GrowableArray<Klass*>(1000);
1644 CollectClassesClosure collect_classes;
1645 ClassLoaderDataGraph::loaded_classes_do(&collect_classes);
1646 _global_klass_objects->sort(global_klass_compare);
1647
1648 print_class_stats();
1649
1650 // Ensure the ConstMethods won't be modified at run-time
1651 log_info(cds)("Updating ConstMethods ... ");
1652 rewrite_nofast_bytecodes_and_calculate_fingerprints(THREAD);
1653 log_info(cds)("done. ");
1654
1655 // Remove all references outside the metadata
1656 log_info(cds)("Removing unshareable information ... ");
1657 remove_unshareable_in_classes();
1658 log_info(cds)("done. ");
1659
1660 MetaspaceShared::allocate_cloned_cpp_vtptrs();
1661 char* cloned_vtables = _mc_region.top();
1662 MetaspaceShared::allocate_cpp_vtable_clones();
1663
1664 ArchiveCompactor::initialize();
1665 ArchiveCompactor::copy_and_compact();
1896 "%sclasslist", os::file_separator());
1897 }
1898 class_list_path = class_list_path_str;
1899 } else {
1900 class_list_path = SharedClassListFile;
1901 }
1902
1903 log_info(cds)("Loading classes to share ...");
1904 _has_error_classes = false;
1905 int class_count = preload_classes(class_list_path, THREAD);
1906 if (ExtraSharedClassListFile) {
1907 class_count += preload_classes(ExtraSharedClassListFile, THREAD);
1908 }
1909 log_info(cds)("Loading classes to share: done.");
1910
1911 log_info(cds)("Shared spaces: preloaded %d classes", class_count);
1912
1913 if (SharedArchiveConfigFile) {
1914 log_info(cds)("Reading extra data from %s ...", SharedArchiveConfigFile);
1915 read_extra_data(SharedArchiveConfigFile, THREAD);
1916 }
1917 log_info(cds)("Reading extra data: done.");
1918
1919 HeapShared::init_subgraph_entry_fields(THREAD);
1920
1921 // Rewrite and link classes
1922 log_info(cds)("Rewriting and linking classes ...");
1923
1924 // Link any classes which got missed. This would happen if we have loaded classes that
1925 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
1926 // fails verification, all other interfaces that were not specified in the classlist but
1927 // are implemented by K are not verified.
1928 link_and_cleanup_shared_classes(CATCH);
1929 log_info(cds)("Rewriting and linking classes: done");
1930
1931 VM_PopulateDumpSharedSpace op;
1932 MutexLocker ml(THREAD, HeapShared::is_heap_object_archiving_allowed() ?
1933 Heap_lock : NULL); // needed by HeapShared::run_gc()
1934 VMThread::execute(&op);
1935 }
1936 }
1937
1938
1939 int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) {
1940 ClassListParser parser(class_list_path);
1941 int class_count = 0;
1942
1943 while (parser.parse_one_line()) {
1944 Klass* klass = parser.load_current_class(THREAD);
1945 if (HAS_PENDING_EXCEPTION) {
1946 if (klass == NULL &&
1947 (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
1948 // print a warning only when the pending exception is class not found
1949 log_warning(cds)("Preload Warning: Cannot find %s", parser.current_class_name());
1950 }
1951 CLEAR_PENDING_EXCEPTION;
1952 }
1953 if (klass != NULL) {
1954 if (log_is_enabled(Trace, cds)) {
1955 ResourceMark rm(THREAD);
1956 log_trace(cds)("Shared spaces preloaded: %s", klass->external_name());
1957 }
1958
2675 st->print("CDS archive(s) mapped at: ");
2676 address base;
2677 address top;
2678 if (UseSharedSpaces) { // Runtime
2679 base = (address)MetaspaceObj::shared_metaspace_base();
2680 address static_top = (address)_shared_metaspace_static_top;
2681 top = (address)MetaspaceObj::shared_metaspace_top();
2682 st->print("[" PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "), ", p2i(base), p2i(static_top), p2i(top));
2683 } else if (DumpSharedSpaces) { // Dump Time
2684 base = (address)_shared_rs.base();
2685 top = (address)_shared_rs.end();
2686 st->print("[" PTR_FORMAT "-" PTR_FORMAT "), ", p2i(base), p2i(top));
2687 }
2688 st->print("size " SIZE_FORMAT ", ", top - base);
2689 st->print("SharedBaseAddress: " PTR_FORMAT ", ArchiveRelocationMode: %d.", SharedBaseAddress, (int)ArchiveRelocationMode);
2690 } else {
2691 st->print("CDS disabled.");
2692 }
2693 st->cr();
2694 }
2695
2696
2697
2698
2699
|
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 "jvm.h"
27 #include "classfile/classFileStream.hpp"
28 #include "classfile/classLoaderDataGraph.hpp"
29 #include "classfile/classListParser.hpp"
30 #include "classfile/classLoaderExt.hpp"
31 #include "classfile/dictionary.hpp"
32 #include "classfile/loaderConstraints.hpp"
33 #include "classfile/javaClasses.inline.hpp"
34 #include "classfile/placeholders.hpp"
35 #include "classfile/symbolTable.hpp"
36 #include "classfile/stringTable.hpp"
37 #include "classfile/systemDictionary.hpp"
38 #include "classfile/systemDictionaryShared.hpp"
39 #include "code/codeCache.hpp"
40 #include "gc/shared/softRefPolicy.hpp"
41 #include "interpreter/bytecodeStream.hpp"
42 #include "interpreter/bytecodes.hpp"
43 #include "logging/log.hpp"
44 #include "logging/logMessage.hpp"
45 #include "memory/archiveUtils.inline.hpp"
46 #include "memory/dynamicArchive.hpp"
47 #include "memory/filemap.hpp"
48 #include "memory/lambdaFormInvokers.hpp"
49 #include "memory/heapShared.inline.hpp"
50 #include "memory/metaspace.hpp"
51 #include "memory/metaspaceClosure.hpp"
52 #include "memory/metaspaceShared.hpp"
53 #include "memory/resourceArea.hpp"
54 #include "memory/universe.hpp"
55 #include "oops/compressedOops.inline.hpp"
56 #include "oops/instanceClassLoaderKlass.hpp"
57 #include "oops/instanceMirrorKlass.hpp"
58 #include "oops/instanceRefKlass.hpp"
59 #include "oops/methodData.hpp"
60 #include "oops/objArrayKlass.hpp"
61 #include "oops/objArrayOop.hpp"
62 #include "oops/oop.inline.hpp"
63 #include "oops/typeArrayKlass.hpp"
64 #include "prims/jvmtiRedefineClasses.hpp"
65 #include "runtime/handles.inline.hpp"
66 #include "runtime/os.hpp"
67 #include "runtime/safepointVerifiers.hpp"
68 #include "runtime/signature.hpp"
646 }
647 }
648
649 class CollectClassesClosure : public KlassClosure {
650 void do_klass(Klass* k) {
651 if (k->is_instance_klass() &&
652 SystemDictionaryShared::is_excluded_class(InstanceKlass::cast(k))) {
653 // Don't add to the _global_klass_objects
654 } else {
655 _global_klass_objects->append_if_missing(k);
656 }
657 if (k->is_array_klass()) {
658 // Add in the array classes too
659 ArrayKlass* ak = ArrayKlass::cast(k);
660 Klass* h = ak->higher_dimension();
661 if (h != NULL) {
662 h->array_klasses_do(collect_array_classes);
663 }
664 }
665 }
666 public:
667 void add_extra_classes(GrowableArray<Klass*>* klass_list) {
668 if (klass_list != NULL && klass_list->length() > 0) {
669 for (int i = 0; i < klass_list->length(); i++) {
670 Klass* k = klass_list->at(i);
671 _global_klass_objects->append_if_missing(k);
672 }
673 }
674 }
675 };
676
677 // Global object for holding symbols that created during class loading. See SymbolTable::new_symbol
678 static GrowableArray<Symbol*>* _global_symbol_objects = NULL;
679
680 static int compare_symbols_by_address(Symbol** a, Symbol** b) {
681 if (a[0] < b[0]) {
682 return -1;
683 } else if (a[0] == b[0]) {
684 ResourceMark rm;
685 log_warning(cds)("Duplicated symbol %s unexpected", (*a)->as_C_string());
686 return 0;
687 } else {
688 return 1;
689 }
690 }
691
692 void MetaspaceShared::add_symbol(Symbol* sym) {
693 MutexLocker ml(CDSAddSymbol_lock, Mutex::_no_safepoint_check_flag);
694 if (_global_symbol_objects == NULL) {
1637
1638 FileMapInfo::check_nonempty_dir_in_shared_path_table();
1639
1640 NOT_PRODUCT(SystemDictionary::verify();)
1641 // The following guarantee is meant to ensure that no loader constraints
1642 // exist yet, since the constraints table is not shared. This becomes
1643 // more important now that we don't re-initialize vtables/itables for
1644 // shared classes at runtime, where constraints were previously created.
1645 guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
1646 "loader constraints are not saved");
1647 guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
1648 "placeholders are not saved");
1649
1650 // At this point, many classes have been loaded.
1651 // Gather systemDictionary classes in a global array and do everything to
1652 // that so we don't have to walk the SystemDictionary again.
1653 SystemDictionaryShared::check_excluded_classes();
1654 _global_klass_objects = new GrowableArray<Klass*>(1000);
1655 CollectClassesClosure collect_classes;
1656 ClassLoaderDataGraph::loaded_classes_do(&collect_classes);
1657 collect_classes.add_extra_classes(LambdaFormInvokers::replacement_holder_classes());
1658 _global_klass_objects->sort(global_klass_compare);
1659
1660 print_class_stats();
1661
1662 // Ensure the ConstMethods won't be modified at run-time
1663 log_info(cds)("Updating ConstMethods ... ");
1664 rewrite_nofast_bytecodes_and_calculate_fingerprints(THREAD);
1665 log_info(cds)("done. ");
1666
1667 // Remove all references outside the metadata
1668 log_info(cds)("Removing unshareable information ... ");
1669 remove_unshareable_in_classes();
1670 log_info(cds)("done. ");
1671
1672 MetaspaceShared::allocate_cloned_cpp_vtptrs();
1673 char* cloned_vtables = _mc_region.top();
1674 MetaspaceShared::allocate_cpp_vtable_clones();
1675
1676 ArchiveCompactor::initialize();
1677 ArchiveCompactor::copy_and_compact();
1908 "%sclasslist", os::file_separator());
1909 }
1910 class_list_path = class_list_path_str;
1911 } else {
1912 class_list_path = SharedClassListFile;
1913 }
1914
1915 log_info(cds)("Loading classes to share ...");
1916 _has_error_classes = false;
1917 int class_count = preload_classes(class_list_path, THREAD);
1918 if (ExtraSharedClassListFile) {
1919 class_count += preload_classes(ExtraSharedClassListFile, THREAD);
1920 }
1921 log_info(cds)("Loading classes to share: done.");
1922
1923 log_info(cds)("Shared spaces: preloaded %d classes", class_count);
1924
1925 if (SharedArchiveConfigFile) {
1926 log_info(cds)("Reading extra data from %s ...", SharedArchiveConfigFile);
1927 read_extra_data(SharedArchiveConfigFile, THREAD);
1928 log_info(cds)("Reading extra data: done.");
1929 }
1930
1931 if (LambdaFormInvokers::lambdaform_lines() != NULL) {
1932 log_info(cds)("Regenerate MethodHandle Holder classes...");
1933 LambdaFormInvokers::regenerate_holder_classes(THREAD);
1934 log_info(cds)("Regenerate MethodHandle Holder classes done.");
1935 }
1936
1937 HeapShared::init_subgraph_entry_fields(THREAD);
1938
1939 // Rewrite and link classes
1940 log_info(cds)("Rewriting and linking classes ...");
1941
1942 // Link any classes which got missed. This would happen if we have loaded classes that
1943 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
1944 // fails verification, all other interfaces that were not specified in the classlist but
1945 // are implemented by K are not verified.
1946 link_and_cleanup_shared_classes(CATCH);
1947 log_info(cds)("Rewriting and linking classes: done");
1948
1949 VM_PopulateDumpSharedSpace op;
1950 MutexLocker ml(THREAD, HeapShared::is_heap_object_archiving_allowed() ?
1951 Heap_lock : NULL); // needed by HeapShared::run_gc()
1952 VMThread::execute(&op);
1953 }
1954 }
1955
1956 int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) {
1957 ClassListParser parser(class_list_path);
1958 int class_count = 0;
1959
1960 while (parser.parse_one_line()) {
1961 Klass* klass = parser.load_current_class(THREAD);
1962 if (HAS_PENDING_EXCEPTION) {
1963 if (klass == NULL &&
1964 (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
1965 // print a warning only when the pending exception is class not found
1966 log_warning(cds)("Preload Warning: Cannot find %s", parser.current_class_name());
1967 }
1968 CLEAR_PENDING_EXCEPTION;
1969 }
1970 if (klass != NULL) {
1971 if (log_is_enabled(Trace, cds)) {
1972 ResourceMark rm(THREAD);
1973 log_trace(cds)("Shared spaces preloaded: %s", klass->external_name());
1974 }
1975
2692 st->print("CDS archive(s) mapped at: ");
2693 address base;
2694 address top;
2695 if (UseSharedSpaces) { // Runtime
2696 base = (address)MetaspaceObj::shared_metaspace_base();
2697 address static_top = (address)_shared_metaspace_static_top;
2698 top = (address)MetaspaceObj::shared_metaspace_top();
2699 st->print("[" PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "), ", p2i(base), p2i(static_top), p2i(top));
2700 } else if (DumpSharedSpaces) { // Dump Time
2701 base = (address)_shared_rs.base();
2702 top = (address)_shared_rs.end();
2703 st->print("[" PTR_FORMAT "-" PTR_FORMAT "), ", p2i(base), p2i(top));
2704 }
2705 st->print("size " SIZE_FORMAT ", ", top - base);
2706 st->print("SharedBaseAddress: " PTR_FORMAT ", ArchiveRelocationMode: %d.", SharedBaseAddress, (int)ArchiveRelocationMode);
2707 } else {
2708 st->print("CDS disabled.");
2709 }
2710 st->cr();
2711 }
|