< 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   size_t _header_size;
188 
189   // The following fields record the states of the VM during dump time.
190   // They are compared with the runtime states to see if the archive
191   // can be used.
192   size_t _core_region_alignment;    // how shared archive should be aligned
193   int    _obj_alignment;            // value of ObjectAlignmentInBytes
194   address _narrow_oop_base;         // compressed oop encoding base
195   int    _narrow_oop_shift;         // compressed oop encoding shift
196   bool   _compact_strings;          // value of CompactStrings
197   uintx  _max_heap_size;            // java max heap size during dumping
198   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
199   int     _narrow_klass_shift;      // save narrow klass base and shift
200   bool    _compressed_oops;         // save the flag UseCompressedOops
201   bool    _compressed_class_ptrs;   // save the flag UseCompressedClassPointers

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

241   char* from_mapped_offset(size_t offset) const {
242     return mapped_base_address() + offset;
243   }
244   void set_as_offset(char* p, size_t *offset);
245 public:
246   // Accessors -- fields declared in CDSFileMapHeaderBase
247   unsigned int magic()                    const { return _magic; }
248   int crc()                               const { return _crc; }
249   int version()                           const { return _version; }
250 
251   void set_crc(int crc_value)                   { _crc = crc_value; }
252   void set_version(int v)                       { _version = v; }
253 
254   // Accessors -- fields declared in FileMapHeader
255 
256   size_t header_size()                     const { return _header_size; }
257   size_t core_region_alignment()           const { return _core_region_alignment; }
258   int obj_alignment()                      const { return _obj_alignment; }
259   address narrow_oop_base()                const { return _narrow_oop_base; }
260   int narrow_oop_shift()                   const { return _narrow_oop_shift; }

306 
307   SharedPathTable shared_path_table() const {
308     return SharedPathTable((Array<u8>*)from_mapped_offset(_shared_path_table_offset),
309                            _shared_path_table_size);
310   }
311 
312   bool validate();
313   int compute_crc();
314 
315   FileMapRegion* space_at(int i) {
316     assert(is_valid_region(i), "invalid region");
317     return FileMapRegion::cast(&_space[i]);
318   }
319 
320   void populate(FileMapInfo* info, size_t core_region_alignment);
321 
322   static bool is_valid_region(int region) {
323     return (0 <= region && region < NUM_CDS_REGIONS);
324   }
325 




326   void print(outputStream* st);
327 };
328 
329 class FileMapInfo : public CHeapObj<mtInternal> {
330 private:
331   friend class ManifestStream;
332   friend class VMStructs;
333   friend class ArchiveBuilder;
334   friend class CDSOffsets;
335   friend class FileMapHeader;
336 
337   bool           _is_static;
338   bool           _file_open;
339   bool           _is_mapped;
340   int            _fd;
341   size_t         _file_offset;
342   const char*    _full_path;
343   const char*    _base_archive_name;
344   FileMapHeader* _header;
345 

 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   size_t _header_size;
217 
218   // The following fields record the states of the VM during dump time.
219   // They are compared with the runtime states to see if the archive
220   // can be used.
221   size_t _core_region_alignment;    // how shared archive should be aligned
222   int    _obj_alignment;            // value of ObjectAlignmentInBytes
223   address _narrow_oop_base;         // compressed oop encoding base
224   int    _narrow_oop_shift;         // compressed oop encoding shift
225   bool   _compact_strings;          // value of CompactStrings
226   uintx  _max_heap_size;            // java max heap size during dumping
227   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
228   int     _narrow_klass_shift;      // save narrow klass base and shift
229   bool    _compressed_oops;         // save the flag UseCompressedOops
230   bool    _compressed_class_ptrs;   // save the flag UseCompressedClassPointers

250   //      validate_non_existent_class_paths()
251   size_t _shared_path_table_offset;
252   int    _shared_path_table_size;
253 
254   jshort _app_class_paths_start_index;  // Index of first app classpath entry
255   jshort _app_module_paths_start_index; // Index of first module path entry
256   jshort _num_module_paths;             // number of module path entries
257   jshort _max_used_path_index;          // max path index referenced during CDS dump
258   bool   _verify_local;                 // BytecodeVerificationLocal setting
259   bool   _verify_remote;                // BytecodeVerificationRemote setting
260   bool   _has_platform_or_app_classes;  // Archive contains app classes
261   char*  _requested_base_address;       // Archive relocation is not necessary if we map with this base address.
262   char*  _mapped_base_address;          // Actual base address where archive is mapped.
263 
264   bool   _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
265   bool   _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
266                                         // some expensive operations.
267   bool   _use_full_module_graph;        // Can we use the full archived module graph?
268   size_t _ptrmap_size_in_bits;          // Size of pointer relocation bitmap
269   narrowOop _heap_obj_roots;            // An objArray that stores all the roots of archived heap objects
270   CDSMustMatchFlags _must_match;        // These flags must be the same between dumptime and runtime
271   char* from_mapped_offset(size_t offset) const {
272     return mapped_base_address() + offset;
273   }
274   void set_as_offset(char* p, size_t *offset);
275 public:
276   // Accessors -- fields declared in CDSFileMapHeaderBase
277   unsigned int magic()                    const { return _magic; }
278   int crc()                               const { return _crc; }
279   int version()                           const { return _version; }
280 
281   void set_crc(int crc_value)                   { _crc = crc_value; }
282   void set_version(int v)                       { _version = v; }
283 
284   // Accessors -- fields declared in FileMapHeader
285 
286   size_t header_size()                     const { return _header_size; }
287   size_t core_region_alignment()           const { return _core_region_alignment; }
288   int obj_alignment()                      const { return _obj_alignment; }
289   address narrow_oop_base()                const { return _narrow_oop_base; }
290   int narrow_oop_shift()                   const { return _narrow_oop_shift; }

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