Skip to content

Commit 93e1cf6

Browse files
author
Jianchun Xu
committed
[MERGE #1735 @jianchun] swb: run write-barrier check/analyze from build.sh
Merge pull request #1735 from jianchun:swbscript Enable build.sh to run write-barrier check/analyze: ``` build.sh -n -d --wb-check lib/Runtime/Base/FunctionBody.cpp ``` Also fix some build breaks and failures/assertions, fix copyright headers and tabs.
2 parents 3ed5c6b + e1da27a commit 93e1cf6

File tree

16 files changed

+235
-154
lines changed

16 files changed

+235
-154
lines changed

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,28 @@ endif(WITHOUT_FEATURES_SH)
310310

311311
enable_language(ASM)
312312

313+
################# Write-barrier check/analyze ##################
314+
if (WB_CHECK_SH OR WB_ANALYZE_SH)
315+
add_definitions(
316+
-Xclang -load
317+
-Xclang ${CMAKE_CURRENT_SOURCE_DIR}/tools/RecyclerChecker/Build/libclangRecyclerChecker.so
318+
)
319+
endif()
320+
if (WB_CHECK_SH)
321+
unset(WB_CHECK_SH CACHE) # don't cache
322+
add_definitions(
323+
-Xclang -plugin
324+
-Xclang check-recycler
325+
)
326+
endif()
327+
if (WB_ANALYZE_SH)
328+
unset(WB_ANALYZE_SH CACHE) # don't cache
329+
add_definitions(
330+
-Xclang -analyze
331+
-Xclang -analyzer-checker=chakra.RecyclerChecker
332+
)
333+
endif()
334+
313335
include_directories(
314336
.
315337
lib/Common

build.sh

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ PRINT_USAGE() {
4949
echo " --without=FEATURE,FEATURE,..."
5050
echo " Disable FEATUREs from JSRT experimental"
5151
echo " features."
52+
echo " --wb-check CPPFILE"
53+
echo " Write-barrier check given CPPFILE (git path)"
54+
echo " --wb-analyze CPPFILE"
55+
echo " Write-barrier analyze given CPPFILE (git path)"
5256
echo ""
5357
echo "example:"
5458
echo " ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j"
@@ -75,6 +79,8 @@ ARCH="-DCC_TARGETS_AMD64_SH=1"
7579
OS_LINUX=0
7680
OS_APT_GET=0
7781
OS_UNIX=0
82+
WB_CHECK=
83+
WB_ANALYZE=
7884

7985
if [ -f "/proc/version" ]; then
8086
OS_LINUX=1
@@ -234,6 +240,24 @@ while [[ $# -gt 0 ]]; do
234240
done
235241
;;
236242

243+
--wb-check)
244+
if [[ "$2" =~ ^[^-] ]]; then
245+
WB_CHECK="$2"
246+
shift
247+
else
248+
PRINT_USAGE && exit 1
249+
fi
250+
;;
251+
252+
--wb-analyze)
253+
if [[ "$2" =~ ^[^-] ]]; then
254+
WB_ANALYZE="$2"
255+
shift
256+
else
257+
PRINT_USAGE && exit 1
258+
fi
259+
;;
260+
237261
*)
238262
echo "Unknown option $1"
239263
PRINT_USAGE
@@ -306,6 +330,43 @@ if [[ ${#_CXX} > 0 ]]; then
306330
CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
307331
fi
308332

333+
################# Write-barrier check/analyze run #################
334+
WB_FLAG=
335+
WB_TARGET=
336+
if [[ $WB_CHECK || $WB_ANALYZE ]]; then
337+
if [[ $MAKE != 'ninja' ]]; then
338+
echo "--wb-check/wb-analyze only works with --ninja" && exit 1
339+
fi
340+
if [[ $WB_CHECK && $WB_ANALYZE ]]; then
341+
echo "Please run only one of --wb-check or --wb-analyze" && exit 1
342+
fi
343+
if [[ $WB_CHECK ]]; then
344+
WB_FLAG="-DWB_CHECK_SH=1"
345+
WB_FILE=$WB_CHECK
346+
fi
347+
if [[ $WB_ANALYZE ]]; then
348+
WB_FLAG="-DWB_ANALYZE_SH=1"
349+
WB_FILE=$WB_ANALYZE
350+
fi
351+
352+
if [[ -f $CHAKRACORE_DIR/$WB_FILE ]]; then
353+
touch $CHAKRACORE_DIR/$WB_FILE
354+
else
355+
echo "$CHAKRACORE_DIR/$WB_FILE not found. Please use full git path for $WB_FILE." && exit 1
356+
fi
357+
358+
WB_FILE_DIR=`dirname $WB_FILE`
359+
WB_FILE_BASE=`basename $WB_FILE`
360+
361+
WB_FILE_CMAKELISTS="$CHAKRACORE_DIR/$WB_FILE_DIR/CMakeLists.txt"
362+
if [[ -f $WB_FILE_CMAKELISTS ]]; then
363+
SUBDIR=$(grep -i add_library $WB_FILE_CMAKELISTS | sed -r "s/.*\((\S+) .*/\1/")
364+
else
365+
echo "$WB_FILE_CMAKELISTS not found." && exit 1
366+
fi
367+
WB_TARGET="$WB_FILE_DIR/CMakeFiles/$SUBDIR.dir/$WB_FILE_BASE.o"
368+
fi
369+
309370
build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE:0}"
310371
if [ ! -d "$build_directory" ]; then
311372
SAFE_RUN `mkdir -p $build_directory`
@@ -322,12 +383,14 @@ fi
322383

323384
echo Generating $BUILD_TYPE makefiles
324385
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $STATIC_LIBRARY $ARCH \
325-
-DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $WITHOUT_FEATURES ../..
386+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $WITHOUT_FEATURES \
387+
$WB_FLAG \
388+
../..
326389

327390
_RET=$?
328391
if [[ $? == 0 ]]; then
329392
if [[ $MAKE != 0 ]]; then
330-
$MAKE $MULTICORE_BUILD 2>&1 | tee build.log
393+
$MAKE $MULTICORE_BUILD $WB_TARGET 2>&1 | tee build.log
331394
_RET=${PIPESTATUS[0]}
332395
else
333396
echo "Visit given folder above for xcode project file ----^"

jenkins/check_copyright.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ git diff --name-only `git merge-base origin/master HEAD` HEAD |
3232
grep -v -E '\.nuspec$' |
3333
grep -v -E '\.def$' |
3434
grep -v -E '\.inc$' |
35+
grep -v -E '\.cmake$' |
3536
grep -v -E 'test/benchmarks/.*\.js$' |
3637
grep -v -E 'bin/External/.*$' |
3738
grep -v -E 'bin/NativeTests/Scripts/splay.js$' |
3839
grep -v -E 'pal/.*' |
3940
grep -v -E 'libChakraCoreLib.version|ch.version' |
4041
xargs -I % sh -c "echo 'Check Copyright > Checking %'; python jenkins/check_copyright.py % > $ERRFILETEMP || cat $ERRFILETEMP >> $ERRFILE"
4142

43+
rm -f $ERRFILETEMP
44+
4245
if [ -e $ERRFILE ]; then # if error file exists then there were errors
4346
>&2 echo "--------------" # leading >&2 means echo to stderr
4447
>&2 echo "--- ERRORS ---"

lib/Backend/LowerMDShared.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,8 @@ LowererMD::Legalize(IR::Instr *const instr, bool fPostRegAlloc)
16751675

16761676
case Js::OpCode::LEA:
16771677
Assert(instr->GetDst()->IsRegOpnd());
1678-
Assert(instr->GetSrc1()->IsIndirOpnd() || instr->GetSrc1()->IsSymOpnd());
1678+
Assert(instr->GetSrc1()->IsIndirOpnd() || instr->GetSrc1()->IsSymOpnd()
1679+
|| instr->GetSrc1()->IsMemRefOpnd()); // We may convert IndirOpnd to MemRefOpnd
16791680
Assert(!instr->GetSrc2());
16801681
break;
16811682
case Js::OpCode::PSRLDQ:
@@ -5031,7 +5032,7 @@ LowererMD::GenerateUntagVar(IR::RegOpnd * src, IR::LabelInstr * labelFail, IR::I
50315032
if (generateTagCheck)
50325033
{
50335034
Assert(!opnd->IsTaggedInt());
5034-
this->GenerateSmIntTest(opnd, insertBeforeInstr, labelFail);
5035+
this->GenerateSmIntTest(opnd, assignInstr, labelFail);
50355036
}
50365037

50375038
// Moving into r2 clears the tag bits on AMD64.

lib/Common/CommonDefines.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@
154154
#ifdef RECYCLER_WRITE_BARRIER
155155
#if defined(__clang__)
156156
#define GLOBAL_FORCE_USE_WRITE_BARRIER 1
157-
#else
158-
#define GLOBAL_FORCE_USE_WRITE_BARRIER 1 // force turn on write barrier in windows
159157
#endif
160158
#endif
161159

lib/Common/Memory/Recycler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct InfoBitsWrapper{};
129129
#define RecyclerNewFinalized(recycler,T,...) static_cast<T *>(static_cast<FinalizableObject *>(AllocatorNewBase(Recycler, recycler, AllocFinalizedInlined, T, __VA_ARGS__)))
130130
#define RecyclerNewFinalizedPlus(recycler, size, T,...) static_cast<T *>(static_cast<FinalizableObject *>(AllocatorNewPlusBase(Recycler, recycler, AllocFinalized, size, T, __VA_ARGS__)))
131131
#define RecyclerNewTracked(recycler,T,...) static_cast<T *>(static_cast<FinalizableObject *>(AllocatorNewBase(Recycler, recycler, AllocTrackedInlined, T, __VA_ARGS__)))
132-
#define RecyclerNewEnumClass(recycler, enumClass, T, ...) new (TRACK_ALLOC_INFO(static_cast<Recycler *>(recycler), T, Recycler, 0, (size_t)-1), enumClass) T(__VA_ARGS__)
132+
#define RecyclerNewEnumClass(recycler, enumClass, T, ...) new (TRACK_ALLOC_INFO(static_cast<Recycler *>(recycler), T, Recycler, 0, (size_t)-1), InfoBitsWrapper<enumClass>()) T(__VA_ARGS__)
133133
#define RecyclerNewWithInfoBits(recycler, infoBits, T, ...) new (TRACK_ALLOC_INFO(static_cast<Recycler *>(recycler), T, Recycler, 0, (size_t)-1), InfoBitsWrapper<infoBits>()) T(__VA_ARGS__)
134134
#define RecyclerNewFinalizedClientTracked(recycler,T,...) static_cast<T *>(static_cast<FinalizableObject *>(AllocatorNewBase(Recycler, recycler, AllocFinalizedClientTrackedInlined, T, __VA_ARGS__)))
135135
#endif
@@ -1351,7 +1351,7 @@ class Recycler
13511351
char * AllocEnumClass(DECLSPEC_GUARD_OVERFLOW size_t size)
13521352
{
13531353
Assert((enumClass & EnumClassMask) != 0);
1354-
Assert((enumClass & ~EnumClassMask & ~WithBarrierBit) == 0);
1354+
//Assert((enumClass & ~EnumClassMask & ~WithBarrierBit) == 0);
13551355
return AllocWithAttributes<(ObjectInfoBits)(enumClass), /* nothrow = */ false>(size);
13561356
}
13571357

lib/Runtime/Base/AuxPtrs.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ namespace Js
2525
template<typename FieldsEnum, uint8 size, uint8 _MaxCount = (size - 1) / (1 + sizeof(void*))>
2626
struct AuxPtrsFix
2727
{
28-
static const uint8 MaxCount = _MaxCount;
29-
Field(uint8) count; // always saving maxCount
30-
Field(FieldsEnum) type[MaxCount]; // save instantiated pointer enum
31-
Pointer(void) ptr[MaxCount]; // save instantiated pointer address
28+
static const uint8 MaxCount;
29+
Field(uint8) count; // always saving maxCount
30+
Field(FieldsEnum) type[_MaxCount]; // save instantiated pointer enum
31+
Pointer(void) ptr[_MaxCount]; // save instantiated pointer address
3232
AuxPtrsFix();
3333
AuxPtrsFix(AuxPtrsFix<FieldsEnum, 16>* ptr16); // called when promoting from AuxPtrs16 to AuxPtrs32
3434
void* Get(FieldsEnum e);
3535
bool Set(FieldsEnum e, void* p);
3636
};
3737

38+
template<typename FieldsEnum, uint8 size, uint8 _MaxCount>
39+
const uint8 AuxPtrsFix<FieldsEnum, size, _MaxCount>::MaxCount = _MaxCount;
40+
3841
// Use flexible size structure to save pointers. when pointer count exceeds AuxPtrsFix<FieldsEnum, 32>::MaxCount,
3942
// it will promote to this structure to save the pointers
4043
// Layout:

lib/Runtime/Language/ModuleNamespace.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Js
1616
Js::FunctionInfo ModuleNamespace::EntryInfo::SymbolIterator(ModuleNamespace::EntrySymbolIterator);
1717

1818
ModuleNamespace::ModuleNamespace(ModuleRecordBase* moduleRecord, DynamicType* type) :
19-
moduleRecord(moduleRecord), DynamicObject(type), unambiguousNonLocalExports(nullptr),
19+
moduleRecord(moduleRecord), DynamicObject(type), unambiguousNonLocalExports(nullptr),
2020
sortedExportedNames(nullptr), nsSlots(nullptr)
2121
{
2222

@@ -56,7 +56,7 @@ namespace Js
5656

5757
DynamicType* type = library->CreateFunctionWithLengthType(&EntryInfo::SymbolIterator);
5858
RuntimeFunction* iteratorFunction = RecyclerNewEnumClass(scriptContext->GetRecycler(),
59-
library->EnumFunctionClass, RuntimeFunction,
59+
JavascriptLibrary::EnumFunctionClass, RuntimeFunction,
6060
type, &EntryInfo::SymbolIterator);
6161
DynamicObject::SetPropertyWithAttributes(PropertyIds::_symbolIterator, iteratorFunction, PropertyBuiltInMethodDefaults, nullptr);
6262

@@ -89,7 +89,7 @@ namespace Js
8989
// update the local slot to use the storage for local exports.
9090
SetNSSlotsForModuleNS(sourceTextModuleRecord->GetLocalExportSlots());
9191

92-
// For items that are not in the local export list, we need to resolve them to get it
92+
// For items that are not in the local export list, we need to resolve them to get it
9393
ExportedNames* exportedNames = sourceTextModuleRecord->GetExportedNames(nullptr);
9494
ModuleNameRecord* moduleNameRecord = nullptr;
9595
#if DBG

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5024,7 +5024,7 @@ namespace Js
50245024

50255025
Js::RecyclableObject* JavascriptLibrary::CreateRevokeFunction_TTD(RecyclableObject* proxy)
50265026
{
5027-
RuntimeFunction* revoker = RecyclerNewEnumClass(this->scriptContext->GetRecycler(), this->EnumFunctionClass, RuntimeFunction, this->CreateFunctionWithLengthType(&JavascriptProxy::EntryInfo::Revoke), &JavascriptProxy::EntryInfo::Revoke);
5027+
RuntimeFunction* revoker = RecyclerNewEnumClass(this->scriptContext->GetRecycler(), JavascriptLibrary::EnumFunctionClass, RuntimeFunction, this->CreateFunctionWithLengthType(&JavascriptProxy::EntryInfo::Revoke), &JavascriptProxy::EntryInfo::Revoke);
50285028

50295029
revoker->SetPropertyWithAttributes(Js::PropertyIds::length, Js::TaggedInt::ToVarUnchecked(0), PropertyNone, NULL);
50305030
revoker->SetInternalProperty(Js::InternalPropertyIds::RevocableProxy, proxy, PropertyOperationFlags::PropertyOperation_Force, nullptr);

lib/Runtime/Library/JavascriptProxy.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace Js
126126
JavascriptLibrary* library = scriptContext->GetLibrary();
127127
DynamicType* type = library->CreateFunctionWithLengthType(&EntryInfo::Revoke);
128128
RuntimeFunction* revoker = RecyclerNewEnumClass(scriptContext->GetRecycler(),
129-
library->EnumFunctionClass, RuntimeFunction,
129+
JavascriptLibrary::EnumFunctionClass, RuntimeFunction,
130130
type, &EntryInfo::Revoke);
131131

132132
revoker->SetPropertyWithAttributes(Js::PropertyIds::length, Js::TaggedInt::ToVarUnchecked(0), PropertyNone, NULL);
@@ -906,16 +906,16 @@ namespace Js
906906
if (!threadContext->RecordImplicitException())
907907
return FALSE;
908908
JavascriptError::ThrowTypeError(GetScriptContext(), JSERR_ErrorOnRevokedProxy, _u("ownKeys"));
909-
}
910-
909+
}
910+
911911
Var propertyName = nullptr;
912912
PropertyId propertyId;
913913
int index = 0;
914914
JsUtil::BaseDictionary<const char16*, Var, Recycler> dict(requestContext->GetRecycler());
915915
JavascriptArray* arrResult = requestContext->GetLibrary()->CreateArray();
916916

917917
// 13.7.5.15 EnumerateObjectProperties(O) (https://tc39.github.io/ecma262/#sec-enumerate-object-properties)
918-
// for (let key of Reflect.ownKeys(obj)) {
918+
// for (let key of Reflect.ownKeys(obj)) {
919919
Var trapResult = JavascriptOperators::GetOwnPropertyNames(this, requestContext);
920920
if (JavascriptArray::Is(trapResult))
921921
{
@@ -941,7 +941,7 @@ namespace Js
941941
dict.Add(str->GetSz(), prop);
942942
// if (desc.enumerable) yield key;
943943
if (desc.IsEnumerable())
944-
{
944+
{
945945
ret = arrResult->SetItem(index++, CrossSite::MarshalVar(requestContext, prop), PropertyOperation_None);
946946
Assert(ret);
947947
}
@@ -1230,7 +1230,7 @@ namespace Js
12301230
//7. ReturnIfAbrupt(keys).
12311231
JavascriptArray* resultArray = JavascriptOperators::GetOwnPropertyKeys(obj, scriptContext);
12321232

1233-
const PropertyRecord* propertyRecord;
1233+
const PropertyRecord* propertyRecord;
12341234
if (integrityLevel == IntegrityLevel::IntegrityLevel_sealed)
12351235
{
12361236
//8. If level is "sealed", then

0 commit comments

Comments
 (0)