/* * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
struct ArchiveHeapBitmapInfo; class CHeapBitMap; class FileMapInfo; class Klass; class MemRegion; class Symbol;
// Metaspace::allocate() requires that all blocks must be aligned with KlassAlignmentInBytes. // We enforce the same alignment rule in blocks allocated from the shared space. constint SharedSpaceObjectAlignment = KlassAlignmentInBytes;
// Overview of CDS archive creation (for both static and dynamic dump): // // [1] Load all classes (static dump: from the classlist, dynamic dump: as part of app execution) // [2] Allocate "output buffer" // [3] Copy contents of the 2 "core" regions (rw/ro) into the output buffer. // - allocate the cpp vtables in rw (static dump only) // - memcpy the MetaspaceObjs into rw/ro: // dump_rw_region(); // dump_ro_region(); // - fix all the pointers in the MetaspaceObjs to point to the copies // relocate_metaspaceobj_embedded_pointers() // [4] Copy symbol table, dictionary, etc, into the ro region // [5] Relocate all the pointers in rw/ro, so that the archive can be mapped to // the "requested" location without runtime relocation. See relocate_to_requested() // // "source" vs "buffered" vs "requested" // // The ArchiveBuilder deals with three types of addresses. // // "source": These are the addresses of objects created in step [1] above. They are the actual // InstanceKlass*, Method*, etc, of the Java classes that are loaded for executing // Java bytecodes in the JVM process that's dumping the CDS archive. // // It may be necessary to contiue Java execution after ArchiveBuilder is finished. // Therefore, we don't modify any of the "source" objects. // // "buffered": The "source" objects that are deemed archivable are copied into a temporary buffer. // Objects in the buffer are modified in steps [2, 3, 4] (e.g., unshareable info is // removed, pointers are relocated, etc) to prepare them to be loaded at runtime. // // "requested": These are the addreses where the "buffered" objects should be loaded at runtime. // When the "buffered" objects are written into the archive file, their addresses // are adjusted in step [5] such that the lowest of these objects would be mapped // at SharedBaseAddress. // // Translation between "source" and "buffered" addresses is done with two hashtables: // _src_obj_table : "source" -> "buffered" // _buffered_to_src_table : "buffered" -> "source" // // Translation between "buffered" and "requested" addresses is done with a simple shift: // buffered_address + _buffer_to_requested_delta == requested_address // class ArchiveBuilder : public StackObj { protected:
DumpRegion* _current_dump_space;
address _buffer_bottom; // for writing the contents of rw/ro regions
address _last_verified_top; int _num_dump_regions_used;
size_t _other_region_used_bytes;
// These are the addresses where we will request the static and dynamic archives to be // mapped at run time. If the request fails (due to ASLR), we will map the archives at // os-selected addresses.
address _requested_static_archive_bottom; // This is determined solely by the value of // SharedBaseAddress during -Xshare:dump.
address _requested_static_archive_top;
address _requested_dynamic_archive_bottom; // Used only during dynamic dump. It's placed // immediately above _requested_static_archive_top.
address _requested_dynamic_archive_top;
// (Used only during dynamic dump) where the static archive is actually mapped. This // may be different than _requested_static_archive_{bottom,top} due to ASLR
address _mapped_static_archive_bottom;
address _mapped_static_archive_top;
private: class SpecialRefInfo { // We have a "special pointer" of the given _type at _field_offset of _src_obj. // See MetaspaceClosure::push_special().
MetaspaceClosure::SpecialRef _type;
address _src_obj;
size_t _field_offset;
class SourceObjInfo {
MetaspaceClosure::Ref* _ref; // The object that's copied into the buffer
uintx _ptrmap_start; // The bit-offset of the start of this object (inclusive)
uintx _ptrmap_end; // The bit-offset of the end of this object (exclusive) bool _read_only;
FollowMode _follow_mode; int _size_in_bytes;
MetaspaceObj::Type _msotype;
address _source_addr; // The value of the source object (_ref->obj()) when this // SourceObjInfo was created. Note that _ref->obj() may change // later if _ref is relocated.
address _buffered_addr; // The copy of _ref->obj() insider the buffer. public:
SourceObjInfo(MetaspaceClosure::Ref* ref, bool read_only, FollowMode follow_mode) :
_ref(ref), _ptrmap_start(0), _ptrmap_end(0), _read_only(read_only), _follow_mode(follow_mode),
_size_in_bytes(ref->size() * BytesPerWord), _msotype(ref->msotype()),
_source_addr(ref->obj()) { if (follow_mode == point_to_it) {
_buffered_addr = ref->obj();
} else {
_buffered_addr = NULL;
}
}
class SourceObjList {
uintx _total_bytes;
GrowableArray<SourceObjInfo*>* _objs; // Source objects to be archived
CHeapBitMap _ptrmap; // Marks the addresses of the pointer fields // in the source objects public:
SourceObjList();
~SourceObjList();
DumpRegion _rw_region;
DumpRegion _ro_region;
CHeapBitMap _ptrmap; // bitmap used by ArchivePtrMarker
SourceObjList _rw_src_objs; // objs to put in rw region
SourceObjList _ro_src_objs; // objs to put in ro region
ResizeableResourceHashtable<address, SourceObjInfo, AnyObj::C_HEAP, mtClassShared> _src_obj_table;
ResizeableResourceHashtable<address, address, AnyObj::C_HEAP, mtClassShared> _buffered_to_src_table;
GrowableArray<Klass*>* _klasses;
GrowableArray<Symbol*>* _symbols;
GrowableArray<SpecialRefInfo>* _special_refs;
// For global access. static ArchiveBuilder* _current;
public: // Use this when you allocate space outside of ArchiveBuilder::dump_{rw,ro}_region. // These are usually for misc tables that are allocated in the RO space. class OtherROAllocMark { char* _oldtop; public:
OtherROAllocMark() {
_oldtop = _current->_ro_region.top();
}
~OtherROAllocMark();
};
// Conservative estimate for number of bytes needed for:
size_t _estimated_metaspaceobj_bytes; // all archived MetaspaceObj's.
size_t _estimated_hashtable_bytes; // symbol table and dictionaries
// The address p points to an object inside the output buffer. When the archive is mapped // at the requested address, what's the offset of this object from _requested_static_archive_bottom?
uintx buffer_to_offset(address p) const;
// Same as buffer_to_offset, except that the address p points to either (a) an object // inside the output buffer, or (b), an object in the currently mapped static archive.
uintx any_to_offset(address p) const;
// All klasses and symbols that will be copied into the archive
GrowableArray<Klass*>* klasses() const { return _klasses; }
GrowableArray<Symbol*>* symbols() const { return _symbols; }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.