Skip to content

Commit

Permalink
[JSC] Rename MegamorphicCache's load related fields
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269811
rdar://123333247

Reviewed by Keith Miller and Michael Saboff.

Let's rename Load related MegamorphicCache fields to explicitly say "Load".
Previously, it didn't since MegamorphicCache implementation started with Load only.
And eventually it gets expanded.

* Source/JavaScriptCore/jit/AssemblyHelpers.cpp:
(JSC::AssemblyHelpers::loadMegamorphicProperty):
* Source/JavaScriptCore/runtime/MegamorphicCache.cpp:
(JSC::MegamorphicCache::age):
(JSC::MegamorphicCache::clearEntries):
* Source/JavaScriptCore/runtime/MegamorphicCache.h:
(JSC::MegamorphicCache::LoadEntry::offsetOfUid):
(JSC::MegamorphicCache::LoadEntry::offsetOfStructureID):
(JSC::MegamorphicCache::LoadEntry::offsetOfEpoch):
(JSC::MegamorphicCache::LoadEntry::offsetOfOffset):
(JSC::MegamorphicCache::LoadEntry::offsetOfHolder):
(JSC::MegamorphicCache::offsetOfLoadCachePrimaryEntries):
(JSC::MegamorphicCache::offsetOfLoadCacheSecondaryEntries):
(JSC::MegamorphicCache::initAsMiss):
(JSC::MegamorphicCache::initAsHit):
(JSC::MegamorphicCache::Entry::offsetOfUid): Deleted.
(JSC::MegamorphicCache::Entry::offsetOfStructureID): Deleted.
(JSC::MegamorphicCache::Entry::offsetOfEpoch): Deleted.
(JSC::MegamorphicCache::Entry::offsetOfOffset): Deleted.
(JSC::MegamorphicCache::Entry::offsetOfHolder): Deleted.
(JSC::MegamorphicCache::Entry::initAsMiss): Deleted.
(JSC::MegamorphicCache::Entry::initAsHit): Deleted.
(JSC::MegamorphicCache::offsetOfPrimaryEntries): Deleted.
(JSC::MegamorphicCache::offsetOfSecondaryEntries): Deleted.

Canonical link: https://commits.webkit.org/275073@main
  • Loading branch information
Constellation committed Feb 20, 2024
1 parent 638c7e3 commit bbcc016
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
40 changes: 20 additions & 20 deletions Source/JavaScriptCore/jit/AssemblyHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,33 +510,33 @@ AssemblyHelpers::JumpList AssemblyHelpers::loadMegamorphicProperty(VM& vm, GPRRe
add32(scratch2GPR, scratch3GPR);
}

and32(TrustedImm32(MegamorphicCache::primaryMask), scratch3GPR);
if (hasOneBitSet(sizeof(MegamorphicCache::Entry))) // is a power of 2
lshift32(TrustedImm32(getLSBSet(sizeof(MegamorphicCache::Entry))), scratch3GPR);
and32(TrustedImm32(MegamorphicCache::loadCachePrimaryMask), scratch3GPR);
if (hasOneBitSet(sizeof(MegamorphicCache::LoadEntry))) // is a power of 2
lshift32(TrustedImm32(getLSBSet(sizeof(MegamorphicCache::LoadEntry))), scratch3GPR);
else
mul32(TrustedImm32(sizeof(MegamorphicCache::Entry)), scratch3GPR, scratch3GPR);
mul32(TrustedImm32(sizeof(MegamorphicCache::LoadEntry)), scratch3GPR, scratch3GPR);
auto& cache = vm.ensureMegamorphicCache();
move(TrustedImmPtr(&cache), scratch2GPR);
ASSERT(!MegamorphicCache::offsetOfPrimaryEntries());
ASSERT(!MegamorphicCache::offsetOfLoadCachePrimaryEntries());
addPtr(scratch2GPR, scratch3GPR);

load16(Address(scratch2GPR, MegamorphicCache::offsetOfEpoch()), scratch2GPR);

