src/share/vm/memory/filemap.hpp

Tue, 13 Apr 2010 13:52:10 -0700

author
jmasa
date
Tue, 13 Apr 2010 13:52:10 -0700
changeset 1822
0bfd3fb24150
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
Summary: Ensure a full GC that clears SoftReferences before throwing an out-of-memory
Reviewed-by: ysr, jcoomes

duke@435 1 /*
duke@435 2 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // Layout of the file:
duke@435 26 // header: dump of archive instance plus versioning info, datestamp, etc.
duke@435 27 // [magic # = 0xF00BABA2]
duke@435 28 // ... padding to align on page-boundary
duke@435 29 // read-write space from CompactingPermGenGen
duke@435 30 // read-only space from CompactingPermGenGen
duke@435 31 // misc data (block offset table, string table, symbols, dictionary, etc.)
duke@435 32 // tag(666)
duke@435 33
duke@435 34 static const int JVM_SHARED_JARS_MAX = 128;
duke@435 35 static const int JVM_SPACENAME_MAX = 128;
duke@435 36 static const int JVM_IDENT_MAX = 256;
duke@435 37 static const int JVM_ARCH_MAX = 12;
duke@435 38
duke@435 39
duke@435 40
duke@435 41 class FileMapInfo : public CHeapObj {
duke@435 42 private:
duke@435 43 enum {
duke@435 44 _invalid_version = -1,
duke@435 45 _current_version = 1
duke@435 46 };
duke@435 47
duke@435 48 bool _file_open;
duke@435 49 int _fd;
duke@435 50 long _file_offset;
duke@435 51
duke@435 52 // FileMapHeader describes the shared space data in the file to be
duke@435 53 // mapped. This structure gets written to a file. It is not a class, so
duke@435 54 // that the compilers don't add any compiler-private data to it.
duke@435 55
duke@435 56 struct FileMapHeader {
duke@435 57 int _magic; // identify file type.
duke@435 58 int _version; // (from enum, above.)
duke@435 59 size_t _alignment; // how shared archive should be aligned
duke@435 60
duke@435 61 struct space_info {
duke@435 62 int _file_offset; // sizeof(this) rounded to vm page size
duke@435 63 char* _base; // copy-on-write base address
duke@435 64 size_t _capacity; // for validity checking
duke@435 65 size_t _used; // for setting space top on read
duke@435 66 bool _read_only; // read only space?
duke@435 67 bool _allow_exec; // executable code in space?
duke@435 68 } _space[CompactingPermGenGen::n_regions];
duke@435 69
duke@435 70 // The following fields are all sanity checks for whether this archive
duke@435 71 // will function correctly with this JVM and the bootclasspath it's
duke@435 72 // invoked with.
duke@435 73 char _arch[JVM_ARCH_MAX]; // architecture
duke@435 74 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm
duke@435 75 int _num_jars; // Number of jars in bootclasspath
duke@435 76
duke@435 77 // Per jar file data: timestamp, size.
duke@435 78
duke@435 79 struct {
duke@435 80 time_t _timestamp; // jar timestamp.
duke@435 81 long _filesize; // jar file size.
duke@435 82 } _jar[JVM_SHARED_JARS_MAX];
duke@435 83 } _header;
duke@435 84 const char* _full_path;
duke@435 85
duke@435 86 static FileMapInfo* _current_info;
duke@435 87
duke@435 88 bool init_from_file(int fd);
duke@435 89 void align_file_position();
duke@435 90
duke@435 91 public:
duke@435 92 FileMapInfo() {
duke@435 93 _file_offset = 0;
duke@435 94 _file_open = false;
duke@435 95 _header._version = _invalid_version;
duke@435 96 }
duke@435 97
duke@435 98 static int current_version() { return _current_version; }
duke@435 99 void populate_header(size_t alignment);
duke@435 100 bool validate();
duke@435 101 void invalidate();
duke@435 102 int version() { return _header._version; }
duke@435 103 size_t alignment() { return _header._alignment; }
duke@435 104 size_t space_capacity(int i) { return _header._space[i]._capacity; }
duke@435 105 char* region_base(int i) { return _header._space[i]._base; }
duke@435 106 struct FileMapHeader* header() { return &_header; }
duke@435 107
duke@435 108 static void set_current_info(FileMapInfo* info) { _current_info = info; }
duke@435 109 static FileMapInfo* current_info() { return _current_info; }
duke@435 110 static void assert_mark(bool check);
duke@435 111
duke@435 112 // File manipulation.
duke@435 113 bool initialize();
duke@435 114 bool open_for_read();
duke@435 115 void open_for_write();
duke@435 116 void write_header();
duke@435 117 void write_space(int i, CompactibleSpace* space, bool read_only);
duke@435 118 void write_region(int region, char* base, size_t size,
duke@435 119 size_t capacity, bool read_only, bool allow_exec);
duke@435 120 void write_bytes(const void* buffer, int count);
duke@435 121 void write_bytes_aligned(const void* buffer, int count);
duke@435 122 bool map_space(int i, ReservedSpace rs, ContiguousSpace *space);
duke@435 123 char* map_region(int i, ReservedSpace rs);
duke@435 124 char* map_region(int i, bool address_must_match);
duke@435 125 void unmap_region(int i);
duke@435 126 void close();
duke@435 127 bool is_open() { return _file_open; }
duke@435 128
duke@435 129 // JVM/TI RedefineClasses() support:
duke@435 130 // Remap the shared readonly space to shared readwrite, private.
duke@435 131 bool remap_shared_readonly_as_readwrite();
duke@435 132
duke@435 133 // Errors.
duke@435 134 static void fail_stop(const char *msg, ...);
duke@435 135 void fail_continue(const char *msg, ...);
duke@435 136
duke@435 137 // Return true if given address is in the mapped shared space.
duke@435 138 bool is_in_shared_space(const void* p);
duke@435 139 };

mercurial