Changeset 209196 in webkit


Ignore:
Timestamp:
Dec 1, 2016, 1:23:27 PM (9 years ago)
Author:
ggaren@apple.com
Message:

Removed some unnecessary indirection in code generation
https://bugs.webkit.org/show_bug.cgi?id=165264

Reviewed by Keith Miller.

There's no need to route through JSGlobalObject when producing code --
it just made the code harder to read.

This patch moves functions from JSGlobalObject to their singleton
call sites.

  • runtime/CodeCache.cpp:

(JSC::CodeCache::getUnlinkedEvalCodeBlock):
(JSC::CodeCache::getUnlinkedGlobalEvalCodeBlock): Deleted.

  • runtime/CodeCache.h:
  • runtime/DirectEvalExecutable.cpp:

(JSC::DirectEvalExecutable::create):

  • runtime/IndirectEvalExecutable.cpp:

(JSC::IndirectEvalExecutable::create):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::createProgramCodeBlock): Deleted.
(JSC::JSGlobalObject::createLocalEvalCodeBlock): Deleted.
(JSC::JSGlobalObject::createGlobalEvalCodeBlock): Deleted.
(JSC::JSGlobalObject::createModuleProgramCodeBlock): Deleted.

  • runtime/JSGlobalObject.h:
  • runtime/ModuleProgramExecutable.cpp:

(JSC::ModuleProgramExecutable::create):

  • runtime/ProgramExecutable.cpp:

(JSC::ProgramExecutable::initializeGlobalProperties):

  • runtime/ProgramExecutable.h:
