|
| 1 | +/* |
| 2 | + * Copyright (c) 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_CDS_AOTMAPLOGGER_HPP |
| 26 | +#define SHARE_CDS_AOTMAPLOGGER_HPP |
| 27 | + |
| 28 | +#include "cds/archiveBuilder.hpp" |
| 29 | +#include "memory/allocation.hpp" |
| 30 | +#include "memory/allStatic.hpp" |
| 31 | +#include "oops/oopsHierarchy.hpp" |
| 32 | +#include "utilities/globalDefinitions.hpp" |
| 33 | +#include "utilities/growableArray.hpp" |
| 34 | + |
| 35 | +class ArchiveHeapInfo; |
| 36 | +class DumpRegion; |
| 37 | +class FileMapInfo; |
| 38 | +class outputStream; |
| 39 | + |
| 40 | +// Write detailed info to a mapfile to analyze contents of the AOT cache/CDS archive. |
| 41 | +// -Xlog:aot+map* can be used both when creating an AOT cache, or when using an AOT cache. |
| 42 | +// |
| 43 | +// Creating cache: |
| 44 | +// java -XX:AOTCacheOutput=app.aot -Xlog:aot+map*=trace -cp app.jar App |
| 45 | +// |
| 46 | +// Using cache: |
| 47 | +// java -XX:AOTCache=app.aot -Xlog:aot+map*=trace -cp app.jar App |
| 48 | +// |
| 49 | +// You can also print the map of a cache without executing the application by using the |
| 50 | +// --version flag: |
| 51 | +// java -XX:AOTCache=app.aot -Xlog:aot+map*=trace --version |
| 52 | +// |
| 53 | +// Because the output can be large, it's best to save it to a file |
| 54 | +// java -XX:AOTCache=app.aot -Xlog:aot+map*=trace:file=aot.map:none:filesize=0 --version |
| 55 | +class AOTMapLogger : AllStatic { |
| 56 | + struct ArchivedObjInfo { |
| 57 | + address _src_addr; |
| 58 | + address _buffered_addr; |
| 59 | + address _requested_addr; |
| 60 | + int _bytes; |
| 61 | + MetaspaceObj::Type _type; |
| 62 | + }; |
| 63 | + |
| 64 | + // FakeOop and subtypes |
| 65 | + class FakeOop; |
| 66 | + class FakeMirror; |
| 67 | + class FakeObjArray; |
| 68 | + class FakeString; |
| 69 | + class FakeTypeArray; |
| 70 | + |
| 71 | + class RequestedMetadataAddr; |
| 72 | + class RuntimeGatherArchivedMetaspaceObjs; |
| 73 | + |
| 74 | + static bool _is_logging_at_bootstrap; |
| 75 | + static bool _is_runtime_logging; |
| 76 | + static size_t _num_root_segments; |
| 77 | + static size_t _num_obj_arrays_logged; |
| 78 | + static GrowableArrayCHeap<FakeOop, mtClass>* _roots; |
| 79 | + static ArchiveHeapInfo* _dumptime_heap_info; |
| 80 | + |
| 81 | + static intx _buffer_to_requested_delta; |
| 82 | + static intx _requested_to_mapped_metadata_delta; |
| 83 | + |
| 84 | + static void runtime_log(FileMapInfo* mapinfo, GrowableArrayCHeap<ArchivedObjInfo, mtClass>* objs); |
| 85 | + static void runtime_log_metaspace_regions(FileMapInfo* mapinfo, GrowableArrayCHeap<ArchivedObjInfo, mtClass>* objs); |
| 86 | + static void dumptime_log_metaspace_region(const char* name, DumpRegion* region, |
| 87 | + const ArchiveBuilder::SourceObjList* src_objs); |
| 88 | + |
| 89 | + // Common code for dumptime/runtime |
| 90 | + static void log_file_header(FileMapInfo* mapinfo); |
| 91 | + static void log_region_range(const char* name, address base, address top, address requested_base); |
| 92 | + static void log_metaspace_objects_impl(address region_base, address region_end, |
| 93 | + GrowableArrayCHeap<ArchivedObjInfo, mtClass>* objs, int start_idx, int end_idx); |
| 94 | + static void log_as_hex(address base, address top, address requested_base, bool is_heap = false); |
| 95 | + |
| 96 | + // Metaspace object: type-specific logging |
| 97 | + static void log_constant_pool(ConstantPool* cp, address requested_addr, const char* type_name, int bytes, Thread* current); |
| 98 | + static void log_constant_pool_cache(ConstantPoolCache* cpc, address requested_addr, |
| 99 | + const char* type_name, int bytes, Thread* current); |
| 100 | + static void log_const_method(ConstMethod* cm, address requested_addr, const char* type_name, int bytes, Thread* current); |
| 101 | + static void log_klass(Klass* k, address requested_addr, const char* type_name, int bytes, Thread* current); |
| 102 | + static void log_method(Method* m, address requested_addr, const char* type_name, int bytes, Thread* current); |
| 103 | + static void log_symbol(Symbol* s, address requested_addr, const char* type_name, int bytes, Thread* current); |
| 104 | + |
| 105 | + |
| 106 | +#if INCLUDE_CDS_JAVA_HEAP |
| 107 | + static void dumptime_log_heap_region(ArchiveHeapInfo* heap_info); |
| 108 | + static void runtime_log_heap_region(FileMapInfo* mapinfo); |
| 109 | + |
| 110 | + static void print_oop_info_cr(outputStream* st, FakeOop fake_oop, bool print_requested_addr = true); |
| 111 | + static void print_oop_details(FakeOop fake_oop, outputStream* st); |
| 112 | + static void log_oops(address buf_start, address buf_end); |
| 113 | + class ArchivedFieldPrinter; // to be replaced by ArchivedFieldPrinter2 |
| 114 | +#endif |
| 115 | + |
| 116 | +public: |
| 117 | + static void ergo_initialize(); |
| 118 | + static bool is_logging_at_bootstrap() { return _is_logging_at_bootstrap; } |
| 119 | + |
| 120 | + static void dumptime_log(ArchiveBuilder* builder, FileMapInfo* mapinfo, |
| 121 | + ArchiveHeapInfo* heap_info, |
| 122 | + char* bitmap, size_t bitmap_size_in_bytes); |
| 123 | + static void runtime_log(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo); |
| 124 | +}; |
| 125 | + |
| 126 | +#endif // SHARE_CDS_AOTMAPLOGGER_HPP |
0 commit comments