Pass VM instead of JSGlobalObject to RegExp constructor.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2013 18:58:51 +0000 (18:58 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2013 18:58:51 +0000 (18:58 +0000)
<https://webkit.org/b/122113>

Reviewed by Darin Adler.

RegExps don't need anything from the global object during their
construction and only use it to get to the VM. Reduce loads by
simply passing the VM around instead.

JSC release binary size -= 120 bytes(!)

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156668 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/dfg/DFGOperations.cpp
Source/JavaScriptCore/jit/JITStubs.cpp
Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/RegExpConstructor.cpp
Source/JavaScriptCore/runtime/RegExpObject.cpp
Source/JavaScriptCore/runtime/RegExpObject.h
Source/JavaScriptCore/runtime/RegExpPrototype.cpp
Source/JavaScriptCore/runtime/RegExpPrototype.h
Source/WebCore/bindings/js/SerializedScriptValue.cpp

index e5eda24..36b4fcd 100644 (file)
@@ -1,3 +1,16 @@
+2013-09-30  Andreas Kling  <akling@apple.com>
+
+        Pass VM instead of JSGlobalObject to RegExp constructor.
+        <https://webkit.org/b/122113>
+
+        Reviewed by Darin Adler.
+
+        RegExps don't need anything from the global object during their
+        construction and only use it to get to the VM. Reduce loads by
+        simply passing the VM around instead.
+
+        JSC release binary size -= 120 bytes(!)
+
 2013-09-30  Patrick Gansterer  <paroga@webkit.org>
 
         Fix compilation for COMPILER(MSVC) && !CPU(X86) after r156490.
index 7241373..cfd6292 100644 (file)
@@ -751,11 +751,11 @@ EncodedJSValue JIT_OPERATION operationNewRegexp(ExecState* exec, void* regexpPtr
     NativeCallFrameTracer tracer(&vm, exec);
     RegExp* regexp = static_cast<RegExp*>(regexpPtr);
     if (!regexp->isValid()) {
-        exec->vm().throwException(exec, createSyntaxError(exec, "Invalid flags supplied to RegExp constructor."));
+        vm.throwException(exec, createSyntaxError(exec, "Invalid flags supplied to RegExp constructor."));
         return JSValue::encode(jsUndefined());
     }
     
-    return JSValue::encode(RegExpObject::create(exec->vm(), exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->regExpStructure(), regexp));
+    return JSValue::encode(RegExpObject::create(vm, exec->lexicalGlobalObject()->regExpStructure(), regexp));
 }
 
 JSCell* JIT_OPERATION operationCreateActivation(ExecState* exec)
index dea6a47..eefdc66 100644 (file)
@@ -1948,7 +1948,7 @@ DEFINE_STUB_FUNCTION(JSObject*, op_new_regexp)
         VM_THROW_EXCEPTION();
     }
 
-    return RegExpObject::create(*stackFrame.vm, stackFrame.callFrame->lexicalGlobalObject(), stackFrame.callFrame->lexicalGlobalObject()->regExpStructure(), regExp);
+    return RegExpObject::create(*stackFrame.vm, stackFrame.callFrame->lexicalGlobalObject()->regExpStructure(), regExp);
 }
 
 DEFINE_STUB_FUNCTION(EncodedJSValue, op_call_eval)
index 930ffa3..616c0f6 100644 (file)
@@ -476,7 +476,7 @@ LLINT_SLOW_PATH_DECL(slow_path_new_regexp)
     RegExp* regExp = exec->codeBlock()->regexp(pc[2].u.operand);
     if (!regExp->isValid())
         LLINT_THROW(createSyntaxError(exec, "Invalid flag supplied to RegExp constructor."));
-    LLINT_RETURN(RegExpObject::create(vm, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->regExpStructure(), regExp));
+    LLINT_RETURN(RegExpObject::create(vm, exec->lexicalGlobalObject()->regExpStructure(), regExp));
 }
 
 LLINT_SLOW_PATH_DECL(slow_path_check_has_instance)
index 4e08985..c416ed2 100644 (file)
@@ -298,7 +298,7 @@ void JSGlobalObject::reset(JSValue prototype)
 
     RegExp* emptyRegex = RegExp::create(vm, "", NoFlags);
     
-    m_regExpPrototype.set(vm, this, RegExpPrototype::create(exec, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex));
+    m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex));
     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
 
 #if ENABLE(PROMISES)
index 32a4c5b..6756011 100644 (file)
@@ -260,7 +260,7 @@ JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const A
         // If called as a function, this just returns the first argument (see 15.10.3.1).
         if (callAsConstructor) {
             RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp();
-            return RegExpObject::create(exec, globalObject, globalObject->regExpStructure(), regExp);
+            return RegExpObject::create(exec->vm(), globalObject->regExpStructure(), regExp);
         }
         return asObject(arg0);
     }
@@ -278,10 +278,11 @@ JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const A
             return exec->vm().throwException(exec, createSyntaxError(exec, ASCIILiteral("Invalid flags supplied to RegExp constructor.")));
     }
 
-    RegExp* regExp = RegExp::create(exec->vm(), pattern, flags);
+    VM& vm = exec->vm();
+    RegExp* regExp = RegExp::create(vm, pattern, flags);
     if (!regExp->isValid())
