Skip to content

Commit 33c2931

Browse files
committed
address cr comments
1 parent e7525e6 commit 33c2931

File tree

6 files changed

+25
-70
lines changed

6 files changed

+25
-70
lines changed

lib/Runtime/Base/ScriptContext.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ namespace Js
256256
memset(byteCodeHistogram, 0, sizeof(byteCodeHistogram));
257257
#endif
258258

259-
ClearArray(this->Cache()->propertyStrings, 80);
260-
261259
#if DBG || defined(RUNTIME_DATA_COLLECTION)
262260
this->allocId = threadContext->GetScriptContextCount();
263261
#endif
@@ -415,10 +413,6 @@ namespace Js
415413
ClearInlineCaches();
416414
Assert(!this->hasProtoOrStoreFieldInlineCache);
417415
}
418-
while (this->GetGlobalPICHead())
419-
{
420-
this->GetGlobalPICHead()->Finalize(true);
421-
}
422416

423417
if (this->hasIsInstInlineCache)
424418
{
@@ -1209,6 +1203,7 @@ namespace Js
12091203
#endif
12101204
#endif
12111205

1206+
ClearArray(this->Cache()->propertyStrings, 80);
12121207
this->Cache()->dynamicRegexMap =
12131208
RegexPatternMruMap::New(
12141209
recycler,
@@ -1597,18 +1592,17 @@ namespace Js
15971592
{
15981593
const char16* buf = propString->GetBuffer();
15991594
const uint i = PropertyStringMap::PStrMapIndex(buf[0]);
1600-
PropertyStringMap* strMap = this->Cache()->propertyStrings[i];
1601-
if (strMap == NULL)
1595+
if (this->Cache()->propertyStrings[i] == NULL)
16021596
{
16031597
InitPropertyStringMap(i);
16041598
}
16051599
const uint j = PropertyStringMap::PStrMapIndex(buf[1]);
1606-
if (strMap->strLen2[j] == NULL && !isClosed)
1600+
if (this->Cache()->propertyStrings[i]->strLen2[j] == NULL && !isClosed)
16071601
{
1608-
strMap->strLen2[j] = GetLibrary()->CreatePropertyString(propString);
1602+
this->Cache()->propertyStrings[i]->strLen2[j] = GetLibrary()->CreatePropertyString(propString);
16091603
this->TrackPid(propString);
16101604
}
1611-
return strMap->strLen2[j];
1605+
return this->Cache()->propertyStrings[i]->strLen2[j];
16121606
}
16131607

16141608
PropertyString* ScriptContext::CachePropertyString2(const PropertyRecord* propString)
@@ -1683,7 +1677,7 @@ namespace Js
16831677
cache->GetInlineCaches()[cache->GetInlineCacheIndexForType(type)].Clear();
16841678
}
16851679
cache = string->GetStElemInlineCache();
1686-
if (cache->PretendTryGetProperty(type, &info))
1680+
if (cache->PretendTrySetProperty(type, type, &info))
16871681
{
16881682
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
16891683
if (PHASE_TRACE1(PropertyStringCachePhase))

lib/Runtime/Base/ScriptContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,6 @@ namespace Js
533533
InlineCache * GetValueOfInlineCache() const { return valueOfInlineCache;}
534534
InlineCache * GetToStringInlineCache() const { return toStringInlineCache; }
535535

536-
ScriptContextPolymorphicInlineCache * GetGlobalPICHead() const { return this->Cache()->globalPICHead; }
537-
void SetGlobalPICHead(ScriptContextPolymorphicInlineCache * cache) { this->Cache()->globalPICHead = cache; }
538-
539536
private:
540537

541538
JavascriptFunction* GenerateRootFunction(ParseNodePtr parseTree, uint sourceIndex, Parser* parser, uint32 grfscr, CompileScriptException * pse, const char16 *rootDisplayName);

lib/Runtime/Language/InlineCache.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,21 +1005,14 @@ namespace Js
10051005
}
10061006
}
10071007

