hotspot/src/share/vm/memory/metaspaceShared.cpp
changeset 36178 9739f8c767da
parent 35231 e89989198037
child 37094 c12f414936a1
child 36508 5f9eee6b383b
equal deleted inserted replaced
36177:b2b76aba8e42 36178:9739f8c767da
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    38 #include "memory/filemap.hpp"
    38 #include "memory/filemap.hpp"
    39 #include "memory/metaspace.hpp"
    39 #include "memory/metaspace.hpp"
    40 #include "memory/metaspaceShared.hpp"
    40 #include "memory/metaspaceShared.hpp"
    41 #include "oops/objArrayOop.hpp"
    41 #include "oops/objArrayOop.hpp"
    42 #include "oops/oop.inline.hpp"
    42 #include "oops/oop.inline.hpp"
       
    43 #include "runtime/logTimer.hpp"
    43 #include "runtime/os.hpp"
    44 #include "runtime/os.hpp"
    44 #include "runtime/signature.hpp"
    45 #include "runtime/signature.hpp"
    45 #include "runtime/vmThread.hpp"
    46 #include "runtime/vmThread.hpp"
    46 #include "runtime/vm_operations.hpp"
    47 #include "runtime/vm_operations.hpp"
    47 #include "utilities/defaultStream.hpp"
    48 #include "utilities/defaultStream.hpp"
   769 }
   770 }
   770 
   771 
   771 // Preload classes from a list, populate the shared spaces and dump to a
   772 // Preload classes from a list, populate the shared spaces and dump to a
   772 // file.
   773 // file.
   773 void MetaspaceShared::preload_and_dump(TRAPS) {
   774 void MetaspaceShared::preload_and_dump(TRAPS) {
   774   TraceTime timer("Dump Shared Spaces", TraceStartupTime);
   775   { TraceStartupTime timer("Dump Shared Spaces");
   775   ResourceMark rm;
   776     ResourceMark rm;
   776   char class_list_path_str[JVM_MAXPATHLEN];
   777     char class_list_path_str[JVM_MAXPATHLEN];
   777 
   778 
   778   tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
   779     tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
   779                 MetaspaceShared::shared_rs()->size(),
   780                   MetaspaceShared::shared_rs()->size(),
   780                 p2i(MetaspaceShared::shared_rs()->base()));
   781                   p2i(MetaspaceShared::shared_rs()->base()));
   781 
   782 
   782   // Preload classes to be shared.
   783     // Preload classes to be shared.
   783   // Should use some os:: method rather than fopen() here. aB.
   784     // Should use some os:: method rather than fopen() here. aB.
   784   const char* class_list_path;
   785     const char* class_list_path;
   785   if (SharedClassListFile == NULL) {
   786     if (SharedClassListFile == NULL) {
   786     // Construct the path to the class list (in jre/lib)
   787       // Construct the path to the class list (in jre/lib)
   787     // Walk up two directories from the location of the VM and
   788       // Walk up two directories from the location of the VM and
   788     // optionally tack on "lib" (depending on platform)
   789       // optionally tack on "lib" (depending on platform)
   789     os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
   790       os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
   790     for (int i = 0; i < 3; i++) {
   791       for (int i = 0; i < 3; i++) {
   791       char *end = strrchr(class_list_path_str, *os::file_separator());
   792         char *end = strrchr(class_list_path_str, *os::file_separator());
   792       if (end != NULL) *end = '\0';
   793         if (end != NULL) *end = '\0';
   793     }
   794       }
   794     int class_list_path_len = (int)strlen(class_list_path_str);
   795       int class_list_path_len = (int)strlen(class_list_path_str);
   795     if (class_list_path_len >= 3) {
   796       if (class_list_path_len >= 3) {
   796       if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
   797         if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
   797         if (class_list_path_len < JVM_MAXPATHLEN - 4) {
   798           if (class_list_path_len < JVM_MAXPATHLEN - 4) {
   798           jio_snprintf(class_list_path_str + class_list_path_len,
   799             jio_snprintf(class_list_path_str + class_list_path_len,
   799                        sizeof(class_list_path_str) - class_list_path_len,
   800                          sizeof(class_list_path_str) - class_list_path_len,
   800                        "%slib", os::file_separator());
   801                          "%slib", os::file_separator());
   801           class_list_path_len += 4;
   802             class_list_path_len += 4;
       
   803           }
   802         }
   804         }
   803       }
   805       }
   804     }
   806       if (class_list_path_len < JVM_MAXPATHLEN - 10) {
   805     if (class_list_path_len < JVM_MAXPATHLEN - 10) {
   807         jio_snprintf(class_list_path_str + class_list_path_len,
   806       jio_snprintf(class_list_path_str + class_list_path_len,
   808                      sizeof(class_list_path_str) - class_list_path_len,
   807                    sizeof(class_list_path_str) - class_list_path_len,
   809                      "%sclasslist", os::file_separator());
   808                    "%sclasslist", os::file_separator());
   810       }
   809     }
   811       class_list_path = class_list_path_str;
   810     class_list_path = class_list_path_str;
   812     } else {
   811   } else {
   813       class_list_path = SharedClassListFile;
   812     class_list_path = SharedClassListFile;
   814     }
   813   }
   815 
   814 
   816     int class_count = 0;
   815   int class_count = 0;
   817     GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
   816   GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
   818 
   817 
   819     // sun.io.Converters
   818   // sun.io.Converters
   820     static const char obj_array_sig[] = "[[Ljava/lang/Object;";
   819   static const char obj_array_sig[] = "[[Ljava/lang/Object;";
   821     SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
   820   SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
   822 
   821 
   823     // java.util.HashMap
   822   // java.util.HashMap
   824     static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
   823   static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
   825     SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
   824   SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
   826 
   825 
   827     // Need to allocate the op here:
   826   // Need to allocate the op here:
   828     // op.misc_data_space_alloc() will be called during preload_and_dump().
   827   // op.misc_data_space_alloc() will be called during preload_and_dump().
   829     ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
   828   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
   830     VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
   829   VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
   831 
   830 
   832     tty->print_cr("Loading classes to share ...");
   831   tty->print_cr("Loading classes to share ...");
   833     _has_error_classes = false;
   832   _has_error_classes = false;
   834     class_count += preload_and_dump(class_list_path, class_promote_order,
   833   class_count += preload_and_dump(class_list_path, class_promote_order,
       
   834                                   THREAD);
       
   835   if (ExtraSharedClassListFile) {
       
   836     class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
       
   837                                     THREAD);
   835                                     THREAD);
   838   }
   836     if (ExtraSharedClassListFile) {
   839   tty->print_cr("Loading classes to share: done.");
   837       class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
   840 
   838                                       THREAD);
   841   if (PrintSharedSpaces) {
   839     }
   842     tty->print_cr("Shared spaces: preloaded %d classes", class_count);
   840     tty->print_cr("Loading classes to share: done.");
   843   }
   841 
   844 
   842     if (PrintSharedSpaces) {
   845   // Rewrite and link classes
   843       tty->print_cr("Shared spaces: preloaded %d classes", class_count);
   846   tty->print_cr("Rewriting and linking classes ...");
   844     }
   847 
   845 
   848   // Link any classes which got missed. This would happen if we have loaded classes that
   846     // Rewrite and link classes
   849   // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
   847     tty->print_cr("Rewriting and linking classes ...");
   850   // fails verification, all other interfaces that were not specified in the classlist but
   848 
   851   // are implemented by K are not verified.
   849     // Link any classes which got missed. This would happen if we have loaded classes that
   852   link_and_cleanup_shared_classes(CATCH);
   850     // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
   853   tty->print_cr("Rewriting and linking classes: done");
   851     // fails verification, all other interfaces that were not specified in the classlist but
   854 
   852     // are implemented by K are not verified.
   855   VMThread::execute(&op);
   853     link_and_cleanup_shared_classes(CATCH);
       
   854     tty->print_cr("Rewriting and linking classes: done");
       
   855 
       
   856     VMThread::execute(&op);
       
   857   }
   856   // Since various initialization steps have been undone by this process,
   858   // Since various initialization steps have been undone by this process,
   857   // it is not reasonable to continue running a java process.
   859   // it is not reasonable to continue running a java process.
   858   exit(0);
   860   exit(0);
   859 }
   861 }
   860 
   862