duke@435: /* stefank@2314: * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_MEMORY_FILEMAP_HPP stefank@2314: #define SHARE_VM_MEMORY_FILEMAP_HPP stefank@2314: stefank@2314: #include "memory/compactingPermGenGen.hpp" stefank@2314: #include "memory/space.hpp" stefank@2314: duke@435: // Layout of the file: duke@435: // header: dump of archive instance plus versioning info, datestamp, etc. duke@435: // [magic # = 0xF00BABA2] duke@435: // ... padding to align on page-boundary duke@435: // read-write space from CompactingPermGenGen duke@435: // read-only space from CompactingPermGenGen duke@435: // misc data (block offset table, string table, symbols, dictionary, etc.) duke@435: // tag(666) duke@435: duke@435: static const int JVM_SHARED_JARS_MAX = 128; duke@435: static const int JVM_SPACENAME_MAX = 128; duke@435: static const int JVM_IDENT_MAX = 256; duke@435: static const int JVM_ARCH_MAX = 12; duke@435: duke@435: duke@435: duke@435: class FileMapInfo : public CHeapObj { duke@435: private: duke@435: enum { duke@435: _invalid_version = -1, duke@435: _current_version = 1 duke@435: }; duke@435: duke@435: bool _file_open; duke@435: int _fd; duke@435: long _file_offset; duke@435: duke@435: // FileMapHeader describes the shared space data in the file to be duke@435: // mapped. This structure gets written to a file. It is not a class, so duke@435: // that the compilers don't add any compiler-private data to it. duke@435: duke@435: struct FileMapHeader { duke@435: int _magic; // identify file type. duke@435: int _version; // (from enum, above.) duke@435: size_t _alignment; // how shared archive should be aligned duke@435: duke@435: struct space_info { duke@435: int _file_offset; // sizeof(this) rounded to vm page size duke@435: char* _base; // copy-on-write base address duke@435: size_t _capacity; // for validity checking duke@435: size_t _used; // for setting space top on read duke@435: bool _read_only; // read only space? duke@435: bool _allow_exec; // executable code in space? duke@435: } _space[CompactingPermGenGen::n_regions]; duke@435: duke@435: // The following fields are all sanity checks for whether this archive duke@435: // will function correctly with this JVM and the bootclasspath it's duke@435: // invoked with. duke@435: char _arch[JVM_ARCH_MAX]; // architecture duke@435: char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm duke@435: int _num_jars; // Number of jars in bootclasspath duke@435: duke@435: // Per jar file data: timestamp, size. duke@435: duke@435: struct { duke@435: time_t _timestamp; // jar timestamp. duke@435: long _filesize; // jar file size. duke@435: } _jar[JVM_SHARED_JARS_MAX]; duke@435: } _header; duke@435: const char* _full_path; duke@435: duke@435: static FileMapInfo* _current_info; duke@435: duke@435: bool init_from_file(int fd); duke@435: void align_file_position(); duke@435: duke@435: public: duke@435: FileMapInfo() { duke@435: _file_offset = 0; duke@435: _file_open = false; duke@435: _header._version = _invalid_version; duke@435: } duke@435: duke@435: static int current_version() { return _current_version; } duke@435: void populate_header(size_t alignment); duke@435: bool validate(); duke@435: void invalidate(); duke@435: int version() { return _header._version; } duke@435: size_t alignment() { return _header._alignment; } duke@435: size_t space_capacity(int i) { return _header._space[i]._capacity; } duke@435: char* region_base(int i) { return _header._space[i]._base; } duke@435: struct FileMapHeader* header() { return &_header; } duke@435: duke@435: static void set_current_info(FileMapInfo* info) { _current_info = info; } duke@435: static FileMapInfo* current_info() { return _current_info; } duke@435: static void assert_mark(bool check); duke@435: duke@435: // File manipulation. duke@435: bool initialize(); duke@435: bool open_for_read(); duke@435: void open_for_write(); duke@435: void write_header(); duke@435: void write_space(int i, CompactibleSpace* space, bool read_only); duke@435: void write_region(int region, char* base, size_t size, duke@435: size_t capacity, bool read_only, bool allow_exec); duke@435: void write_bytes(const void* buffer, int count); duke@435: void write_bytes_aligned(const void* buffer, int count); duke@435: bool map_space(int i, ReservedSpace rs, ContiguousSpace *space); duke@435: char* map_region(int i, ReservedSpace rs); duke@435: char* map_region(int i, bool address_must_match); duke@435: void unmap_region(int i); duke@435: void close(); duke@435: bool is_open() { return _file_open; } duke@435: duke@435: // JVM/TI RedefineClasses() support: duke@435: // Remap the shared readonly space to shared readwrite, private. duke@435: bool remap_shared_readonly_as_readwrite(); duke@435: duke@435: // Errors. duke@435: static void fail_stop(const char *msg, ...); duke@435: void fail_continue(const char *msg, ...); duke@435: duke@435: // Return true if given address is in the mapped shared space. duke@435: bool is_in_shared_space(const void* p); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_MEMORY_FILEMAP_HPP