Skip to content

Commit 2c6dd13

Browse files
committed
WebAssembly: Don't tier up the same function twice
https://bugs.webkit.org/show_bug.cgi?id=171397 Reviewed by Filip Pizlo. Because we don't CAS the tier up count on function entry/loop backedge and we use the least significant to indicate whether or not tier up has already started we could see the following: Threads A and B are running count in memory is (0): A: load tier up count (0) B: load tier up count (0) A: decrement count to -2 and see we need to check for tier up (0) A: store -2 to count (-2) A: exchangeOr(1) to tier up count (-1) B: decrement count to -2 and see we need to check for tier up (-1) B: store -2 to count (-2) B: exchangeOr(1) to tier up count (-1) This would cause us to tier up the same function twice, which we would rather avoid. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::emitTierUpCheck): * wasm/WasmTierUpCount.h: (JSC::Wasm::TierUpCount::TierUpCount): (JSC::Wasm::TierUpCount::loopDecrement): (JSC::Wasm::TierUpCount::functionEntryDecrement): (JSC::Wasm::TierUpCount::shouldStartTierUp): Canonical link: https://commits.webkit.org/188292@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215898 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent a695856 commit 2c6dd13

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

Source/JavaScriptCore/ChangeLog

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
2017-04-27 Keith Miller <keith_miller@apple.com>
2+
3+
WebAssembly: Don't tier up the same function twice
4+
https://bugs.webkit.org/show_bug.cgi?id=171397
5+
6+
Reviewed by Filip Pizlo.
7+
8+
Because we don't CAS the tier up count on function entry/loop backedge and we use the least significant to indicate whether or not tier up has already started we could see the following:
9+
10+
Threads A and B are running count in memory is (0):
11+
12+
A: load tier up count (0)
13+
B: load tier up count (0)
14+
A: decrement count to -2 and see we need to check for tier up (0)
15+
A: store -2 to count (-2)
16+
A: exchangeOr(1) to tier up count (-1)
17+
B: decrement count to -2 and see we need to check for tier up (-1)
18+
B: store -2 to count (-2)
19+
B: exchangeOr(1) to tier up count (-1)
20+
21+
This would cause us to tier up the same function twice, which we would rather avoid.
22+
23+
* wasm/WasmB3IRGenerator.cpp:
24+
(JSC::Wasm::B3IRGenerator::emitTierUpCheck):
25+
* wasm/WasmTierUpCount.h:
26+
(JSC::Wasm::TierUpCount::TierUpCount):
27+
(JSC::Wasm::TierUpCount::loopDecrement):
28+
(JSC::Wasm::TierUpCount::functionEntryDecrement):
29+
(JSC::Wasm::TierUpCount::shouldStartTierUp):
30+
131
2017-04-27 Keith Miller <keith_miller@apple.com>
232

333
REGRESSION (r215843): ASSERTION FAILED: !m_completionTasks[0].first in JSC::Wasm::Plan::tryRemoveVMAndCancelIfLast(JSC::VM &)

Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,6 @@ BasicBlock* B3IRGenerator::emitTierUpCheck(BasicBlock* entry, uint32_t decrement
834834
if (!m_tierUp)
835835
return entry;
836836

837-
ASSERT(!(decrementCount % 2));
838837
// FIXME: Make this a patchpoint.
839838
BasicBlock* continuation = m_proc.addBlock();
840839

Source/JavaScriptCore/wasm/WasmTierUpCount.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,30 @@ class TierUpCount {
4242
WTF_MAKE_NONCOPYABLE(TierUpCount);
4343
public:
4444
TierUpCount()
45-
: m_count(Options::webAssemblyOMGTierUpCount() * 2)
45+
: m_count(Options::webAssemblyOMGTierUpCount())
46+
, m_tierUpStarted(false)
4647
{
4748
}
4849

4950
TierUpCount(TierUpCount&& other)
5051
{
51-
ASSERT(other.m_count == Options::webAssemblyOMGTierUpCount() * 2);
52+
ASSERT(other.m_count == Options::webAssemblyOMGTierUpCount());
5253
m_count = other.m_count;
5354
}
5455

55-
static uint32_t loopDecrement() { return Options::webAssemblyLoopDecrement() * 2; }
56-
static uint32_t functionEntryDecrement() { return Options::webAssemblyFunctionEntryDecrement() * 2; }
56+
static uint32_t loopDecrement() { return Options::webAssemblyLoopDecrement(); }
57+
static uint32_t functionEntryDecrement() { return Options::webAssemblyFunctionEntryDecrement(); }
5758

5859
bool shouldStartTierUp()
5960
{
60-
return !(WTF::atomicExchangeOr(&m_count, 1) & 1);
61+
return !m_tierUpStarted.exchange(true);
6162
}
6263

6364
int32_t count() { return bitwise_cast<int32_t>(m_count); }
6465

6566
private:
6667
uint32_t m_count;
68+
Atomic<bool> m_tierUpStarted;
6769
};
6870

6971
} } // namespace JSC::Wasm

0 commit comments

Comments
 (0)