1008-
ScriptContextPolymorphicInlineCache * ScriptContextPolymorphicInlineCache::New(uint16 size, ScriptContext* scriptContext)
1008+
ScriptContextPolymorphicInlineCache * ScriptContextPolymorphicInlineCache::New(uint16 size, JavascriptLibrary* javascriptLibrary)
10091009
{
1010+
ScriptContext * scriptContext = javascriptLibrary->GetScriptContext();
10101011
InlineCache * inlineCaches = AllocatorNewArrayZ(InlineCacheAllocator, scriptContext->GetInlineCacheAllocator(), InlineCache, size);
10111012
#ifdef POLY_INLINE_CACHE_SIZE_STATS
10121013
scriptContext->GetInlineCacheAllocator()->LogPolyCacheAlloc(size * sizeof(InlineCache));
10131014
#endif
1014-
ScriptContextPolymorphicInlineCache * polymorphicInlineCache = RecyclerNewFinalizedLeaf(scriptContext->GetRecycler(), ScriptContextPolymorphicInlineCache, inlineCaches, size, scriptContext);
1015-
1016-
polymorphicInlineCache->prev = nullptr;
1017-
polymorphicInlineCache->next = polymorphicInlineCache->scriptContext->GetGlobalPICHead();
1018-
if (polymorphicInlineCache->next)
1019-
{
1020-
polymorphicInlineCache->next->prev = polymorphicInlineCache;
1021-
}
1022-
polymorphicInlineCache->scriptContext->SetGlobalPICHead(polymorphicInlineCache);
1015+
ScriptContextPolymorphicInlineCache * polymorphicInlineCache = RecyclerNewFinalized(scriptContext->GetRecycler(), ScriptContextPolymorphicInlineCache, inlineCaches, size, javascriptLibrary);
10231016

10241017
return polymorphicInlineCache;
10251018
}
@@ -1029,7 +1022,7 @@ namespace Js
10291022
if (size == 0)
10301023
{
10311024
// Already finalized
1032-
Assert(!inlineCaches && !prev && !next);
1025+
Assert(!inlineCaches);
10331026
return;
10341027
}
10351028

@@ -1063,43 +1056,17 @@ namespace Js
10631056
unregisteredInlineCacheCount++;
10641057
}
10651058
}
1066-
1067-
AllocatorDeleteArray(InlineCacheAllocator, this->scriptContext->GetInlineCacheAllocator(), size, inlineCaches);
1059+
AllocatorDeleteArray(InlineCacheAllocator, this->javascriptLibrary->scriptContext->GetInlineCacheAllocator(), size, inlineCaches);
10681060
#ifdef POLY_INLINE_CACHE_SIZE_STATS
1069-
this->scriptContext->GetInlineCacheAllocator()->LogPolyCacheFree(size * sizeof(InlineCache));
1061+
this->javascriptLibrary->scriptContext->GetInlineCacheAllocator()->LogPolyCacheFree(size * sizeof(InlineCache));
10701062
#endif
10711063
}
10721064

1073-
// Remove this PolymorphicInlineCache from the list
1074-
if (this == this->scriptContext->GetGlobalPICHead())
1075-
{
1076-
Assert(!prev);
1077-
if (next)
1078-
{
1079-
Assert(next->prev == this);
1080-
next->prev = nullptr;
1081-
}
1082-
this->scriptContext->SetGlobalPICHead(next);
1083-
}
1084-
else
1085-
{
1086-
if (prev)
1087-
{
1088-
Assert(prev->next == this);
1089-
prev->next = next;
1090-
}
1091-
if (next)
1092-
{
1093-
Assert(next->prev == this);
1094-
next->prev = prev;
1095-
}
1096-
}
1097-
prev = next = nullptr;
10981065
inlineCaches = nullptr;
10991066
size = 0;
11001067
if (unregisteredInlineCacheCount > 0)
11011068
{
1102-
this->scriptContext->GetThreadContext()->NotifyInlineCacheBatchUnregistered(unregisteredInlineCacheCount);
1069+
this->javascriptLibrary->scriptContext->GetThreadContext()->NotifyInlineCacheBatchUnregistered(unregisteredInlineCacheCount);
11031070
}
11041071
}
11051072

@@ -1146,7 +1113,7 @@ namespace Js
11461113

11471114
ScriptContext* ScriptContextPolymorphicInlineCache::GetScriptContext() const
11481115
{
1149-
return this->scriptContext;
1116+
return this->javascriptLibrary->scriptContext;
11501117
}
11511118
#endif
11521119

