2011-06-15 Oliver Hunt <oliver@apple.com>
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2011 19:30:57 +0000 (19:30 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2011 19:30:57 +0000 (19:30 +0000)
        Reviewed by Geoffrey Garen.

        Reduce memory usage of resolve_global
        https://bugs.webkit.org/show_bug.cgi?id=62765

        If we have a large number of resolve_globals in a single
        block start planting plain resolve instructions instead
        whenever we aren't in a loop.  This allows us to reduce
        the code size for extremely large functions without
        losing the performance benefits of op_resolve_global.

        * bytecode/CodeBlock.h:
        (JSC::CodeBlock::globalResolveInfoCount):
        * bytecompiler/BytecodeGenerator.cpp:
        (JSC::BytecodeGenerator::shouldAvoidResolveGlobal):
        (JSC::BytecodeGenerator::emitResolve):
        (JSC::BytecodeGenerator::emitResolveWithBase):
        * bytecompiler/BytecodeGenerator.h:

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.h
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

index 608b7f1..7d29ab3 100644 (file)
@@ -1,3 +1,24 @@
+2011-06-15  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Geoffrey Garen.
+
+        Reduce memory usage of resolve_global
+        https://bugs.webkit.org/show_bug.cgi?id=62765
+
+        If we have a large number of resolve_globals in a single
+        block start planting plain resolve instructions instead 
+        whenever we aren't in a loop.  This allows us to reduce
+        the code size for extremely large functions without
+        losing the performance benefits of op_resolve_global.
+
+        * bytecode/CodeBlock.h:
+        (JSC::CodeBlock::globalResolveInfoCount):
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::shouldAvoidResolveGlobal):
+        (JSC::BytecodeGenerator::emitResolve):
+        (JSC::BytecodeGenerator::emitResolveWithBase):
+        * bytecompiler/BytecodeGenerator.h:
+
 2011-06-16  Qi Zhang  <qi.2.zhang@nokia.com>
 
         Reviewed by Laszlo Gombos.
index c271415..92cafd1 100644 (file)
@@ -372,6 +372,14 @@ namespace JSC {
         void addMethodCallLinkInfos(unsigned n) { m_methodCallLinkInfos.grow(n); }
         MethodCallLinkInfo& methodCallLinkInfo(int index) { return m_methodCallLinkInfos[index]; }
 #endif
+        unsigned globalResolveInfoCount() const
+        {
+#if ENABLE(JIT)    
+            if (m_globalData->canUseJIT())
+                return m_globalResolveInfos.size();
+#endif
+            return 0;
+        }
 
         // Exception handling support
 
index b53544c..efc35c2 100644 (file)
@@ -1201,6 +1201,13 @@ RegisterID* BytecodeGenerator::emitInstanceOf(RegisterID* dst, RegisterID* value
     return dst;
 }
 
+static const unsigned maxGlobalResolves = 128;
+
+bool BytecodeGenerator::shouldAvoidResolveGlobal()
+{
+    return m_codeBlock->globalResolveInfoCount() > maxGlobalResolves && !m_labelScopes.size();
+}
+
 RegisterID* BytecodeGenerator::emitResolve(RegisterID* dst, const Identifier& property)
 {
     size_t depth = 0;
@@ -1214,7 +1221,11 @@ RegisterID* BytecodeGenerator::emitResolve(RegisterID* dst, const Identifier& pr
         instructions().append(addConstant(property));
         return dst;
     }
-
+    if (shouldAvoidResolveGlobal()) {
+        globalObject = 0;
+        requiresDynamicChecks = true;
+    }
+        
     if (globalObject) {
         bool forceGlobalResolve = false;
 
@@ -1363,7 +1374,12 @@ RegisterID* BytecodeGenerator::emitResolveWithBase(RegisterID* baseDst, Register
         emitGetScopedVar(propDst, depth, index, globalObject);
         return baseDst;
     }
-
+    if (shouldAvoidResolveGlobal()) {
+        emitOpcode(op_resolve);
+        instructions().append(propDst->index());
+        instructions().append(addConstant(property));
+        return baseDst;
+    }
 #if ENABLE(JIT)
     m_codeBlock->addGlobalResolveInfo(instructions().size());
 #endif
index 608e854..4daa198 100644 (file)
@@ -459,6 +459,7 @@ namespace JSC {
         void addParameter(const Identifier&, int parameterIndex);
         
         void preserveLastVar();
+        bool shouldAvoidResolveGlobal();
 
         RegisterID& registerFor(int index)
         {