Skip to content

Commit 77dfeba

Browse files
author
Jianchun Xu
committed
swb: fix AllocateArray annotations
RecyclerChecker plugin was not able to detect (write barriered) types allocated through AllocateArray because AllocateArray was an inlined function. The plugin works by checking "new" operators. Fixed by enhancing the plugin to check AllocateArray. (Originally attempted to revert AllocateArray back to macro, but run into prefast failures.) Fixed a plugin bug introduced in last commit that results in over annotating. I was checking wrong bits and ended up requiring any Recycler allocation including leaf annotation to be annotated. Fixed the bits. Annotated newly discovered types from AllocateArray.
1 parent 3c07f8b commit 77dfeba

File tree

16 files changed

+161
-118
lines changed

16 files changed

+161
-118
lines changed

build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,10 @@ else
413413
fi
414414

415415
echo Generating $BUILD_TYPE makefiles
416+
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON useful for clang-query tool
416417
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $LTO $STATIC_LIBRARY $ARCH \
417418
-DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $WITHOUT_FEATURES \
418-
$WB_FLAG $WB_ARGS \
419+
$WB_FLAG $WB_ARGS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
419420
../..
420421

421422
_RET=$?

lib/Backend/Encoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ Encoder::Encode()
490490
equivalentTypeGuardOffsets->guards[i].cache.record.propertyOffset = NativeCodeData::GetDataTotalOffset(cache->record.properties);
491491
for (int j = 0; j < EQUIVALENT_TYPE_CACHE_SIZE; j++)
492492
{
493-
equivalentTypeGuardOffsets->guards[i].cache.types[j] = (intptr_t)cache->types[j];
493+
equivalentTypeGuardOffsets->guards[i].cache.types[j] = (intptr_t)PointerValue(cache->types[j]);
494494
}
495495
i++;
496496
});

lib/Backend/GlobOpt.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,8 +2900,6 @@ BOOL GlobOpt::PreloadPRECandidate(Loop *loop, GlobHashBucket* candidate)
29002900
IR::Instr * ldInstr = this->prePassInstrMap->Lookup(propertySym->m_id, nullptr);
29012901
Assert(ldInstr);
29022902

2903-
JITTypeHolder propertyType(nullptr);
2904-
29052903
// Create instr to put in landing pad for compensation
29062904
Assert(IsPREInstrCandidateLoad(ldInstr->m_opcode));
29072905
IR::SymOpnd *ldSrc = ldInstr->GetSrc1()->AsSymOpnd();
@@ -2928,11 +2926,6 @@ BOOL GlobOpt::PreloadPRECandidate(Loop *loop, GlobHashBucket* candidate)
29282926
IR::PropertySymOpnd *propSymOpnd = ldSrc->AsPropertySymOpnd();
29292927
IR::PropertySymOpnd *newPropSymOpnd;
29302928

2931-
if (propSymOpnd->IsMonoObjTypeSpecCandidate())
2932-
{
2933-
propertyType = propSymOpnd->GetType();
2934-
}
2935-
29362929
newPropSymOpnd = propSymOpnd->AsPropertySymOpnd()->CopyWithoutFlowSensitiveInfo(this->func);
29372930
ldInstr->ReplaceSrc1(newPropSymOpnd);
29382931
}
@@ -4191,7 +4184,7 @@ GlobOpt::OptArguments(IR::Instr *instr)
41914184
{
41924185
instr->usesStackArgumentsObject = true;
41934186
}
4194-
4187+
41954188
break;
41964189
}
41974190

lib/Backend/JITObjTypeSpecFldInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ JITObjTypeSpecFldInfo::BuildObjTypeSpecFldInfoArray(
302302
Js::FixedFieldInfo * ffInfo = objTypeSpecInfo[i]->GetFixedFieldInfoArray();
303303
for (uint16 j = 0; j < jitData[i].fixedFieldInfoArraySize; ++j)
304304
{
305-
jitData[i].fixedFieldInfoArray[j].fieldValue = (intptr_t)ffInfo[j].fieldValue;
305+
jitData[i].fixedFieldInfoArray[j].fieldValue = (intptr_t)PointerValue(ffInfo[j].fieldValue);
306306
jitData[i].fixedFieldInfoArray[j].nextHasSameFixedField = ffInfo[j].nextHasSameFixedField;
307307
if (ffInfo[j].fieldValue != nullptr && Js::JavascriptFunction::Is(ffInfo[j].fieldValue))
308308
{

lib/Backend/JITTimeConstructorCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ JITTimeConstructorCache::JITTimeConstructorCache(const JITTimeConstructorCache*
3232
Assert(other->GetRuntimeCacheAddr() != 0);
3333
m_data.runtimeCacheAddr = other->GetRuntimeCacheAddr();
3434
m_data.runtimeCacheGuardAddr = other->GetRuntimeCacheGuardAddr();
35-
m_data.type = *(TypeIDL*)other->GetType().t;
35+
m_data.type = *(TypeIDL*)PointerValue(other->GetType().t);
3636
m_data.slotCount = other->GetSlotCount();
3737
m_data.inlineSlotCount = other->GetInlineSlotCount();
3838
m_data.skipNewScObject = other->SkipNewScObject();

lib/Backend/JITType.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class JITType
3232
class JITTypeHolder
3333
{
3434
public:
35-
JITType * t;
35+
// SWB-TODO: Fix this. JITTypeHolder is used both as GC object and also
36+
// background JIT stack object. The later cannot use write barrier currently.
37+
FieldNoBarrier(JITType *) t;
3638

3739
JITTypeHolder();
3840
JITTypeHolder(JITType * t);

lib/Common/Memory/RecyclerPointers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ template <class Policy>
495495
struct _QuickSortImpl
496496
{
497497
template<class T, class Comparer>
498-
static void qsort_s(T* arr, size_t count, const Comparer& comparer, void* context)
498+
static void Sort(T* arr, size_t count, const Comparer& comparer, void* context)
499499
{
500500
// by default use system qsort_s
501501
::qsort_s(arr, count, sizeof(T), comparer, context);
@@ -505,7 +505,7 @@ template <>
505505
struct _QuickSortImpl<_write_barrier_policy>
506506
{
507507
template<class T, class Comparer>
508-
static void qsort_s(T* arr, size_t count, const Comparer& comparer, void* context)
508+
static void Sort(T* arr, size_t count, const Comparer& comparer, void* context)
509509
{
510510
// Use custom implementation if policy needs write barrier
511511
JsUtil::QuickSort<T, Comparer>::Sort(arr, arr + count - 1, comparer, context);
@@ -517,7 +517,7 @@ void qsort_s(T* arr, size_t count, const Comparer& comparer, void* context)
517517
{
518518
// Note use of "_ArrayItemWriteBarrierPolicy".
519519
typedef typename _ArrayItemWriteBarrierPolicy<PolicyType>::Policy Policy;
520-
_QuickSortImpl<Policy>::qsort_s(arr, count, comparer, context);
520+
_QuickSortImpl<Policy>::Sort(arr, count, comparer, context);
521521
}
522522
template<class T, class Comparer>
523523
void qsort_s(WriteBarrierPtr<T>* _Base, size_t _NumOfElements, size_t _SizeOfElements,

lib/JITIDL/JITTypes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,11 @@ typedef struct XProcNumberPageSegment
632632

633633
typedef struct PolymorphicInlineCacheIDL
634634
{
635-
unsigned short size;
635+
IDL_Field(unsigned short) size;
636636
IDL_PAD2(0)
637637
X64_PAD4(1)
638-
CHAKRA_PTR addr;
639-
CHAKRA_PTR inlineCachesAddr;
638+
IDL_Field(CHAKRA_PTR) addr;
639+
IDL_Field(CHAKRA_PTR) inlineCachesAddr;
640640
} PolymorphicInlineCacheIDL;
641641

642642
typedef struct PolymorphicInlineCacheInfoIDL

lib/Parser/Parse.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ bool Parser::IsES6DestructuringEnabled() const
3131

3232
struct DeferredFunctionStub
3333
{
34-
RestorePoint restorePoint;
35-
uint fncFlags;
36-
uint nestedCount;
37-
DeferredFunctionStub *deferredStubs;
38-
charcount_t ichMin;
34+
Field(RestorePoint) restorePoint;
35+
Field(uint) fncFlags;
36+
Field(uint) nestedCount;
37+
Field(DeferredFunctionStub *) deferredStubs;
38+
Field(charcount_t) ichMin;
3939
};
4040

4141
struct StmtNest

lib/Parser/Scan.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,17 @@ typedef HRESULT (*CommentCallback)(void *data, OLECHAR firstChar, OLECHAR second
326326
// Restore point defined using a relative offset rather than a pointer.
327327
struct RestorePoint
328328
{
329-
charcount_t m_ichMinTok;
330-
charcount_t m_ichMinLine;
331-
size_t m_cMinTokMultiUnits;
332-
size_t m_cMinLineMultiUnits;
333-
charcount_t m_line;
334-
uint functionIdIncrement;
335-
size_t lengthDecr;
336-
BOOL m_fHadEol;
329+
Field(charcount_t) m_ichMinTok;
330+
Field(charcount_t) m_ichMinLine;
331+
Field(size_t) m_cMinTokMultiUnits;
332+
Field(size_t) m_cMinLineMultiUnits;
333+
Field(charcount_t) m_line;
334+
Field(uint) functionIdIncrement;
335+
Field(size_t) lengthDecr;
336+
Field(BOOL) m_fHadEol;
337337

338338
#ifdef DEBUG
339-
size_t m_cMultiUnits;
339+
Field(size_t) m_cMultiUnits;
340340
#endif
341341

342342
RestorePoint()

0 commit comments

Comments
 (0)