< prev index next >

src/hotspot/share/memory/metaspaceShared.cpp

Print this page


  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/classListParser.hpp"
  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/dictionary.hpp"
  30 #include "classfile/loaderConstraints.hpp"
  31 #include "classfile/placeholders.hpp"
  32 #include "classfile/sharedClassUtil.hpp"
  33 #include "classfile/symbolTable.hpp"
  34 #include "classfile/stringTable.hpp"
  35 #include "classfile/systemDictionary.hpp"
  36 #include "classfile/systemDictionaryShared.hpp"
  37 #include "code/codeCache.hpp"
  38 #include "interpreter/bytecodeStream.hpp"
  39 #include "interpreter/bytecodes.hpp"
  40 #include "logging/log.hpp"
  41 #include "logging/logMessage.hpp"
  42 #include "memory/filemap.hpp"
  43 #include "memory/metaspace.hpp"
  44 #include "memory/metaspaceClosure.hpp"
  45 #include "memory/metaspaceShared.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/compressedOops.inline.hpp"
  48 #include "oops/instanceClassLoaderKlass.hpp"
  49 #include "oops/instanceMirrorKlass.hpp"
  50 #include "oops/instanceRefKlass.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/objArrayOop.hpp"


 304   // Set the range of klass addresses to 4GB.
 305   Universe::set_narrow_klass_range(cds_total);
 306 
 307   Metaspace::initialize_class_space(tmp_class_space);
 308   tty->print_cr("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
 309                 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
 310 
 311   tty->print_cr("Allocated temporary class space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 312                 CompressedClassSpaceSize, p2i(tmp_class_space.base()));
 313 #endif
 314 
 315   // Start with 0 committed bytes. The memory will be committed as needed by
 316   // MetaspaceShared::commit_shared_space_to().
 317   if (!_shared_vs.initialize(_shared_rs, 0)) {
 318     vm_exit_during_initialization("Unable to allocate memory for shared space");
 319   }
 320 
 321   _mc_region.init(&_shared_rs);
 322   tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 323                 _shared_rs.size(), p2i(_shared_rs.base()));








































 324 }
 325 
 326 void MetaspaceShared::commit_shared_space_to(char* newtop) {
 327   assert(DumpSharedSpaces, "dump-time only");
 328   char* base = _shared_rs.base();
 329   size_t need_committed_size = newtop - base;
 330   size_t has_committed_size = _shared_vs.committed_size();
 331   if (need_committed_size < has_committed_size) {
 332     return;
 333   }
 334 
 335   size_t min_bytes = need_committed_size - has_committed_size;
 336   size_t preferred_bytes = 1 * M;
 337   size_t uncommitted = _shared_vs.reserved_size() - has_committed_size;
 338 
 339   size_t commit = MAX2(min_bytes, preferred_bytes);
 340   assert(commit <= uncommitted, "sanity");
 341 
 342   bool result = _shared_vs.expand_by(commit, false);
 343   if (!result) {




  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/classListParser.hpp"
  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/dictionary.hpp"
  30 #include "classfile/loaderConstraints.hpp"
  31 #include "classfile/placeholders.hpp"

  32 #include "classfile/symbolTable.hpp"
  33 #include "classfile/stringTable.hpp"
  34 #include "classfile/systemDictionary.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #include "code/codeCache.hpp"
  37 #include "interpreter/bytecodeStream.hpp"
  38 #include "interpreter/bytecodes.hpp"
  39 #include "logging/log.hpp"
  40 #include "logging/logMessage.hpp"
  41 #include "memory/filemap.hpp"
  42 #include "memory/metaspace.hpp"
  43 #include "memory/metaspaceClosure.hpp"
  44 #include "memory/metaspaceShared.hpp"
  45 #include "memory/resourceArea.hpp"
  46 #include "oops/compressedOops.inline.hpp"
  47 #include "oops/instanceClassLoaderKlass.hpp"
  48 #include "oops/instanceMirrorKlass.hpp"
  49 #include "oops/instanceRefKlass.hpp"
  50 #include "oops/objArrayKlass.hpp"
  51 #include "oops/objArrayOop.hpp"


 303   // Set the range of klass addresses to 4GB.
 304   Universe::set_narrow_klass_range(cds_total);
 305 
 306   Metaspace::initialize_class_space(tmp_class_space);
 307   tty->print_cr("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
 308                 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
 309 
 310   tty->print_cr("Allocated temporary class space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 311                 CompressedClassSpaceSize, p2i(tmp_class_space.base()));
 312 #endif
 313 
 314   // Start with 0 committed bytes. The memory will be committed as needed by
 315   // MetaspaceShared::commit_shared_space_to().
 316   if (!_shared_vs.initialize(_shared_rs, 0)) {
 317     vm_exit_during_initialization("Unable to allocate memory for shared space");
 318   }
 319 
 320   _mc_region.init(&_shared_rs);
 321   tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
 322                 _shared_rs.size(), p2i(_shared_rs.base()));
 323 }
 324 
 325 // Called by universe_post_init()
 326 void MetaspaceShared::post_initialize(TRAPS) {
 327   if (UseSharedSpaces) {
 328     int size = FileMapInfo::get_number_of_shared_paths();
 329     if (size > 0) {
 330       SystemDictionaryShared::allocate_shared_data_arrays(size, THREAD);
 331       FileMapInfo::FileMapHeader* header = FileMapInfo::current_info()->header();
 332       ClassLoaderExt::init_paths_start_index(header->_app_class_paths_start_index);
 333       ClassLoaderExt::init_app_module_paths_start_index(header->_app_module_paths_start_index);
 334     }
 335   }
 336 
 337   if (DumpSharedSpaces) {
 338     if (SharedArchiveConfigFile) {
 339       read_extra_data(SharedArchiveConfigFile, THREAD);
 340     }
 341   }
 342 }
 343 
 344 void MetaspaceShared::read_extra_data(const char* filename, TRAPS) {
 345   HashtableTextDump reader(filename);
 346   reader.check_version("VERSION: 1.0");
 347 
 348   while (reader.remain() > 0) {
 349     int utf8_length;
 350     int prefix_type = reader.scan_prefix(&utf8_length);
 351     ResourceMark rm(THREAD);
 352     char* utf8_buffer = NEW_RESOURCE_ARRAY(char, utf8_length);
 353     reader.get_utf8(utf8_buffer, utf8_length);
 354 
 355     if (prefix_type == HashtableTextDump::SymbolPrefix) {
 356       SymbolTable::new_symbol(utf8_buffer, utf8_length, THREAD);
 357     } else{
 358       assert(prefix_type == HashtableTextDump::StringPrefix, "Sanity");
 359       utf8_buffer[utf8_length] = '\0';
 360       oop s = StringTable::intern(utf8_buffer, THREAD);
 361     }
 362   }
 363 }
 364 
 365 void MetaspaceShared::commit_shared_space_to(char* newtop) {
 366   assert(DumpSharedSpaces, "dump-time only");
 367   char* base = _shared_rs.base();
 368   size_t need_committed_size = newtop - base;
 369   size_t has_committed_size = _shared_vs.committed_size();
 370   if (need_committed_size < has_committed_size) {
 371     return;
 372   }
 373 
 374   size_t min_bytes = need_committed_size - has_committed_size;
 375   size_t preferred_bytes = 1 * M;
 376   size_t uncommitted = _shared_vs.reserved_size() - has_committed_size;
 377 
 378   size_t commit = MAX2(min_bytes, preferred_bytes);
 379   assert(commit <= uncommitted, "sanity");
 380 
 381   bool result = _shared_vs.expand_by(commit, false);
 382   if (!result) {


< prev index next >