Bug 903193 - Part 2: Refactor isThreadLocal to ThreadSafeContext. (r=bhackett)
authorShu-yu Guo <shu@rfrn.org>
Tue, 08 Oct 2013 15:14:03 -0700
changeset 150126 4941a43066c5c16e906b49e626b179bc39d22bac
parent 150125 fb5785358e6322dbe8236535187b790207e7cd24
child 150127 b3b4142a3ecbeda7b8b111f73f7cc76b0d16cefb
push id25423
push usercbook@mozilla.com
push dateWed, 09 Oct 2013 08:10:49 +0000
treeherdermozilla-central@2a8a173a0ae1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs903193
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 903193 - Part 2: Refactor isThreadLocal to ThreadSafeContext. (r=bhackett)
js/src/jit/ParallelFunctions.cpp
js/src/jit/ParallelFunctions.h
js/src/jscntxt.h
js/src/jsgcinlines.h
--- a/js/src/jit/ParallelFunctions.cpp
+++ b/js/src/jit/ParallelFunctions.cpp
@@ -38,18 +38,17 @@ jit::NewGCThingPar(ForkJoinSlice *slice,
 }
 
 // Check that the object was created by the current thread
 // (and hence is writable).
 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
 static void
 printTrace(const char *prefix, struct IonLIRTraceData *cached)
 {
     fprintf(stderr, "%s / Block %3u / LIR %3u / Mode %u / LIR %s\n",
             prefix,
--- a/js/src/jit/ParallelFunctions.h
+++ b/js/src/jit/ParallelFunctions.h
@@ -10,19 +10,19 @@
 #include "gc/Heap.h"
 #include "vm/ForkJoin.h"
 
 namespace js {
 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
 // constraining the reg alloc for the slow path.
 struct PushParArgs {
     JSObject *object;
     Value value;
 };
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -243,16 +243,19 @@ struct ThreadSafeContext : ContextFriend
         return thing->zoneFromAnyThread() == zone_;
     }
 
     template <typename T>
     inline bool isInsideCurrentCompartment(T thing) const {
         return thing->compartment() == compartment_;
     }
 
+    template <typename T>
+    inline bool isThreadLocal(T thing) const;
+
     void *onOutOfMemory(void *p, size_t nbytes) {
         return runtime_->onOutOfMemory(p, nbytes, maybeJSContext());
     }
 
     inline void updateMallocCounter(size_t nbytes) {
         // Note: this is racy.
         runtime_->updateMallocCounter(zone_, nbytes);
     }
--- a/js/src/jsgcinlines.h
+++ b/js/src/jsgcinlines.h
@@ -44,16 +44,37 @@ struct AutoMarkInDeadZone
 
 inline Allocator *const
 ThreadSafeContext::allocator()
 {
     JS_ASSERT_IF(isJSContext(), &asJSContext()->zone()->allocator == allocator_);
     return allocator_;
 }
 
+template <typename T>
+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
 GetGCObjectKind(const Class *clasp)
 {
     if (clasp == FunctionClassPtr)
         return JSFunction::FinalizeKind;
     uint32_t nslots = JSCLASS_RESERVED_SLOTS(clasp);