< prev index next >

src/hotspot/share/memory/filemap.cpp

Print this page
   1 /*
   2  * Copyright (c) 2003, 2018, 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  *


  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "classfile/systemDictionaryShared.hpp"
  31 #include "classfile/altHashing.hpp"
  32 #include "logging/log.hpp"
  33 #include "logging/logStream.hpp"
  34 #include "logging/logMessage.hpp"
  35 #include "memory/filemap.hpp"
  36 #include "memory/heapShared.inline.hpp"
  37 #include "memory/iterator.inline.hpp"
  38 #include "memory/metadataFactory.hpp"
  39 #include "memory/metaspaceClosure.hpp"
  40 #include "memory/metaspaceShared.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "oops/compressedOops.inline.hpp"
  43 #include "oops/objArrayOop.hpp"
  44 #include "oops/oop.inline.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "runtime/arguments.hpp"
  47 #include "runtime/java.hpp"

  48 #include "runtime/os.inline.hpp"
  49 #include "runtime/vm_version.hpp"
  50 #include "services/memTracker.hpp"
  51 #include "utilities/align.hpp"
  52 #include "utilities/defaultStream.hpp"
  53 #if INCLUDE_G1GC
  54 #include "gc/g1/g1CollectedHeap.hpp"
  55 #include "gc/g1/heapRegion.hpp"
  56 #endif
  57 
  58 # include <sys/stat.h>
  59 # include <errno.h>
  60 
  61 #ifndef O_BINARY       // if defined (Win32) use binary files.
  62 #define O_BINARY 0     // otherwise do nothing.
  63 #endif
  64 
  65 extern address JVM_FunctionAtStart();
  66 extern address JVM_FunctionAtEnd();
  67 


 484   // validate the path entries up to the _max_used_path_index
 485   for (int i=0; i < _header->_max_used_path_index + 1; i++) {
 486     if (i < module_paths_start_index) {
 487       if (shared_path(i)->validate()) {
 488         log_info(class, path)("ok");
 489       } else {
 490         assert(!UseSharedSpaces, "UseSharedSpaces should be disabled");
 491         return false;
 492       }
 493     } else if (i >= module_paths_start_index) {
 494       if (shared_path(i)->validate(false /* not a class path entry */)) {
 495         log_info(class, path)("ok");
 496       } else {
 497         assert(!UseSharedSpaces, "UseSharedSpaces should be disabled");
 498         return false;
 499       }
 500     }
 501   }
 502 
 503   _validating_shared_path_table = false;










 504   return true;
 505 }
 506 
 507 // Read the FileMapInfo information from the file.
 508 
 509 bool FileMapInfo::init_from_file(int fd) {
 510   size_t sz = sizeof(FileMapHeader);
 511   size_t n = os::read(fd, _header, (unsigned int)sz);
 512   if (n != sz) {
 513     fail_continue("Unable to read the file header.");
 514     return false;
 515   }
 516   if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) {
 517     fail_continue("The shared archive file has the wrong version.");
 518     return false;
 519   }
 520   _file_offset = (long)n;
 521 
 522   size_t info_size = _header->_paths_misc_info_size;
 523   _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass);


