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()

lib/Runtime/Base/FunctionBody.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,19 +1179,19 @@ namespace Js
11791179
struct LoopHeader
11801180
{
11811181
private:
1182-
LoopEntryPointList* entryPoints;
1182+
Field(LoopEntryPointList*) entryPoints;
11831183

11841184
public:
1185-
uint startOffset;
1186-
uint endOffset;
1187-
uint interpretCount;
1188-
uint profiledLoopCounter;
1189-
bool isNested;
1190-
bool isInTry;
1191-
FunctionBody * functionBody;
1185+
Field(uint) startOffset;
1186+
Field(uint) endOffset;
1187+
Field(uint) interpretCount;
1188+
Field(uint) profiledLoopCounter;
1189+
Field(bool) isNested;
1190+
Field(bool) isInTry;
1191+
Field(FunctionBody *) functionBody;
11921192

11931193
#if DBG_DUMP
1194-
uint nativeCount;
1194+
Field(uint) nativeCount;
11951195
#endif
11961196
static const uint NoLoop = (uint)-1;
11971197

lib/Runtime/Language/AsmJsModule.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -349,31 +349,32 @@ namespace Js {
349349
/// proxy of asmjs module
350350
struct ModuleVar
351351
{
352-
RegSlot location;
353-
AsmJsVarType::Which type;
354-
union
352+
Field(RegSlot) location;
353+
Field(AsmJsVarType::Which) type;
354+
union InitialiserType
355355
{
356-
int intInit;
357-
float floatInit;
358-
double doubleInit;
359-
AsmJsSIMDValue simdInit;
360-
} initialiser;
361-
bool isMutable;
356+
Field(int) intInit;
357+
Field(float) floatInit;
358+
Field(double) doubleInit;
359+
Field(AsmJsSIMDValue) simdInit;
360+
};
361+
Field(InitialiserType) initialiser;
362+
Field(bool) isMutable;
362363
};
363364
struct ModuleVarImport
364365
{
365-
RegSlot location;
366-
AsmJsVarType::Which type;
367-
PropertyId field;
366+
Field(RegSlot) location;
367+
Field(AsmJsVarType::Which) type;
368+
Field(PropertyId) field;
368369
};
369370
struct ModuleFunctionImport
370371
{
371-
RegSlot location;
372-
PropertyId field;
372+
Field(RegSlot) location;
373+
Field(PropertyId) field;
373374
};
374375
struct ModuleFunction
375376
{
376-
RegSlot location;
377+
Field(RegSlot) location;
377378
};
378379
struct ModuleExport
379380
{
@@ -382,8 +383,8 @@ namespace Js {
382383
};
383384
struct ModuleFunctionTable
384385
{
385-
uint size;
386-
RegSlot* moduleFunctionIndex;
386+
Field(uint) size;
387+
Field(RegSlot*) moduleFunctionIndex;
387388
};
388389

389390
typedef JsUtil::BaseDictionary<PropertyId, AsmJsSlot*, Memory::Recycler> AsmJsSlotMap;

lib/Runtime/Language/ObjTypeSpecFldInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ namespace Js
1717

1818
struct FixedFieldInfo
1919
{
20-
Var fieldValue;
21-
Type* type;
22-
bool nextHasSameFixedField; // set to true if the next entry in the FixedFieldInfo array on ObjTypeSpecFldInfo has the same type
20+
Field(Var) fieldValue;
21+
Field(Type*) type;
22+
Field(bool) nextHasSameFixedField; // set to true if the next entry in the FixedFieldInfo array on ObjTypeSpecFldInfo has the same type
2323
};
2424

2525
// Union with uint16 flags for fast default initialization

lib/Runtime/Library/JavascriptObject.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,9 +1668,9 @@ namespace Js
16681668
size_t descCount = 0;
16691669
struct DescriptorMap
16701670
{
1671-
PropertyRecord const * propRecord;
1672-
PropertyDescriptor descriptor;
1673-
Var originalVar;
1671+
Field(PropertyRecord const *) propRecord;
1672+
Field(PropertyDescriptor) descriptor;
1673+
Field(Var) originalVar;
16741674
};
16751675

16761676
JavascriptStaticEnumerator enumerator;
@@ -1764,8 +1764,8 @@ namespace Js
17641764
size_t descCount = 0;
17651765
struct DescriptorMap
17661766
{
1767-
PropertyRecord const * propRecord;
1768-
PropertyDescriptor descriptor;
1767+
Field(PropertyRecord const *) propRecord;
1768+
Field(PropertyDescriptor) descriptor;
17691769
};
17701770

17711771
//3. Let keys be props.[[OwnPropertyKeys]]().

0 commit comments

Comments
 (0)