Bug 887334 - Use the new AutoCompartment overload for the atoms compartment and remove AutoEnterAtomsCompartment. r=bhackett
authorBobby Holley <bobbyholley@gmail.com>
Wed, 17 Jul 2013 11:53:52 -0700
changeset 138957 d09d109a7e88f753da58e2e427bdbb7f5fea093a
parent 138956 e8125c01b1b0e27bd4ca773053fb623b1dc18a0c
child 138958 4f4167826bc2e2ed20ea7a3bf53a345e1668313a
push id24977
push userryanvm@gmail.com
push dateFri, 19 Jul 2013 00:35:38 +0000
treeherdermozilla-central@0d0263a58f06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs887334
milestone25.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 887334 - Use the new AutoCompartment overload for the atoms compartment and remove AutoEnterAtomsCompartment. r=bhackett We have to do some temporary hackiness to deal with some of the new PJS work. This patch stays as true to the old world as possible, so that we can more easily backport it.
js/src/ion/Ion.cpp
js/src/jsatom.cpp
js/src/jscompartment.h
js/src/jscompartmentinlines.h
js/src/vm/String.cpp
--- a/js/src/ion/Ion.cpp
+++ b/js/src/ion/Ion.cpp
@@ -188,17 +188,17 @@ IonRuntime::~IonRuntime()
 {
     js_delete(functionWrappers_);
     freeOsrTempData();
 }
 
 bool
 IonRuntime::initialize(JSContext *cx)
 {
-    AutoEnterAtomsCompartment ac(cx);
+    AutoCompartment ac(cx, cx->runtime()->atomsCompartment);
 
     IonContext ictx(cx, NULL);
     AutoFlushCache afc("IonRuntime::initialize");
 
     execAlloc_ = cx->runtime()->getExecAlloc(cx);
     if (!execAlloc_)
         return false;
 
@@ -272,17 +272,17 @@ IonRuntime::initialize(JSContext *cx)
 }
 
 IonCode *
 IonRuntime::debugTrapHandler(JSContext *cx)
 {
     if (!debugTrapHandler_) {
         // IonRuntime code stubs are shared across compartments and have to
         // be allocated in the atoms compartment.
-        AutoEnterAtomsCompartment ac(cx);
+        AutoCompartment ac(cx, cx->runtime()->atomsCompartment);
         debugTrapHandler_ = generateDebugTrapHandler(cx);
     }
     return debugTrapHandler_;
 }
 
 uint8_t *
 IonRuntime::allocateOsrTempData(size_t size)
 {
--- a/js/src/jsatom.cpp
+++ b/js/src/jsatom.cpp
@@ -253,17 +253,17 @@ AtomizeAndTakeOwnership(ExclusiveContext
     SkipRoot skipHash(cx, &p); /* Prevent the hash from being poisoned. */
     if (p) {
         JSAtom *atom = p->asPtr();
         p->setTagged(bool(ib));
         js_free(tbchars);
         return atom;
     }
 
-    AutoEnterAtomsCompartment ac(cx);
+    AutoCompartment ac(cx, cx->asJSContext()->runtime()->atomsCompartment);
 
     JSFlatString *flat = js_NewString<CanGC>(cx, tbchars, length);
     if (!flat) {
         js_free(tbchars);
         return NULL;
     }
 
     JSAtom *atom = flat->morphAtomizedStringIntoAtom();
@@ -297,17 +297,17 @@ AtomizeAndCopyChars(ExclusiveContext *cx
     AtomSet::AddPtr p = atoms.lookupForAdd(AtomHasher::Lookup(tbchars, length));
     SkipRoot skipHash(cx, &p); /* Prevent the hash from being poisoned. */
     if (p) {
         JSAtom *atom = p->asPtr();
         p->setTagged(bool(ib));
         return atom;
     }
 
-    AutoEnterAtomsCompartment ac(cx);
+    AutoCompartment ac(cx, cx->asJSContext()->runtime()->atomsCompartment);
 
     JSFlatString *flat = js_NewStringCopyN<allowGC>(cx, tbchars, length);
     if (!flat)
         return NULL;
 
     JSAtom *atom = flat->morphAtomizedStringIntoAtom();
 
     if (!atoms.relookupOrAdd(p, AtomHasher::Lookup(tbchars, length),
--- a/js/src/jscompartment.h
+++ b/js/src/jscompartment.h
@@ -455,17 +455,17 @@ class AssertCompartmentUnchanged
 
 class AutoCompartment
 {
     JSContext * const cx_;
     JSCompartment * const origin_;
 
   public:
     inline AutoCompartment(JSContext *cx, JSObject *target);
-    inline AutoCompartment(JSContext *cx, JSCompartment *target);
+    inline AutoCompartment(ExclusiveContext *cx, JSCompartment *target);
     inline ~AutoCompartment();
 
     JSContext *context() const { return cx_; }
     JSCompartment *origin() const { return origin_; }
 
   private:
     AutoCompartment(const AutoCompartment &) MOZ_DELETE;
     AutoCompartment & operator=(const AutoCompartment &) MOZ_DELETE;
--- a/js/src/jscompartmentinlines.h
+++ b/js/src/jscompartmentinlines.h
@@ -28,51 +28,21 @@ JSCompartment::maybeGlobal() const
 
 js::AutoCompartment::AutoCompartment(JSContext *cx, JSObject *target)
   : cx_(cx),
     origin_(cx->compartment())
 {
     cx_->enterCompartment(target->compartment());
 }
 
-js::AutoCompartment::AutoCompartment(JSContext *cx, JSCompartment *target)
-  : cx_(cx),
-    origin_(cx->compartment())
+js::AutoCompartment::AutoCompartment(ExclusiveContext *cx, JSCompartment *target)
+  : cx_(cx->asJSContext()),
+    origin_(cx_->compartment())
 {
     cx_->enterCompartment(target);
 }
 
 js::AutoCompartment::~AutoCompartment()
 {
     cx_->leaveCompartment(origin_);
 }
 
-namespace js {
-
-/*
- * Entering the atoms compartment is not possible with AutoCompartment
- * since the atoms compartment does not have a global.
- *
- * Note: since most of the VM assumes that cx->global is non-null, only a
- * restricted set of (atom creating/destroying) operations may be used from
- * inside the atoms compartment.
- */
-class AutoEnterAtomsCompartment
-{
-    ExclusiveContext *cx;
-    JSCompartment *oldCompartment;
-  public:
-    AutoEnterAtomsCompartment(ExclusiveContext *cx)
-      : cx(cx),
-        oldCompartment(cx->compartment_)
-    {
-        cx->privateSetCompartment(cx->runtime_->atomsCompartment);
-    }
-
-    ~AutoEnterAtomsCompartment()
-    {
-        cx->privateSetCompartment(oldCompartment);
-    }
-};
-
-} /* namespace js */
-
 #endif /* jscompartmentinlines_h */
--- a/js/src/vm/String.cpp
+++ b/js/src/vm/String.cpp
@@ -653,17 +653,17 @@ ScopedThreadSafeStringInspector::ensureC
 
 #define R TO_SMALL_CHAR
 const StaticStrings::SmallChar StaticStrings::toSmallChar[] = { R7(0) };
 #undef R
 
 bool
 StaticStrings::init(JSContext *cx)
 {
-    AutoEnterAtomsCompartment ac(cx);
+    AutoCompartment ac(cx, cx->runtime()->atomsCompartment);
 
     for (uint32_t i = 0; i < UNIT_STATIC_LIMIT; i++) {
         jschar buffer[] = { jschar(i), '\0' };
         JSFlatString *s = js_NewStringCopyN<CanGC>(cx, buffer, 1);
         if (!s)
             return false;
         unitStaticTable[i] = s->morphAtomizedStringIntoAtom();
     }