Skip to content

Commit 4178834

Browse files
committed
8256172: Clean up CDS handling of i2i_entry
Reviewed-by: minqi, ccheung
1 parent cfa92a5 commit 4178834

File tree

8 files changed

+45
-61
lines changed

8 files changed

+45
-61
lines changed

src/hotspot/share/interpreter/abstractInterpreter.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,27 @@ AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(const methodHan
200200

201201
#if INCLUDE_CDS
202202

203-
address AbstractInterpreter::get_trampoline_code_buffer(AbstractInterpreter::MethodKind kind) {
203+
// For a shared Method m, to improve sharing across processes, we avoid writing to m->_i2i_entry
204+
// at runtime. Instead, m->_i2i_entry points to a fixed location inside the CDS archive.
205+
// This location contains a trampoline (generated by generate_entry_for_cds_method)
206+
// which jumps to _entry_table[kind].
207+
address AbstractInterpreter::entry_for_cds_method(const methodHandle& m) {
208+
MethodKind kind = method_kind(m);
209+
assert(0 <= kind && kind < number_of_method_entries, "illegal kind");
210+
return entry_for_cds_method(kind);
211+
}
212+
213+
address AbstractInterpreter::entry_for_cds_method(AbstractInterpreter::MethodKind kind) {
204214
const size_t trampoline_size = SharedRuntime::trampoline_size();
205-
address addr = MetaspaceShared::i2i_entry_code_buffers((size_t)(AbstractInterpreter::number_of_method_entries) * trampoline_size);
215+
address addr = MetaspaceShared::i2i_entry_code_buffers();
206216
addr += (size_t)(kind) * trampoline_size;
207217

208218
return addr;
209219
}
210220

211-
void AbstractInterpreter::update_cds_entry_table(AbstractInterpreter::MethodKind kind) {
212-
if (DumpSharedSpaces || UseSharedSpaces) {
213-
address trampoline = get_trampoline_code_buffer(kind);
214-
_cds_entry_table[kind] = trampoline;
215-
221+
void AbstractInterpreter::generate_entry_for_cds_method(AbstractInterpreter::MethodKind kind) {
222+
if (UseSharedSpaces) {
223+
address trampoline = entry_for_cds_method(kind);
216224
CodeBuffer buffer(trampoline, (int)(SharedRuntime::trampoline_size()));
217225
MacroAssembler _masm(&buffer);
218226
SharedRuntime::generate_trampoline(&_masm, _entry_table[kind]);
@@ -232,7 +240,7 @@ void AbstractInterpreter::set_entry_for_kind(AbstractInterpreter::MethodKind kin
232240
assert(_entry_table[kind] == _entry_table[abstract], "previous value must be AME entry");
233241
_entry_table[kind] = entry;
234242

235-
update_cds_entry_table(kind);
243+
generate_entry_for_cds_method(kind);
236244
}
237245

238246
// Return true if the interpreter can prove that the given bytecode has
@@ -468,6 +476,6 @@ void AbstractInterpreter::initialize_method_handle_entries() {
468476
for (int i = method_handle_invoke_FIRST; i <= method_handle_invoke_LAST; i++) {
469477
MethodKind kind = (MethodKind) i;
470478
_entry_table[kind] = _entry_table[Interpreter::abstract];
471-
Interpreter::update_cds_entry_table(kind);
479+
Interpreter::generate_entry_for_cds_method(kind);
472480
}
473481
}

src/hotspot/share/interpreter/abstractInterpreter.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,10 @@ class AbstractInterpreter: AllStatic {
133133
static address entry_for_kind(MethodKind k) { assert(0 <= k && k < number_of_method_entries, "illegal kind"); return _entry_table[k]; }
134134
static address entry_for_method(const methodHandle& m) { return entry_for_kind(method_kind(m)); }
135135

136-
static address entry_for_cds_method(const methodHandle& m) {
137-
MethodKind k = method_kind(m);
138-
assert(0 <= k && k < number_of_method_entries, "illegal kind");
139-
return _cds_entry_table[k];
140-
}
141-
142136
// used by class data sharing
143-
static void update_cds_entry_table(MethodKind kind) NOT_CDS_RETURN;
144-
145-
static address get_trampoline_code_buffer(AbstractInterpreter::MethodKind kind) NOT_CDS_RETURN_(0);
137+
static address entry_for_cds_method(const methodHandle& m) NOT_CDS_RETURN_(NULL);
138+
static address entry_for_cds_method(AbstractInterpreter::MethodKind kind) NOT_CDS_RETURN_(NULL);
139+
static void generate_entry_for_cds_method(MethodKind kind) NOT_CDS_RETURN;
146140

147141
// used for bootstrapping method handles:
148142
static void set_entry_for_kind(MethodKind k, address e);

src/hotspot/share/interpreter/templateInterpreterGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void TemplateInterpreterGenerator::generate_all() {
181181
#define method_entry(kind) \
182182
{ CodeletMark cm(_masm, "method entry point (kind = " #kind ")"); \
183183
Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind); \
184-
Interpreter::update_cds_entry_table(Interpreter::kind); \
184+
Interpreter::generate_entry_for_cds_method(Interpreter::kind); \
185185
}
186186

187187
// all non-native method kinds

src/hotspot/share/memory/archiveBuilder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ void ArchiveBuilder::gather_klasses_and_symbols() {
281281
// DynamicArchiveBuilder::sort_methods()).
282282
sort_symbols_and_fix_hash();
283283
sort_klasses();
284-
allocate_method_trampoline_info();
285-
allocate_method_trampolines();
286284
}
287285
}
288286

src/hotspot/share/memory/filemap.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ void FileMapHeader::print(outputStream* st) {
278278
st->print_cr("- cloned_vtables_offset: " SIZE_FORMAT_HEX, _cloned_vtables_offset);
279279
st->print_cr("- serialized_data_offset: " SIZE_FORMAT_HEX, _serialized_data_offset);
280280
st->print_cr("- i2i_entry_code_buffers_offset: " SIZE_FORMAT_HEX, _i2i_entry_code_buffers_offset);
281-
st->print_cr("- i2i_entry_code_buffers_size: " SIZE_FORMAT, _i2i_entry_code_buffers_size);
282281
st->print_cr("- heap_end: " INTPTR_FORMAT, p2i(_heap_end));
283282
st->print_cr("- base_archive_is_default: %d", _base_archive_is_default);
284283
st->print_cr("- jvm_ident: %s", _jvm_ident);

src/hotspot/share/memory/filemap.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ class FileMapHeader: private CDSFileMapHeaderBase {
202202
size_t _cloned_vtables_offset; // The address of the first cloned vtable
203203
size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
204204
size_t _i2i_entry_code_buffers_offset;
205-
size_t _i2i_entry_code_buffers_size;
206205
address _heap_end; // heap end at dump time.
207206
bool _base_archive_is_default; // indicates if the base archive is the system default one
208207

@@ -270,7 +269,6 @@ class FileMapHeader: private CDSFileMapHeaderBase {
270269
char* cloned_vtables() const { return from_mapped_offset(_cloned_vtables_offset); }
271270
char* serialized_data() const { return from_mapped_offset(_serialized_data_offset); }
272271
address i2i_entry_code_buffers() const { return (address)from_mapped_offset(_i2i_entry_code_buffers_offset); }
273-
size_t i2i_entry_code_buffers_size() const { return _i2i_entry_code_buffers_size; }
274272
address heap_end() const { return _heap_end; }
275273
bool base_archive_is_default() const { return _base_archive_is_default; }
276274
const char* jvm_ident() const { return _jvm_ident; }
@@ -297,10 +295,8 @@ class FileMapHeader: private CDSFileMapHeaderBase {
297295
void set_ptrmap_size_in_bits(size_t s) { _ptrmap_size_in_bits = s; }
298296
void set_mapped_base_address(char* p) { _mapped_base_address = p; }
299297
void set_heap_obj_roots(narrowOop r) { _heap_obj_roots = r; }
300-
301-
void set_i2i_entry_code_buffers(address p, size_t s) {
298+
void set_i2i_entry_code_buffers(address p) {
302299
set_mapped_offset((char*)p, &_i2i_entry_code_buffers_offset);
303-
_i2i_entry_code_buffers_size = s;
304300
}
305301

306302
void set_shared_path_table(SharedPathTable table) {
@@ -417,9 +413,8 @@ class FileMapInfo : public CHeapObj<mtInternal> {
417413
void align_file_position();
418414

419415
address i2i_entry_code_buffers() const { return header()->i2i_entry_code_buffers(); }
420-
size_t i2i_entry_code_buffers_size() const { return header()->i2i_entry_code_buffers_size(); }
421-
void set_i2i_entry_code_buffers(address addr, size_t s) const {
422-
header()->set_i2i_entry_code_buffers(addr, s);
416+
void set_i2i_entry_code_buffers(address addr) const {
417+
header()->set_i2i_entry_code_buffers(addr);
423418
}
424419

425420
bool is_static() const { return _is_static; }

src/hotspot/share/memory/metaspaceShared.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "classfile/systemDictionary.hpp"
3737
#include "classfile/systemDictionaryShared.hpp"
3838
#include "code/codeCache.hpp"
39+
#include "interpreter/abstractInterpreter.hpp"
3940
#include "interpreter/bytecodeStream.hpp"
4041
#include "interpreter/bytecodes.hpp"
4142
#include "logging/log.hpp"
@@ -61,6 +62,7 @@
6162
#include "runtime/handles.inline.hpp"
6263
#include "runtime/os.hpp"
6364
#include "runtime/safepointVerifiers.hpp"
65+
#include "runtime/sharedRuntime.hpp"
6466
#include "runtime/timerTrace.hpp"
6567
#include "runtime/vmThread.hpp"
6668
#include "runtime/vmOperations.hpp"
@@ -82,7 +84,6 @@ bool MetaspaceShared::_has_error_classes;
8284
bool MetaspaceShared::_archive_loading_failed = false;
8385
bool MetaspaceShared::_remapped_readwrite = false;
8486
address MetaspaceShared::_i2i_entry_code_buffers = NULL;
85-
size_t MetaspaceShared::_i2i_entry_code_buffers_size = 0;
8687
void* MetaspaceShared::_shared_metaspace_static_top = NULL;
8788
intx MetaspaceShared::_relocation_delta;
8889
char* MetaspaceShared::_requested_base_address;
@@ -339,10 +340,6 @@ void MetaspaceShared::initialize_dumptime_shared_and_meta_spaces() {
339340
log_info(cds)("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
340341
_shared_rs.size(), p2i(_shared_rs.base()));
341342

342-
// We don't want any valid object to be at the very bottom of the archive.
343-
// See ArchivePtrMarker::mark_pointer().
344-
MetaspaceShared::misc_code_space_alloc(16);
345-
346343
size_t symbol_rs_size = LP64_ONLY(3 * G) NOT_LP64(128 * M);
347344
_symbol_rs = ReservedSpace(symbol_rs_size);
348345
if (!_symbol_rs.is_reserved()) {
@@ -510,19 +507,19 @@ void MetaspaceShared::serialize(SerializeClosure* soc) {
510507
soc->do_tag(666);
511508
}
512509

513-
address MetaspaceShared::i2i_entry_code_buffers(size_t total_size) {
514-
if (DumpSharedSpaces) {
515-
if (_i2i_entry_code_buffers == NULL) {
516-
_i2i_entry_code_buffers = (address)misc_code_space_alloc(total_size);
517-
_i2i_entry_code_buffers_size = total_size;
518-
}
519-
} else if (UseSharedSpaces) {
520-
assert(_i2i_entry_code_buffers != NULL, "must already been initialized");
521-
} else {
522-
return NULL;
523-
}
510+
void MetaspaceShared::init_misc_code_space() {
511+
// We don't want any valid object to be at the very bottom of the archive.
512+
// See ArchivePtrMarker::mark_pointer().
513+
MetaspaceShared::misc_code_space_alloc(16);
524514

525-
assert(_i2i_entry_code_buffers_size == total_size, "must not change");
515+
size_t trampoline_size = SharedRuntime::trampoline_size();
516+
size_t buf_size = (size_t)AbstractInterpreter::number_of_method_entries * trampoline_size;
517+
_i2i_entry_code_buffers = (address)misc_code_space_alloc(buf_size);
518+
}
519+
520+
address MetaspaceShared::i2i_entry_code_buffers() {
521+
assert(DumpSharedSpaces || UseSharedSpaces, "must be");
522+
assert(_i2i_entry_code_buffers != NULL, "must already been initialized");
526523
return _i2i_entry_code_buffers;
527524
}
528525

@@ -733,6 +730,10 @@ void VM_PopulateDumpSharedSpace::doit() {
733730

734731
builder.gather_source_objs();
735732

733+
MetaspaceShared::init_misc_code_space();
734+
builder.allocate_method_trampoline_info();
735+
builder.allocate_method_trampolines();
736+
736737
char* cloned_vtables = CppVtables::dumptime_init();
737738

738739
{
@@ -785,8 +786,6 @@ void VM_PopulateDumpSharedSpace::doit() {
785786
// The vtable clones contain addresses of the current process.
786787
// We don't want to write these addresses into the archive. Same for i2i buffer.
787788
CppVtables::zero_archived_vtables();
788-
memset(MetaspaceShared::i2i_entry_code_buffers(), 0,
789-
MetaspaceShared::i2i_entry_code_buffers_size());
790789

791790
// relocate the data so that it can be mapped to MetaspaceShared::requested_base_address()
792791
// without runtime relocation.
@@ -798,8 +797,7 @@ void VM_PopulateDumpSharedSpace::doit() {
798797
mapinfo->populate_header(os::vm_allocation_granularity());
799798
mapinfo->set_serialized_data(serialized_data);
800799
mapinfo->set_cloned_vtables(cloned_vtables);
801-
mapinfo->set_i2i_entry_code_buffers(MetaspaceShared::i2i_entry_code_buffers(),
802-
MetaspaceShared::i2i_entry_code_buffers_size());
800+
mapinfo->set_i2i_entry_code_buffers(MetaspaceShared::i2i_entry_code_buffers());
803801
mapinfo->open_for_write();
804802
size_t bitmap_size_in_bytes;
805803
char* bitmap = MetaspaceShared::write_core_archive_regions(mapinfo, _closed_archive_heap_oopmaps,
@@ -1720,7 +1718,6 @@ void MetaspaceShared::unmap_archive(FileMapInfo* mapinfo) {
17201718
void MetaspaceShared::initialize_shared_spaces() {
17211719
FileMapInfo *static_mapinfo = FileMapInfo::current_info();
17221720
_i2i_entry_code_buffers = static_mapinfo->i2i_entry_code_buffers();
1723-
_i2i_entry_code_buffers_size = static_mapinfo->i2i_entry_code_buffers_size();
17241721

17251722
// Verify various attributes of the archive, plus initialize the
17261723
// shared string/symbol tables

src/hotspot/share/memory/metaspaceShared.hpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class MetaspaceShared : AllStatic {
7676
static bool _archive_loading_failed;
7777
static bool _remapped_readwrite;
7878
static address _i2i_entry_code_buffers;
79-
static size_t _i2i_entry_code_buffers_size;
8079
static size_t _core_spaces_size;
8180
static void* _shared_metaspace_static_top;
8281
static intx _relocation_delta;
@@ -237,16 +236,10 @@ class MetaspaceShared : AllStatic {
237236
return align_up(byte_size, SharedSpaceObjectAlignment);
238237
}
239238

240-
static address i2i_entry_code_buffers(size_t total_size);
239+
static void init_misc_code_space();
240+
static address i2i_entry_code_buffers();
241241

242-
static address i2i_entry_code_buffers() {
243-
return _i2i_entry_code_buffers;
244-
}
245-
static size_t i2i_entry_code_buffers_size() {
246-
return _i2i_entry_code_buffers_size;
247-
}
248242
static void relocate_klass_ptr(oop o);
249-
250243
static Klass* get_relocated_klass(Klass *k, bool is_final=false);
251244

252245
static void initialize_ptr_marker(CHeapBitMap* ptrmap);

0 commit comments

Comments
 (0)