1 /* 2 * Copyright (c) 2018, 2025, 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 4 // 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_PREIMAGE_ARCHIVE_MAGIC 0xcafea07c 42 #define CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION 13 43 #define CURRENT_CDS_ARCHIVE_VERSION 18 44 45 typedef struct CDSFileMapRegion { 46 int _crc; // CRC checksum of this region. 47 int _read_only; // read only region? 48 int _allow_exec; // executable code in this region? 49 int _is_heap_region; // Used by SA and debug build. 50 int _is_bitmap_region; // Relocation bitmap for RO/RW regions (used by SA and debug build). 51 int _mapped_from_file; // Is this region mapped from a file? 52 // If false, this region was initialized using ::read(). 53 size_t _file_offset; // Data for this region starts at this offset in the archive file. 54 size_t _mapping_offset; // This encodes the requested address for this region to be mapped at runtime. 55 // However, the JVM may choose to map at an alternative location (e.g., for ASLR, 56 // or to adapt to the available ranges in the Java heap range). 57 // - For an RO/RW region, the requested address is: 58 // FileMapHeader::requested_base_address() + _mapping_offset 59 // - For a heap region, the requested address is: 60 // +UseCompressedOops: /*runtime*/ CompressedOops::base() + _mapping_offset 61 // -UseCompressedOops: FileMapHeader::heap_begin() + _mapping_offset 62 // See FileMapInfo::heap_region_requested_address(). 63 // - For bitmap regions, the _mapping_offset is always zero. The runtime address 64 // is picked by the OS. 65 size_t _used; // Number of bytes actually used by this region (excluding padding bytes added 66 // for alignment purposed. 67 size_t _oopmap_offset; // Bitmap for relocating oop fields in archived heap objects. 68 // (The base address is the bottom of the BM region) 69 size_t _oopmap_size_in_bits; 70 size_t _ptrmap_offset; // Bitmap for relocating native pointer fields in archived heap objects. 71 // (The base address is the bottom of the BM region). 72 size_t _ptrmap_size_in_bits; 73 char* _mapped_base; // Actually mapped address (null if this region is not mapped). 74 bool _in_reserved_space; // Is this region in a ReservedSpace 75 } CDSFileMapRegion; 76 77 // This portion of the archive file header must remain unchanged for 78 // _version >= CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION (13). 79 // This makes it possible to read important information from a CDS archive created by 80 // a different version of HotSpot, so that we can automatically regenerate the archive as necessary. 81 typedef struct GenericCDSFileMapHeader { 82 unsigned int _magic; // identification of file type 83 int _crc; // header crc checksum, start from _base_archive_name_offset 84 int _version; // CURRENT_CDS_ARCHIVE_VERSION of the jdk that dumped the this archive 85 unsigned int _header_size; // total size of the header, in bytes 86 unsigned int _base_archive_name_offset; // offset where the base archive name is stored 87 // static archive: 0 88 // dynamic archive: 89 // 0 for default base archive 90 // non-zero for non-default base archive 91 // (char*)this + _base_archive_name_offset 92 // points to a 0-terminated string for the base archive name 93 unsigned int _base_archive_name_size; // size of base archive name including ending '\0' 94 // static: 0 95 // dynamic: 96 // 0 for default base archive 97 // non-zero for non-default base archive 98 99 } GenericCDSFileMapHeader; 100 101 // This type is used by the Serviceability Agent to access the contents of 102 // a memory-mapped CDS archive. 103 typedef struct CDSFileMapHeaderBase { 104 // We cannot inherit from GenericCDSFileMapHeader as this type may be used 105 // by both C and C++ code. 106 GenericCDSFileMapHeader _generic_header; 107 CDSFileMapRegion _regions[NUM_CDS_REGIONS]; 108 } CDSFileMapHeaderBase; 109 110 #endif // SHARE_INCLUDE_CDS_H