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