Skip to content

Commit 41ce658

Browse files
committed
8292225: Rename ArchiveBuilder APIs related to source and buffered addresses
Reviewed-by: ccheung
1 parent 155b10a commit 41ce658

File tree

8 files changed

+104
-87
lines changed

8 files changed

+104
-87
lines changed

src/hotspot/share/cds/archiveBuilder.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,18 @@ void ArchiveBuilder::SourceObjList::remember_embedded_pointer(SourceObjInfo* src
109109

110110
class RelocateEmbeddedPointers : public BitMapClosure {
111111
ArchiveBuilder* _builder;
112-
address _dumped_obj;
112+
address _buffered_obj;
113113
BitMap::idx_t _start_idx;
114114
public:
115-
RelocateEmbeddedPointers(ArchiveBuilder* builder, address dumped_obj, BitMap::idx_t start_idx) :
116-
_builder(builder), _dumped_obj(dumped_obj), _start_idx(start_idx) {}
115+
RelocateEmbeddedPointers(ArchiveBuilder* builder, address buffered_obj, BitMap::idx_t start_idx) :
116+
_builder(builder), _buffered_obj(buffered_obj), _start_idx(start_idx) {}
117117

118118
bool do_bit(BitMap::idx_t bit_offset) {
119119
size_t field_offset = size_t(bit_offset - _start_idx) * sizeof(address);
120-
address* ptr_loc = (address*)(_dumped_obj + field_offset);
120+
address* ptr_loc = (address*)(_buffered_obj + field_offset);
121121

122122
address old_p = *ptr_loc;
123-
address new_p = _builder->get_dumped_addr(old_p);
123+
address new_p = _builder->get_buffered_addr(old_p);
124124

125125
log_trace(cds)("Ref: [" PTR_FORMAT "] -> " PTR_FORMAT " => " PTR_FORMAT,
126126
p2i(ptr_loc), p2i(old_p), p2i(new_p));
@@ -136,7 +136,7 @@ void ArchiveBuilder::SourceObjList::relocate(int i, ArchiveBuilder* builder) {
136136
BitMap::idx_t start = BitMap::idx_t(src_info->ptrmap_start()); // inclusive
137137
BitMap::idx_t end = BitMap::idx_t(src_info->ptrmap_end()); // exclusive
138138

139-
RelocateEmbeddedPointers relocator(builder, src_info->dumped_addr(), start);
139+
RelocateEmbeddedPointers relocator(builder, src_info->buffered_addr(), start);
140140
_ptrmap.iterate(&relocator, start, end);
141141
}
142142

@@ -158,7 +158,7 @@ ArchiveBuilder::ArchiveBuilder() :
158158
_rw_src_objs(),
159159
_ro_src_objs(),
160160
_src_obj_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
161-
_dumped_to_src_obj_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
161+
_buffered_to_src_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
162162
_total_closed_heap_region_size(0),
163163
_total_open_heap_region_size(0),
164164
_estimated_metaspaceobj_bytes(0),
@@ -632,10 +632,10 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s
632632
memcpy(dest, src, bytes);
633633
{
634634
bool created;
635-
_dumped_to_src_obj_table.put_if_absent((address)dest, src, &created);
635+
_buffered_to_src_table.put_if_absent((address)dest, src, &created);
636636
assert(created, "must be");
637-
if (_dumped_to_src_obj_table.maybe_grow()) {
638-
log_info(cds, hashtables)("Expanded _dumped_to_src_obj_table table to %d", _dumped_to_src_obj_table.table_size());
637+
if (_buffered_to_src_table.maybe_grow()) {
638+
log_info(cds, hashtables)("Expanded _buffered_to_src_table table to %d", _buffered_to_src_table.table_size());
639639
}
640640
}
641641

@@ -646,23 +646,23 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s
646646
}
647647

648648
log_trace(cds)("Copy: " PTR_FORMAT " ==> " PTR_FORMAT " %d", p2i(src), p2i(dest), bytes);
649-
src_info->set_dumped_addr((address)dest);
649+
src_info->set_buffered_addr((address)dest);
650650

651651
_alloc_stats.record(ref->msotype(), int(newtop - oldtop), src_info->read_only());
652652
}
653653

654-
address ArchiveBuilder::get_dumped_addr(address src_obj) const {
655-
SourceObjInfo* p = _src_obj_table.get(src_obj);
654+
address ArchiveBuilder::get_buffered_addr(address src_addr) const {
655+
SourceObjInfo* p = _src_obj_table.get(src_addr);
656656
assert(p != NULL, "must be");
657657

658-
return p->dumped_addr();
658+
return p->buffered_addr();
659659
}
660660

661-
address ArchiveBuilder::get_src_obj(address dumped_addr) const {
662-
assert(is_in_buffer_space(dumped_addr), "must be");
663-
address* src_obj = _dumped_to_src_obj_table.get(dumped_addr);
664-
assert(src_obj != NULL && *src_obj != NULL, "must be");
665-
return *src_obj;
661+
address ArchiveBuilder::get_source_addr(address buffered_addr) const {
662+
assert(is_in_buffer_space(buffered_addr), "must be");
663+
address* src_p = _buffered_to_src_table.get(buffered_addr);
664+
assert(src_p != NULL && *src_p != NULL, "must be");
665+
return *src_p;
666666
}
667667

668668
void ArchiveBuilder::relocate_embedded_pointers(ArchiveBuilder::SourceObjList* src_objs) {
@@ -676,7 +676,7 @@ void ArchiveBuilder::update_special_refs() {
676676
SpecialRefInfo s = _special_refs->at(i);
677677
size_t field_offset = s.field_offset();
678678
address src_obj = s.src_obj();
679-
address dst_obj = get_dumped_addr(src_obj);
679+
address dst_obj = get_buffered_addr(src_obj);
680680
intptr_t* src_p = (intptr_t*)(src_obj + field_offset);
681681
intptr_t* dst_p = (intptr_t*)(dst_obj + field_offset);
682682
assert(s.type() == MetaspaceClosure::_method_entry_ref, "only special type allowed for now");
@@ -694,7 +694,7 @@ class RefRelocator: public MetaspaceClosure {
694694

695695
virtual bool do_ref(Ref* ref, bool read_only) {
696696
if (ref->not_null()) {
697-
ref->update(_builder->get_dumped_addr(ref->obj()));
697+
ref->update(_builder->get_buffered_addr(ref->obj()));
698698
ArchivePtrMarker::mark_pointer(ref->addr());
699699
}
700700
return false; // Do not recurse.
@@ -829,11 +829,11 @@ uintx ArchiveBuilder::any_to_offset(address p) const {
829829
return buffer_to_offset(p);
830830
}
831831

832-
// Update a Java object to point its Klass* to the new location after
833-
// shared archive has been compacted.
834-
void ArchiveBuilder::relocate_klass_ptr(oop o) {
832+
// Update a Java object to point its Klass* to the address whene
833+
// the class would be mapped at runtime.
834+
void ArchiveBuilder::relocate_klass_ptr_of_oop(oop o) {
835835
assert(DumpSharedSpaces, "sanity");
836-
Klass* k = get_relocated_klass(o->klass());
836+
Klass* k = get_buffered_klass(o->klass());
837837
Klass* requested_k = to_requested(k);
838838
narrowKlass nk = CompressedKlassPointers::encode_not_null(requested_k, _requested_static_archive_bottom);
839839
o->set_narrow_klass(nk);
@@ -981,8 +981,8 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
981981
Thread* current = Thread::current();
982982
for (int i = 0; i < src_objs->objs()->length(); i++) {
983983
SourceObjInfo* src_info = src_objs->at(i);
984-
address src = src_info->orig_obj();
985-
address dest = src_info->dumped_addr();
984+
address src = src_info->source_addr();
985+
address dest = src_info->buffered_addr();
986986
log_data(last_obj_base, dest, last_obj_base + buffer_to_runtime_delta());
987987
address runtime_dest = dest + buffer_to_runtime_delta();
988988
int bytes = src_info->size_in_bytes();

src/hotspot/share/cds/archiveBuilder.hpp

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,34 @@ const int SharedSpaceObjectAlignment = KlassAlignmentInBytes;
6161
// [4] Copy symbol table, dictionary, etc, into the ro region
6262
// [5] Relocate all the pointers in rw/ro, so that the archive can be mapped to
6363
// 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+
//
69+
// "source": These are the addresses of objects created in step [1] above. They are the actual
70+
// InstanceKlass*, Method*, etc, of the Java classes that are loaded for executing
71+
// Java bytecodes in the JVM process that's dumping the CDS archive.
72+
//
73+
// It may be necessary to contiue Java execution after ArchiveBuilder is finished.
74+
// Therefore, we don't modify any of the "source" objects.
75+
//
76+
// "buffered": The "source" objects that are deemed archivable are copied into a temporary buffer.
77+
// Objects in the buffer are modified in steps [2, 3, 4] (e.g., unshareable info is
78+
// removed, pointers are relocated, etc) to prepare them to be loaded at runtime.
79+
//
80+
// "requested": These are the addreses where the "buffered" objects should be loaded at runtime.
81+
// When the "buffered" objects are written into the archive file, their addresses
82+
// are adjusted in step [5] such that the lowest of these objects would be mapped
83+
// at SharedBaseAddress.
84+
//
85+
// Translation between "source" and "buffered" addresses is done with two hashtables:
86+
// _src_obj_table : "source" -> "buffered"
87+
// _buffered_to_src_table : "buffered" -> "source"
88+
//
89+
// Translation between "buffered" and "requested" addresses is done with a simple shift:
90+
// buffered_address + _buffer_to_requested_delta == requested_address
91+
//
6492
class ArchiveBuilder : public StackObj {
6593
protected:
6694
DumpRegion* _current_dump_space;
@@ -112,46 +140,45 @@ class ArchiveBuilder : public StackObj {
112140
};
113141

114142
class SourceObjInfo {
115-
MetaspaceClosure::Ref* _ref;
143+
MetaspaceClosure::Ref* _ref; // The object that's copied into the buffer
116144
uintx _ptrmap_start; // The bit-offset of the start of this object (inclusive)
117145
uintx _ptrmap_end; // The bit-offset of the end of this object (exclusive)
118146
bool _read_only;
119147
FollowMode _follow_mode;
120148
int _size_in_bytes;
121149
MetaspaceObj::Type _msotype;
122-
address _dumped_addr; // Address this->obj(), as used by the dumped archive.
123-
address _orig_obj; // The value of the original object (_ref->obj()) when this
150+
address _source_addr; // The value of the source object (_ref->obj()) when this
124151
// SourceObjInfo was created. Note that _ref->obj() may change
125152
// later if _ref is relocated.
126-
153+
address _buffered_addr; // The copy of _ref->obj() insider the buffer.
127154
public:
128155
SourceObjInfo(MetaspaceClosure::Ref* ref, bool read_only, FollowMode follow_mode) :
129156
_ref(ref), _ptrmap_start(0), _ptrmap_end(0), _read_only(read_only), _follow_mode(follow_mode),
130157
_size_in_bytes(ref->size() * BytesPerWord), _msotype(ref->msotype()),
131-
_orig_obj(ref->obj()) {
158+
_source_addr(ref->obj()) {
132159
if (follow_mode == point_to_it) {
133-
_dumped_addr = ref->obj();
160+
_buffered_addr = ref->obj();
134161
} else {
135-
_dumped_addr = NULL;
162+
_buffered_addr = NULL;
136163
}
137164
}
138165

139166
bool should_copy() const { return _follow_mode == make_a_copy; }
140167
MetaspaceClosure::Ref* ref() const { return _ref; }
141-
void set_dumped_addr(address dumped_addr) {
168+
void set_buffered_addr(address addr) {
142169
assert(should_copy(), "must be");
143-
assert(_dumped_addr == NULL, "cannot be copied twice");
144-
assert(dumped_addr != NULL, "must be a valid copy");
145-
_dumped_addr = dumped_addr;
170+
assert(_buffered_addr == NULL, "cannot be copied twice");
171+
assert(addr != NULL, "must be a valid copy");
172+
_buffered_addr = addr;
146173
}
147174
void set_ptrmap_start(uintx v) { _ptrmap_start = v; }
148175
void set_ptrmap_end(uintx v) { _ptrmap_end = v; }
149176
uintx ptrmap_start() const { return _ptrmap_start; } // inclusive
150177
uintx ptrmap_end() const { return _ptrmap_end; } // exclusive
151178
bool read_only() const { return _read_only; }
152179
int size_in_bytes() const { return _size_in_bytes; }
153-
address orig_obj() const { return _orig_obj; }
154-
address dumped_addr() const { return _dumped_addr; }
180+
address source_addr() const { return _source_addr; }
181+
address buffered_addr() const { return _buffered_addr; }
155182
MetaspaceObj::Type msotype() const { return _msotype; }
156183

157184
// convenience accessor
@@ -200,7 +227,7 @@ class ArchiveBuilder : public StackObj {
200227
SourceObjList _rw_src_objs; // objs to put in rw region
201228
SourceObjList _ro_src_objs; // objs to put in ro region
202229
ResizeableResourceHashtable<address, SourceObjInfo, ResourceObj::C_HEAP, mtClassShared> _src_obj_table;
203-
ResizeableResourceHashtable<address, address, ResourceObj::C_HEAP, mtClassShared> _dumped_to_src_obj_table;
230+
ResizeableResourceHashtable<address, address, ResourceObj::C_HEAP, mtClassShared> _buffered_to_src_table;
204231
GrowableArray<Klass*>* _klasses;
205232
GrowableArray<Symbol*>* _symbols;
206233
GrowableArray<SpecialRefInfo>* _special_refs;
@@ -384,16 +411,10 @@ class ArchiveBuilder : public StackObj {
384411
void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
385412
bool read_only, bool allow_exec);
386413

387-
// + When creating a CDS archive, we first load Java classes and create metadata
388-
// objects as usual. These are call "source" objects.
389-
// + We then copy the source objects into the output buffer at "dumped addresses".
390-
//
391-
// The following functions translate between these two (non-overlapping) spaces.
392-
// (The API should be renamed to be less confusing!)
393-
address get_dumped_addr(address src_obj) const;
394-
address get_src_obj(address dumped_addr) const;
395-
template <typename T> T get_src_obj(T dumped_addr) const {
396-
return (T)get_src_obj((address)dumped_addr);
414+
address get_buffered_addr(address src_addr) const;
415+
address get_source_addr(address buffered_addr) const;
416+
template <typename T> T get_source_addr(T buffered_addr) const {
417+
return (T)get_source_addr((address)buffered_addr);
397418
}
398419

399420
// All klasses and symbols that will be copied into the archive
@@ -422,16 +443,16 @@ class ArchiveBuilder : public StackObj {
422443
return alloc_stats()->string_stats();
423444
}
424445

425-
void relocate_klass_ptr(oop o);
446+
void relocate_klass_ptr_of_oop(oop o);
426447

427-
static Klass* get_relocated_klass(Klass* orig_klass) {
428-
Klass* klass = (Klass*)current()->get_dumped_addr((address)orig_klass);
448+
static Klass* get_buffered_klass(Klass* src_klass) {
449+
Klass* klass = (Klass*)current()->get_buffered_addr((address)src_klass);
429450
assert(klass != NULL && klass->is_klass(), "must be");
430451
return klass;
431452
}
432453

433-
static Symbol* get_relocated_symbol(Symbol* orig_symbol) {
434-
return (Symbol*)current()->get_dumped_addr((address)orig_symbol);
454+
static Symbol* get_buffered_symbol(Symbol* src_symbol) {
455+
return (Symbol*)current()->get_buffered_addr((address)src_symbol);
435456
}
436457

437458
void print_stats();

src/hotspot/share/cds/dynamicArchive.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ class DynamicArchiveBuilder : public ArchiveBuilder {
5858
ArchivePtrMarker::mark_pointer(ptr_loc);
5959
}
6060

61-
template <typename T> T get_dumped_addr(T obj) {
62-
return (T)ArchiveBuilder::get_dumped_addr((address)obj);
63-
}
64-
6561
static int dynamic_dump_method_comparator(Method* a, Method* b) {
6662
Symbol* a_name = a->name();
6763
Symbol* b_name = b->name();

0 commit comments

Comments
 (0)