Bug 941805 - Unbreak non-threadsafe JS builds.

This commit is contained in:
Brian Hackett 2014-01-31 19:43:40 -07:00
parent 33607bb122
commit c339fa01fb
4 changed files with 28 additions and 7 deletions

View File

@ -1405,7 +1405,11 @@ static bool
WorkerThreadCount(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
#ifdef JS_THREADSAFE
args.rval().setInt32(cx->runtime()->useHelperThreads() ? WorkerThreadState().threadCount : 0);
#else
args.rval().setInt32(0);
#endif
return true;
}

View File

@ -515,6 +515,7 @@ jit::FinishOffThreadBuilder(IonBuilder *builder)
static inline void
FinishAllOffThreadCompilations(JSCompartment *comp)
{
#ifdef JS_THREADSAFE
AutoLockWorkerThreadState lock;
GlobalWorkerThreadState::IonBuilderVector &finished = WorkerThreadState().ionFinishedList();
@ -525,6 +526,7 @@ FinishAllOffThreadCompilations(JSCompartment *comp)
WorkerThreadState().remove(finished, &i);
}
}
#endif
}
/* static */ void
@ -1578,6 +1580,7 @@ static const size_t BUILDER_LIFO_ALLOC_PRIMARY_CHUNK_SIZE = 1 << 12;
static inline bool
OffThreadCompilationAvailable(JSContext *cx)
{
#ifdef JS_THREADSAFE
// Even if off thread compilation is enabled, compilation must still occur
// on the main thread in some cases. Do not compile off thread during an
// incremental GC, as this may trip incremental read barriers.
@ -1592,6 +1595,9 @@ OffThreadCompilationAvailable(JSContext *cx)
&& WorkerThreadState().cpuCount > 1
&& cx->runtime()->gcIncrementalState == gc::NO_INCREMENTAL
&& !cx->runtime()->profilingScripts;
#else
return false;
#endif
}
static void
@ -1849,9 +1855,12 @@ CheckScriptSize(JSContext *cx, JSScript* script)
if (script->length() > MAX_MAIN_THREAD_SCRIPT_SIZE ||
numLocalsAndArgs > MAX_MAIN_THREAD_LOCALS_AND_ARGS)
{
if (cx->runtime()->canUseParallelIonCompilation() &&
WorkerThreadState().cpuCount > 1)
{
#ifdef JS_THREADSAFE
size_t cpuCount = WorkerThreadState().cpuCount;
#else
size_t cpuCount = 1;
#endif
if (cx->runtime()->canUseParallelIonCompilation() && cpuCount > 1) {
// Even if off thread compilation is enabled, there are cases where
// compilation must still occur on the main thread. Don't compile
// in these cases (except when profiling scripts, as compilations

View File

@ -1302,11 +1302,15 @@ ScriptSource::setSourceCopy(ExclusiveContext *cx, const jschar *src, uint32_t le
// thread (see WorkerThreadState::canStartParseTask) which would cause a
// deadlock if there wasn't a second worker thread that could make
// progress on our compression task.
const size_t HUGE_SCRIPT = 5 * 1024 * 1024;
if (length < HUGE_SCRIPT &&
#ifdef JS_THREADSAFE
bool canCompressOffThread =
WorkerThreadState().cpuCount > 1 &&
WorkerThreadState().threadCount >= 2)
{
WorkerThreadState().threadCount >= 2;
#else
bool canCompressOffThread = false;
#endif
const size_t HUGE_SCRIPT = 5 * 1024 * 1024;
if (length < HUGE_SCRIPT && canCompressOffThread) {
task->ss = this;
task->chars = src;
ready_ = false;

View File

@ -391,8 +391,12 @@ ThreadPool::init()
uint32_t
ThreadPool::numWorkers() const
{
#ifdef JS_THREADSAFE
// Subtract one for the main thread, which always exists.
return WorkerThreadState().cpuCount - 1;
#else
return 0;
#endif
}
bool