Bug 852518 - reorganize ifdefs and in particular do not include FJ code if no ion r=bhackett
--- a/js/src/vm/ForkJoin.cpp
+++ b/js/src/vm/ForkJoin.cpp
@@ -15,17 +15,20 @@
#include "jsinferinlines.h"
#ifdef JS_THREADSAFE
# include "prthread.h"
#endif
using namespace js;
-#ifdef JS_THREADSAFE
+#if defined(JS_THREADSAFE) && defined(JS_ION)
+
+unsigned ForkJoinSlice::ThreadPrivateIndex;
+bool ForkJoinSlice::TLSInitialized;
class js::ForkJoinShared : public TaskExecutor, public Monitor
{
/////////////////////////////////////////////////////////////////////////
// Constant fields
JSContext *const cx_; // Current context
ThreadPool *const threadPool_; // The thread pool.
@@ -139,19 +142,16 @@ class js::AutoRendezvous
threadCx.shared->initiateRendezvous(threadCx);
}
~AutoRendezvous() {
threadCx.shared->endRendezvous(threadCx);
}
};
-unsigned ForkJoinSlice::ThreadPrivateIndex;
-bool ForkJoinSlice::TLSInitialized;
-
class js::AutoSetForkJoinSlice
{
public:
AutoSetForkJoinSlice(ForkJoinSlice *threadCx) {
PR_SetThreadPrivate(ForkJoinSlice::ThreadPrivateIndex, threadCx);
}
~AutoSetForkJoinSlice() {
@@ -470,18 +470,16 @@ ForkJoinShared::requestZoneGC(JS::Zone *
} else {
// Otherwise, just GC this zone.
gcZone_ = zone;
gcReason_ = reason;
gcRequested_ = true;
}
}
-#endif // JS_THREADSAFE
-
/////////////////////////////////////////////////////////////////////////////
// ForkJoinSlice
//
ForkJoinSlice::ForkJoinSlice(PerThreadData *perThreadData,
uint32_t sliceId, uint32_t numSlices,
Allocator *allocator, ForkJoinShared *shared)
: perThreadData(perThreadData),
@@ -490,96 +488,74 @@ ForkJoinSlice::ForkJoinSlice(PerThreadDa
allocator(allocator),
abortedScript(NULL),
shared(shared)
{ }
bool
ForkJoinSlice::isMainThread()
{
-#ifdef JS_THREADSAFE
return perThreadData == &shared->runtime()->mainThread;
-#else
- return true;
-#endif
}
JSRuntime *
ForkJoinSlice::runtime()
{
-#ifdef JS_THREADSAFE
return shared->runtime();
-#else
- return NULL;
-#endif
}
bool
ForkJoinSlice::check()
{
-#ifdef JS_THREADSAFE
if (runtime()->interrupt)
return shared->check(*this);
else
return true;
-#else
- return false;
-#endif
}
bool
ForkJoinSlice::InitializeTLS()
{
-#ifdef JS_THREADSAFE
if (!TLSInitialized) {
TLSInitialized = true;
PRStatus status = PR_NewThreadPrivateIndex(&ThreadPrivateIndex, NULL);
return status == PR_SUCCESS;
}
return true;
-#else
- return true;
-#endif
}
void
ForkJoinSlice::requestGC(gcreason::Reason reason)
{
-#ifdef JS_THREADSAFE
shared->requestGC(reason);
triggerAbort();
-#endif
}
void
ForkJoinSlice::requestZoneGC(JS::Zone *zone, gcreason::Reason reason)
{
-#ifdef JS_THREADSAFE
shared->requestZoneGC(zone, reason);
triggerAbort();
-#endif
}
-#ifdef JS_THREADSAFE
void
ForkJoinSlice::triggerAbort()
{
shared->setAbortFlag(false);
// set iontracklimit to -1 so that on next entry to a function,
// the thread will trigger the overrecursedcheck. If the thread
// is in a loop, then it will be calling ForkJoinSlice::check(),
// in which case it will notice the shared abort_ flag.
//
// In principle, we probably ought to set the ionStackLimit's for
// the other threads too, but right now the various slice objects
// are not on a central list so that's not possible.
perThreadData->ionStackLimit = -1;
}
-#endif
/////////////////////////////////////////////////////////////////////////////
namespace js {
class AutoEnterParallelSection
{
private:
JSContext *cx_;
@@ -607,37 +583,82 @@ class AutoEnterParallelSection
cx_->runtime->mainThread.ionTop = prevIonTop_;
}
};
} /* namespace js */
uint32_t
js::ForkJoinSlices(JSContext *cx)
{
-#ifndef JS_THREADSAFE
- return 1;
-#else
// Parallel workers plus this main thread.
return cx->runtime->threadPool.numWorkers() + 1;
-#endif
}
ParallelResult
js::ExecuteForkJoinOp(JSContext *cx, ForkJoinOp &op)
{
-#ifdef JS_THREADSAFE
// Recursive use of the ThreadPool is not supported.
JS_ASSERT(!InParallelSection());
AutoEnterParallelSection enter(cx);
ThreadPool *threadPool = &cx->runtime->threadPool;
uint32_t numSlices = ForkJoinSlices(cx);
ForkJoinShared shared(cx, threadPool, op, numSlices, numSlices - 1);
if (!shared.init())
return TP_RETRY_SEQUENTIALLY;
return shared.execute();
+}
+
#else
+
+bool
+ForkJoinSlice::isMainThread()
+{
+ return true;
+}
+
+JSRuntime *
+ForkJoinSlice::runtime()
+{
+ return NULL;
+}
+
+bool
+ForkJoinSlice::check()
+{
+ return false;
+}
+
+bool
+ForkJoinSlice::InitializeTLS()
+{
+ return true;
+}
+
+void
+ForkJoinSlice::requestGC(gcreason::Reason reason)
+{
+ JS_NOT_REACHED("No threadsafe, no ion");
+}
+
+void
+ForkJoinSlice::requestZoneGC(JS::Zone *zone, gcreason::Reason reason)
+{
+ JS_NOT_REACHED("No threadsafe, no ion");
+}
+
+uint32_t
+js::ForkJoinSlices(JSContext *cx)
+{
+ return 1;
+}
+
+ParallelResult
+js::ExecuteForkJoinOp(JSContext *cx, ForkJoinOp &op)
+{
return TP_RETRY_SEQUENTIALLY;
-#endif
}
+
+#endif // defined(JS_THREADSAFE) && defined(JS_ION)
+
--- a/js/src/vm/ForkJoin.h
+++ b/js/src/vm/ForkJoin.h
@@ -202,23 +202,23 @@ struct ForkJoinSlice
// Initializes the thread-local state.
static bool InitializeTLS();
private:
friend class AutoRendezvous;
friend class AutoSetForkJoinSlice;
-#ifdef JS_THREADSAFE
+#if defined(JS_THREADSAFE) && defined(JS_ION)
// Initialized by InitializeTLS()
static unsigned ThreadPrivateIndex;
static bool TLSInitialized;
#endif
-#ifdef JS_THREADSAFE
+#if defined(JS_THREADSAFE) && defined(JS_ION)
// Sets the abort flag and adjusts ionStackLimit so as to cause
// the overrun check to fail. This should lead to the operation
// as a whole aborting.
void triggerAbort();
#endif
ForkJoinShared *const shared;
};
@@ -241,16 +241,16 @@ InParallelSection()
return ForkJoinSlice::Current() != NULL;
}
} // namespace js
/* static */ inline js::ForkJoinSlice *
js::ForkJoinSlice::Current()
{
-#ifdef JS_THREADSAFE
+#if defined(JS_THREADSAFE) && defined(JS_ION)
return (ForkJoinSlice*) PR_GetThreadPrivate(ThreadPrivateIndex);
#else
return NULL;
#endif
}
#endif // ForkJoin_h__