primaryFail.append(branch32(NotEqual, scratch1GPR, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfStructureID())));
primaryFail.append(branch32(NotEqual, scratch1GPR, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfStructureID())));
if (uid)
primaryFail.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfUid()), TrustedImmPtr(uid)));
primaryFail.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfUid()), TrustedImmPtr(uid)));
else
primaryFail.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfUid()), uidGPR));
primaryFail.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfUid()), uidGPR));
// We already hit StructureID and uid. And we get stale epoch for this entry.
// Since all entries in the secondary cache has stale epoch for this StructureID and uid pair, we should just go to the slow case.
slowCases.append(branch32WithMemory16(NotEqual, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfEpoch()), scratch2GPR));
slowCases.append(branch32WithMemory16(NotEqual, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfEpoch()), scratch2GPR));

// Cache hit!
Label cacheHit = label();
loadPtr(Address(scratch3GPR, MegamorphicCache::Entry::offsetOfHolder()), scratch2GPR);
loadPtr(Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfHolder()), scratch2GPR);
auto missed = branchTestPtr(Zero, scratch2GPR);
moveConditionally64(Equal, scratch2GPR, TrustedImm32(bitwise_cast<uintptr_t>(JSCell::seenMultipleCalleeObjects())), baseGPR, scratch2GPR, scratch1GPR);
load16(Address(scratch3GPR, MegamorphicCache::Entry::offsetOfOffset()), scratch2GPR);
load16(Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfOffset()), scratch2GPR);
loadProperty(scratch1GPR, scratch2GPR, JSValueRegs { resultGPR });
auto done = jump();

Expand All @@ -549,19 +549,19 @@ AssemblyHelpers::JumpList AssemblyHelpers::loadMegamorphicProperty(VM& vm, GPRRe
else
add32(uidGPR, scratch1GPR, scratch3GPR);
addUnsignedRightShift32(scratch3GPR, scratch3GPR, TrustedImm32(MegamorphicCache::structureIDHashShift3), scratch3GPR);
and32(TrustedImm32(MegamorphicCache::secondaryMask), scratch3GPR);
if constexpr (hasOneBitSet(sizeof(MegamorphicCache::Entry))) // is a power of 2
lshift32(TrustedImm32(getLSBSet(sizeof(MegamorphicCache::Entry))), scratch3GPR);
and32(TrustedImm32(MegamorphicCache::loadCacheSecondaryMask), scratch3GPR);
if constexpr (hasOneBitSet(sizeof(MegamorphicCache::LoadEntry))) // is a power of 2
lshift32(TrustedImm32(getLSBSet(sizeof(MegamorphicCache::LoadEntry))), scratch3GPR);
else
mul32(TrustedImm32(sizeof(MegamorphicCache::Entry)), scratch3GPR, scratch3GPR);
addPtr(TrustedImmPtr(bitwise_cast<uint8_t*>(&cache) + MegamorphicCache::offsetOfSecondaryEntries()), scratch3GPR);
mul32(TrustedImm32(sizeof(MegamorphicCache::LoadEntry)), scratch3GPR, scratch3GPR);
addPtr(TrustedImmPtr(bitwise_cast<uint8_t*>(&cache) + MegamorphicCache::offsetOfLoadCacheSecondaryEntries()), scratch3GPR);

slowCases.append(branch32(NotEqual, scratch1GPR, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfStructureID())));
slowCases.append(branch32(NotEqual, scratch1GPR, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfStructureID())));
if (uid)
slowCases.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfUid()), TrustedImmPtr(uid)));
slowCases.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfUid()), TrustedImmPtr(uid)));
else
slowCases.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfUid()), uidGPR));
slowCases.append(branch32WithMemory16(NotEqual, Address(scratch3GPR, MegamorphicCache::Entry::offsetOfEpoch()), scratch2GPR));
slowCases.append(branchPtr(NotEqual, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfUid()), uidGPR));
slowCases.append(branch32WithMemory16(NotEqual, Address(scratch3GPR, MegamorphicCache::LoadEntry::offsetOfEpoch()), scratch2GPR));
jump().linkTo(cacheHit, this);

