From 304fdd6a5e70253a06e1ef3264a0aac1f55e6952 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Tue, 8 Oct 2013 15:14:03 -0700 Subject: [PATCH] Bug 903193 - Part 2: Refactor isThreadLocal to ThreadSafeContext. (r=bhackett) --- js/src/jit/ParallelFunctions.cpp | 3 +-- js/src/jit/ParallelFunctions.h | 4 ++-- js/src/jscntxt.h | 3 +++ js/src/jsgcinlines.h | 21 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/js/src/jit/ParallelFunctions.cpp b/js/src/jit/ParallelFunctions.cpp index b16ff5d3995..436364030af 100644 --- a/js/src/jit/ParallelFunctions.cpp +++ b/js/src/jit/ParallelFunctions.cpp @@ -43,8 +43,7 @@ bool jit::IsThreadLocalObject(ForkJoinSlice *slice, JSObject *object) { JS_ASSERT(ForkJoinSlice::Current() == slice); - return !IsInsideNursery(slice->runtime(), object) && - slice->allocator()->arenas.containsArena(slice->runtime(), object->arenaHeader()); + return slice->isThreadLocal(object); } #ifdef DEBUG diff --git a/js/src/jit/ParallelFunctions.h b/js/src/jit/ParallelFunctions.h index 8096c63b950..2fc36b84224 100644 --- a/js/src/jit/ParallelFunctions.h +++ b/js/src/jit/ParallelFunctions.h @@ -15,9 +15,9 @@ namespace jit { ForkJoinSlice *ForkJoinSlicePar(); JSObject *NewGCThingPar(ForkJoinSlice *slice, gc::AllocKind allocKind); -bool IsThreadLocalObject(ForkJoinSlice *context, JSObject *object); +bool IsThreadLocalObject(ForkJoinSlice *slice, JSObject *object); bool CheckOverRecursedPar(ForkJoinSlice *slice); -bool CheckInterruptPar(ForkJoinSlice *context); +bool CheckInterruptPar(ForkJoinSlice *slice); // We pass the arguments to PushPar in a structure because, in code // gen, it is convenient to store them on the stack to avoid diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 023d8ad748f..b43245f8904 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -248,6 +248,9 @@ struct ThreadSafeContext : ContextFriendFields, return thing->compartment() == compartment_; } + template + inline bool isThreadLocal(T thing) const; + void *onOutOfMemory(void *p, size_t nbytes) { return runtime_->onOutOfMemory(p, nbytes, maybeJSContext()); } diff --git a/js/src/jsgcinlines.h b/js/src/jsgcinlines.h index 44e2c8ec28b..abab06b00ad 100644 --- a/js/src/jsgcinlines.h +++ b/js/src/jsgcinlines.h @@ -49,6 +49,27 @@ ThreadSafeContext::allocator() return allocator_; } +template +inline bool +ThreadSafeContext::isThreadLocal(T thing) const +{ + if (!isForkJoinSlice()) + return true; + + if (!IsInsideNursery(runtime_, thing) && + allocator_->arenas.containsArena(runtime_, thing->arenaHeader())) + { + // GC should be suppressed in preparation for mutating thread local + // objects, as we don't want to trip any barriers. + JS_ASSERT(!thing->zoneFromAnyThread()->needsBarrier()); + JS_ASSERT(!thing->runtimeFromAnyThread()->needsBarrier()); + + return true; + } + + return false; +} + namespace gc { static inline AllocKind