Skip to content
Permalink
Browse files
[JSC] Do not use bytecode cache on $.agent worker threads
Patch by Geza Lore <glore@igalia.com> on 2022-05-23
https://bugs.webkit.org/show_bug.cgi?id=240642

Reviewed by Yusuke Suzuki.

Workers started via $.agent.start are not shut down in a synchronous
manner, and it is possible the main thread terminates the process while
a worker is writing its bytecode cache, which results in intermittent
test failures. As $.agent.start is only a rarely used testing facility,
we simply do not cache bytecode on these threads.

Also un-skip test on ARMv7 that used to fail because of this.

* Source/JavaScriptCore/jsc.cpp:
(Worker::isMain const):
(Worker::Worker):
(runJSC):
 * JSTests/stress/lars-sab-workers.js:

Canonical link: https://commits.webkit.org/250858@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294632 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
gezalore authored and webkit-commit-queue committed May 23, 2022
1 parent 1a6e1cb commit 20ac310fd8a9017c3021563c68365c61b484495a
Showing 2 changed files with 15 additions and 10 deletions.
@@ -1,4 +1,3 @@
//@ skip if $architecture == "arm"
//@ defaultRunNoisyTest
var sab = new SharedArrayBuffer(100 * 4);

@@ -229,19 +229,21 @@ class Message : public ThreadSafeRefCounted<Message> {

class Worker : public BasicRawSentinelNode<Worker> {
public:
Worker(Workers&);
Worker(Workers&, bool isMain);
~Worker();

void enqueue(const AbstractLocker&, RefPtr<Message>);
RefPtr<Message> dequeue();

bool isMain() const { return m_isMain; }

static Worker& current();

private:
static ThreadSpecific<Worker*>& currentWorker();

Workers& m_workers;
Deque<RefPtr<Message>> m_messages;
const bool m_isMain;
};

class Workers {
@@ -1129,16 +1131,19 @@ class ShellSourceProvider final : public StringSourceProvider {

ShellSourceProvider(const String& source, const SourceOrigin& sourceOrigin, String&& sourceURL, const TextPosition& startPosition, SourceProviderSourceType sourceType)
: StringSourceProvider(source, sourceOrigin, WTFMove(sourceURL), startPosition, sourceType)
{
}
// Workers started via $.agent.start are not shut down in a synchronous manner, and it
// is possible the main thread terminates the process while a worker is writing its
// bytecode cache, which results in intermittent test failures. As $.agent.start is only
// a rarely used testing facility, we simply do not cache bytecode on these threads.
, m_cacheEnabled(Worker::current().isMain() && !!Options::diskCachePath())

static bool cacheEnabled()
{
static bool enabled = !!Options::diskCachePath();
return enabled;
}

bool cacheEnabled() const { return m_cacheEnabled; }

mutable RefPtr<CachedBytecode> m_cachedBytecode;
const bool m_cacheEnabled;
};

static inline SourceCode jscSource(const String& source, const SourceOrigin& sourceOrigin, String sourceURL = String(), const TextPosition& startPosition = TextPosition(), SourceProviderSourceType sourceType = SourceProviderSourceType::Program)
@@ -1925,8 +1930,9 @@ Message::~Message()
{
}

Worker::Worker(Workers& workers)
Worker::Worker(Workers& workers, bool isMain)
: m_workers(workers)
, m_isMain(isMain)
{
Locker locker { m_workers.m_lock };
m_workers.m_workers.append(this);
@@ -3651,7 +3657,7 @@ CommandLine::CommandLine(CommandLineForWorkersTag)
template<typename Func>
int runJSC(const CommandLine& options, bool isWorker, const Func& func)
{
Worker worker(Workers::singleton());
Worker worker(Workers::singleton(), !isWorker);

VM& vm = VM::create(HeapType::Large).leakRef();
if (!isWorker && options.m_canBlockIsFalse)

0 comments on commit 20ac310

Please sign in to comment.