Skip to content

Commit 241808e

Browse files
committed
8364269: Simplify code cache API by storing adapter entry offsets in blob
Reviewed-by: kvn, shade, asmehra
1 parent 1b3e231 commit 241808e

File tree

5 files changed

+60
-72
lines changed

5 files changed

+60
-72
lines changed

src/hotspot/share/code/aotCodeCache.cpp

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ bool AOTCodeCache::finish_write() {
799799

800800
//------------------Store/Load AOT code ----------------------
801801

802-
bool AOTCodeCache::store_code_blob(CodeBlob& blob, AOTCodeEntry::Kind entry_kind, uint id, const char* name, int entry_offset_count, int* entry_offsets) {
802+
bool AOTCodeCache::store_code_blob(CodeBlob& blob, AOTCodeEntry::Kind entry_kind, uint id, const char* name) {
803803
AOTCodeCache* cache = open_for_dump();
804804
if (cache == nullptr) {
805805
return false;
@@ -883,18 +883,6 @@ bool AOTCodeCache::store_code_blob(CodeBlob& blob, AOTCodeEntry::Kind entry_kind
883883
return false;
884884
}
885885

886-
// Write entries offsets
887-
n = cache->write_bytes(&entry_offset_count, sizeof(int));
888-
if (n != sizeof(int)) {
889-
return false;
890-
}
891-
for (int i = 0; i < entry_offset_count; i++) {
892-
uint32_t off = (uint32_t)entry_offsets[i];
893-
n = cache->write_bytes(&off, sizeof(uint32_t));
894-
if (n != sizeof(uint32_t)) {
895-
return false;
896-
}
897-
}
898886
uint entry_size = cache->_write_position - entry_position;
899887
AOTCodeEntry* entry = new(cache) AOTCodeEntry(entry_kind, encode_id(entry_kind, id),
900888
entry_position, entry_size, name_offset, name_size,
@@ -903,13 +891,13 @@ bool AOTCodeCache::store_code_blob(CodeBlob& blob, AOTCodeEntry::Kind entry_kind
903891
return true;
904892
}
905893

906-
bool AOTCodeCache::store_code_blob(CodeBlob& blob, AOTCodeEntry::Kind entry_kind, BlobId id, int entry_offset_count, int* entry_offsets) {
894+
bool AOTCodeCache::store_code_blob(CodeBlob& blob, AOTCodeEntry::Kind entry_kind, BlobId id) {
907895
assert(AOTCodeEntry::is_blob(entry_kind),
908896
"wrong entry kind for blob id %s", StubInfo::name(id));
909-
return store_code_blob(blob, entry_kind, (uint)id, StubInfo::name(id), entry_offset_count, entry_offsets);
897+
return store_code_blob(blob, entry_kind, (uint)id, StubInfo::name(id));
910898
}
911899

912-
CodeBlob* AOTCodeCache::load_code_blob(AOTCodeEntry::Kind entry_kind, uint id, const char* name, int entry_offset_count, int* entry_offsets) {
900+
CodeBlob* AOTCodeCache::load_code_blob(AOTCodeEntry::Kind entry_kind, uint id, const char* name) {
913901
AOTCodeCache* cache = open_for_use();
914902
if (cache == nullptr) {
915903
return nullptr;
@@ -929,20 +917,20 @@ CodeBlob* AOTCodeCache::load_code_blob(AOTCodeEntry::Kind entry_kind, uint id, c
929917
return nullptr;
930918
}
931919
AOTCodeReader reader(cache, entry);
932-
CodeBlob* blob = reader.compile_code_blob(name, entry_offset_count, entry_offsets);
920+
CodeBlob* blob = reader.compile_code_blob(name);
933921

934922
log_debug(aot, codecache, stubs)("%sRead blob '%s' (id=%u, kind=%s) from AOT Code Cache",
935923
(blob == nullptr? "Failed to " : ""), name, id, aot_code_entry_kind_name[entry_kind]);
936924
return blob;
937925
}
938926

939-
CodeBlob* AOTCodeCache::load_code_blob(AOTCodeEntry::Kind entry_kind, BlobId id, int entry_offset_count, int* entry_offsets) {
927+
CodeBlob* AOTCodeCache::load_code_blob(AOTCodeEntry::Kind entry_kind, BlobId id) {
940928
assert(AOTCodeEntry::is_blob(entry_kind),
941929
"wrong entry kind for blob id %s", StubInfo::name(id));
942-
return load_code_blob(entry_kind, (uint)id, StubInfo::name(id), entry_offset_count, entry_offsets);
930+
return load_code_blob(entry_kind, (uint)id, StubInfo::name(id));
943931
}
944932

945-
CodeBlob* AOTCodeReader::compile_code_blob(const char* name, int entry_offset_count, int* entry_offsets) {
933+
CodeBlob* AOTCodeReader::compile_code_blob(const char* name) {
946934
uint entry_position = _entry->offset();
947935

948936
// Read name
@@ -989,21 +977,6 @@ CodeBlob* AOTCodeReader::compile_code_blob(const char* name, int entry_offset_co
989977

990978
fix_relocations(code_blob);
991979

992-
// Read entries offsets
993-
offset = read_position();
994-
int stored_count = *(int*)addr(offset);
995-
assert(stored_count == entry_offset_count, "entry offset count mismatch, count in AOT code cache=%d, expected=%d", stored_count, entry_offset_count);
996-
offset += sizeof(int);
997-
set_read_position(offset);
998-
for (int i = 0; i < stored_count; i++) {
999-
uint32_t off = *(uint32_t*)addr(offset);
1000-
offset += sizeof(uint32_t);
1001-
const char* entry_name = (_entry->kind() == AOTCodeEntry::Adapter) ? AdapterHandlerEntry::entry_name(i) : "";
1002-
log_trace(aot, codecache, stubs)("Reading adapter '%s:%s' (0x%x) offset: 0x%x from AOT Code Cache",
1003-
stored_name, entry_name, _entry->id(), off);
1004-
entry_offsets[i] = off;
1005-
}
1006-
1007980
#ifdef ASSERT
1008981
LogStreamHandle(Trace, aot, codecache, stubs) log;
1009982
if (log.is_enabled()) {

src/hotspot/share/code/aotCodeCache.hpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -332,26 +332,18 @@ class AOTCodeCache : public CHeapObj<mtCode> {
332332
// save and restore API for non-enumerable code blobs
333333
static bool store_code_blob(CodeBlob& blob,
334334
AOTCodeEntry::Kind entry_kind,
335-
uint id, const char* name,
336-
int entry_offset_count = 0,
337-
int* entry_offsets = nullptr) NOT_CDS_RETURN_(false);
335+
uint id, const char* name) NOT_CDS_RETURN_(false);
338336

339337
static CodeBlob* load_code_blob(AOTCodeEntry::Kind kind,
340-
uint id, const char* name,
341-
int entry_offset_count = 0,
342-
int* entry_offsets = nullptr) NOT_CDS_RETURN_(nullptr);
338+
uint id, const char* name) NOT_CDS_RETURN_(nullptr);
343339

344340
// save and restore API for enumerable code blobs
345341
static bool store_code_blob(CodeBlob& blob,
346342
AOTCodeEntry::Kind entry_kind,
347-
BlobId id,
348-
int entry_offset_count = 0,
349-
int* entry_offsets = nullptr) NOT_CDS_RETURN_(false);
343+
BlobId id) NOT_CDS_RETURN_(false);
350344

351345
static CodeBlob* load_code_blob(AOTCodeEntry::Kind kind,
352-
BlobId id,
353-
int entry_offset_count = 0,
354-
int* entry_offsets = nullptr) NOT_CDS_RETURN_(nullptr);
346+
BlobId id) NOT_CDS_RETURN_(nullptr);
355347

356348
static uint store_entries_cnt() {
357349
if (is_on_for_dump()) {
@@ -414,7 +406,7 @@ class AOTCodeReader {
414406
public:
415407
AOTCodeReader(AOTCodeCache* cache, AOTCodeEntry* entry);
416408

417-
CodeBlob* compile_code_blob(const char* name, int entry_offset_count, int* entry_offsets);
409+
CodeBlob* compile_code_blob(const char* name);
418410

419411
ImmutableOopMapSet* read_oop_map_set();
420412

src/hotspot/share/code/codeBlob.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ void RuntimeBlob::trace_new_stub(RuntimeBlob* stub, const char* name1, const cha
389389
//----------------------------------------------------------------------------------------------------
390390
// Implementation of BufferBlob
391391

392-
BufferBlob::BufferBlob(const char* name, CodeBlobKind kind, int size)
393-
: RuntimeBlob(name, kind, size, sizeof(BufferBlob))
392+
BufferBlob::BufferBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size)
393+
: RuntimeBlob(name, kind, size, header_size)
394394
{}
395395

396396
BufferBlob* BufferBlob::create(const char* name, uint buffer_size) {
@@ -413,8 +413,8 @@ BufferBlob* BufferBlob::create(const char* name, uint buffer_size) {
413413
}
414414

415415

416-
BufferBlob::BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size)
417-
: RuntimeBlob(name, kind, cb, size, sizeof(BufferBlob), CodeOffsets::frame_never_safe, 0, nullptr)
416+
BufferBlob::BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size)
417+
: RuntimeBlob(name, kind, cb, size, header_size, CodeOffsets::frame_never_safe, 0, nullptr)
418418
{}
419419

420420
// Used by gtest
@@ -446,12 +446,20 @@ void BufferBlob::free(BufferBlob *blob) {
446446
//----------------------------------------------------------------------------------------------------
447447
// Implementation of AdapterBlob
448448

449-
AdapterBlob::AdapterBlob(int size, CodeBuffer* cb) :
450-
BufferBlob("I2C/C2I adapters", CodeBlobKind::Adapter, cb, size) {
449+
AdapterBlob::AdapterBlob(int size, CodeBuffer* cb, int entry_offset[AdapterBlob::ENTRY_COUNT]) :
450+
BufferBlob("I2C/C2I adapters", CodeBlobKind::Adapter, cb, size, sizeof(AdapterBlob)) {
451+
assert(entry_offset[0] == 0, "sanity check");
452+
for (int i = 1; i < AdapterBlob::ENTRY_COUNT; i++) {
453+
assert(entry_offset[i] > 0 && entry_offset[i] < cb->insts()->size(),
454+
"invalid entry offset 0x%x", entry_offset[i]);
455+
}
456+
_c2i_offset = entry_offset[1];
457+
_c2i_unverified_offset = entry_offset[2];
458+
_c2i_no_clinit_check_offset = entry_offset[3];
451459
CodeCache::commit(this);
452460
}
453461

454-
AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
462+
AdapterBlob* AdapterBlob::create(CodeBuffer* cb, int entry_offset[AdapterBlob::ENTRY_COUNT]) {
455463
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
456464

457465
CodeCache::gc_on_allocation();
@@ -460,14 +468,21 @@ AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
460468
unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
461469
{
462470
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
463-
blob = new (size) AdapterBlob(size, cb);
471+
blob = new (size) AdapterBlob(size, cb, entry_offset);
464472
}
465473
// Track memory usage statistic after releasing CodeCache_lock
466474
MemoryService::track_code_cache_memory_usage();
467475

468476
return blob;
469477
}
470478

479+
void AdapterBlob::get_offsets(int entry_offset[ENTRY_COUNT]) {
480+
entry_offset[0] = 0;
481+
entry_offset[1] = _c2i_offset;
482+
entry_offset[2] = _c2i_unverified_offset;
483+
entry_offset[3] = _c2i_no_clinit_check_offset;
484+
}
485+
471486
//----------------------------------------------------------------------------------------------------
472487
// Implementation of VtableBlob
473488

src/hotspot/share/code/codeBlob.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ class BufferBlob: public RuntimeBlob {
372372

373373
private:
374374
// Creation support
375-
BufferBlob(const char* name, CodeBlobKind kind, int size);
376-
BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size);
375+
BufferBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size = sizeof(BufferBlob));
376+
BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size = sizeof(BufferBlob));
377377

378378
void* operator new(size_t s, unsigned size) throw();
379379

@@ -404,12 +404,18 @@ class BufferBlob: public RuntimeBlob {
404404
// AdapterBlob: used to hold C2I/I2C adapters
405405

406406
class AdapterBlob: public BufferBlob {
407+
public:
408+
static const int ENTRY_COUNT = 4;
407409
private:
408-
AdapterBlob(int size, CodeBuffer* cb);
409-
410+
AdapterBlob(int size, CodeBuffer* cb, int entry_offset[ENTRY_COUNT]);
411+
// _i2c_offset is always 0 so no need to store it
412+
int _c2i_offset;
413+
int _c2i_unverified_offset;
414+
int _c2i_no_clinit_check_offset;
410415
public:
411416
// Creation
412-
static AdapterBlob* create(CodeBuffer* cb);
417+
static AdapterBlob* create(CodeBuffer* cb, int entry_offset[ENTRY_COUNT]);
418+
void get_offsets(int entry_offset[ENTRY_COUNT]);
413419
};
414420

415421
//---------------------------------------------------------------------------------------------------

src/hotspot/share/runtime/sharedRuntime.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,12 +2769,13 @@ AdapterBlob* AdapterHandlerLibrary::lookup_aot_cache(AdapterHandlerEntry* handle
27692769
ResourceMark rm;
27702770
const char* name = AdapterHandlerLibrary::name(handler->fingerprint());
27712771
const uint32_t id = AdapterHandlerLibrary::id(handler->fingerprint());
2772-
int offsets[AdapterHandlerEntry::ENTRIES_COUNT];
2772+
int offsets[AdapterBlob::ENTRY_COUNT];
27732773

27742774
AdapterBlob* adapter_blob = nullptr;
2775-
CodeBlob* blob = AOTCodeCache::load_code_blob(AOTCodeEntry::Adapter, id, name, AdapterHandlerEntry::ENTRIES_COUNT, offsets);
2775+
CodeBlob* blob = AOTCodeCache::load_code_blob(AOTCodeEntry::Adapter, id, name);
27762776
if (blob != nullptr) {
27772777
adapter_blob = blob->as_adapter_blob();
2778+
adapter_blob->get_offsets(offsets);
27782779
address i2c_entry = adapter_blob->content_begin();
27792780
assert(offsets[0] == 0, "sanity check");
27802781
handler->set_entry_points(i2c_entry, i2c_entry + offsets[1], i2c_entry + offsets[2], i2c_entry + offsets[3]);
@@ -2837,7 +2838,15 @@ bool AdapterHandlerLibrary::generate_adapter_code(AdapterBlob*& adapter_blob,
28372838
}
28382839
#endif
28392840

2840-
adapter_blob = AdapterBlob::create(&buffer);
2841+
int entry_offset[AdapterBlob::ENTRY_COUNT];
2842+
assert(AdapterBlob::ENTRY_COUNT == 4, "sanity");
2843+
address i2c_entry = handler->get_i2c_entry();
2844+
entry_offset[0] = 0; // i2c_entry offset
2845+
entry_offset[1] = handler->get_c2i_entry() - i2c_entry;
2846+
entry_offset[2] = handler->get_c2i_unverified_entry() - i2c_entry;
2847+
entry_offset[3] = handler->get_c2i_no_clinit_check_entry() - i2c_entry;
2848+
2849+
adapter_blob = AdapterBlob::create(&buffer, entry_offset);
28412850
if (adapter_blob == nullptr) {
28422851
// CodeCache is full, disable compilation
28432852
// Ought to log this but compile log is only per compile thread
@@ -2848,14 +2857,7 @@ bool AdapterHandlerLibrary::generate_adapter_code(AdapterBlob*& adapter_blob,
28482857
// try to save generated code
28492858
const char* name = AdapterHandlerLibrary::name(handler->fingerprint());
28502859
const uint32_t id = AdapterHandlerLibrary::id(handler->fingerprint());
2851-
int entry_offset[AdapterHandlerEntry::ENTRIES_COUNT];
2852-
assert(AdapterHandlerEntry::ENTRIES_COUNT == 4, "sanity");
2853-
address i2c_entry = handler->get_i2c_entry();
2854-
entry_offset[0] = 0; // i2c_entry offset
2855-
entry_offset[1] = handler->get_c2i_entry() - i2c_entry;
2856-
entry_offset[2] = handler->get_c2i_unverified_entry() - i2c_entry;
2857-
entry_offset[3] = handler->get_c2i_no_clinit_check_entry() - i2c_entry;
2858-
bool success = AOTCodeCache::store_code_blob(*adapter_blob, AOTCodeEntry::Adapter, id, name, AdapterHandlerEntry::ENTRIES_COUNT, entry_offset);
2860+
bool success = AOTCodeCache::store_code_blob(*adapter_blob, AOTCodeEntry::Adapter, id, name);
28592861
assert(success || !AOTCodeCache::is_dumping_adapter(), "caching of adapter must be disabled");
28602862
}
28612863
handler->relocate(adapter_blob->content_begin());

0 commit comments

Comments
 (0)