filemap.hpp revision 1879
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_MEMORY_FILEMAP_HPP
#define SHARE_VM_MEMORY_FILEMAP_HPP
#include "memory/compactingPermGenGen.hpp"
// Layout of the file:
// header: dump of archive instance plus versioning info, datestamp, etc.
// [magic # = 0xF00BABA2]
// ... padding to align on page-boundary
// read-write space from CompactingPermGenGen
// read-only space from CompactingPermGenGen
// misc data (block offset table, string table, symbols, dictionary, etc.)
// tag(666)
static const int JVM_SHARED_JARS_MAX = 128;
static const int JVM_SPACENAME_MAX = 128;
static const int JVM_IDENT_MAX = 256;
static const int JVM_ARCH_MAX = 12;
class FileMapInfo : public CHeapObj {
private:
enum {
_invalid_version = -1,
_current_version = 1
};
bool _file_open;
int _fd;
long _file_offset;
// FileMapHeader describes the shared space data in the file to be
// mapped. This structure gets written to a file. It is not a class, so
// that the compilers don't add any compiler-private data to it.
struct FileMapHeader {
int _magic; // identify file type.
int _version; // (from enum, above.)
struct space_info {
int _file_offset; // sizeof(this) rounded to vm page size
char* _base; // copy-on-write base address
bool _read_only; // read only space?
bool _allow_exec; // executable code in space?
// The following fields are all sanity checks for whether this archive
// will function correctly with this JVM and the bootclasspath it's
// invoked with.
int _num_jars; // Number of jars in bootclasspath
// Per jar file data: timestamp, size.
struct {
long _filesize; // jar file size.
} _header;
const char* _full_path;
static FileMapInfo* _current_info;
bool init_from_file(int fd);
void align_file_position();
public:
FileMapInfo() {
_file_offset = 0;
_file_open = false;
}
static int current_version() { return _current_version; }
bool validate();
void invalidate();
static void assert_mark(bool check);
// File manipulation.
bool initialize();
bool open_for_read();
void open_for_write();
void write_header();
char* map_region(int i, bool address_must_match);
void unmap_region(int i);
void close();
bool is_open() { return _file_open; }
// Remap the shared readonly space to shared readwrite, private.
// Errors.
void fail_continue(const char *msg, ...);
// Return true if given address is in the mapped shared space.
bool is_in_shared_space(const void* p);
};
#endif // SHARE_VM_MEMORY_FILEMAP_HPP