From b55a0cb9bc292f368a48384c9934920511a973e0 Mon Sep 17 00:00:00 2001 From: Christian Despres Date: Mon, 31 Oct 2022 15:23:37 +0000 Subject: [PATCH] Unify JITServer AOT cache read functions Signed-off-by: Christian Despres --- .../compiler/runtime/JITServerAOTCache.cpp | 235 +++++++----------- .../compiler/runtime/JITServerAOTCache.hpp | 89 +++++-- .../JITServerAOTSerializationRecords.hpp | 26 +- 3 files changed, 168 insertions(+), 182 deletions(-) diff --git a/runtime/compiler/runtime/JITServerAOTCache.cpp b/runtime/compiler/runtime/JITServerAOTCache.cpp index dfaec13362c..eab8b3be02d 100644 --- a/runtime/compiler/runtime/JITServerAOTCache.cpp +++ b/runtime/compiler/runtime/JITServerAOTCache.cpp @@ -46,6 +46,39 @@ AOTCacheRecord::free(void *ptr) TR::Compiler->persistentGlobalMemory()->freePersistentMemory(ptr); } +// Read a single AOT cache record R from a cache file +template R * +AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context) + { + typename R::SerializationRecord header; + if (1 != fread(&header, sizeof(header), 1, context._f)) + return NULL; + + if (!header.isValid(context)) + return NULL; + + R *record = new (AOTCacheRecord::allocate(R::size(header))) R(context, header); + memcpy((void *)record->dataAddr(), &header, sizeof(header)); + + size_t variableDataBytes = record->dataAddr()->size() - sizeof(header); + if (0 != variableDataBytes) + { + if (1 != fread((uint8_t *)record->dataAddr() + sizeof(header), variableDataBytes, 1, context._f)) + { + AOTCacheRecord::free(record); + return NULL; + } + } + + if (!record->setSubrecordPointers(context)) + { + AOTCacheRecord::free(record); + return NULL; + } + + return record; + } + bool AOTSerializationRecord::isValid(AOTSerializationRecordType type) const { @@ -79,27 +112,6 @@ AOTCacheClassLoaderRecord::create(uintptr_t id, const uint8_t *name, size_t name return new (ptr) AOTCacheClassLoaderRecord(id, name, nameLength); } -AOTCacheClassLoaderRecord * -AOTCacheClassLoaderRecord::read(JITServerAOTCacheReadContext &context) - { - ClassLoaderSerializationRecord header; - if (1 != fread(&header, sizeof(header), 1, context._f)) - return NULL; - - if (!header.isValid()) - return NULL; - - auto record = new (AOTCacheRecord::allocate(size(header.nameLength()))) AOTCacheClassLoaderRecord(); - memcpy((void *)record->dataAddr(), &header, sizeof(header)); - if (1 != fread((uint8_t *)record->dataAddr() + sizeof(header), header.AOTSerializationRecord::size() - sizeof(header), 1, context._f)) - { - AOTCacheRecord::free(record); - return NULL; - } - - return record; - } - ClassSerializationRecord::ClassSerializationRecord(uintptr_t id, uintptr_t classLoaderId, const JITServerROMClassHash &hash, const J9ROMClass *romClass) : AOTSerializationRecord(size(J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(romClass))), id, AOTSerializationRecordType::Class), @@ -115,6 +127,14 @@ ClassSerializationRecord::ClassSerializationRecord() : { } +bool +ClassSerializationRecord::isValid(const JITServerAOTCacheReadContext &context) const + { + return AOTSerializationRecord::isValid(AOTSerializationRecordType::Class) && + (classLoaderId() < context._classLoaderRecords.size()) && + context._classLoaderRecords[classLoaderId()]; + } + AOTCacheClassRecord::AOTCacheClassRecord(uintptr_t id, const AOTCacheClassLoaderRecord *classLoaderRecord, const JITServerROMClassHash &hash, const J9ROMClass *romClass) : _classLoaderRecord(classLoaderRecord), @@ -122,8 +142,8 @@ AOTCacheClassRecord::AOTCacheClassRecord(uintptr_t id, const AOTCacheClassLoader { } -AOTCacheClassRecord::AOTCacheClassRecord(const AOTCacheClassLoaderRecord *classLoaderRecord) : - _classLoaderRecord(classLoaderRecord) +AOTCacheClassRecord::AOTCacheClassRecord(const JITServerAOTCacheReadContext &context, const ClassSerializationRecord &header) : + _classLoaderRecord(context._classLoaderRecords[header.classLoaderId()]) { } @@ -141,29 +161,6 @@ AOTCacheClassRecord::subRecordsDo(const std::function= context._classLoaderRecords.size()) || - !context._classLoaderRecords[header.classLoaderId()]) - return NULL; - - auto record = new (AOTCacheRecord::allocate(size(header.nameLength()))) AOTCacheClassRecord(context._classLoaderRecords[header.classLoaderId()]); - memcpy((void *)record->dataAddr(), &header, sizeof(header)); - if (1 != fread((uint8_t *)record->dataAddr() + sizeof(header), header.AOTSerializationRecord::size() - sizeof(header), 1, context._f)) - { - AOTCacheRecord::free(record); - return NULL; - } - - return record; - } - MethodSerializationRecord::MethodSerializationRecord(uintptr_t id, uintptr_t definingClassId, uint32_t index) : AOTSerializationRecord(sizeof(*this), id, AOTSerializationRecordType::Method), _definingClassId(definingClassId), _index(index) @@ -176,6 +173,14 @@ MethodSerializationRecord::MethodSerializationRecord() : { } +bool +MethodSerializationRecord::isValid(const JITServerAOTCacheReadContext &context) const + { + return AOTSerializationRecord::isValid(AOTSerializationRecordType::Method) && + (definingClassId() < context._classRecords.size()) && + context._classRecords[definingClassId()]; + } + AOTCacheMethodRecord::AOTCacheMethodRecord(uintptr_t id, const AOTCacheClassRecord *definingClassRecord, uint32_t index) : _definingClassRecord(definingClassRecord), @@ -183,8 +188,8 @@ AOTCacheMethodRecord::AOTCacheMethodRecord(uintptr_t id, const AOTCacheClassReco { } -AOTCacheMethodRecord::AOTCacheMethodRecord(const AOTCacheClassRecord *definingClassRecord) : - _definingClassRecord(definingClassRecord) +AOTCacheMethodRecord::AOTCacheMethodRecord(const JITServerAOTCacheReadContext &context, const MethodSerializationRecord &header) : + _definingClassRecord(context._classRecords[header.definingClassId()]) { } @@ -201,24 +206,6 @@ AOTCacheMethodRecord::subRecordsDo(const std::function= context._classRecords.size()) || - !context._classRecords[header.definingClassId()]) - return NULL; - - auto record = new (AOTCacheRecord::allocate(sizeof(AOTCacheMethodRecord))) AOTCacheMethodRecord(context._classRecords[header.definingClassId()]); - memcpy((void *)record->dataAddr(), &header, sizeof(header)); - - return record; - } - template AOTCacheListRecord::AOTCacheListRecord(uintptr_t id, const R *const *records, size_t length, Args... args) : @@ -236,37 +223,19 @@ AOTCacheListRecord::subRecordsDo(const std::function AOTCacheListRecord* -AOTCacheListRecord::read(FILE *f, const Vector &cacheRecords) +template bool +AOTCacheListRecord::setSubrecordPointers(const Vector &cacheRecords) { - D header; - if (1 != fread(&header, sizeof(header), 1, f)) - return NULL; - - if (!header.isValid()) - return NULL; - - auto record = new (AOTCacheRecord::allocate(size(header.list().length()))) AOTCacheListRecord(); - memcpy((void *)record->dataAddr(), &header, sizeof(header)); - - if (1 != fread((uint8_t *)record->dataAddr() + sizeof(header), header.AOTSerializationRecord::size() - sizeof(header), 1, f)) + for (size_t i = 0; i < data().list().length(); ++i) { - AOTCacheRecord::free(record); - return NULL; - } - - for (size_t i = 0; i < header.list().length(); ++i) - { - uintptr_t id = record->data().list().ids()[i]; + uintptr_t id = data().list().ids()[i]; if ((id >= cacheRecords.size()) || !cacheRecords[id]) { - AOTCacheRecord::free(record); - return NULL; + return false; } - record->records()[i] = cacheRecords[id]; + records()[i] = cacheRecords[id]; } - - return record; + return true; } ClassChainSerializationRecord::ClassChainSerializationRecord(uintptr_t id, size_t length) : @@ -335,22 +304,6 @@ AOTCacheAOTHeaderRecord::create(uintptr_t id, const TR_AOTHeader *header) return new (ptr) AOTCacheAOTHeaderRecord(id, header); } -AOTCacheAOTHeaderRecord * -AOTCacheAOTHeaderRecord::read(JITServerAOTCacheReadContext &context) - { - AOTHeaderSerializationRecord header; - if (1 != fread(&header, sizeof(header), 1, context._f)) - return NULL; - - if (!header.isValid()) - return NULL; - - auto record = new (AOTCacheRecord::allocate(sizeof(AOTCacheAOTHeaderRecord))) AOTCacheAOTHeaderRecord(); - memcpy((void *)record->dataAddr(), &header, sizeof(header)); - - return record; - } - SerializedAOTMethod::SerializedAOTMethod(uintptr_t definingClassChainId, uint32_t index, TR_Hotness optLevel, uintptr_t aotHeaderId, size_t numRecords, const void *code, size_t codeSize, const void *data, size_t dataSize) : @@ -372,9 +325,12 @@ SerializedAOTMethod::SerializedAOTMethod() : } bool -SerializedAOTMethod::isValid() const +SerializedAOTMethod::isValid(const JITServerAOTCacheReadContext &context) const { - return _optLevel < TR_Hotness::numHotnessLevels; + return _optLevel < TR_Hotness::numHotnessLevels && + (definingClassChainId() < context._classChainRecords.size()) && + (aotHeaderId() < context._aotHeaderRecords.size()) && + context._classChainRecords[definingClassChainId()]; } CachedAOTMethod::CachedAOTMethod(const AOTCacheClassChainRecord *definingClassChainRecord, uint32_t index, @@ -394,9 +350,9 @@ CachedAOTMethod::CachedAOTMethod(const AOTCacheClassChainRecord *definingClassCh } } -CachedAOTMethod::CachedAOTMethod(const AOTCacheClassChainRecord *definingClassChainRecord) : +CachedAOTMethod::CachedAOTMethod(const JITServerAOTCacheReadContext &context, const SerializedAOTMethod &header) : _nextRecord(NULL), - _definingClassChainRecord(definingClassChainRecord) + _definingClassChainRecord(context._classChainRecords[header.definingClassChainId()]) { } @@ -411,68 +367,47 @@ CachedAOTMethod::create(const AOTCacheClassChainRecord *definingClassChainRecord records, code, codeSize, data, dataSize); } -CachedAOTMethod * -CachedAOTMethod::read(JITServerAOTCacheReadContext &context) +bool +CachedAOTMethod::setSubrecordPointers(JITServerAOTCacheReadContext &context) { - SerializedAOTMethod header; - if (1 != fread(&header, sizeof(header), 1, context._f)) - return NULL; - - if ((!header.isValid()) || - (header.definingClassChainId() >= context._classChainRecords.size()) || - (header.aotHeaderId() >= context._aotHeaderRecords.size()) || - !context._classChainRecords[header.definingClassChainId()]) - return NULL; - - auto record = new (AOTCacheRecord::allocate(size(header.numRecords(), header.codeSize(), header.dataSize()))) - CachedAOTMethod(context._classChainRecords[header.definingClassChainId()]); - memcpy(&record->_data, &header, sizeof(header)); - - if (1 != fread(record->data().offsets(), sizeof(SerializedSCCOffset) * header.numRecords() + header.codeSize() + header.dataSize(), 1, context._f)) - goto error; - - for (size_t i = 0; i < header.numRecords(); ++i) + for (size_t i = 0; i < data().numRecords(); ++i) { - const SerializedSCCOffset &sccOffset = record->data().offsets()[i]; + const SerializedSCCOffset &sccOffset = data().offsets()[i]; switch (sccOffset.recordType()) { case AOTSerializationRecordType::ClassLoader: if ((sccOffset.recordId() >= context._classLoaderRecords.size()) || !context._classLoaderRecords[sccOffset.recordId()]) - goto error; - record->records()[i] = context._classLoaderRecords[sccOffset.recordId()]; + return false; + records()[i] = context._classLoaderRecords[sccOffset.recordId()]; break; case AOTSerializationRecordType::Class: if ((sccOffset.recordId() >= context._classRecords.size()) || !context._classRecords[sccOffset.recordId()]) - goto error; - record->records()[i] = context._classRecords[sccOffset.recordId()]; + return false; + records()[i] = context._classRecords[sccOffset.recordId()]; break; case AOTSerializationRecordType::Method: if ((sccOffset.recordId() >= context._methodRecords.size()) || !context._methodRecords[sccOffset.recordId()]) - goto error; - record->records()[i] = context._methodRecords[sccOffset.recordId()]; + return false; + records()[i] = context._methodRecords[sccOffset.recordId()]; break; case AOTSerializationRecordType::ClassChain: if ((sccOffset.recordId() >= context._classChainRecords.size()) || !context._classChainRecords[sccOffset.recordId()]) - goto error; - record->records()[i] = context._classChainRecords[sccOffset.recordId()]; + return false; + records()[i] = context._classChainRecords[sccOffset.recordId()]; break; case AOTSerializationRecordType::WellKnownClasses: if ((sccOffset.recordId() >= context._wellKnownClassesRecords.size()) || !context._wellKnownClassesRecords[sccOffset.recordId()]) - goto error; - record->records()[i] = context._wellKnownClassesRecords[sccOffset.recordId()]; + return false; + records()[i] = context._wellKnownClassesRecords[sccOffset.recordId()]; break; case AOTSerializationRecordType::AOTHeader: // never associated with an SCC offset default: - goto error; + return false; } } - return record; - -error: - AOTCacheRecord::free(record); - return NULL; + return true; } bool @@ -1257,7 +1192,7 @@ JITServerAOTCache::readRecords(JITServerAOTCacheReadContext &context, if (!JITServerAOTCacheMap::cacheHasSpace()) return false; - V *record = V::read(context); + V *record = AOTCacheRecord::readRecord(context); if (!record) return false; @@ -1323,7 +1258,7 @@ JITServerAOTCache::readCache(FILE *f, const JITServerAOTCacheHeader &header, TR_ if (!JITServerAOTCacheMap::cacheHasSpace()) return false; - auto record = CachedAOTMethod::read(context); + auto record = AOTCacheRecord::readRecord(context); if (!record || !aotHeaderRecords[record->data().aotHeaderId()]) return false; diff --git a/runtime/compiler/runtime/JITServerAOTCache.hpp b/runtime/compiler/runtime/JITServerAOTCache.hpp index 58b68b88a4e..c6bcf003da8 100644 --- a/runtime/compiler/runtime/JITServerAOTCache.hpp +++ b/runtime/compiler/runtime/JITServerAOTCache.hpp @@ -130,6 +130,8 @@ class AOTCacheRecord static void *allocate(size_t size); static void free(void *ptr); + template static R *readRecord(JITServerAOTCacheReadContext &context); + AOTCacheRecord *getNextRecord() const { return _nextRecord; } void setNextRecord(AOTCacheRecord *record) { _nextRecord = record; } @@ -137,6 +139,9 @@ class AOTCacheRecord AOTCacheRecord() : _nextRecord(NULL) {} private: + // Set the subrecord pointers in the variable-length portion of a record if necessary + virtual bool setSubrecordPointers(const JITServerAOTCacheReadContext &context) { return true; } + AOTCacheRecord *_nextRecord; }; @@ -149,17 +154,21 @@ class AOTCacheClassLoaderRecord final : public AOTCacheRecord static AOTCacheClassLoaderRecord *create(uintptr_t id, const uint8_t *name, size_t nameLength); - static AOTCacheClassLoaderRecord *read(JITServerAOTCacheReadContext &context); - private: + using SerializationRecord = ClassLoaderSerializationRecord; + + template friend R *AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context); + AOTCacheClassLoaderRecord(uintptr_t id, const uint8_t *name, size_t nameLength); - AOTCacheClassLoaderRecord() {} + AOTCacheClassLoaderRecord(JITServerAOTCacheReadContext &context, const ClassLoaderSerializationRecord &header) {} static size_t size(size_t nameLength) { return offsetof(AOTCacheClassLoaderRecord, _data) + ClassLoaderSerializationRecord::size(nameLength); } + static size_t size(const ClassLoaderSerializationRecord &header) { return size(header.nameLength()); } + const ClassLoaderSerializationRecord _data; }; @@ -175,18 +184,22 @@ class AOTCacheClassRecord final : public AOTCacheRecord const JITServerROMClassHash &hash, const J9ROMClass *romClass); void subRecordsDo(const std::function &f) const override; - static AOTCacheClassRecord *read(JITServerAOTCacheReadContext &context); - private: + using SerializationRecord = ClassSerializationRecord; + + template friend R *AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context); + AOTCacheClassRecord(uintptr_t id, const AOTCacheClassLoaderRecord *classLoaderRecord, const JITServerROMClassHash &hash, const J9ROMClass *romClass); - AOTCacheClassRecord(const AOTCacheClassLoaderRecord *classLoaderRecord); + AOTCacheClassRecord(const JITServerAOTCacheReadContext &context, const ClassSerializationRecord &header); static size_t size(size_t nameLength) { return offsetof(AOTCacheClassRecord, _data) + ClassSerializationRecord::size(nameLength); } + static size_t size(const ClassSerializationRecord &header) { return size(header.nameLength()); } + const AOTCacheClassLoaderRecord *const _classLoaderRecord; const ClassSerializationRecord _data; }; @@ -202,11 +215,15 @@ class AOTCacheMethodRecord final : public AOTCacheRecord static AOTCacheMethodRecord *create(uintptr_t id, const AOTCacheClassRecord *definingClassRecord, uint32_t index); void subRecordsDo(const std::function &f) const override; - static AOTCacheMethodRecord *read(JITServerAOTCacheReadContext &context); - private: + using SerializationRecord = MethodSerializationRecord; + + template friend R *AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context); + AOTCacheMethodRecord(uintptr_t id, const AOTCacheClassRecord *definingClassRecord, uint32_t index); - AOTCacheMethodRecord(const AOTCacheClassRecord *definingClassRecord); + AOTCacheMethodRecord(const JITServerAOTCacheReadContext &context, const MethodSerializationRecord &header); + + static size_t size(const MethodSerializationRecord &header) { return sizeof(AOTCacheMethodRecord); } const AOTCacheClassRecord *const _definingClassRecord; const MethodSerializationRecord _data; @@ -228,17 +245,19 @@ class AOTCacheListRecord : public AOTCacheRecord void subRecordsDo(const std::function &f) const override; - static AOTCacheListRecord *read(FILE *f, const Vector &cacheRecords); - protected: AOTCacheListRecord(uintptr_t id, const R *const *records, size_t length, Args... args); - AOTCacheListRecord() {} + AOTCacheListRecord(const JITServerAOTCacheReadContext &context, const D &header) {} static size_t size(size_t length) { return offsetof(AOTCacheListRecord, _data) + D::size(length) + length * sizeof(R *); } + static size_t size(const D &header) { return size(header.list().length()); } + + bool setSubrecordPointers(const Vector &cacheRecords); + // Layout: struct D header, uintptr_t ids[length], const R *records[length] D _data; }; @@ -252,10 +271,14 @@ class AOTCacheClassChainRecord final : public AOTCacheListRecordclassLoaderRecord(); } - static AOTCacheClassChainRecord *read(JITServerAOTCacheReadContext &context) - { return (AOTCacheClassChainRecord *)AOTCacheListRecord::read(context._f, context._classRecords); } - private: + using SerializationRecord = ClassChainSerializationRecord; + + template friend R *AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context); + + bool setSubrecordPointers(const JITServerAOTCacheReadContext &context) override + { return AOTCacheListRecord::setSubrecordPointers(context._classRecords); } + using AOTCacheListRecord::AOTCacheListRecord; }; @@ -264,14 +287,18 @@ class AOTCacheWellKnownClassesRecord final : public AOTCacheListRecord { public: + static AOTCacheWellKnownClassesRecord *create(uintptr_t id, const AOTCacheClassChainRecord *const *records, size_t length, uintptr_t includedClasses); - static AOTCacheWellKnownClassesRecord *read(JITServerAOTCacheReadContext &context) - { return (AOTCacheWellKnownClassesRecord *) - AOTCacheListRecord::read(context._f, context._classChainRecords); } - private: + using SerializationRecord = WellKnownClassesSerializationRecord; + + template friend R *AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context); + + bool setSubrecordPointers(const JITServerAOTCacheReadContext &context) override + { return AOTCacheListRecord::setSubrecordPointers(context._classChainRecords); } + using AOTCacheListRecord::AOTCacheListRecord; }; @@ -284,11 +311,15 @@ class AOTCacheAOTHeaderRecord final : public AOTCacheRecord static AOTCacheAOTHeaderRecord *create(uintptr_t id, const TR_AOTHeader *header); - static AOTCacheAOTHeaderRecord *read(JITServerAOTCacheReadContext &context); - private: + using SerializationRecord = AOTHeaderSerializationRecord; + + template friend R *AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context); + AOTCacheAOTHeaderRecord(uintptr_t id, const TR_AOTHeader *header); - AOTCacheAOTHeaderRecord() {} + AOTCacheAOTHeaderRecord(const JITServerAOTCacheReadContext &context, const AOTHeaderSerializationRecord &header) {} + + static size_t size(const AOTHeaderSerializationRecord &header) { return sizeof(AOTHeaderSerializationRecord); } const AOTHeaderSerializationRecord _data; }; @@ -315,17 +346,21 @@ class CachedAOTMethod const Vector> &records, const void *code, size_t codeSize, const void *data, size_t dataSize); - static CachedAOTMethod *read(JITServerAOTCacheReadContext &context); - CachedAOTMethod *getNextRecord() const { return _nextRecord; } void setNextRecord(CachedAOTMethod *record) { _nextRecord = record; } private: + using SerializationRecord = SerializedAOTMethod; + + template friend R *AOTCacheRecord::readRecord(JITServerAOTCacheReadContext &context); + CachedAOTMethod(const AOTCacheClassChainRecord *definingClassChainRecord, uint32_t index, TR_Hotness optLevel, const AOTCacheAOTHeaderRecord *aotHeaderRecord, const Vector> &records, const void *code, size_t codeSize, const void *data, size_t dataSize); - CachedAOTMethod(const AOTCacheClassChainRecord *definingClassChainRecord); + CachedAOTMethod(const JITServerAOTCacheReadContext &context, const SerializedAOTMethod &header); + + SerializedAOTMethod *dataAddr() { return &_data; } static size_t size(size_t numRecords, size_t codeSize, size_t dataSize) { @@ -333,6 +368,10 @@ class CachedAOTMethod numRecords * sizeof(AOTCacheRecord *); } + static size_t size(const SerializedAOTMethod &header) { return size(header.numRecords(), header.codeSize(), header.dataSize()); } + + bool setSubrecordPointers(JITServerAOTCacheReadContext &context); + CachedAOTMethod *_nextRecord; const AOTCacheClassChainRecord *const _definingClassChainRecord; SerializedAOTMethod _data; diff --git a/runtime/compiler/runtime/JITServerAOTSerializationRecords.hpp b/runtime/compiler/runtime/JITServerAOTSerializationRecords.hpp index 3afcfd244f5..b32c053c31f 100644 --- a/runtime/compiler/runtime/JITServerAOTSerializationRecords.hpp +++ b/runtime/compiler/runtime/JITServerAOTSerializationRecords.hpp @@ -27,6 +27,7 @@ #include "runtime/JITServerROMClassHash.hpp" #include "runtime/RelocationRuntime.hpp" +struct JITServerAOTCacheReadContext; enum AOTSerializationRecordType { @@ -111,9 +112,11 @@ struct ClassLoaderSerializationRecord : public AOTSerializationRecord public: size_t nameLength() const { return _nameLength; } const uint8_t *name() const { return _name; } - bool isValid() const { return AOTSerializationRecord::isValid(AOTSerializationRecordType::ClassLoader); } + bool isValid(const JITServerAOTCacheReadContext &context) const + { return AOTSerializationRecord::isValid(AOTSerializationRecordType::ClassLoader); } private: + friend class AOTCacheRecord; friend class AOTCacheClassLoaderRecord; ClassLoaderSerializationRecord(uintptr_t id, const uint8_t *name, size_t nameLength); @@ -138,9 +141,10 @@ struct ClassSerializationRecord : public AOTSerializationRecord uint32_t romClassSize() const { return _romClassSize; } size_t nameLength() const { return _nameLength; } const uint8_t *name() const { return _name; } - bool isValid() const { return AOTSerializationRecord::isValid(AOTSerializationRecordType::Class); } + bool isValid(const JITServerAOTCacheReadContext &context) const; private: + friend class AOTCacheRecord; friend class AOTCacheClassRecord; ClassSerializationRecord(uintptr_t id, uintptr_t classLoaderId, @@ -167,9 +171,10 @@ struct MethodSerializationRecord : public AOTSerializationRecord public: uintptr_t definingClassId() const { return _definingClassId; } uint32_t index() const { return _index; } - bool isValid() const { return AOTSerializationRecord::isValid(AOTSerializationRecordType::Method); } + bool isValid(const JITServerAOTCacheReadContext &context) const; private: + friend class AOTCacheRecord; friend class AOTCacheMethodRecord; MethodSerializationRecord(uintptr_t id, uintptr_t definingClassId, uint32_t index); @@ -202,9 +207,11 @@ struct ClassChainSerializationRecord : public AOTSerializationRecord { public: const IdList &list() const { return _list; } - bool isValid() const { return AOTSerializationRecord::isValid(AOTSerializationRecordType::ClassChain); } + bool isValid(const JITServerAOTCacheReadContext &context) const + { return AOTSerializationRecord::isValid(AOTSerializationRecordType::ClassChain); } private: + friend class AOTCacheRecord; template friend class AOTCacheListRecord; ClassChainSerializationRecord(uintptr_t id, size_t length); @@ -227,9 +234,11 @@ struct WellKnownClassesSerializationRecord : public AOTSerializationRecord public: uintptr_t includedClasses() const { return _includedClasses; } const IdList &list() const { return _list; } - bool isValid() const { return AOTSerializationRecord::isValid(AOTSerializationRecordType::WellKnownClasses); } + bool isValid(const JITServerAOTCacheReadContext &context) const + { return AOTSerializationRecord::isValid(AOTSerializationRecordType::WellKnownClasses); } private: + friend class AOTCacheRecord; template friend class AOTCacheListRecord; WellKnownClassesSerializationRecord(uintptr_t id, size_t length, uintptr_t includedClasses); @@ -253,9 +262,11 @@ struct AOTHeaderSerializationRecord : public AOTSerializationRecord { public: const TR_AOTHeader *header() const { return &_header; } - bool isValid() const { return AOTSerializationRecord::isValid(AOTSerializationRecordType::AOTHeader); } + bool isValid(const JITServerAOTCacheReadContext &context) const + { return AOTSerializationRecord::isValid(AOTSerializationRecordType::AOTHeader); } private: + friend class AOTCacheRecord; friend class AOTCacheAOTHeaderRecord; AOTHeaderSerializationRecord(uintptr_t id, const TR_AOTHeader *header); @@ -307,7 +318,7 @@ struct SerializedAOTMethod const uint8_t *data() const { return code() + _codeSize; } uint8_t *data() { return (uint8_t *)(code() + _codeSize); } const uint8_t *end() const { return (const uint8_t *)this + size(); } - bool isValid() const; + bool isValid(const JITServerAOTCacheReadContext &context) const; static SerializedAOTMethod *get(std::string &str) { @@ -317,6 +328,7 @@ struct SerializedAOTMethod } private: + friend class AOTCacheRecord; friend class CachedAOTMethod; SerializedAOTMethod(uintptr_t definingClassChainId, uint32_t index,