-        return exec->vm().throwException(exec, createSyntaxError(exec, regExp->errorMessage()));
-    return RegExpObject::create(exec, exec->lexicalGlobalObject(), globalObject->regExpStructure(), regExp);
+        return vm.throwException(exec, createSyntaxError(exec, regExp->errorMessage()));
+    return RegExpObject::create(vm, globalObject->regExpStructure(), regExp);
 }
 
 static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
index 148779b..ccea708 100644 (file)
@@ -63,17 +63,17 @@ const ClassInfo RegExpObject::s_info = { "RegExp", &Base::s_info, 0, ExecState::
 @end
 */
 
-RegExpObject::RegExpObject(JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
-    : JSNonFinalObject(globalObject->vm(), structure)
-    , m_regExp(globalObject->vm(), this, regExp)
+RegExpObject::RegExpObject(VM& vm, Structure* structure, RegExp* regExp)
+    : JSNonFinalObject(vm, structure)
+    , m_regExp(vm, this, regExp)
     , m_lastIndexIsWritable(true)
 {
     m_lastIndex.setWithoutWriteBarrier(jsNumber(0));
 }
 
-void RegExpObject::finishCreation(JSGlobalObject* globalObject)
+void RegExpObject::finishCreation(VM& vm)
 {
-    Base::finishCreation(globalObject->vm());
+    Base::finishCreation(vm);
     ASSERT(inherits(info()));
 }
 
index 7b8e4a6..2b49ba2 100644 (file)
@@ -30,17 +30,10 @@ namespace JSC {
     public:
         typedef JSNonFinalObject Base;
 
-        static RegExpObject* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
+        static RegExpObject* create(VM& vm, Structure* structure, RegExp* regExp)
         {
-            RegExpObject* object = new (NotNull, allocateCell<RegExpObject>(*exec->heap())) RegExpObject(globalObject, structure, regExp);
-            object->finishCreation(globalObject);
-            return object;
-        }
-        
-        static RegExpObject* create(VM& vm, JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
-        {
-            RegExpObject* object = new (NotNull, allocateCell<RegExpObject>(vm.heap)) RegExpObject(globalObject, structure, regExp);
-            object->finishCreation(globalObject);
+            RegExpObject* object = new (NotNull, allocateCell<RegExpObject>(vm.heap)) RegExpObject(vm, structure, regExp);
+            object->finishCreation(vm);
             return object;
         }
 
@@ -81,8 +74,8 @@ namespace JSC {
         }
 
     protected:
-        JS_EXPORT_PRIVATE RegExpObject(JSGlobalObject*, Structure*, RegExp*);
-        JS_EXPORT_PRIVATE void finishCreation(JSGlobalObject*);
+        JS_EXPORT_PRIVATE RegExpObject(VM&, Structure*, RegExp*);
+        JS_EXPORT_PRIVATE void finishCreation(VM&);
 
         static const unsigned StructureFlags = OverridesVisitChildren | OverridesGetOwnPropertySlot | Base::StructureFlags;
 
index b01f476..d4fc4da 100644 (file)
@@ -60,8 +60,8 @@ const ClassInfo RegExpPrototype::s_info = { "RegExp", &RegExpObject::s_info, 0,
 @end
 */
 
-RegExpPrototype::RegExpPrototype(JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
-    : RegExpObject(globalObject, structure, regExp)
+RegExpPrototype::RegExpPrototype(VM& vm, Structure* structure, RegExp* regExp)
+    : RegExpObject(vm, structure, regExp)
 {
 }
 
index 4ba637e..e9fef17 100644 (file)
@@ -30,10 +30,10 @@ namespace JSC {
     public:
         typedef RegExpObject Base;
 
-        static RegExpPrototype* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
+        static RegExpPrototype* create(VM& vm, Structure* structure, RegExp* regExp)
         {
-            RegExpPrototype* prototype = new (NotNull, allocateCell<RegExpPrototype>(*exec->heap())) RegExpPrototype(globalObject, structure, regExp);
-            prototype->finishCreation(globalObject);
+            RegExpPrototype* prototype = new (NotNull, allocateCell<RegExpPrototype>(vm.heap)) RegExpPrototype(vm, structure, regExp);
+            prototype->finishCreation(vm);
             return prototype;
         }
         
@@ -45,7 +45,7 @@ namespace JSC {
         }
 
     protected:
-        RegExpPrototype(JSGlobalObject*, Structure*, RegExp*);
+        RegExpPrototype(VM&, Structure*, RegExp*);
         static const unsigned StructureFlags = OverridesGetOwnPropertySlot | RegExpObject::StructureFlags;
 
     private:
index 941b72f..a77c7cf 100644 (file)
@@ -1609,8 +1609,9 @@ private:
                 return JSValue();
             RegExpFlags reFlags = regExpFlags(flags->string());
             ASSERT(reFlags != InvalidFlags);
-            RegExp* regExp = RegExp::create(m_exec->vm(), pattern->string(), reFlags);
-            return RegExpObject::create(m_exec, m_exec->lexicalGlobalObject(), m_globalObject->regExpStructure(), regExp); 
+            VM& vm = m_exec->vm();
+            RegExp* regExp = RegExp::create(vm, pattern->string(), reFlags);
+            return RegExpObject::create(vm, m_globalObject->regExpStructure(), regExp);
         }
         case ObjectReferenceTag: {
             unsigned index = 0;