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_CDS_ARCHIVEBUILDER_HPP
26 #define SHARE_CDS_ARCHIVEBUILDER_HPP
27
28 #include "cds/archiveUtils.hpp"
29 #include "cds/dumpAllocStats.hpp"
30 #include "memory/metaspaceClosure.hpp"
31 #include "oops/array.hpp"
32 #include "oops/klass.hpp"
33 #include "runtime/os.hpp"
34 #include "utilities/bitMap.hpp"
35 #include "utilities/growableArray.hpp"
36 #include "utilities/resizeableResourceHash.hpp"
37 #include "utilities/resourceHash.hpp"
38
39 class ArchiveHeapInfo;
40 class CHeapBitMap;
41 class FileMapInfo;
42 class Klass;
43 class MemRegion;
44 class Symbol;
45
46 // Metaspace::allocate() requires that all blocks must be aligned with KlassAlignmentInBytes.
47 // We enforce the same alignment rule in blocks allocated from the shared space.
48 const int SharedSpaceObjectAlignment = KlassAlignmentInBytes;
49
50 // Overview of CDS archive creation (for both static and dynamic dump):
51 //
52 // [1] Load all classes (static dump: from the classlist, dynamic dump: as part of app execution)
53 // [2] Allocate "output buffer"
54 // [3] Copy contents of the 2 "core" regions (rw/ro) into the output buffer.
55 // - allocate the cpp vtables in rw (static dump only)
56 // - memcpy the MetaspaceObjs into rw/ro:
57 // dump_rw_region();
58 // dump_ro_region();
59 // - fix all the pointers in the MetaspaceObjs to point to the copies
60 // relocate_metaspaceobj_embedded_pointers()
61 // [4] Copy symbol table, dictionary, etc, into the ro region
62 // [5] Relocate all the pointers in rw/ro, so that the archive can be mapped to
63 // the "requested" location without runtime relocation. See relocate_to_requested()
64 //
65 // "source" vs "buffered" vs "requested"
66 //
67 // The ArchiveBuilder deals with three types of addresses.
68 //
446 }
447
448 static CompactHashtableStats* string_stats() {
449 return alloc_stats()->string_stats();
450 }
451
452 narrowKlass get_requested_narrow_klass(Klass* k);
453
454 static Klass* get_buffered_klass(Klass* src_klass) {
455 Klass* klass = (Klass*)current()->get_buffered_addr((address)src_klass);
456 assert(klass != nullptr && klass->is_klass(), "must be");
457 return klass;
458 }
459
460 static Symbol* get_buffered_symbol(Symbol* src_symbol) {
461 return (Symbol*)current()->get_buffered_addr((address)src_symbol);
462 }
463
464 void print_stats();
465 void report_out_of_space(const char* name, size_t needed_bytes);
466 };
467
468 #endif // SHARE_CDS_ARCHIVEBUILDER_HPP
|
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_CDS_ARCHIVEBUILDER_HPP
26 #define SHARE_CDS_ARCHIVEBUILDER_HPP
27
28 #include "cds/archiveUtils.hpp"
29 #include "cds/dumpAllocStats.hpp"
30 #include "memory/metaspace.hpp"
31 #include "memory/metaspaceClosure.hpp"
32 #include "oops/array.hpp"
33 #include "oops/klass.hpp"
34 #include "runtime/os.hpp"
35 #include "utilities/bitMap.hpp"
36 #include "utilities/growableArray.hpp"
37 #include "utilities/resizeableResourceHash.hpp"
38 #include "utilities/resourceHash.hpp"
39
40 class ArchiveHeapInfo;
41 class CHeapBitMap;
42 class FileMapInfo;
43 class Klass;
44 class MemRegion;
45 class Symbol;
46
47 // The minimum alignment for non-Klass objects inside the CDS archive. Klass objects need
48 // to follow CompressedKlassPointers::klass_alignment_in_bytes().
49 constexpr size_t SharedSpaceObjectAlignment = Metaspace::min_allocation_alignment_bytes;
50
51 // Overview of CDS archive creation (for both static and dynamic dump):
52 //
53 // [1] Load all classes (static dump: from the classlist, dynamic dump: as part of app execution)
54 // [2] Allocate "output buffer"
55 // [3] Copy contents of the 2 "core" regions (rw/ro) into the output buffer.
56 // - allocate the cpp vtables in rw (static dump only)
57 // - memcpy the MetaspaceObjs into rw/ro:
58 // dump_rw_region();
59 // dump_ro_region();
60 // - fix all the pointers in the MetaspaceObjs to point to the copies
61 // relocate_metaspaceobj_embedded_pointers()
62 // [4] Copy symbol table, dictionary, etc, into the ro region
63 // [5] Relocate all the pointers in rw/ro, so that the archive can be mapped to
64 // the "requested" location without runtime relocation. See relocate_to_requested()
65 //
66 // "source" vs "buffered" vs "requested"
67 //
68 // The ArchiveBuilder deals with three types of addresses.
69 //
447 }
448
449 static CompactHashtableStats* string_stats() {
450 return alloc_stats()->string_stats();
451 }
452
453 narrowKlass get_requested_narrow_klass(Klass* k);
454
455 static Klass* get_buffered_klass(Klass* src_klass) {
456 Klass* klass = (Klass*)current()->get_buffered_addr((address)src_klass);
457 assert(klass != nullptr && klass->is_klass(), "must be");
458 return klass;
459 }
460
461 static Symbol* get_buffered_symbol(Symbol* src_symbol) {
462 return (Symbol*)current()->get_buffered_addr((address)src_symbol);
463 }
464
465 void print_stats();
466 void report_out_of_space(const char* name, size_t needed_bytes);
467
468 #ifdef _LP64
469 // Archived heap object headers (and soon, with Lilliput, markword prototypes) carry pre-computed
470 // narrow Klass ids calculated with the following scheme:
471 // 1) the encoding base must be the mapping start address.
472 // 2) shift must be large enough to result in an encoding range that covers the runtime Klass range.
473 // That Klass range is defined by CDS archive size and runtime class space size. Luckily, the maximum
474 // size can be predicted: archive size is assumed to be <1G, class space size capped at 3G, and at
475 // runtime we put both regions adjacent to each other. Therefore, runtime Klass range size < 4G.
476 // The value of this precomputed shift depends on the class pointer mode at dump time.
477 // Legacy Mode:
478 // Since nKlass itself is 32 bit, our encoding range len is 4G, and since we set the base directly
479 // at mapping start, these 4G are enough. Therefore, we don't need to shift at all (shift=0).
480 // TinyClassPointer Mode:
481 // To cover the 4G, we need the highest possible shift value. That may change in the future, if
482 // we decide to correct the pre-calculated narrow Klass IDs at load time.
483 static int precomputed_narrow_klass_shift();
484 #endif // _LP64
485
486 };
487
488 #endif // SHARE_CDS_ARCHIVEBUILDER_HPP
|