Skip to content

Commit

Permalink
[JSC] Remove unnecessary RELEASE_ASSERT and use memset_pattern4 in re…
Browse files Browse the repository at this point in the history
…cordLinkOffsets

https://bugs.webkit.org/show_bug.cgi?id=263625
rdar://117443303

Reviewed by Mark Lam and Justin Michaud.

This patch cleans up some of RELEASE_ASSERT in ARM64Assembler.

1. We are doing meaningless RELEASE_ASSERT repeatedly. We hoist the critical part and remove unnecessary ones if the first one meets the requirement.
   This meaningless assertions are actually hot in traces.
2. Use memset_pattern4 to fill out 4-byte patterns on Darwin.

* Source/JavaScriptCore/assembler/ARM64Assembler.h:
* Source/JavaScriptCore/assembler/LinkBuffer.cpp:
(JSC::recordLinkOffsets):

Canonical link: https://commits.webkit.org/269746@main
  • Loading branch information
Constellation committed Oct 25, 2023
1 parent 95809c7 commit 20fbc27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 6 additions & 11 deletions Source/JavaScriptCore/assembler/ARM64Assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2269,9 +2269,10 @@ class ARM64Assembler {
{
RELEASE_ASSERT(!(size % sizeof(int32_t)));
size_t n = size / sizeof(int32_t);
for (int32_t* ptr = static_cast<int32_t*>(base); n--;) {
int32_t* ptr = static_cast<int32_t*>(base);
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(ptr) == ptr);
for (; n--;) {
int insn = nopPseudo();
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(ptr) == ptr);
copy(ptr++, &insn, sizeof(int));
}
}
Expand Down Expand Up @@ -3808,6 +3809,7 @@ class ARM64Assembler {
template<BranchTargetType type, CopyFunction copy = performJITMemcpy>
static void linkCompareAndBranch(Condition condition, bool is64Bit, RegisterID rt, int* from, const int* fromInstruction, void* to)
{
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
intptr_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(fromInstruction)) >> 2;
Expand All @@ -3818,16 +3820,13 @@ class ARM64Assembler {
if (useDirect || type == DirectBranch) {
ASSERT(isInt<19>(offset));
int insn = compareAndBranchImmediate(is64Bit ? Datasize_64 : Datasize_32, condition == ConditionNE, static_cast<int>(offset), rt);
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
copy(from, &insn, sizeof(int));
if (type == IndirectBranch) {
insn = nopPseudo();
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from + 1) == (from + 1));
copy(from + 1, &insn, sizeof(int));
}
} else {
int insn = compareAndBranchImmediate(is64Bit ? Datasize_64 : Datasize_32, invert(condition) == ConditionNE, 2, rt);
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
copy(from, &insn, sizeof(int));
linkJumpOrCall<BranchType_JMP, copy>(from + 1, fromInstruction + 1, to);
}
Expand All @@ -3836,6 +3835,7 @@ class ARM64Assembler {
template<BranchTargetType type, CopyFunction copy = performJITMemcpy>
static void linkConditionalBranch(Condition condition, int* from, const int* fromInstruction, void* to)
{
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
intptr_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(fromInstruction)) >> 2;
Expand All @@ -3846,16 +3846,13 @@ class ARM64Assembler {
if (useDirect || type == DirectBranch) {
ASSERT(isInt<19>(offset));
int insn = conditionalBranchImmediate(static_cast<int>(offset), condition);
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
copy(from, &insn, sizeof(int));
if (type == IndirectBranch) {
insn = nopPseudo();
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from + 1) == (from + 1));
copy(from + 1, &insn, sizeof(int));
}
} else {
int insn = conditionalBranchImmediate(2, invert(condition));
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
copy(from, &insn, sizeof(int));
linkJumpOrCall<BranchType_JMP, copy>(from + 1, fromInstruction + 1, to);
}
Expand All @@ -3864,6 +3861,7 @@ class ARM64Assembler {
template<BranchTargetType type, CopyFunction copy = performJITMemcpy>
static void linkTestAndBranch(Condition condition, unsigned bitNumber, RegisterID rt, int* from, const int* fromInstruction, void* to)
{
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
intptr_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(fromInstruction)) >> 2;
Expand All @@ -3875,16 +3873,13 @@ class ARM64Assembler {
if (useDirect || type == DirectBranch) {
ASSERT(isInt<14>(offset));
int insn = testAndBranchImmediate(condition == ConditionNE, static_cast<int>(bitNumber), static_cast<int>(offset), rt);
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
copy(from, &insn, sizeof(int));
if (type == IndirectBranch) {
insn = nopPseudo();
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from + 1) == (from + 1));
copy(from + 1, &insn, sizeof(int));
}
} else {
int insn = testAndBranchImmediate(invert(condition) == ConditionNE, static_cast<int>(bitNumber), 2, rt);
RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(from) == from);
copy(from, &insn, sizeof(int));
linkJumpOrCall<BranchType_JMP, copy>(from + 1, fromInstruction + 1, to);
}
Expand Down
4 changes: 4 additions & 0 deletions Source/JavaScriptCore/assembler/LinkBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,15 @@ class BranchCompactionLinkBuffer {

static ALWAYS_INLINE void recordLinkOffsets(AssemblerData& assemblerData, int32_t regionStart, int32_t regionEnd, int32_t offset)
{
#if OS(DARWIN)
memset_pattern4(bitwise_cast<uint8_t*>(assemblerData.buffer()) + regionStart, &offset, regionEnd - regionStart);
#else
int32_t ptr = regionStart / sizeof(int32_t);
const int32_t end = regionEnd / sizeof(int32_t);
int32_t* offsets = reinterpret_cast_ptr<int32_t*>(assemblerData.buffer());
while (ptr < end)
offsets[ptr++] = offset;
#endif
}

// We use this to prevent compile errors on some platforms that are unhappy
Expand Down

0 comments on commit 20fbc27

Please sign in to comment.