missed.link(this);
Expand Down
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/runtime/MegamorphicCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ void MegamorphicCache::age(CollectionScope collectionScope)
{
++m_epoch;
if (collectionScope == CollectionScope::Full || m_epoch == invalidEpoch) {
for (auto& entry : m_primaryEntries) {
for (auto& entry : m_loadCachePrimaryEntries) {
entry.m_uid = nullptr;
entry.m_epoch = invalidEpoch;
}
for (auto& entry : m_secondaryEntries) {
for (auto& entry : m_loadCacheSecondaryEntries) {
entry.m_uid = nullptr;
entry.m_epoch = invalidEpoch;
}
Expand All @@ -68,9 +68,9 @@ void MegamorphicCache::age(CollectionScope collectionScope)

void MegamorphicCache::clearEntries()
{
for (auto& entry : m_primaryEntries)
for (auto& entry : m_loadCachePrimaryEntries)
entry.m_epoch = invalidEpoch;
for (auto& entry : m_secondaryEntries)
for (auto& entry : m_loadCacheSecondaryEntries)
entry.m_epoch = invalidEpoch;
for (auto& entry : m_storeCachePrimaryEntries)
entry.m_epoch = invalidEpoch;
Expand Down
52 changes: 26 additions & 26 deletions Source/JavaScriptCore/runtime/MegamorphicCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class MegamorphicCache {
WTF_MAKE_TZONE_ALLOCATED(MegamorphicCache);
WTF_MAKE_NONCOPYABLE(MegamorphicCache);
public:
static constexpr uint32_t primarySize = 2048;
static constexpr uint32_t secondarySize = 512;
static_assert(hasOneBitSet(primarySize), "size should be a power of two.");
static_assert(hasOneBitSet(secondarySize), "size should be a power of two.");
static constexpr uint32_t primaryMask = primarySize - 1;
static constexpr uint32_t secondaryMask = secondarySize - 1;
static constexpr uint32_t loadCachePrimarySize = 2048;
static constexpr uint32_t loadCacheSecondarySize = 512;
static_assert(hasOneBitSet(loadCachePrimarySize), "size should be a power of two.");
static_assert(hasOneBitSet(loadCacheSecondarySize), "size should be a power of two.");
static constexpr uint32_t loadCachePrimaryMask = loadCachePrimarySize - 1;
static constexpr uint32_t loadCacheSecondaryMask = loadCacheSecondarySize - 1;

static constexpr uint32_t storeCachePrimarySize = 2048;
static constexpr uint32_t storeCacheSecondarySize = 512;
Expand All @@ -60,12 +60,12 @@ class MegamorphicCache {
static constexpr uint16_t invalidEpoch = 0;
static constexpr PropertyOffset maxOffset = UINT16_MAX;

struct Entry {
static ptrdiff_t offsetOfUid() { return OBJECT_OFFSETOF(Entry, m_uid); }
static ptrdiff_t offsetOfStructureID() { return OBJECT_OFFSETOF(Entry, m_structureID); }
static ptrdiff_t offsetOfEpoch() { return OBJECT_OFFSETOF(Entry, m_epoch); }
static ptrdiff_t offsetOfOffset() { return OBJECT_OFFSETOF(Entry, m_offset); }
static ptrdiff_t offsetOfHolder() { return OBJECT_OFFSETOF(Entry, m_holder); }
struct LoadEntry {
static ptrdiff_t offsetOfUid() { return OBJECT_OFFSETOF(LoadEntry, m_uid); }
static ptrdiff_t offsetOfStructureID() { return OBJECT_OFFSETOF(LoadEntry, m_structureID); }
static ptrdiff_t offsetOfEpoch() { return OBJECT_OFFSETOF(LoadEntry, m_epoch); }
static ptrdiff_t offsetOfOffset() { return OBJECT_OFFSETOF(LoadEntry, m_offset); }
static ptrdiff_t offsetOfHolder() { return OBJECT_OFFSETOF(LoadEntry, m_holder); }

void initAsMiss(StructureID structureID, UniquedStringImpl* uid, uint16_t epoch)
{
Expand Down Expand Up @@ -135,8 +135,8 @@ class MegamorphicCache {
uint16_t m_result { false };
};

static ptrdiff_t offsetOfPrimaryEntries() { return OBJECT_OFFSETOF(MegamorphicCache, m_primaryEntries); }
static ptrdiff_t offsetOfSecondaryEntries() { return OBJECT_OFFSETOF(MegamorphicCache, m_secondaryEntries); }
static ptrdiff_t offsetOfLoadCachePrimaryEntries() { return OBJECT_OFFSETOF(MegamorphicCache, m_loadCachePrimaryEntries); }
static ptrdiff_t offsetOfLoadCacheSecondaryEntries() { return OBJECT_OFFSETOF(MegamorphicCache, m_loadCacheSecondaryEntries); }

static ptrdiff_t offsetOfStoreCachePrimaryEntries() { return OBJECT_OFFSETOF(MegamorphicCache, m_storeCachePrimaryEntries); }
static ptrdiff_t offsetOfStoreCacheSecondaryEntries() { return OBJECT_OFFSETOF(MegamorphicCache, m_storeCacheSecondaryEntries); }
Expand Down Expand Up @@ -204,24 +204,24 @@ class MegamorphicCache {

void initAsMiss(StructureID structureID, UniquedStringImpl* uid)
{
uint32_t primaryIndex = MegamorphicCache::primaryHash(structureID, uid) & primaryMask;
auto& entry = m_primaryEntries[primaryIndex];
uint32_t primaryIndex = MegamorphicCache::primaryHash(structureID, uid) & loadCachePrimaryMask;
auto& entry = m_loadCachePrimaryEntries[primaryIndex];
if (entry.m_epoch == m_epoch) {
uint32_t secondaryIndex = MegamorphicCache::secondaryHash(entry.m_structureID, entry.m_uid.get()) & secondaryMask;
m_secondaryEntries[secondaryIndex] = WTFMove(entry);
uint32_t secondaryIndex = MegamorphicCache::secondaryHash(entry.m_structureID, entry.m_uid.get()) & loadCacheSecondaryMask;
m_loadCacheSecondaryEntries[secondaryIndex] = WTFMove(entry);
}
m_primaryEntries[primaryIndex].initAsMiss(structureID, uid, m_epoch);
m_loadCachePrimaryEntries[primaryIndex].initAsMiss(structureID, uid, m_epoch);
}

void initAsHit(StructureID structureID, UniquedStringImpl* uid, JSCell* holder, uint16_t offset, bool ownProperty)
{
uint32_t primaryIndex = MegamorphicCache::primaryHash(structureID, uid) & primaryMask;
auto& entry = m_primaryEntries[primaryIndex];
uint32_t primaryIndex = MegamorphicCache::primaryHash(structureID, uid) & loadCachePrimaryMask;
auto& entry = m_loadCachePrimaryEntries[primaryIndex];
if (entry.m_epoch == m_epoch) {
uint32_t secondaryIndex = MegamorphicCache::secondaryHash(entry.m_structureID, entry.m_uid.get()) & secondaryMask;
m_secondaryEntries[secondaryIndex] = WTFMove(entry);
uint32_t secondaryIndex = MegamorphicCache::secondaryHash(entry.m_structureID, entry.m_uid.get()) & loadCacheSecondaryMask;
m_loadCacheSecondaryEntries[secondaryIndex] = WTFMove(entry);
}
m_primaryEntries[primaryIndex].initAsHit(structureID, uid, m_epoch, holder, offset, ownProperty);
m_loadCachePrimaryEntries[primaryIndex].initAsHit(structureID, uid, m_epoch, holder, offset, ownProperty);
}

void initAsTransition(StructureID oldStructureID, StructureID newStructureID, UniquedStringImpl* uid, uint16_t offset)
Expand Down Expand Up @@ -280,8 +280,8 @@ class MegamorphicCache {
private:
JS_EXPORT_PRIVATE void clearEntries();

std::array<Entry, primarySize> m_primaryEntries { };
std::array<Entry, secondarySize> m_secondaryEntries { };
std::array<LoadEntry, loadCachePrimarySize> m_loadCachePrimaryEntries { };
std::array<LoadEntry, loadCacheSecondarySize> m_loadCacheSecondaryEntries { };
std::array<StoreEntry, storeCachePrimarySize> m_storeCachePrimaryEntries { };
std::array<StoreEntry, storeCacheSecondarySize> m_storeCacheSecondaryEntries { };
std::array<HasEntry, hasCachePrimarySize> m_hasCachePrimaryEntries { };
Expand Down

0 comments on commit bbcc016

Please sign in to comment.