Backed out changeset 0d90de935ba3 (bug 869740) for mochitest-1 shutdown crashes.
authorRyan VanderMeulen <ryanvm@gmail.com>
Fri, 10 May 2013 13:52:03 -0400
changeset 142554 82ab6b5d0c036fc2f347d99f00a9621e76f36fc9
parent 142553 f908d830e4c8b36d5827369213e4ee5f94df52b9
child 142555 e7ca39ff01cc55c1868387d271365f756b4d8ee7
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs869740
milestone23.0a1
backs out0d90de935ba3db467adfe681a2d5c638fc055708
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
Backed out changeset 0d90de935ba3 (bug 869740) for mochitest-1 shutdown crashes.
js/xpconnect/src/XPCCallContext.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCCallContext.cpp
+++ b/js/xpconnect/src/XPCCallContext.cpp
@@ -32,53 +32,44 @@ XPCCallContext::XPCCallContext(XPCContex
         mCallerLanguage(callerLanguage),
         mScopeForNewJSObjects(cx),
         mFlattenedJSObject(cx),
         mWrapper(nullptr),
         mTearOff(nullptr),
         mName(cx)
 {
     MOZ_ASSERT(cx);
-    Init(callerLanguage == NATIVE_CALLER, obj, funobj,
+    Init(callerLanguage, callerLanguage == NATIVE_CALLER, obj, funobj,
          INIT_SHOULD_LOOKUP_WRAPPER, name, argc, argv, rval);
 }
 
-XPCCallContext::XPCCallContext(JSContext *cx)
+XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage,
+                               JSContext* cx,
+                               JSBool callBeginRequest,
+                               HandleObject obj,
+                               HandleObject flattenedJSObject,
+                               XPCWrappedNative* wrapper,
+                               XPCWrappedNativeTearOff* tearOff)
     :   mState(INIT_FAILED),
         mXPC(nsXPConnect::GetXPConnect()),
         mXPCContext(nullptr),
         mJSContext(cx),
         mContextPopRequired(false),
         mDestroyJSContextInDestructor(false),
-        mCallerLanguage(XPCContext::LANG_UNKNOWN),
+        mCallerLanguage(callerLanguage),
         mScopeForNewJSObjects(cx),
-        mFlattenedJSObject(cx),
+        mFlattenedJSObject(cx, flattenedJSObject),
+        mWrapper(wrapper),
+        mTearOff(tearOff),
         mName(cx)
 {
-    // Called from XPCLazyCallContext only.
-    MOZ_ASSERT(mJSContext);
-}
-
-void
-XPCCallContext::LazyInit(XPCContext::LangType callerLanguage,
-                         JSBool callBeginRequest,
-                         HandleObject obj,
-                         HandleObject flattenedJSObject,
-                         XPCWrappedNative* wrapper,
-                         XPCWrappedNativeTearOff* tearOff)
-{
-    // Called from XPCLazyCallContext only.
-    MOZ_ASSERT(mState == INIT_FAILED);
-    MOZ_ASSERT(mJSContext);
-    mCallerLanguage = callerLanguage;
-    mFlattenedJSObject = flattenedJSObject;
-    mWrapper = wrapper;
-    mTearOff = tearOff;
-    Init(callBeginRequest, obj, NullPtr(), WRAPPER_PASSED_TO_CONSTRUCTOR,
-         JSID_VOIDHANDLE, NO_ARGS, nullptr, nullptr);
+    MOZ_ASSERT(cx);
+    Init(callerLanguage, callBeginRequest, obj, NullPtr(),
+         WRAPPER_PASSED_TO_CONSTRUCTOR, JSID_VOIDHANDLE, NO_ARGS,
+         nullptr, nullptr);
 }
 
 #define IS_TEAROFF_CLASS(clazz) ((clazz) == &XPC_WN_Tearoff_JSClass)
 
 
 // static
 JSContext *
 XPCCallContext::GetDefaultJSContext()
@@ -93,17 +84,18 @@ XPCCallContext::GetDefaultJSContext()
 
     XPCJSContextStack* stack = XPCJSRuntime::Get()->GetJSContextStack();
     JSContext *topJSContext = stack->Peek();
 
     return topJSContext ? topJSContext : stack->GetSafeJSContext();
 }
 
 void