Location:
trunk/Source/JavaScriptCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r209175 r209196  
     12016-12-01  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Removed some unnecessary indirection in code generation
     4        https://bugs.webkit.org/show_bug.cgi?id=165264
     5
     6        Reviewed by Keith Miller.
     7
     8        There's no need to route through JSGlobalObject when producing code --
     9        it just made the code harder to read.
     10
     11        This patch moves functions from JSGlobalObject to their singleton
     12        call sites.
     13
     14        * runtime/CodeCache.cpp:
     15        (JSC::CodeCache::getUnlinkedEvalCodeBlock):
     16        (JSC::CodeCache::getUnlinkedGlobalEvalCodeBlock): Deleted.
     17        * runtime/CodeCache.h:
     18        * runtime/DirectEvalExecutable.cpp:
     19        (JSC::DirectEvalExecutable::create):
     20        * runtime/IndirectEvalExecutable.cpp:
     21        (JSC::IndirectEvalExecutable::create):
     22        * runtime/JSGlobalObject.cpp:
     23        (JSC::JSGlobalObject::createProgramCodeBlock): Deleted.
     24        (JSC::JSGlobalObject::createLocalEvalCodeBlock): Deleted.
     25        (JSC::JSGlobalObject::createGlobalEvalCodeBlock): Deleted.
     26        (JSC::JSGlobalObject::createModuleProgramCodeBlock): Deleted.
     27        * runtime/JSGlobalObject.h:
     28        * runtime/ModuleProgramExecutable.cpp:
     29        (JSC::ModuleProgramExecutable::create):
     30        * runtime/ProgramExecutable.cpp:
     31        (JSC::ProgramExecutable::initializeGlobalProperties):
     32        * runtime/ProgramExecutable.h:
     33
    1342016-11-30  JF Bastien  <jfbastien@apple.com>
    235
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r208830 r209196  
    8686}
    8787
    88 UnlinkedEvalCodeBlock* CodeCache::getUnlinkedGlobalEvalCodeBlock(VM& vm, IndirectEvalExecutable* executable, const SourceCode& source, JSParserStrictMode strictMode, DebuggerMode debuggerMode, ParserError& error, EvalContextType evalContextType)
     88UnlinkedEvalCodeBlock* CodeCache::getUnlinkedEvalCodeBlock(VM& vm, IndirectEvalExecutable* executable, const SourceCode& source, JSParserStrictMode strictMode, DebuggerMode debuggerMode, ParserError& error, EvalContextType evalContextType)
    8989{
    9090    return getUnlinkedGlobalCodeBlock<UnlinkedEvalCodeBlock>(vm, executable, source, strictMode, JSParserScriptMode::Classic, debuggerMode, error, evalContextType);
  • trunk/Source/JavaScriptCore/runtime/CodeCache.h

    r208830 r209196  
    195195public:
    196196    UnlinkedProgramCodeBlock* getUnlinkedProgramCodeBlock(VM&, ProgramExecutable*, const SourceCode&, JSParserStrictMode, DebuggerMode, ParserError&);
    197     UnlinkedEvalCodeBlock* getUnlinkedGlobalEvalCodeBlock(VM&, IndirectEvalExecutable*, const SourceCode&, JSParserStrictMode, DebuggerMode, ParserError&, EvalContextType);
     197    UnlinkedEvalCodeBlock* getUnlinkedEvalCodeBlock(VM&, IndirectEvalExecutable*, const SourceCode&, JSParserStrictMode, DebuggerMode, ParserError&, EvalContextType);
    198198    UnlinkedModuleProgramCodeBlock* getUnlinkedModuleProgramCodeBlock(VM&, ModuleProgramExecutable*, const SourceCode&, DebuggerMode, ParserError&);
    199199    UnlinkedFunctionExecutable* getUnlinkedGlobalFunctionExecutable(VM&, const Identifier&, const SourceCode&, DebuggerMode, ParserError&);
  • trunk/Source/JavaScriptCore/runtime/DirectEvalExecutable.cpp

    r208950 r209196  
    2727#include "DirectEvalExecutable.h"
    2828
     29#include "CodeCache.h"
     30#include "Debugger.h"
    2931#include "Error.h"
    3032#include "HeapInlines.h"
    3133#include "JSCJSValueInlines.h"
     34#include "ParserError.h"
    3235
    3336namespace JSC {
     
    4750    executable->finishCreation(vm);
    4851
    49     UnlinkedEvalCodeBlock* unlinkedEvalCode = globalObject->createLocalEvalCodeBlock(exec, executable, variablesUnderTDZ);
    50     ASSERT(!!scope.exception() == !unlinkedEvalCode);
    51     if (!unlinkedEvalCode)
    52         return 0;
     52    ParserError error;
     53    JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
     54    DebuggerMode debuggerMode = globalObject->hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
     55
     56    // We don't bother with CodeCache here because direct eval uses a specialized EvalCodeCache.
     57    UnlinkedEvalCodeBlock* unlinkedEvalCode = generateUnlinkedCodeBlock<UnlinkedEvalCodeBlock>(
     58        vm, executable, executable->source(), strictMode, JSParserScriptMode::Classic, debuggerMode, error, evalContextType, variablesUnderTDZ);
     59
     60    if (globalObject->hasDebugger())
     61        globalObject->debugger()->sourceParsed(exec, executable->source().provider(), error.line(), error.message());
     62
     63    if (error.isValid()) {
     64        throwVMError(exec, scope, error.toErrorObject(globalObject, executable->source()));
     65        return nullptr;
     66    }
    5367
    5468    executable->m_unlinkedEvalCodeBlock.set(vm, executable, unlinkedEvalCode);
  • trunk/Source/JavaScriptCore/runtime/IndirectEvalExecutable.cpp

    r208950 r209196  
    2727#include "IndirectEvalExecutable.h"
    2828
     29#include "CodeCache.h"
     30#include "Debugger.h"
    2931#include "Error.h"
    3032#include "HeapInlines.h"
    3133#include "JSCJSValueInlines.h"
     34#include "ParserError.h"
    3235
    3336namespace JSC {
     
    4750    executable->finishCreation(vm);
    4851
    49     UnlinkedEvalCodeBlock* unlinkedEvalCode = globalObject->createGlobalEvalCodeBlock(exec, executable);
    50     ASSERT(!!scope.exception() == !unlinkedEvalCode);
    51     if (!unlinkedEvalCode)
    52         return 0;
     52    ParserError error;
     53    JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
     54    DebuggerMode debuggerMode = globalObject->hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
     55   
     56    UnlinkedEvalCodeBlock* unlinkedEvalCode = vm.codeCache()->getUnlinkedEvalCodeBlock(
     57        vm, executable, executable->source(), strictMode, debuggerMode, error, evalContextType);
     58
     59    if (globalObject->hasDebugger())
     60        globalObject->debugger()->sourceParsed(exec, executable->source().provider(), error.line(), error.message());
     61
     62    if (error.isValid()) {
     63        throwVMError(exec, scope, error.toErrorObject(globalObject, executable->source()));
     64        return nullptr;
     65    }
    5366
    5467    executable->m_unlinkedEvalCodeBlock.set(vm, executable, unlinkedEvalCode);
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r209123 r209196  
    13331333}
    13341334
    1335 UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
    1336 {
    1337     ParserError error;
    1338     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
    1339     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
    1340     UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getUnlinkedProgramCodeBlock(
    1341         vm(), executable, executable->source(), strictMode,
    1342         debuggerMode, error);
    1343 
    1344     if (hasDebugger())
    1345         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
    1346 
    1347     if (error.isValid()) {
    1348         *exception = error.toErrorObject(this, executable->source());
    1349         return nullptr;
    1350     }
    1351    
    1352     return unlinkedCodeBlock;
    1353 }
    1354 
    1355 UnlinkedEvalCodeBlock* JSGlobalObject::createLocalEvalCodeBlock(CallFrame* callFrame, DirectEvalExecutable* executable, const VariableEnvironment* variablesUnderTDZ)
    1356 {
    1357     VM& vm = this->vm();
    1358     auto scope = DECLARE_THROW_SCOPE(vm);
    1359 
    1360     ParserError error;
    1361     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
    1362     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
    1363     EvalContextType evalContextType = executable->executableInfo().evalContextType();
    1364 
    1365     // We don't bother with CodeCache here because local eval uses a specialized EvalCodeCache.
    1366     UnlinkedEvalCodeBlock* unlinkedCodeBlock = generateUnlinkedCodeBlock<UnlinkedEvalCodeBlock>(
    1367         vm, executable, executable->source(), strictMode, JSParserScriptMode::Classic, debuggerMode, error, evalContextType, variablesUnderTDZ);
    1368 
    1369     if (hasDebugger())
    1370         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
    1371 
    1372     if (error.isValid()) {
    1373         throwVMError(callFrame, scope, error.toErrorObject(this, executable->source()));
    1374         return nullptr;
    1375     }
    1376 
    1377     return unlinkedCodeBlock;
    1378 }
    1379 
    1380 UnlinkedEvalCodeBlock* JSGlobalObject::createGlobalEvalCodeBlock(CallFrame* callFrame, IndirectEvalExecutable* executable)
    1381 {
    1382     VM& vm = this->vm();
    1383     auto scope = DECLARE_THROW_SCOPE(vm);
    1384 
    1385     ParserError error;
    1386     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
    1387     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
    1388     EvalContextType evalContextType = executable->executableInfo().evalContextType();
    1389    
    1390     UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm.codeCache()->getUnlinkedGlobalEvalCodeBlock(
    1391         vm, executable, executable->source(), strictMode, debuggerMode, error, evalContextType);
    1392 
    1393     if (hasDebugger())
    1394         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
    1395 
    1396     if (error.isValid()) {
    1397         throwVMError(callFrame, scope, error.toErrorObject(this, executable->source()));
    1398         return nullptr;
    1399     }
    1400 
    1401     return unlinkedCodeBlock;
    1402 }
    1403 
    1404 UnlinkedModuleProgramCodeBlock* JSGlobalObject::createModuleProgramCodeBlock(CallFrame* callFrame, ModuleProgramExecutable* executable)
    1405 {
    1406     VM& vm = this->vm();
    1407     auto scope = DECLARE_THROW_SCOPE(vm);
    1408 
    1409     ParserError error;
    1410     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
    1411     UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock = vm.codeCache()->getUnlinkedModuleProgramCodeBlock(
    1412         vm, executable, executable->source(), debuggerMode, error);
    1413 
    1414     if (hasDebugger())
    1415         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
    1416 
    1417     if (error.isValid()) {
    1418         throwVMError(callFrame, scope, error.toErrorObject(this, executable->source()));
    1419         return nullptr;
    1420     }
    1421 
    1422     return unlinkedCodeBlock;
    1423 }
    1424 
    14251335void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
    14261336{
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r209123 r209196  
    835835    WeakRandom& weakRandom() { return m_weakRandom; }
    836836
    837     UnlinkedProgramCodeBlock* createProgramCodeBlock(CallFrame*, ProgramExecutable*, JSObject** exception);
    838     UnlinkedEvalCodeBlock* createLocalEvalCodeBlock(CallFrame*, DirectEvalExecutable*, const VariableEnvironment*);
    839     UnlinkedEvalCodeBlock* createGlobalEvalCodeBlock(CallFrame*, IndirectEvalExecutable*);
    840     UnlinkedModuleProgramCodeBlock* createModuleProgramCodeBlock(CallFrame*, ModuleProgramExecutable*);
    841 
    842837    bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
    843838
  • trunk/Source/JavaScriptCore/runtime/ModuleProgramExecutable.cpp

    r208309 r209196  
    2828#include "BatchedTransitionOptimizer.h"
    2929#include "CodeBlock.h"
     30#include "CodeCache.h"
    3031#include "Debugger.h"
    3132#include "JIT.h"
     
    5455ModuleProgramExecutable* ModuleProgramExecutable::create(ExecState* exec, const SourceCode& source)
    5556{
     57    VM& vm = exec->vm();
     58    auto scope = DECLARE_THROW_SCOPE(vm);
     59
    5660    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    5761    ModuleProgramExecutable* executable = new (NotNull, allocateCell<ModuleProgramExecutable>(*exec->heap())) ModuleProgramExecutable(exec, source);
    5862    executable->finishCreation(exec->vm());
    5963
    60     UnlinkedModuleProgramCodeBlock* unlinkedModuleProgramCode = globalObject->createModuleProgramCodeBlock(exec, executable);
    61     if (!unlinkedModuleProgramCode)
     64    ParserError error;
     65    DebuggerMode debuggerMode = globalObject->hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
     66    UnlinkedModuleProgramCodeBlock* unlinkedModuleProgramCode = vm.codeCache()->getUnlinkedModuleProgramCodeBlock(
     67        vm, executable, executable->source(), debuggerMode, error);
     68
     69    if (globalObject->hasDebugger())
     70        globalObject->debugger()->sourceParsed(exec, executable->source().provider(), error.line(), error.message());
     71
     72    if (error.isValid()) {
     73        throwVMError(exec, scope, error.toErrorObject(globalObject, executable->source()));
    6274        return nullptr;
     75    }
     76
    6377    executable->m_unlinkedModuleProgramCodeBlock.set(exec->vm(), executable, unlinkedModuleProgramCode);
    6478
  • trunk/Source/JavaScriptCore/runtime/ProgramExecutable.cpp

    r209149 r209196  
    2828#include "BatchedTransitionOptimizer.h"
    2929#include "CodeBlock.h"
     30#include "CodeCache.h"
    3031#include "Debugger.h"
    3132#include "Exception.h"
     
    8081    ASSERT(&globalObject->vm() == &vm);
    8182
     83    ParserError error;
     84    JSParserStrictMode strictMode = isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
     85    DebuggerMode debuggerMode = globalObject->hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
     86
     87    UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm.codeCache()->getUnlinkedProgramCodeBlock(
     88        vm, this, source(), strictMode, debuggerMode, error);
     89
     90    if (globalObject->hasDebugger())
     91        globalObject->debugger()->sourceParsed(callFrame, source().provider(), error.line(), error.message());
     92
     93    if (error.isValid())
     94        return error.toErrorObject(globalObject, source());
     95
    8296    JSValue nextPrototype = globalObject->getPrototypeDirect();
    8397    while (nextPrototype && nextPrototype.isObject()) {
     
    89103    }
    90104   
    91     JSObject* exception = nullptr;
    92     UnlinkedProgramCodeBlock* unlinkedCodeBlock = globalObject->createProgramCodeBlock(callFrame, this, &exception);
    93     if (UNLIKELY(exception))
    94         return exception;
    95 
    96105    JSGlobalLexicalEnvironment* globalLexicalEnvironment = globalObject->globalLexicalEnvironment();
    97106    const VariableEnvironment& variableDeclarations = unlinkedCodeBlock->variableDeclarations();
  • trunk/Source/JavaScriptCore/runtime/ProgramExecutable.h

    r208063 r209196  
    4343    }
    4444
    45 
    4645    JSObject* initializeGlobalProperties(VM&, CallFrame*, JSScope*);
    4746
Note: See TracChangeset for help on using the changeset viewer.