~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalData.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
61
using namespace WTF;
 
62
 
 
63
namespace JSC {
 
64
 
 
65
extern JSC_CONST_HASHTABLE HashTable arrayTable;
 
66
extern JSC_CONST_HASHTABLE HashTable jsonTable;
 
67
extern JSC_CONST_HASHTABLE HashTable dateTable;
 
68
extern JSC_CONST_HASHTABLE HashTable mathTable;
 
69
extern JSC_CONST_HASHTABLE HashTable numberTable;
 
70
extern JSC_CONST_HASHTABLE HashTable regExpTable;
 
71
extern JSC_CONST_HASHTABLE HashTable regExpConstructorTable;
 
72
extern JSC_CONST_HASHTABLE HashTable stringTable;
 
73
 
 
74
struct VPtrSet {
 
75
    VPtrSet();
 
76
 
 
77
    void* jsArrayVPtr;
 
78
    void* jsByteArrayVPtr;
 
79
    void* jsStringVPtr;
 
80
    void* jsFunctionVPtr;
 
81
};
 
82
 
 
83
VPtrSet::VPtrSet()
 
84
{
 
85
    // Bizarrely, calling fastMalloc here is faster than allocating space on the stack.
 
86
    void* storage = fastMalloc(sizeof(CollectorBlock));
 
87
 
 
88
    JSCell* jsArray = new (storage) JSArray(JSArray::createStructure(jsNull()));
 
89
    jsArrayVPtr = jsArray->vptr();
 
90
    jsArray->~JSCell();
 
91
 
 
92
    JSCell* jsByteArray = new (storage) JSByteArray(JSByteArray::VPtrStealingHack);
 
93
    jsByteArrayVPtr = jsByteArray->vptr();
 
94
    jsByteArray->~JSCell();
 
95
 
 
96
    JSCell* jsString = new (storage) JSString(JSString::VPtrStealingHack);
 
97
    jsStringVPtr = jsString->vptr();
 
98
    jsString->~JSCell();
 
99
 
 
100
    JSCell* jsFunction = new (storage) JSFunction(JSFunction::createStructure(jsNull()));
 
101
    jsFunctionVPtr = jsFunction->vptr();
 
102
    jsFunction->~JSCell();
 
103
 
 
104
    fastFree(storage);
 
105
}
 
106
 
 
107
JSGlobalData::JSGlobalData(bool isShared, const VPtrSet& vptrSet)
 
108
    : isSharedInstance(isShared)
 
109
    , clientData(0)
 
110
    , arrayTable(fastNew<HashTable>(JSC::arrayTable))
 
111
    , dateTable(fastNew<HashTable>(JSC::dateTable))
 
112
    , jsonTable(fastNew<HashTable>(JSC::jsonTable))
 
113
    , mathTable(fastNew<HashTable>(JSC::mathTable))
 
114
    , numberTable(fastNew<HashTable>(JSC::numberTable))
 
115
    , regExpTable(fastNew<HashTable>(JSC::regExpTable))
 
116
    , regExpConstructorTable(fastNew<HashTable>(JSC::regExpConstructorTable))
 
117
    , stringTable(fastNew<HashTable>(JSC::stringTable))
 
118
    , activationStructure(JSActivation::createStructure(jsNull()))
 
119
    , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull()))
 
120
    , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull()))
 
121
    , stringStructure(JSString::createStructure(jsNull()))
 
122
    , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNull()))
 
123
    , notAnObjectStructure(JSNotAnObject::createStructure(jsNull()))
 
124
    , propertyNameIteratorStructure(JSPropertyNameIterator::createStructure(jsNull()))
 
125
    , getterSetterStructure(GetterSetter::createStructure(jsNull()))
 
126
    , apiWrapperStructure(JSAPIValueWrapper::createStructure(jsNull()))
 
127
#if USE(JSVALUE32)
 
128
    , numberStructure(JSNumberCell::createStructure(jsNull()))
 
129
#endif
 
130
    , jsArrayVPtr(vptrSet.jsArrayVPtr)
 
131
    , jsByteArrayVPtr(vptrSet.jsByteArrayVPtr)
 
132
    , jsStringVPtr(vptrSet.jsStringVPtr)
 
133
    , jsFunctionVPtr(vptrSet.jsFunctionVPtr)
 
134
    , identifierTable(createIdentifierTable())
 
135
    , propertyNames(new CommonIdentifiers(this))
 
136
    , emptyList(new MarkedArgumentBuffer)
 
137
    , lexer(new Lexer(this))
 
138
    , parser(new Parser)
 
139
    , interpreter(new Interpreter)
 
140
#if ENABLE(JIT)
 