-XPCCallContext::Init(JSBool callBeginRequest,
+XPCCallContext::Init(XPCContext::LangType callerLanguage,
+                     JSBool callBeginRequest,
                      HandleObject obj,
                      HandleObject funobj,
                      WrapperInitOptions wrapperInitOptions,
                      HandleId name,
                      unsigned argc,
                      jsval *argv,
                      jsval *rval)
 {
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1209,39 +1209,32 @@ public:
     operator JSContext*() const {return GetJSContext();}
 
 private:
 
     // no copy ctor or assignment allowed
     XPCCallContext(const XPCCallContext& r); // not implemented
     XPCCallContext& operator= (const XPCCallContext& r); // not implemented
 
-    // The following are for construction from XPCLazyCallContext. Delay doing
-    // the initialization work until we know that the XPCCallContext will
-    // actually be needed, but still eagerly construct the overall
-    // XPCCallContext because it contains Rooted<T> fields that must be
-    // destroyed in LIFO order. An XPCCallContext will always push its
-    // Rooted<T>'s onto the stack upon construction, and then pop them off in
-    // LIFO order during its destruction, regardless of whether LazyInit ever
-    // gets called.
     friend class XPCLazyCallContext;
-    XPCCallContext(JSContext *cx);
-    void LazyInit(XPCContext::LangType callerLanguage,
-                  JSBool callBeginRequest,
-                  JS::HandleObject obj,
-                  JS::HandleObject flattenedJSObject,
-                  XPCWrappedNative* wn,
-                  XPCWrappedNativeTearOff* tearoff);
+    XPCCallContext(XPCContext::LangType callerLanguage,
+                   JSContext* cx,
+                   JSBool callBeginRequest,
+                   JS::HandleObject obj,
+                   JS::HandleObject flattenedJSObject,
+                   XPCWrappedNative* wn,
+                   XPCWrappedNativeTearOff* tearoff);
 
     enum WrapperInitOptions {
         WRAPPER_PASSED_TO_CONSTRUCTOR,
         INIT_SHOULD_LOOKUP_WRAPPER
     };
 
-    void Init(JSBool callBeginRequest,
+    void Init(XPCContext::LangType callerLanguage,
+              JSBool callBeginRequest,
               JS::HandleObject obj,
               JS::HandleObject funobj,
               WrapperInitOptions wrapperInitOptions,
               JS::HandleId name,
               unsigned argc,
               jsval *argv,
               jsval *rval);
 
@@ -1325,37 +1318,28 @@ public:
     XPCLazyCallContext(XPCContext::LangType callerLanguage, JSContext* cx,
                        JSObject* obj = nullptr,
                        JSObject* flattenedJSObject = nullptr,
                        XPCWrappedNative* wrapper = nullptr,
                        XPCWrappedNativeTearOff* tearoff = nullptr)
         : mCallBeginRequest(callerLanguage == NATIVE_CALLER ?
                             CALL_BEGINREQUEST : DONT_CALL_BEGINREQUEST),
           mCcx(nullptr),
+          mCcxToDestroy(nullptr),
           mCx(cx),
           mCallerLanguage(callerLanguage),
           mObj(cx, obj),
           mFlattenedJSObject(cx, flattenedJSObject),
           mWrapper(wrapper),
           mTearOff(tearoff)
     {
         NS_ASSERTION(cx, "Need a JS context!");
         NS_ASSERTION(callerLanguage == NATIVE_CALLER ||
                      callerLanguage == JS_CALLER,
                      "Can't deal with unknown caller language!");
-        // Construct with placement new to allow for the other constructor,
-        // which accepts an existing XPCCallContext to use. This constructed
-        // XPCCallContext may never be needed, in which case its LazyInit will
-        // not be invoked, but it must be eagerly constructed here in order to
-        // maintain LIFO order of its Rooted<T> fields and the ones contained
-        // in XPCLazyCallContext. (If its construction were delayed, then any
-        // Rooted<T> created in between the construction of XPCLazyCallContext
-        // and the LazyInit call would not get destroyed during
-        // ~XPCLazyCallContext and therefore would not follow LIFO ordering.)
-        mCcxToDestroy = new (mData.addr()) XPCCallContext(mCx);
 #ifdef DEBUG
         AssertContextIsTopOfStack(cx);
 #endif
     }
     ~XPCLazyCallContext()
     {
         if (mCcxToDestroy)
             mCcxToDestroy->~XPCCallContext();
@@ -1399,25 +1383,26 @@ public:
         if (mCcx)
             return mCcx->GetFlattenedJSObject();
 
         return xpc_UnmarkGrayObject(mFlattenedJSObject);
     }
     XPCCallContext &GetXPCCallContext()
     {
         if (!mCcx) {
+            XPCCallContext *data = mData.addr();
             xpc_UnmarkGrayObject(mObj);
             xpc_UnmarkGrayObject(mFlattenedJSObject);
-            mCcxToDestroy = mCcx = mData.addr();
-            mCcx->LazyInit(mCallerLanguage,
-                           mCallBeginRequest == CALL_BEGINREQUEST,
-                           mObj,
-                           mFlattenedJSObject,
-                           mWrapper,
-                           mTearOff);
+            mCcxToDestroy = mCcx =
+                new (data) XPCCallContext(mCallerLanguage, mCx,
+                                          mCallBeginRequest == CALL_BEGINREQUEST,
+                                          mObj,
+                                          mFlattenedJSObject,
+                                          mWrapper,
+                                          mTearOff);
             if (!mCcx->IsValid()) {
                 NS_ERROR("This is not supposed to fail!");
             }
         }
 
         return *mCcx;
     }