2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2014-03-26 21:47:45 -04:00
|
|
|
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_MEMORY_FILEMAP_HPP
|
|
|
|
#define SHARE_VM_MEMORY_FILEMAP_HPP
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
#include "memory/metaspaceShared.hpp"
|
2013-10-07 15:51:08 +02:00
|
|
|
#include "memory/metaspace.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Layout of the file:
|
|
|
|
// header: dump of archive instance plus versioning info, datestamp, etc.
|
|
|
|
// [magic # = 0xF00BABA2]
|
|
|
|
// ... padding to align on page-boundary
|
2014-03-26 21:47:45 -04:00
|
|
|
// read-write space
|
|
|
|
// read-only space
|
2007-12-01 00:00:00 +00:00
|
|
|
// misc data (block offset table, string table, symbols, dictionary, etc.)
|
|
|
|
// tag(666)
|
|
|
|
|
|
|
|
static const int JVM_IDENT_MAX = 256;
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
class Metaspace;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
class SharedClassPathEntry VALUE_OBJ_CLASS_SPEC {
|
|
|
|
public:
|
|
|
|
const char *_name;
|
|
|
|
time_t _timestamp; // jar timestamp, 0 if is directory
|
|
|
|
long _filesize; // jar file size, -1 if is directory
|
|
|
|
bool is_dir() {
|
|
|
|
return _filesize == -1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class FileMapInfo : public CHeapObj<mtInternal> {
|
2007-12-01 00:00:00 +00:00
|
|
|
private:
|
2014-08-12 17:29:00 -07:00
|
|
|
friend class ManifestStream;
|
2007-12-01 00:00:00 +00:00
|
|
|
enum {
|
|
|
|
_invalid_version = -1,
|
2014-08-12 17:29:00 -07:00
|
|
|
_current_version = 2
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool _file_open;
|
|
|
|
int _fd;
|
2014-10-14 18:47:46 -07:00
|
|
|
size_t _file_offset;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
private:
|
|
|
|
static SharedClassPathEntry* _classpath_entry_table;
|
|
|
|
static int _classpath_entry_table_size;
|
|
|
|
static size_t _classpath_entry_size;
|
|
|
|
static bool _validating_classpath_entry_table;
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
public:
|
|
|
|
struct FileMapHeaderBase : public CHeapObj<mtClass> {
|
|
|
|
virtual bool validate() = 0;
|
|
|
|
virtual void populate(FileMapInfo* info, size_t alignment) = 0;
|
|
|
|
};
|
|
|
|
struct FileMapHeader : FileMapHeaderBase {
|
|
|
|
// Use data() and data_size() to memcopy to/from the FileMapHeader. We need to
|
|
|
|
// avoid read/writing the C++ vtable pointer.
|
|
|
|
static size_t data_size();
|
|
|
|
char* data() {
|
|
|
|
return ((char*)this) + sizeof(FileMapHeaderBase);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
int _magic; // identify file type.
|
2014-10-14 18:47:46 -07:00
|
|
|
int _crc; // header crc checksum.
|
2007-12-01 00:00:00 +00:00
|
|
|
int _version; // (from enum, above.)
|
|
|
|
size_t _alignment; // how shared archive should be aligned
|
2013-01-08 13:38:11 -05:00
|
|
|
int _obj_alignment; // value of ObjectAlignmentInBytes
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
struct space_info {
|
2014-10-14 18:47:46 -07:00
|
|
|
int _crc; // crc checksum of the current space
|
|
|
|
size_t _file_offset; // sizeof(this) rounded to vm page size
|
2007-12-01 00:00:00 +00:00
|
|
|
char* _base; // copy-on-write base address
|
|
|
|
size_t _capacity; // for validity checking
|
|
|
|
size_t _used; // for setting space top on read
|
|
|
|
bool _read_only; // read only space?
|
|
|
|
bool _allow_exec; // executable code in space?
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
} _space[MetaspaceShared::n_regions];
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// The following fields are all sanity checks for whether this archive
|
|
|
|
// will function correctly with this JVM and the bootclasspath it's
|
|
|
|
// invoked with.
|
|
|
|
char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm
|
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
// The _paths_misc_info is a variable-size structure that records "miscellaneous"
|
|
|
|
// information during dumping. It is generated and validated by the
|
|
|
|
// SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp and sharedClassUtil.hpp for
|
|
|
|
// detailed description.
|
|
|
|
//
|
|
|
|
// The _paths_misc_info data is stored as a byte array in the archive file header,
|
|
|
|
// immediately after the _header field. This information is used only when
|
|
|
|
// checking the validity of the archive and is deallocated after the archive is loaded.
|
|
|
|
//
|
|
|
|
// Note that the _paths_misc_info does NOT include information for JAR files
|
|
|
|
// that existed during dump time. Their information is stored in _classpath_entry_table.
|
|
|
|
int _paths_misc_info_size;
|
|
|
|
|
|
|
|
// The following is a table of all the class path entries that were used
|
|
|
|
// during dumping. At run time, we require these files to exist and have the same
|
|
|
|
// size/modification time, or else the archive will refuse to load.
|
|
|
|
//
|
|
|
|
// All of these entries must be JAR files. The dumping process would fail if a non-empty
|
|
|
|
// directory was specified in the classpaths. If an empty directory was specified
|
|
|
|
// it is checked by the _paths_misc_info as described above.
|
|
|
|
//
|
|
|
|
// FIXME -- if JAR files in the tail of the list were specified but not used during dumping,
|
|
|
|
// they should be removed from this table, to save space and to avoid spurious
|
|
|
|
// loading failures during runtime.
|
|
|
|
int _classpath_entry_table_size;
|
|
|
|
size_t _classpath_entry_size;
|
|
|
|
SharedClassPathEntry* _classpath_entry_table;
|
|
|
|
|
|
|
|
virtual bool validate();
|
|
|
|
virtual void populate(FileMapInfo* info, size_t alignment);
|
2014-10-14 18:47:46 -07:00
|
|
|
int compute_crc();
|
2014-08-12 17:29:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
FileMapHeader * _header;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
const char* _full_path;
|
2014-08-12 17:29:00 -07:00
|
|
|
char* _paths_misc_info;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
static FileMapInfo* _current_info;
|
|
|
|
|
|
|
|
bool init_from_file(int fd);
|
|
|
|
void align_file_position();
|
2014-08-12 17:29:00 -07:00
|
|
|
bool validate_header_impl();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public:
|
2014-08-12 17:29:00 -07:00
|
|
|
FileMapInfo();
|
|
|
|
~FileMapInfo();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
static int current_version() { return _current_version; }
|
2014-10-14 18:47:46 -07:00
|
|
|
int compute_header_crc() { return _header->compute_crc(); }
|
|
|
|
void set_header_crc(int crc) { _header->_crc = crc; }
|
2007-12-01 00:00:00 +00:00
|
|
|
void populate_header(size_t alignment);
|
2014-08-12 17:29:00 -07:00
|
|
|
bool validate_header();
|
2007-12-01 00:00:00 +00:00
|
|
|
void invalidate();
|
2014-08-12 17:29:00 -07:00
|
|
|
int version() { return _header->_version; }
|
|
|
|
size_t alignment() { return _header->_alignment; }
|
|
|
|
size_t space_capacity(int i) { return _header->_space[i]._capacity; }
|
|
|
|
char* region_base(int i) { return _header->_space[i]._base; }
|
|
|
|
struct FileMapHeader* header() { return _header; }
|
2013-03-06 13:38:17 -05:00
|
|
|
|
|
|
|
static FileMapInfo* current_info() {
|
|
|
|
CDS_ONLY(return _current_info;)
|
|
|
|
NOT_CDS(return NULL;)
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
static void assert_mark(bool check);
|
|
|
|
|
|
|
|
// File manipulation.
|
2013-03-06 13:38:17 -05:00
|
|
|
bool initialize() NOT_CDS_RETURN_(false);
|
2007-12-01 00:00:00 +00:00
|
|
|
bool open_for_read();
|
|
|
|
void open_for_write();
|
|
|
|
void write_header();
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
void write_space(int i, Metaspace* space, bool read_only);
|
2007-12-01 00:00:00 +00:00
|
|
|
void write_region(int region, char* base, size_t size,
|
|
|
|
size_t capacity, bool read_only, bool allow_exec);
|
|
|
|
void write_bytes(const void* buffer, int count);
|
|
|
|
void write_bytes_aligned(const void* buffer, int count);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
char* map_region(int i);
|
2007-12-01 00:00:00 +00:00
|
|
|
void unmap_region(int i);
|
2014-10-14 18:47:46 -07:00
|
|
|
bool verify_region_checksum(int i);
|
2007-12-01 00:00:00 +00:00
|
|
|
void close();
|
|
|
|
bool is_open() { return _file_open; }
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ReservedSpace reserve_shared_memory();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// JVM/TI RedefineClasses() support:
|
|
|
|
// Remap the shared readonly space to shared readwrite, private.
|
|
|
|
bool remap_shared_readonly_as_readwrite();
|
|
|
|
|
|
|
|
// Errors.
|
2014-08-22 08:13:38 +02:00
|
|
|
static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
|
|
|
|
static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Return true if given address is in the mapped shared space.
|
2013-03-06 13:38:17 -05:00
|
|
|
bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
|
2013-06-27 10:03:21 -07:00
|
|
|
void print_shared_spaces() NOT_CDS_RETURN;
|
2013-08-15 20:04:10 -04:00
|
|
|
|
|
|
|
static size_t shared_spaces_size() {
|
|
|
|
return align_size_up(SharedReadOnlySize + SharedReadWriteSize +
|
|
|
|
SharedMiscDataSize + SharedMiscCodeSize,
|
|
|
|
os::vm_allocation_granularity());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop CDS sharing and unmap CDS regions.
|
|
|
|
static void stop_sharing_and_unmap(const char* msg);
|
2014-08-12 17:29:00 -07:00
|
|
|
|
|
|
|
static void allocate_classpath_entry_table();
|
|
|
|
bool validate_classpath_entry_table();
|
|
|
|
|
|
|
|
static SharedClassPathEntry* shared_classpath(int index) {
|
|
|
|
char* p = (char*)_classpath_entry_table;
|
|
|
|
p += _classpath_entry_size * index;
|
|
|
|
return (SharedClassPathEntry*)p;
|
|
|
|
}
|
|
|
|
static const char* shared_classpath_name(int index) {
|
|
|
|
return shared_classpath(index)->_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_number_of_share_classpaths() {
|
|
|
|
return _classpath_entry_table_size;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_MEMORY_FILEMAP_HPP
|