141
    , jitStubs(this)
 
142
#endif
 
143
    , timeoutChecker(new TimeoutChecker)
 
144
    , heap(this)
 
145
    , initializingLazyNumericCompareFunction(false)
 
146
    , head(0)
 
147
    , dynamicGlobalObject(0)
 
148
    , functionCodeBlockBeingReparsed(0)
 
149
    , firstStringifierToMark(0)
 
150
    , markStack(vptrSet.jsArrayVPtr)
 
151
#ifndef NDEBUG
 
152
    , mainThreadOnly(false)
 
153
#endif
 
154
{
 
155
#if PLATFORM(MAC)
 
156
    startProfilerServerIfNeeded();
 
157
#endif
 
158
}
 
159
 
 
160
JSGlobalData::~JSGlobalData()
 
161
{
 
162
    // By the time this is destroyed, heap.destroy() must already have been called.
 
163
 
 
164
    delete interpreter;
 
165
#ifndef NDEBUG
 
166
    // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
 
167
    interpreter = 0;
 
168
#endif
 
169
 
 
170
    arrayTable->deleteTable();
 
171
    dateTable->deleteTable();
 
172
    jsonTable->deleteTable();
 
173
    mathTable->deleteTable();
 
174
    numberTable->deleteTable();
 
175
    regExpTable->deleteTable();
 
176
    regExpConstructorTable->deleteTable();
 
177
    stringTable->deleteTable();
 
178
 
 
179
    fastDelete(const_cast<HashTable*>(arrayTable));
 
180
    fastDelete(const_cast<HashTable*>(dateTable));
 
181
    fastDelete(const_cast<HashTable*>(jsonTable));
 
182
    fastDelete(const_cast<HashTable*>(mathTable));
 
183
    fastDelete(const_cast<HashTable*>(numberTable));
 
184
    fastDelete(const_cast<HashTable*>(regExpTable));
 
185
    fastDelete(const_cast<HashTable*>(regExpConstructorTable));
 
186
    fastDelete(const_cast<HashTable*>(stringTable));
 
187
 
 
188
    delete parser;
 
189
    delete lexer;
 
190
    delete timeoutChecker;
 
191
 
 
192
    deleteAllValues(opaqueJSClassData);
 
193
 
 
194
    delete emptyList;
 
195
 
 
196
    delete propertyNames;
 
197
    deleteIdentifierTable(identifierTable);
 
198
 
 
199
    delete clientData;
 
200
}
 
201
 
 
202
PassRefPtr<JSGlobalData> JSGlobalData::create(bool isShared)
 
203
{
 
204
    return adoptRef(new JSGlobalData(isShared, VPtrSet()));
 
205
}
 
206
 
 
207
PassRefPtr<JSGlobalData> JSGlobalData::createLeaked()
 
208
{
 
209
    Structure::startIgnoringLeaks();
 
210
    RefPtr<JSGlobalData> data = create();
 
211
    Structure::stopIgnoringLeaks();
 
212
    return data.release();
 
213
}
 
214
 
 
215
bool JSGlobalData::sharedInstanceExists()
 
216
{
 
217
    return sharedInstanceInternal();
 
218
}
 
219
 
 
220
JSGlobalData& JSGlobalData::sharedInstance()
 
221
{
 
222
    JSGlobalData*& instance = sharedInstanceInternal();
 
223
    if (!instance) {
 
224
        instance = create(true).releaseRef();
 
225
#if ENABLE(JSC_MULTIPLE_THREADS)
 
226
        instance->makeUsableFromMultipleThreads();
 
227
#endif
 
228
    }
 
229
    return *instance;
 
230
}
 
231
 
 
232
JSGlobalData*& JSGlobalData::sharedInstanceInternal()
 
233
{
 
234
    ASSERT(JSLock::currentThreadIsHoldingLock());
 
235
    static JSGlobalData* sharedInstance;
 
236
    return sharedInstance;
 
237
}
 
238
 
 
239
// FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc.
 
240
const Vector<Instruction>& JSGlobalData::numericCompareFunction(ExecState* exec)
 
241
{
 
242
    if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) {
 
243
        initializingLazyNumericCompareFunction = true;
 
244
        RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(Identifier(exec, "numericCompare"), exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
 
245
        lazyNumericCompareFunction = function->bytecode(exec, exec->scopeChain()).instructions();
 
246
        initializingLazyNumericCompareFunction = false;
 
247
    }
 
248
 
 
249
    return lazyNumericCompareFunction;
 
250
}
 
251
 
 
252
JSGlobalData::ClientData::~ClientData()
 
253
{
 
254
}
 
255
 
 
256
} // namespace JSC