lib/Runtime/Language/InlineCache.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ namespace Js
543543
class FunctionBodyPolymorphicInlineCache sealed : public PolymorphicInlineCache
544544
{
545545
private:
546-
Field(FunctionBody *) functionBody;
546+
FunctionBody * functionBody;
547547

548548
// DList chaining all polymorphic inline caches of a FunctionBody together.
549549
// Since PolymorphicInlineCache is a leaf object, these references do not keep
@@ -552,8 +552,8 @@ namespace Js
552552
// We maintain this linked list of polymorphic caches because when we allocate a larger cache,
553553
// the old one might still be used by some code on the stack. Consequently, we can't release
554554
// the inline cache array back to the arena allocator.
555-
Field(FunctionBodyPolymorphicInlineCache *) next;
556-
Field(FunctionBodyPolymorphicInlineCache *) prev;
555+
FunctionBodyPolymorphicInlineCache * next;
556+
FunctionBodyPolymorphicInlineCache * prev;
557557

558558
FunctionBodyPolymorphicInlineCache(InlineCache * inlineCaches, uint16 size, FunctionBody * functionBody)
559559
: PolymorphicInlineCache(inlineCaches, size), functionBody(functionBody), next(nullptr), prev(nullptr)
@@ -575,20 +575,17 @@ namespace Js
575575
class ScriptContextPolymorphicInlineCache sealed : public PolymorphicInlineCache
576576
{
577577
private:
578-
FieldNoBarrier(ScriptContext *) scriptContext;
578+
Field(JavascriptLibrary*) javascriptLibrary;
579579

580-
Field(ScriptContextPolymorphicInlineCache *) next;
581-
Field(ScriptContextPolymorphicInlineCache *) prev;
582-
583-
ScriptContextPolymorphicInlineCache(InlineCache * inlineCaches, uint16 size, ScriptContext * scriptContext)
584-
: PolymorphicInlineCache(inlineCaches, size), scriptContext(scriptContext), next(nullptr), prev(nullptr)
580+
ScriptContextPolymorphicInlineCache(InlineCache * inlineCaches, uint16 size, JavascriptLibrary * javascriptLibrary)
581+
: PolymorphicInlineCache(inlineCaches, size), javascriptLibrary(javascriptLibrary)
585582
{
586583
Assert((size == 0 && inlineCaches == nullptr) ||
587584
(inlineCaches != nullptr && size >= MinPropertyStringInlineCacheSize && size <= MaxPolymorphicInlineCacheSize));
588585
}
589586

590587
public:
591-
static ScriptContextPolymorphicInlineCache * New(uint16 size, ScriptContext * scriptContext);
588+
static ScriptContextPolymorphicInlineCache * New(uint16 size, JavascriptLibrary * javascriptLibrary);
592589

593590
#ifdef INLINE_CACHE_STATS
594591
virtual void PrintStats(InlineCacheData *data) const override;

lib/Runtime/Library/JavascriptLibrary.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ namespace Js
6666
struct Cache
6767
{
6868
Field(PropertyStringMap*) propertyStrings[80];
69-
Field(ScriptContextPolymorphicInlineCache *) globalPICHead;
7069
Field(JavascriptString *) lastNumberToStringRadix10String;
7170
Field(EnumeratedObjectCache) enumObjCache;
7271
Field(JavascriptString *) lastUtcTimeFromStrString;

lib/Runtime/Library/PropertyString.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ namespace Js
2121
PropertyString* PropertyString::New(StaticType* type, const Js::PropertyRecord* propertyRecord, Recycler *recycler)
2222
{
2323
PropertyString * propertyString = RecyclerNewZ(recycler, PropertyString, type, propertyRecord);
24-
propertyString->ldElemInlineCache = ScriptContextPolymorphicInlineCache::New(MinPropertyStringInlineCacheSize, type->GetScriptContext());
25-
propertyString->stElemInlineCache = ScriptContextPolymorphicInlineCache::New(MinPropertyStringInlineCacheSize, type->GetScriptContext());
24+
// TODO: in future, might be worth putting these inline to avoid extra allocations. PIC copy API needs to be updated to support this though
25+
propertyString->ldElemInlineCache = ScriptContextPolymorphicInlineCache::New(MinPropertyStringInlineCacheSize, type->GetLibrary());
26+
propertyString->stElemInlineCache = ScriptContextPolymorphicInlineCache::New(MinPropertyStringInlineCacheSize, type->GetLibrary());
2627
return propertyString;
2728
}
2829

@@ -68,7 +69,7 @@ namespace Js
6869
uint16 polymorphicInlineCacheSize = polymorphicInlineCache->GetSize();
6970
uint16 newPolymorphicInlineCacheSize = PolymorphicInlineCache::GetNextSize(polymorphicInlineCacheSize);
7071
Assert(newPolymorphicInlineCacheSize > polymorphicInlineCacheSize);
71-
PolymorphicInlineCache * newPolymorphicInlineCache = ScriptContextPolymorphicInlineCache::New(newPolymorphicInlineCacheSize, GetScriptContext());
72+
PolymorphicInlineCache * newPolymorphicInlineCache = ScriptContextPolymorphicInlineCache::New(newPolymorphicInlineCacheSize, GetLibrary());
7273
polymorphicInlineCache->CopyTo(this->propertyRecord->GetPropertyId(), GetScriptContext(), newPolymorphicInlineCache);
7374
if (isLdElem)
7475
{

0 commit comments

Comments
 (0)