Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/memory/filemap.hpp
32285 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_MEMORY_FILEMAP_HPP25#define SHARE_VM_MEMORY_FILEMAP_HPP2627#include "memory/metaspaceShared.hpp"28#include "memory/metaspace.hpp"2930// Layout of the file:31// header: dump of archive instance plus versioning info, datestamp, etc.32// [magic # = 0xF00BABA2]33// ... padding to align on page-boundary34// read-write space from CompactingPermGenGen35// read-only space from CompactingPermGenGen36// misc data (block offset table, string table, symbols, dictionary, etc.)37// tag(666)3839static const int JVM_IDENT_MAX = 256;4041class Metaspace;4243class SharedClassPathEntry VALUE_OBJ_CLASS_SPEC {44public:45const char *_name;46time_t _timestamp; // jar timestamp, 0 if is directory47long _filesize; // jar file size, -1 if is directory48bool is_dir() {49return _filesize == -1;50}51};5253class FileMapInfo : public CHeapObj<mtInternal> {54private:55friend class ManifestStream;56enum {57_invalid_version = -1,58_current_version = 259};6061bool _file_open;62int _fd;63size_t _file_offset;6465private:66static SharedClassPathEntry* _classpath_entry_table;67static int _classpath_entry_table_size;68static size_t _classpath_entry_size;69static bool _validating_classpath_entry_table;7071// FileMapHeader describes the shared space data in the file to be72// mapped. This structure gets written to a file. It is not a class, so73// that the compilers don't add any compiler-private data to it.7475public:76struct FileMapHeaderBase : public CHeapObj<mtClass> {77virtual bool validate() = 0;78virtual void populate(FileMapInfo* info, size_t alignment) = 0;79};80struct FileMapHeader : FileMapHeaderBase {81// Use data() and data_size() to memcopy to/from the FileMapHeader. We need to82// avoid read/writing the C++ vtable pointer.83static size_t data_size();84char* data() {85return ((char*)this) + sizeof(FileMapHeaderBase);86}8788int _magic; // identify file type.89int _crc; // header crc checksum.90int _version; // (from enum, above.)91size_t _alignment; // how shared archive should be aligned92int _obj_alignment; // value of ObjectAlignmentInBytes9394struct space_info {95int _crc; // crc checksum of the current space96size_t _file_offset; // sizeof(this) rounded to vm page size97char* _base; // copy-on-write base address98size_t _capacity; // for validity checking99size_t _used; // for setting space top on read100bool _read_only; // read only space?101bool _allow_exec; // executable code in space?102} _space[MetaspaceShared::n_regions];103104// The following fields are all sanity checks for whether this archive105// will function correctly with this JVM and the bootclasspath it's106// invoked with.107char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm108109// The _paths_misc_info is a variable-size structure that records "miscellaneous"110// information during dumping. It is generated and validated by the111// SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp and sharedClassUtil.hpp for112// detailed description.113//114// The _paths_misc_info data is stored as a byte array in the archive file header,115// immediately after the _header field. This information is used only when116// checking the validity of the archive and is deallocated after the archive is loaded.117//118// Note that the _paths_misc_info does NOT include information for JAR files119// that existed during dump time. Their information is stored in _classpath_entry_table.120int _paths_misc_info_size;121122// The following is a table of all the class path entries that were used123// during dumping. At run time, we require these files to exist and have the same124// size/modification time, or else the archive will refuse to load.125//126// All of these entries must be JAR files. The dumping process would fail if a non-empty127// directory was specified in the classpaths. If an empty directory was specified128// it is checked by the _paths_misc_info as described above.129//130// FIXME -- if JAR files in the tail of the list were specified but not used during dumping,131// they should be removed from this table, to save space and to avoid spurious132// loading failures during runtime.133int _classpath_entry_table_size;134size_t _classpath_entry_size;135SharedClassPathEntry* _classpath_entry_table;136137virtual bool validate();138virtual void populate(FileMapInfo* info, size_t alignment);139int compute_crc();140};141142FileMapHeader * _header;143144const char* _full_path;145char* _paths_misc_info;146147static FileMapInfo* _current_info;148149bool init_from_file(int fd);150void align_file_position();151bool validate_header_impl();152153public:154FileMapInfo();155~FileMapInfo();156157static int current_version() { return _current_version; }158int compute_header_crc();159void set_header_crc(int crc) { _header->_crc = crc; }160void populate_header(size_t alignment);161bool validate_header();162void invalidate();163int version() { return _header->_version; }164size_t alignment() { return _header->_alignment; }165size_t space_capacity(int i) { return _header->_space[i]._capacity; }166char* region_base(int i) { return _header->_space[i]._base; }167struct FileMapHeader* header() { return _header; }168169static FileMapInfo* current_info() {170CDS_ONLY(return _current_info;)171NOT_CDS(return NULL;)172}173174static void assert_mark(bool check);175176// File manipulation.177bool initialize() NOT_CDS_RETURN_(false);178bool open_for_read();179void open_for_write();180void write_header();181void write_space(int i, Metaspace* space, bool read_only);182void write_region(int region, char* base, size_t size,183size_t capacity, bool read_only, bool allow_exec);184void write_bytes(const void* buffer, int count);185void write_bytes_aligned(const void* buffer, int count);186char* map_region(int i);187void unmap_region(int i);188bool verify_region_checksum(int i);189void close();190bool is_open() { return _file_open; }191ReservedSpace reserve_shared_memory();192193// JVM/TI RedefineClasses() support:194// Remap the shared readonly space to shared readwrite, private.195bool remap_shared_readonly_as_readwrite();196197// Errors.198static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);199static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);200201// Return true if given address is in the mapped shared space.202bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);203void print_shared_spaces() NOT_CDS_RETURN;204205static size_t shared_spaces_size() {206return align_size_up(SharedReadOnlySize + SharedReadWriteSize +207SharedMiscDataSize + SharedMiscCodeSize,208os::vm_allocation_granularity());209}210211// Stop CDS sharing and unmap CDS regions.212static void stop_sharing_and_unmap(const char* msg);213214static void allocate_classpath_entry_table();215bool validate_classpath_entry_table();216217static SharedClassPathEntry* shared_classpath(int index) {218char* p = (char*)_classpath_entry_table;219p += _classpath_entry_size * index;220return (SharedClassPathEntry*)p;221}222static const char* shared_classpath_name(int index) {223return shared_classpath(index)->_name;224}225226static int get_number_of_share_classpaths() {227return _classpath_entry_table_size;228}229};230231#endif // SHARE_VM_MEMORY_FILEMAP_HPP232233234