1 /*
  2  * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 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_INCLUDE_CDS_H
 26 #define SHARE_INCLUDE_CDS_H
 27 
 28 #include <stddef.h>
 29 
 30 // This file declares the CDS data structures that are used by the HotSpot Serviceability Agent
 31 // (see C sources inside src/jdk.hotspot.agent).
 32 //
 33 // We should use only standard C types. Do not use custom types such as bool, intx,
 34 // etc, to avoid introducing unnecessary dependencies to other HotSpot type declarations.
 35 //
 36 // Also, this is a C header file. Do not use C++ here.
 37 
 38 #define NUM_CDS_REGIONS 5 // this must be the same as MetaspaceShared::n_regions
 39 #define CDS_ARCHIVE_MAGIC 0xf00baba2
 40 #define CDS_DYNAMIC_ARCHIVE_MAGIC 0xf00baba8
 41 #define CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION 13
 42 #define CURRENT_CDS_ARCHIVE_VERSION 19
 43 
 44 typedef struct CDSFileMapRegion {
 45   int     _crc;               // CRC checksum of this region.
 46   int     _read_only;         // read only region?
 47   int     _allow_exec;        // executable code in this region?
 48   int     _is_heap_region;    // Used by SA and debug build.
 49   int     _is_bitmap_region;  // Relocation bitmap for RO/RW regions (used by SA and debug build).
 50   int     _mapped_from_file;  // Is this region mapped from a file?
 51                               // If false, this region was initialized using ::read().
 52   size_t  _file_offset;       // Data for this region starts at this offset in the archive file.
 53   size_t  _mapping_offset;    // This encodes the requested address for this region to be mapped at runtime.
 54                               // However, the JVM may choose to map at an alternative location (e.g., for ASLR,
 55                               // or to adapt to the available ranges in the Java heap range).
 56                               // - For an RO/RW region, the requested address is:
 57                               //     FileMapHeader::requested_base_address() + _mapping_offset
 58                               // - For a heap region, the requested address is:
 59                               //     +UseCompressedOops: /*runtime*/ CompressedOops::base() + _mapping_offset
 60                               //     -UseCompressedOops: FileMapHeader::heap_begin() + _mapping_offset
 61                               //     See FileMapInfo::heap_region_requested_address().
 62                               // - For bitmap regions, the _mapping_offset is always zero. The runtime address
 63                               //   is picked by the OS.
 64   size_t  _used;              // Number of bytes actually used by this region (excluding padding bytes added
 65                               // for alignment purposed.
 66   size_t  _oopmap_offset;     // Bitmap for relocating oop fields in archived heap objects.
 67                               // (The base address is the bottom of the BM region)
 68   size_t  _oopmap_size_in_bits;
 69   size_t  _ptrmap_offset;     // Bitmap for relocating native pointer fields in archived heap objects.
 70                               // (The base address is the bottom of the BM region).
 71   size_t  _ptrmap_size_in_bits;
 72   char*   _mapped_base;       // Actually mapped address (null if this region is not mapped).
 73 } CDSFileMapRegion;
 74 
 75 // This portion of the archive file header must remain unchanged for
 76 // _version >= CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION (13).
 77 // This makes it possible to read important information from a CDS archive created by
 78 // a different version of HotSpot, so that we can automatically regenerate the archive as necessary.
 79 typedef struct GenericCDSFileMapHeader {
 80   unsigned int _magic;                    // identification of file type
 81   int          _crc;                      // header crc checksum, start from _base_archive_name_offset
 82   int          _version;                  // CURRENT_CDS_ARCHIVE_VERSION of the jdk that dumped the this archive
 83   unsigned int _header_size;              // total size of the header, in bytes
 84   unsigned int _base_archive_name_offset; // offset where the base archive name is stored
 85                                           //   static archive:  0
 86                                           //   dynamic archive:
 87                                           //     0 for default base archive
 88                                           //     non-zero for non-default base archive
 89                                           //       (char*)this + _base_archive_name_offset
 90                                           //       points to a 0-terminated string for the base archive name
 91   unsigned int _base_archive_name_size;   // size of base archive name including ending '\0'
 92                                           //   static:  0
 93                                           //   dynamic:
 94                                           //     0 for default base archive
 95                                           //     non-zero for non-default base archive
 96 
 97 } GenericCDSFileMapHeader;
 98 
 99 // This type is used by the Serviceability Agent to access the contents of
100 // a memory-mapped CDS archive.
101 typedef struct CDSFileMapHeaderBase {
102   // We cannot inherit from GenericCDSFileMapHeader as this type may be used
103   // by both C and C++ code.
104   GenericCDSFileMapHeader _generic_header;
105   CDSFileMapRegion _regions[NUM_CDS_REGIONS];
106 } CDSFileMapHeaderBase;
107 
108 #endif // SHARE_INCLUDE_CDS_H