< prev index next >

src/hotspot/share/cds/filemap.hpp

Print this page

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_CDS_FILEMAP_HPP
 26 #define SHARE_CDS_FILEMAP_HPP
 27 
 28 #include "cds/metaspaceShared.hpp"
 29 #include "include/cds.h"
 30 #include "oops/array.hpp"
 31 #include "oops/compressedOops.hpp"

 32 #include "utilities/align.hpp"
 33 
 34 // To understand the layout of the CDS archive file:
 35 //
 36 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
 37 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
 38 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
 39 
 40 static const int JVM_IDENT_MAX = 256;
 41 
 42 class CHeapBitMap;
 43 class ClassFileStream;
 44 class ClassLoaderData;
 45 class ClassPathEntry;
 46 class outputStream;
 47 
 48 class SharedClassPathEntry {
 49   enum {
 50     modules_image_entry,
 51     jar_entry,

162   bool   allow_exec()               const { return _allow_exec != 0; }
163   bool   mapped_from_file()         const { return _mapped_from_file != 0; }
164   size_t oopmap_offset()            const { assert_is_heap_region();     return _oopmap_offset; }
165   size_t oopmap_size_in_bits()      const { assert_is_heap_region();     return _oopmap_size_in_bits; }
166 
167   void set_file_offset(size_t s)     { _file_offset = s; }
168   void set_read_only(bool v)         { _read_only = v; }
169   void set_mapped_base(char* p)      { _mapped_base = p; }
170   void set_mapped_from_file(bool v)  { _mapped_from_file = v; }
171   void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
172             bool allow_exec, int crc);
173 
174   void init_oopmap(size_t oopmap_offset, size_t size_in_bits) {
175     _oopmap_offset = oopmap_offset;
176     _oopmap_size_in_bits = size_in_bits;
177   }
178 
179   void print(outputStream* st, int region_index);
180 };
181 




























182 class FileMapHeader: private CDSFileMapHeaderBase {
183   friend class CDSConstants;
184   friend class VMStructs;
185 
186 private:
187   // The following fields record the states of the VM during dump time.
188   // They are compared with the runtime states to see if the archive
189   // can be used.
190   size_t _core_region_alignment;    // how shared archive should be aligned
191   int    _obj_alignment;            // value of ObjectAlignmentInBytes
192   address _narrow_oop_base;         // compressed oop encoding base
193   int    _narrow_oop_shift;         // compressed oop encoding shift
194   bool   _compact_strings;          // value of CompactStrings
195   uintx  _max_heap_size;            // java max heap size during dumping
196   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
197   int     _narrow_klass_shift;      // save narrow klass base and shift
198   bool    _compressed_oops;         // save the flag UseCompressedOops
199   bool    _compressed_class_ptrs;   // save the flag UseCompressedClassPointers
200   size_t  _cloned_vtables_offset;   // The address of the first cloned vtable
201   size_t  _serialized_data_offset;  // Data accessed using {ReadClosure,WriteClosure}::serialize()

215   //      validate_shared_path_table()
216   //      validate_non_existent_class_paths()
217   size_t _shared_path_table_offset;
218   int    _shared_path_table_size;
219 
220   jshort _app_class_paths_start_index;  // Index of first app classpath entry
221   jshort _app_module_paths_start_index; // Index of first module path entry
222   jshort _num_module_paths;             // number of module path entries
223   jshort _max_used_path_index;          // max path index referenced during CDS dump
224   bool   _verify_local;                 // BytecodeVerificationLocal setting
225   bool   _verify_remote;                // BytecodeVerificationRemote setting
226   bool   _has_platform_or_app_classes;  // Archive contains app classes
227   char*  _requested_base_address;       // Archive relocation is not necessary if we map with this base address.
228   char*  _mapped_base_address;          // Actual base address where archive is mapped.
229 
230   bool   _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
231   bool   _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
232                                         // some expensive operations.
233   bool   _use_full_module_graph;        // Can we use the full archived module graph?
234   size_t _ptrmap_size_in_bits;          // Size of pointer relocation bitmap

235   char* from_mapped_offset(size_t offset) const {
236     return mapped_base_address() + offset;
237   }
238   void set_as_offset(char* p, size_t *offset);
239 public:
240   // Accessors -- fields declared in GenericCDSFileMapHeader
241   unsigned int magic()                    const { return _generic_header._magic;    }
242   int crc()                               const { return _generic_header._crc;      }
243   int version()                           const { return _generic_header._version;  }
244   unsigned int header_size()              const { return _generic_header._header_size;              }
245   unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
246   unsigned int base_archive_name_size()   const { return _generic_header._base_archive_name_size;   }
247 
248   void set_magic(unsigned int m)                    { _generic_header._magic = m;       }
249   void set_crc(int crc_value)                       { _generic_header._crc = crc_value; }
250   void set_version(int v)                           { _generic_header._version = v;     }
251   void set_header_size(unsigned int s)              { _generic_header._header_size = s;              }
252   void set_base_archive_name_offset(unsigned int s) { _generic_header._base_archive_name_offset = s; }
253   void set_base_archive_name_size(unsigned int s)   { _generic_header._base_archive_name_size = s;   }
254 

298 
299   SharedPathTable shared_path_table() const {
300     return SharedPathTable((Array<u8>*)from_mapped_offset(_shared_path_table_offset),
301                            _shared_path_table_size);
302   }
303 
304   bool validate();
305   int compute_crc();
306 
307   FileMapRegion* space_at(int i) {
308     assert(is_valid_region(i), "invalid region");
309     return FileMapRegion::cast(&_space[i]);
310   }
311 
312   void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
313                 size_t base_archive_name_size, size_t base_archive_name_offset);
314   static bool is_valid_region(int region) {
315     return (0 <= region && region < NUM_CDS_REGIONS);
316   }
317 




