source: webkit/trunk/JavaScriptCore/kjs/ExecState.cpp@ 28884

Last change on this file since 28884 was 28884, checked in by [email protected], 17 years ago

JavaScriptCore:

Reviewed by Oliver Hunt.


Optimized global access to global variables, using a symbol table.


SunSpider reports a 1.5% overall speedup, a 6.2% speedup on 3d-morph,
and a whopping 33.1% speedup on bitops-bitwise-and.

  • API/JSCallbackObjectFunctions.h: Replaced calls to JSObject:: with calls to Base::, since JSObject is not always our base class. This was always a bug, but the bug is even more apparent after some of my changes.

(KJS::::staticFunctionGetter): Replaced use of getDirect with call to
getOwnPropertySlot. Global declarations are no longer stored in the
property map, so a call to getDirect is insufficient for finding
override properties.

  • API/testapi.c:
  • API/testapi.js: Added test for the getDirect change mentioned above.
  • kjs/ExecState.cpp:
  • kjs/ExecState.h: Dialed back the optimization to store a direct pointer to the localStorage buffer. One ExecState can grow the global object's localStorage without another ExecState's knowledge, so ExecState can't store a direct pointer to the localStorage buffer unless/until we invent a way to update all the relevant ExecStates.
  • kjs/JSGlobalObject.cpp: Inserted the symbol table into get and put operations. (KJS::JSGlobalObject::reset): Reset the symbol table and local storage, too. Also, clear the property map here, removing the need for a separate call.
  • kjs/JSVariableObject.cpp:
  • kjs/JSVariableObject.h: Added support for saving localStorage and the symbol table to the back/forward cache, and restoring them.
  • kjs/function.cpp: (KJS::GlobalFuncImp::callAsFunction): Renamed progNode to evalNode because it's an EvalNode, not a ProgramNode.
  • kjs/lookup.h: (KJS::cacheGlobalObject): Replaced put with faster putDirect, since that's how the rest of lookup.h works. putDirect is safe here because cacheGlobalObject is only used for objects whose names are not valid identifiers.
  • kjs/nodes.cpp: The good stuff!

(KJS::EvalNode::processDeclarations): Replaced hasProperty with
the new hasOwnProperty, which is slightly faster.

  • kjs/object.h: Nixed clearProperties because clear() does this job now.
  • kjs/property_map.cpp:
  • kjs/property_map.h: More back/forward cache support.


  • wtf/Vector.h: (WTF::::grow): Added fast non-branching grow function. I used it in an earlier version of this patch, even though it's not used anymore.

JavaScriptGlue:

Build fix.

  • ForwardingHeaders/wtf/VectorTraits.h: Added.

WebCore:

Reviewed by Oliver Hunt.

Build support:

  • ForwardingHeaders/kjs/SymbolTable.h: Added.
  • ForwardingHeaders/wtf/VectorTraits.h: Added.
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::customGetOwnPropertySlot): Replaced use of getDirectLocation with getOwnPropertySlot. getDirectLocation is no longer valid, since global declarations are not stored in the property map.

(WebCore::JSDOMWindow::customPut): Replaced use of JSObject::put with
JSGlobalObject::put. JSObject::put is no longer valid, since global
declarations are not stored in the property map.

  • bindings/js/kjs_window.cpp: Replaced JSObject:: calls with Base:: calls, since JSObject is not our base class. This was always a bug, but the bug is even more apparent after some of my changes.

(KJS::Window::clear): Removed call to clearProperties because
JSGlobalObject::reset takes care of that now.

  • history/CachedPage.cpp:
  • history/CachedPage.h: Added support for saving a symbol table and localStorage to the page cache, and restoring it.

WebKit/mac:

Reviewed by Oliver Hunt.

Build fix.

  • ForwardingHeaders/kjs/SymbolTable.h: Added.
  • ForwardingHeaders/wtf/VectorTraits.h: Added.

LayoutTests:

Reviewed by Oliver Hunt.


Added some tests to verify some of the changes I made while optimizing
global access to global variables.

  • fast/dom/Window/resources/window-property-clearing-iframe0.html: Added.
  • fast/dom/Window/resources/window-property-clearing-iframe1.html: Added.
  • fast/dom/Window/window-property-clearing-expected.txt: Added.
  • fast/dom/Window/window-property-clearing.html: Added.
  • fast/dom/getter-on-window-object2-expected.txt: Added.
  • fast/dom/getter-on-window-object2.html: Added.

Checked in failing results for these const tests. The symbol table
optimization broke const. (We didn't know this before because our only
tests used global variables.)

  • fast/js/const-expected.txt:
  • fast/js/kde/const-expected.txt:
  • fast/js/resources/for-in-avoid-duplicates.js: Fixed a typo I noticed. Not related to this patch.
  • fast/dom/Window/window-property-shadowing.html: Changed this test to use "this" instead of "window". The fact that "window" worked before, despite an overriding / shadowing var declaration, was a bug.
  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten ([email protected])
5 * Copyright (C) 2001 Peter Kelly ([email protected])
6 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "config.h"
26#include "ExecState.h"
27
28#include "JSGlobalObject.h"
29#include "function.h"
30#include "internal.h"
31
32namespace KJS {
33
34// ECMA 10.2
35ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisV,
36 ScopeNode* scopeNode, CodeType type, ExecState* callingExec, ExecState* currentExec,
37 FunctionImp* func, const List* args)
38 : m_globalObject(globalObject)
39 , m_exception(0)
40 , m_propertyNames(CommonIdentifiers::shared())
41 , m_callingExec(callingExec)
42 , m_savedExec(currentExec)
43 , m_scopeNode(scopeNode)
44 , m_function(func)
45 , m_arguments(args)
46 , m_iterationDepth(0)
47 , m_switchDepth(0)
48 , m_codeType(type)
49{
50 // create and initialize activation object (ECMA 10.1.6)
51 if (type == FunctionCode) {
52 m_activation = new ActivationImp(this);
53 m_variableObject = m_activation;
54 } else {
55 m_activation = 0;
56 m_variableObject = globalObject;
57 }
58
59 // ECMA 10.2
60 switch(type) {
61 case EvalCode:
62 if (m_callingExec) {
63 m_scopeChain = m_callingExec->scopeChain();
64 m_variableObject = m_callingExec->variableObject();
65 m_thisVal = m_callingExec->thisValue();
66 break;
67 } // else same as GlobalCode
68 case GlobalCode:
69 m_scopeChain.push(globalObject);
70 m_thisVal = globalObject;
71 break;
72 case FunctionCode:
73 m_scopeChain = func->scope();
74 m_scopeChain.push(m_activation);
75 m_variableObject = m_activation;
76 m_thisVal = thisV;
77 break;
78 }
79
80 m_localStorage = &m_variableObject->localStorage();
81
82 if (scopeNode)
83 m_globalObject->setCurrentExec(this);
84}
85
86ExecState::~ExecState()
87{
88 m_globalObject->setCurrentExec(m_savedExec);
89}
90
91void ExecState::mark()
92{
93 for (ExecState* exec = this; exec; exec = exec->m_callingExec)
94 exec->m_scopeChain.mark();
95}
96
97JSGlobalObject* ExecState::lexicalGlobalObject() const
98{
99 if (scopeChain().isEmpty())
100 return dynamicGlobalObject();
101
102 JSObject* object = scopeChain().bottom();
103 if (object && object->isGlobalObject())
104 return static_cast<JSGlobalObject*>(object);
105
106 return dynamicGlobalObject();
107}
108
109} // namespace KJS
Note: See TracBrowser for help on using the repository browser.