source: webkit/trunk/JavaScriptCore/runtime/JSGlobalData.cpp@ 51457

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

2009-11-28 Zoltan Herczeg <[email protected]>

Reviewed by Gavin Barraclough.

https://bugs.webkit.org/show_bug.cgi?id=31930

Seems a typo. We don't need ~270k memory to determine the vptrs.

  • runtime/JSGlobalData.cpp: (JSC::VPtrSet::VPtrSet):
  • Property svn:eol-style set to native
File size: 9.0 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 "Collector.h"
34#include "CommonIdentifiers.h"
35#include "FunctionConstructor.h"
36#include "GetterSetter.h"
37#include "Interpreter.h"
38#include "JSActivation.h"
39#include "JSAPIValueWrapper.h"
40#include "JSArray.h"
41#include "JSByteArray.h"
42#include "JSClassRef.h"
43#include "JSFunction.h"
44#include "JSLock.h"
45#include "JSNotAnObject.h"
46#include "JSPropertyNameIterator.h"
47#include "JSStaticScopeObject.h"
48#include "Parser.h"
49#include "Lexer.h"
50#include "Lookup.h"
51#include "Nodes.h"
52
53#if ENABLE(JSC_MULTIPLE_THREADS)
54#include <wtf/Threading.h>
55#endif
56
57#if PLATFORM(MAC)
58#include "ProfilerServer.h"
59#endif
60
61using namespace WTF;
62
63namespace JSC {
64
65extern JSC_CONST_HASHTABLE HashTable arrayTable;
66extern JSC_CONST_HASHTABLE HashTable jsonTable;
67extern JSC_CONST_HASHTABLE HashTable dateTable;
68extern JSC_CONST_HASHTABLE HashTable mathTable;
69extern JSC_CONST_HASHTABLE HashTable numberTable;
70extern JSC_CONST_HASHTABLE HashTable regExpTable;
71extern JSC_CONST_HASHTABLE HashTable regExpConstructorTable;
72extern JSC_CONST_HASHTABLE HashTable stringTable;
73
74void JSGlobalData::ClientData::willExecute(ExecState*)
75{
76}
77
78void JSGlobalData::ClientData::didExecute(ExecState*)
79{
80}
81
82struct VPtrSet {
83 VPtrSet();
84
85 void* jsArrayVPtr;
86 void* jsByteArrayVPtr;
87 void* jsStringVPtr;
88 void* jsFunctionVPtr;
89};
90
91VPtrSet::VPtrSet()
92{
93 CollectorCell cell;
94 void* storage = &cell;
95
96 ASSERT(sizeof(JSArray) <= sizeof(CollectorCell));
97 JSCell* jsArray = new (storage) JSArray(JSArray::createStructure(jsNull()));
98 jsArrayVPtr = jsArray->vptr();
99 jsArray->~JSCell();
100
101 ASSERT(sizeof(JSByteArray) <= sizeof(CollectorCell));
102 JSCell* jsByteArray = new (storage) JSByteArray(JSByteArray::VPtrStealingHack);
103 jsByteArrayVPtr = jsByteArray->vptr();
104 jsByteArray->~JSCell();
105
106 ASSERT(sizeof(JSString) <= sizeof(CollectorCell));
107 JSCell* jsString = new (storage) JSString(JSString::VPtrStealingHack);
108 jsStringVPtr = jsString->vptr();
109 jsString->~JSCell();
110
111 ASSERT(sizeof(JSFunction) <= sizeof(CollectorCell));
112 JSCell* jsFunction = new (storage) JSFunction(JSFunction::createStructure(jsNull()));
113 jsFunctionVPtr = jsFunction->vptr();
114 jsFunction->~JSCell();
115}
116
117JSGlobalData::JSGlobalData(bool isShared, const VPtrSet& vptrSet)
118 : isSharedInstance(isShared)
119 , clientData(0)
120 , arrayTable(fastNew<HashTable>(JSC::arrayTable))
121 , dateTable(fastNew<HashTable>(JSC::dateTable))
122 , jsonTable(fastNew<HashTable>(JSC::jsonTable))
123 , mathTable(fastNew<HashTable>(JSC::mathTable))
124 , numberTable(fastNew<HashTable>(JSC::numberTable))
125 , regExpTable(fastNew<HashTable>(JSC::regExpTable))
126 , regExpConstructorTable(fastNew<HashTable>(JSC::regExpConstructorTable))
127 , stringTable(fastNew<HashTable>(JSC::stringTable))
128 , activationStructure(JSActivation::createStructure(jsNull()))
129 , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull()))
130 , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull()))
131 , stringStructure(JSString::createStructure(jsNull()))
132 , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNull()))
133 , notAnObjectStructure(JSNotAnObject::createStructure(jsNull()))
134 , propertyNameIteratorStructure(JSPropertyNameIterator::createStructure(jsNull()))
135 , getterSetterStructure(GetterSetter::createStructure(jsNull()))
136 , apiWrapperStructure(JSAPIValueWrapper::createStructure(jsNull()))
137#if USE(JSVALUE32)
138 , numberStructure(JSNumberCell::createStructure(jsNull()))
139#endif
140 , jsArrayVPtr(vptrSet.jsArrayVPtr)
141 , jsByteArrayVPtr(vptrSet.jsByteArrayVPtr)
142 , jsStringVPtr(vptrSet.jsStringVPtr)
143 , jsFunctionVPtr(vptrSet.jsFunctionVPtr)
144 , identifierTable(createIdentifierTable())
145 , propertyNames(new CommonIdentifiers(this))
146 , emptyList(new MarkedArgumentBuffer)
147 , lexer(new Lexer(this))
148 , parser(new Parser)
149 , interpreter(new Interpreter)
150#if ENABLE(JIT)
151 , jitStubs(this)
152#endif
153 , heap(this)
154 , initializingLazyNumericCompareFunction(false)
155 , head(0)
156 , dynamicGlobalObject(0)
157 , functionCodeBlockBeingReparsed(0)
158 , firstStringifierToMark(0)
159 , markStack(vptrSet.jsArrayVPtr)
160 , cachedUTCOffset(NaN)
161 , weakRandom(static_cast<int>(currentTime()))
162#ifndef NDEBUG
163 , mainThreadOnly(false)
164#endif
165{
166#if PLATFORM(MAC)
167 startProfilerServerIfNeeded();
168#endif
169}
170
171JSGlobalData::~JSGlobalData()
172{
173 // By the time this is destroyed, heap.destroy() must already have been called.
174
175 delete interpreter;
176#ifndef NDEBUG
177 // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
178 interpreter = 0;
179#endif
180
181 arrayTable->deleteTable();
182 dateTable->deleteTable();
183 jsonTable->deleteTable();
184 mathTable->deleteTable();
185 numberTable->deleteTable();
186 regExpTable->deleteTable();
187 regExpConstructorTable->deleteTable();
188 stringTable->deleteTable();
189
190 fastDelete(const_cast<HashTable*>(arrayTable));
191 fastDelete(const_cast<HashTable*>(dateTable));
192 fastDelete(const_cast<HashTable*>(jsonTable));
193 fastDelete(const_cast<HashTable*>(mathTable));
194 fastDelete(const_cast<HashTable*>(numberTable));
195 fastDelete(const_cast<HashTable*>(regExpTable));
196 fastDelete(const_cast<HashTable*>(regExpConstructorTable));
197 fastDelete(const_cast<HashTable*>(stringTable));
198
199 delete parser;
200 delete lexer;
201
202 deleteAllValues(opaqueJSClassData);
203
204 delete emptyList;
205
206 delete propertyNames;
207 deleteIdentifierTable(identifierTable);
208
209 delete clientData;
210}
211
212PassRefPtr<JSGlobalData> JSGlobalData::create(bool isShared)
213{
214 return adoptRef(new JSGlobalData(isShared, VPtrSet()));
215}
216
217PassRefPtr<JSGlobalData> JSGlobalData::createLeaked()
218{
219 Structure::startIgnoringLeaks();
220 RefPtr<JSGlobalData> data = create();
221 Structure::stopIgnoringLeaks();
222 return data.release();
223}
224
225bool JSGlobalData::sharedInstanceExists()
226{
227 return sharedInstanceInternal();
228}
229
230JSGlobalData& JSGlobalData::sharedInstance()
231{
232 JSGlobalData*& instance = sharedInstanceInternal();
233 if (!instance) {
234 instance = create(true).releaseRef();
235#if ENABLE(JSC_MULTIPLE_THREADS)
236 instance->makeUsableFromMultipleThreads();
237#endif
238 }
239 return *instance;
240}
241
242JSGlobalData*& JSGlobalData::sharedInstanceInternal()
243{
244 ASSERT(JSLock::currentThreadIsHoldingLock());
245 static JSGlobalData* sharedInstance;
246 return sharedInstance;
247}
248
249// FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc.
250const Vector<Instruction>& JSGlobalData::numericCompareFunction(ExecState* exec)
251{
252 if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) {
253 initializingLazyNumericCompareFunction = true;
254 RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(Identifier(exec, "numericCompare"), exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
255 lazyNumericCompareFunction = function->bytecode(exec, exec->scopeChain()).instructions();
256 initializingLazyNumericCompareFunction = false;
257 }
258
259 return lazyNumericCompareFunction;
260}
261
262JSGlobalData::ClientData::~ClientData()
263{
264}
265
266void JSGlobalData::resetDateCache()
267{
268 cachedUTCOffset = NaN;
269 dstOffsetCache.reset();
270 cachedDateString = UString();
271 dateInstanceCache.reset();
272}
273
274void JSGlobalData::startSampling()
275{
276 interpreter->startSampling();
277}
278
279void JSGlobalData::stopSampling()
280{
281 interpreter->stopSampling();
282}
283
284void JSGlobalData::dumpSampleData(ExecState* exec)
285{
286 interpreter->dumpSampleData(exec);
287}
288
289} // namespace JSC
Note: See TracBrowser for help on using the repository browser.