1423       if (!HeapShared::is_heap_region(i)) {
1424         char *addr = map_info->region_addr(i);
1425         if (addr != NULL) {
1426           map_info->unmap_region(i);
1427           map_info->space_at(i)->_addr._base = NULL;
1428         }
1429       }
1430     }
1431     // Dealloc the archive heap regions only without unmapping. The regions are part
1432     // of the java heap. Unmapping of the heap regions are managed by GC.
1433     map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
1434                                            num_open_archive_heap_ranges,
1435                                            true);
1436     map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
1437                                            num_closed_archive_heap_ranges,
1438                                            false);
1439   } else if (DumpSharedSpaces) {
1440     fail_stop("%s", msg);
1441   }
1442 }






















































   1 /*
   2  * Copyright (c) 2003, 2019, 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  *


  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "classfile/systemDictionaryShared.hpp"
  31 #include "classfile/altHashing.hpp"
  32 #include "logging/log.hpp"
  33 #include "logging/logStream.hpp"
  34 #include "logging/logMessage.hpp"
  35 #include "memory/filemap.hpp"
  36 #include "memory/heapShared.inline.hpp"
  37 #include "memory/iterator.inline.hpp"
  38 #include "memory/metadataFactory.hpp"
  39 #include "memory/metaspaceClosure.hpp"
  40 #include "memory/metaspaceShared.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "oops/compressedOops.inline.hpp"
  43 #include "oops/objArrayOop.hpp"
  44 #include "oops/oop.inline.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "runtime/arguments.hpp"
  47 #include "runtime/java.hpp"
  48 #include "runtime/mutexLocker.hpp"
  49 #include "runtime/os.inline.hpp"
  50 #include "runtime/vm_version.hpp"
  51 #include "services/memTracker.hpp"
  52 #include "utilities/align.hpp"
  53 #include "utilities/defaultStream.hpp"
  54 #if INCLUDE_G1GC
  55 #include "gc/g1/g1CollectedHeap.hpp"
  56 #include "gc/g1/heapRegion.hpp"
  57 #endif
  58 
  59 # include <sys/stat.h>
  60 # include <errno.h>
  61 
  62 #ifndef O_BINARY       // if defined (Win32) use binary files.
  63 #define O_BINARY 0     // otherwise do nothing.
  64 #endif
  65 
  66 extern address JVM_FunctionAtStart();
  67 extern address JVM_FunctionAtEnd();
  68 


 485   // validate the path entries up to the _max_used_path_index
 486   for (int i=0; i < _header->_max_used_path_index + 1; i++) {
 487     if (i < module_paths_start_index) {
 488       if (shared_path(i)->validate()) {
 489         log_info(class, path)("ok");
 490       } else {
 491         assert(!UseSharedSpaces, "UseSharedSpaces should be disabled");
 492         return false;
 493       }
 494     } else if (i >= module_paths_start_index) {
 495       if (shared_path(i)->validate(false /* not a class path entry */)) {
 496         log_info(class, path)("ok");
 497       } else {
 498         assert(!UseSharedSpaces, "UseSharedSpaces should be disabled");
 499         return false;
 500       }
 501     }
 502   }
 503 
 504   _validating_shared_path_table = false;
 505 
 506 #if INCLUDE_JVMTI
 507   if (_classpath_entries_for_jvmti != NULL) {
 508     os::free(_classpath_entries_for_jvmti);
 509   }
 510   size_t sz = sizeof(ClassPathEntry*) *  _shared_path_table_size;
 511   _classpath_entries_for_jvmti = (ClassPathEntry**)os::malloc(sz, mtClass);
 512   memset(_classpath_entries_for_jvmti, 0, sz);
 513 #endif
 514 
 515   return true;
 516 }
 517 
 518 // Read the FileMapInfo information from the file.
 519 
 520 bool FileMapInfo::init_from_file(int fd) {
 521   size_t sz = sizeof(FileMapHeader);
 522   size_t n = os::read(fd, _header, (unsigned int)sz);
 523   if (n != sz) {
 524     fail_continue("Unable to read the file header.");
 525     return false;
 526   }
 527   if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) {
 528     fail_continue("The shared archive file has the wrong version.");
 529     return false;
 530   }
 531   _file_offset = (long)n;
 532 
 533   size_t info_size = _header->_paths_misc_info_size;
 534   _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass);


1434       if (!HeapShared::is_heap_region(i)) {
1435         char *addr = map_info->region_addr(i);
1436         if (addr != NULL) {
1437           map_info->unmap_region(i);
1438           map_info->space_at(i)->_addr._base = NULL;
1439         }
1440       }
1441     }
1442     // Dealloc the archive heap regions only without unmapping. The regions are part
1443     // of the java heap. Unmapping of the heap regions are managed by GC.
1444     map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
1445                                            num_open_archive_heap_ranges,
1446                                            true);
1447     map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
1448                                            num_closed_archive_heap_ranges,
1449                                            false);
1450   } else if (DumpSharedSpaces) {
1451     fail_stop("%s", msg);
1452   }
1453 }
1454 
1455 #if INCLUDE_JVMTI
1456 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = NULL;
1457 
1458 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
1459   ClassPathEntry* ent = _classpath_entries_for_jvmti[i];
1460   if (ent == NULL) {
1461     if (i == 0) {
1462       ent = ClassLoader:: get_jrt_entry();
1463       assert(ent != NULL, "must be");
1464     } else {
1465       SharedClassPathEntry* scpe = shared_path(i);
1466       assert(scpe->is_jar(), "must be"); // other types of scpe will not produce archived classes
1467 
1468       const char* path = scpe->name();
1469       struct stat st;
1470       if (os::stat(path, &st) != 0) {
1471         char *msg = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(path) + 128); ;
1472         jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
1473         THROW_MSG_(vmSymbols::java_io_IOException(), msg, NULL);
1474       } else {
1475         ent = ClassLoader::create_class_path_entry(path, &st, /*throw_exception=*/true, false, CHECK_NULL);
1476       }
1477     }
1478 
1479     MutexLocker mu(CDSClassFileStream_lock, THREAD);
1480     if (_classpath_entries_for_jvmti[i] == NULL) {
1481       _classpath_entries_for_jvmti[i] = ent;
1482     } else {
1483       // Another thread has beat me to creating this entry
1484       delete ent;
1485       ent = _classpath_entries_for_jvmti[i];
1486     }
1487   }
1488 
1489   return ent;
1490 }
1491 
1492 ClassFileStream* FileMapInfo::open_stream_for_jvmti(InstanceKlass* ik, TRAPS) {
1493   int path_index = ik->shared_classpath_index();
1494   assert(path_index >= 0, "should be called for shared built-in classes only");
1495   assert(path_index < (int)_shared_path_table_size, "sanity");
1496 
1497   ClassPathEntry* cpe = get_classpath_entry_for_jvmti(path_index, CHECK_NULL);
1498   assert(cpe != NULL, "must be");
1499 
1500   Symbol* name = ik->name();
1501   const char* const class_name = name->as_C_string();
1502   const char* const file_name = ClassLoader::file_name_for_class_name(class_name,
1503                                                                       name->utf8_length());
1504   return cpe->open_stream(file_name, THREAD);
1505 }
1506 
1507 #endif
< prev index next >