318   void print(outputStream* st);
319 };
320 
321 class FileMapInfo : public CHeapObj<mtInternal> {
322 private:
323   friend class ManifestStream;
324   friend class VMStructs;
325   friend class ArchiveBuilder;
326   friend class CDSOffsets;
327   friend class FileMapHeader;
328 
329   bool           _is_static;
330   bool           _file_open;
331   bool           _is_mapped;
332   int            _fd;
333   size_t         _file_offset;
334   const char*    _full_path;
335   const char*    _base_archive_name;
336   FileMapHeader* _header;
337 

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_CDS_FILEMAP_HPP
 26 #define SHARE_CDS_FILEMAP_HPP
 27 
 28 #include "cds/metaspaceShared.hpp"
 29 #include "include/cds.h"
 30 #include "oops/array.hpp"
 31 #include "oops/compressedOops.hpp"
 32 #include "runtime/globals.hpp"
 33 #include "utilities/align.hpp"
 34 
 35 // To understand the layout of the CDS archive file:
 36 //
 37 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
 38 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
 39 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
 40 
 41 static const int JVM_IDENT_MAX = 256;
 42 
 43 class CHeapBitMap;
 44 class ClassFileStream;
 45 class ClassLoaderData;
 46 class ClassPathEntry;
 47 class outputStream;
 48 
 49 class SharedClassPathEntry {
 50   enum {
 51     modules_image_entry,
 52     jar_entry,

163   bool   allow_exec()               const { return _allow_exec != 0; }
164   bool   mapped_from_file()         const { return _mapped_from_file != 0; }
165   size_t oopmap_offset()            const { assert_is_heap_region();     return _oopmap_offset; }
166   size_t oopmap_size_in_bits()      const { assert_is_heap_region();     return _oopmap_size_in_bits; }
167 
168   void set_file_offset(size_t s)     { _file_offset = s; }
169   void set_read_only(bool v)         { _read_only = v; }
170   void set_mapped_base(char* p)      { _mapped_base = p; }
171   void set_mapped_from_file(bool v)  { _mapped_from_file = v; }
172   void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
173             bool allow_exec, int crc);
174 
175   void init_oopmap(size_t oopmap_offset, size_t size_in_bits) {
176     _oopmap_offset = oopmap_offset;
177     _oopmap_size_in_bits = size_in_bits;
178   }
179 
180   void print(outputStream* st, int region_index);
181 };
182 
183 #define CDS_MUST_MATCH_FLAGS_DO(f) \
184   f(EnableValhalla) \
185   f(FlatArrayElementMaxOops) \
186   f(FlatArrayElementMaxSize) \
187   f(InlineFieldMaxFlatSize) \
188   f(InlineTypePassFieldsAsArgs) \
189   f(InlineTypeReturnedAsFields)
190 
191 class CDSMustMatchFlags {
192 private:
193   size_t _max_name_width;
194 #define DECLARE_CDS_MUST_MATCH_FLAG(n) \
195   decltype(n) _v_##n;
196   CDS_MUST_MATCH_FLAGS_DO(DECLARE_CDS_MUST_MATCH_FLAG);
197 #undef DECLARE_CDS_MUST_MATCH_FLAG
198 
199   inline static void do_print(outputStream* st, bool v);
200   inline static void do_print(outputStream* st, intx v);
201   inline static void do_print(outputStream* st, uintx v);
202   inline static void do_print(outputStream* st, double v);
203   void print_info() const;
204 
205 public:
206   void init();
207   bool runtime_check() const;
208   void print(outputStream* st) const;
209 };
210 
211 class FileMapHeader: private CDSFileMapHeaderBase {
212   friend class CDSConstants;
213   friend class VMStructs;
214 
215 private:
216   // The following fields record the states of the VM during dump time.
217   // They are compared with the runtime states to see if the archive
218   // can be used.
219   size_t _core_region_alignment;    // how shared archive should be aligned
220   int    _obj_alignment;            // value of ObjectAlignmentInBytes
221   address _narrow_oop_base;         // compressed oop encoding base
222   int    _narrow_oop_shift;         // compressed oop encoding shift
223   bool   _compact_strings;          // value of CompactStrings
224   uintx  _max_heap_size;            // java max heap size during dumping
225   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
226   int     _narrow_klass_shift;      // save narrow klass base and shift
227   bool    _compressed_oops;         // save the flag UseCompressedOops
228   bool    _compressed_class_ptrs;   // save the flag UseCompressedClassPointers
229   size_t  _cloned_vtables_offset;   // The address of the first cloned vtable
230   size_t  _serialized_data_offset;  // Data accessed using {ReadClosure,WriteClosure}::serialize()

244   //      validate_shared_path_table()
245   //      validate_non_existent_class_paths()
246   size_t _shared_path_table_offset;
247   int    _shared_path_table_size;
248 
249   jshort _app_class_paths_start_index;  // Index of first app classpath entry
250   jshort _app_module_paths_start_index; // Index of first module path entry
251   jshort _num_module_paths;             // number of module path entries
252   jshort _max_used_path_index;          // max path index referenced during CDS dump
253   bool   _verify_local;                 // BytecodeVerificationLocal setting
254   bool   _verify_remote;                // BytecodeVerificationRemote setting
255   bool   _has_platform_or_app_classes;  // Archive contains app classes
256   char*  _requested_base_address;       // Archive relocation is not necessary if we map with this base address.
257   char*  _mapped_base_address;          // Actual base address where archive is mapped.
258 
259   bool   _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
260   bool   _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
261                                         // some expensive operations.
262   bool   _use_full_module_graph;        // Can we use the full archived module graph?
263   size_t _ptrmap_size_in_bits;          // Size of pointer relocation bitmap
264   CDSMustMatchFlags _must_match;        // These flags must be the same between dumptime and runtime
265   char* from_mapped_offset(size_t offset) const {
266     return mapped_base_address() + offset;
267   }
268   void set_as_offset(char* p, size_t *offset);
269 public:
270   // Accessors -- fields declared in GenericCDSFileMapHeader
271   unsigned int magic()                    const { return _generic_header._magic;    }
272   int crc()                               const { return _generic_header._crc;      }
273   int version()                           const { return _generic_header._version;  }
274   unsigned int header_size()              const { return _generic_header._header_size;              }
275   unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
276   unsigned int base_archive_name_size()   const { return _generic_header._base_archive_name_size;   }
277 
278   void set_magic(unsigned int m)                    { _generic_header._magic = m;       }
279   void set_crc(int crc_value)                       { _generic_header._crc = crc_value; }
280   void set_version(int v)                           { _generic_header._version = v;     }
281   void set_header_size(unsigned int s)              { _generic_header._header_size = s;              }
282   void set_base_archive_name_offset(unsigned int s) { _generic_header._base_archive_name_offset = s; }
283   void set_base_archive_name_size(unsigned int s)   { _generic_header._base_archive_name_size = s;   }
284 

328 
329   SharedPathTable shared_path_table() const {
330     return SharedPathTable((Array<u8>*)from_mapped_offset(_shared_path_table_offset),
331                            _shared_path_table_size);
332   }
333 
334   bool validate();
335   int compute_crc();
336 
337   FileMapRegion* space_at(int i) {
338     assert(is_valid_region(i), "invalid region");
339     return FileMapRegion::cast(&_space[i]);
340   }
341 
342   void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
343                 size_t base_archive_name_size, size_t base_archive_name_offset);
344   static bool is_valid_region(int region) {
345     return (0 <= region && region < NUM_CDS_REGIONS);
346   }
347 
348   bool check_must_match_flags() const {
349     return _must_match.runtime_check();
350   }
351 
352   void print(outputStream* st);
353 };
354 
355 class FileMapInfo : public CHeapObj<mtInternal> {
356 private:
357   friend class ManifestStream;
358   friend class VMStructs;
359   friend class ArchiveBuilder;
360   friend class CDSOffsets;
361   friend class FileMapHeader;
362 
363   bool           _is_static;
364   bool           _file_open;
365   bool           _is_mapped;
366   int            _fd;
367   size_t         _file_offset;
368   const char*    _full_path;
369   const char*    _base_archive_name;
370   FileMapHeader* _header;
371 
< prev index next >