source: webkit/trunk/JavaScriptCore/kjs/JSGlobalData.cpp@ 37337

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

2008-10-05 Maciej Stachowiak <[email protected]>

Reviewed by Oliver Hunt.



The problem is that dynamicGlobalObject had become O(N) in number
of call frames, but unwinding the stack for an exception called it
for every call frame, resulting in O(N2) behavior for an
exception thrown from inside deep recursion.

Instead of doing it that way, stash the dynamic global object in JSGlobalData.


  • JavaScriptCore.exp:
  • VM/Machine.cpp: (JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): Helper class to temporarily store and later restore a dynamicGlobalObject in JSGlobalData. (JSC::DynamicGlobalObjectScope::~DynamicGlobalObjectScope): (JSC::Machine::execute): In each version, establish a DynamicGlobalObjectScope. For ProgramNode, always establish set new dynamicGlobalObject, for FunctionBody and Eval, only if none is currently set.
  • VM/Machine.h:
  • kjs/ExecState.h:
  • kjs/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): Ininitalize new dynamicGlobalObject field to 0.
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.h: (JSC::ExecState::dynamicGlobalObject): Moved here from ExecState for benefit of inlining. Return lexical global object if this is a globalExec(), otherwise look in JSGlobalData for the one stashed there.
  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "config.h"
30#include "JSGlobalData.h"
31
32#include "ArgList.h"
33#include "CommonIdentifiers.h"
34#include "JSActivation.h"
35#include "JSClassRef.h"
36#include "JSLock.h"
37#include "JSStaticScopeObject.h"
38#include "Machine.h"
39#include "Parser.h"
40#include "collector.h"
41#include "lexer.h"
42#include "lookup.h"
43#include "nodes.h"
44
45#if ENABLE(JSC_MULTIPLE_THREADS)
46#include <wtf/Threading.h>
47#endif
48
49using namespace WTF;
50
51namespace JSC {
52
53extern const HashTable arrayTable;
54extern const HashTable dateTable;
55extern const HashTable mathTable;
56extern const HashTable numberTable;
57extern const HashTable regExpTable;
58extern const HashTable regExpConstructorTable;
59extern const HashTable stringTable;
60
61JSGlobalData::JSGlobalData(bool isShared)
62 : machine(new Machine)
63 , exception(0)
64#if ENABLE(JSC_MULTIPLE_THREADS)
65 , arrayTable(new HashTable(JSC::arrayTable))
66 , dateTable(new HashTable(JSC::dateTable))
67 , mathTable(new HashTable(JSC::mathTable))
68 , numberTable(new HashTable(JSC::numberTable))
69 , regExpTable(new HashTable(JSC::regExpTable))
70 , regExpConstructorTable(new HashTable(JSC::regExpConstructorTable))
71 , stringTable(new HashTable(JSC::stringTable))
72#else
73 , arrayTable(&JSC::arrayTable)
74 , dateTable(&JSC::dateTable)
75 , mathTable(&JSC::mathTable)
76 , numberTable(&JSC::numberTable)
77 , regExpTable(&JSC::regExpTable)
78 , regExpConstructorTable(&JSC::regExpConstructorTable)
79 , stringTable(&JSC::stringTable)
80#endif
81 , nullProtoStructureID(JSObject::createStructureID(jsNull()))
82 , activationStructureID(JSActivation::createStructureID(jsNull()))
83 , staticScopeStructureID(JSStaticScopeObject::createStructureID(jsNull()))
84 , stringStructureID(JSString::createStructureID(jsNull()))
85 , numberStructureID(JSNumberCell::createStructureID(jsNull()))
86 , identifierTable(createIdentifierTable())
87 , propertyNames(new CommonIdentifiers(this))
88 , emptyList(new ArgList)
89 , newParserObjects(0)
90 , parserObjectExtraRefCounts(0)
91 , lexer(new Lexer(this))
92 , parser(new Parser)
93 , head(0)
94 , dynamicGlobalObject(0)
95 , isSharedInstance(isShared)
96 , clientData(0)
97 , heap(this)
98{
99}
100
101JSGlobalData::~JSGlobalData()
102{
103 // By the time this is destroyed, heap.destroy() must already have been called.
104
105 delete machine;
106#ifndef NDEBUG
107 // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
108 machine = 0;
109#endif
110
111#if ENABLE(JSC_MULTIPLE_THREADS)
112 arrayTable->deleteTable();
113 dateTable->deleteTable();
114 mathTable->deleteTable();
115 numberTable->deleteTable();
116 regExpTable->deleteTable();
117 regExpConstructorTable->deleteTable();
118 stringTable->deleteTable();
119 delete arrayTable;
120 delete dateTable;
121 delete mathTable;
122 delete numberTable;
123 delete regExpTable;
124 delete regExpConstructorTable;
125 delete stringTable;
126#endif
127
128 delete parser;
129 delete lexer;
130
131 deleteAllValues(opaqueJSClassData);
132
133 delete emptyList;
134
135 delete propertyNames;
136 deleteIdentifierTable(identifierTable);
137
138 delete newParserObjects;
139 delete parserObjectExtraRefCounts;
140
141 delete clientData;
142}
143
144PassRefPtr<JSGlobalData> JSGlobalData::create()
145{
146 return adoptRef(new JSGlobalData);
147}
148
149bool JSGlobalData::sharedInstanceExists()
150{
151 return sharedInstanceInternal();
152}
153
154JSGlobalData& JSGlobalData::sharedInstance()
155{
156 JSGlobalData*& instance = sharedInstanceInternal();
157 if (!instance)
158 instance = new JSGlobalData(true);
159 return *instance;
160}
161
162JSGlobalData*& JSGlobalData::sharedInstanceInternal()
163{
164 ASSERT(JSLock::currentThreadIsHoldingLock());
165 static JSGlobalData* sharedInstance;
166 return sharedInstance;
167}
168
169JSGlobalData::ClientData::~ClientData()
170{
171}
172
173}
Note: See TracBrowser for help on using the repository browser.