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 "JSClassRef.h"
|
---|
35 | #include "JSLock.h"
|
---|
36 | #include "Machine.h"
|
---|
37 | #include "Parser.h"
|
---|
38 | #include "collector.h"
|
---|
39 | #include "lexer.h"
|
---|
40 | #include "lookup.h"
|
---|
41 | #include "nodes.h"
|
---|
42 |
|
---|
43 | #if ENABLE(JSC_MULTIPLE_THREADS)
|
---|
44 | #include <wtf/Threading.h>
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | using namespace WTF;
|
---|
48 |
|
---|
49 | namespace JSC {
|
---|
50 |
|
---|
51 | extern const HashTable arrayTable;
|
---|
52 | extern const HashTable dateTable;
|
---|
53 | extern const HashTable mathTable;
|
---|
54 | extern const HashTable numberTable;
|
---|
55 | extern const HashTable regExpTable;
|
---|
56 | extern const HashTable regExpConstructorTable;
|
---|
57 | extern const HashTable stringTable;
|
---|
58 |
|
---|
59 | JSGlobalData::JSGlobalData(bool isShared)
|
---|
60 | : machine(new Machine)
|
---|
61 | , heap(new Heap(this))
|
---|
62 | #if ENABLE(JSC_MULTIPLE_THREADS)
|
---|
63 | , arrayTable(new HashTable(JSC::arrayTable))
|
---|
64 | , dateTable(new HashTable(JSC::dateTable))
|
---|
65 | , mathTable(new HashTable(JSC::mathTable))
|
---|
66 | , numberTable(new HashTable(JSC::numberTable))
|
---|
67 | , regExpTable(new HashTable(JSC::regExpTable))
|
---|
68 | , regExpConstructorTable(new HashTable(JSC::regExpConstructorTable))
|
---|
69 | , stringTable(new HashTable(JSC::stringTable))
|
---|
70 | #else
|
---|
71 | , arrayTable(&JSC::arrayTable)
|
---|
72 | , dateTable(&JSC::dateTable)
|
---|
73 | , mathTable(&JSC::mathTable)
|
---|
74 | , numberTable(&JSC::numberTable)
|
---|
75 | , regExpTable(&JSC::regExpTable)
|
---|
76 | , regExpConstructorTable(&JSC::regExpConstructorTable)
|
---|
77 | , stringTable(&JSC::stringTable)
|
---|
78 | #endif
|
---|
79 | , nullProtoStructureID(JSObject::createStructureID(jsNull()))
|
---|
80 | , stringStructureID(JSString::createStructureID(jsNull()))
|
---|
81 | , numberStructureID(JSNumberCell::createStructureID(jsNull()))
|
---|
82 | , identifierTable(createIdentifierTable())
|
---|
83 | , propertyNames(new CommonIdentifiers(this))
|
---|
84 | , emptyList(new ArgList)
|
---|
85 | , opaqueJSClassData(new HashMap<OpaqueJSClass*, OpaqueJSClassContextData*>)
|
---|
86 | , newParserObjects(0)
|
---|
87 | , parserObjectExtraRefCounts(0)
|
---|
88 | , lexer(new Lexer(this))
|
---|
89 | , parser(new Parser)
|
---|
90 | , head(0)
|
---|
91 | , isSharedInstance(isShared)
|
---|
92 | {
|
---|
93 | }
|
---|
94 |
|
---|
95 | JSGlobalData::~JSGlobalData()
|
---|
96 | {
|
---|
97 | delete heap;
|
---|
98 | delete machine;
|
---|
99 | #ifndef NDEBUG
|
---|
100 | // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
|
---|
101 | heap = 0;
|
---|
102 | machine = 0;
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | #if ENABLE(JSC_MULTIPLE_THREADS)
|
---|
106 | arrayTable->deleteTable();
|
---|
107 | dateTable->deleteTable();
|
---|
108 | mathTable->deleteTable();
|
---|
109 | numberTable->deleteTable();
|
---|
110 | regExpTable->deleteTable();
|
---|
111 | regExpConstructorTable->deleteTable();
|
---|
112 | stringTable->deleteTable();
|
---|
113 | delete arrayTable;
|
---|
114 | delete dateTable;
|
---|
115 | delete mathTable;
|
---|
116 | delete numberTable;
|
---|
117 | delete regExpTable;
|
---|
118 | delete regExpConstructorTable;
|
---|
119 | delete stringTable;
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | delete parser;
|
---|
123 | delete lexer;
|
---|
124 |
|
---|
125 | deleteAllValues(*opaqueJSClassData);
|
---|
126 | delete opaqueJSClassData;
|
---|
127 |
|
---|
128 | delete emptyList;
|
---|
129 |
|
---|
130 | delete propertyNames;
|
---|
131 | deleteIdentifierTable(identifierTable);
|
---|
132 |
|
---|
133 | delete newParserObjects;
|
---|
134 | delete parserObjectExtraRefCounts;
|
---|
135 | }
|
---|
136 |
|
---|
137 | PassRefPtr<JSGlobalData> JSGlobalData::create()
|
---|
138 | {
|
---|
139 | return adoptRef(new JSGlobalData);
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool JSGlobalData::sharedInstanceExists()
|
---|
143 | {
|
---|
144 | return sharedInstanceInternal();
|
---|
145 | }
|
---|
146 |
|
---|
147 | JSGlobalData& JSGlobalData::sharedInstance()
|
---|
148 | {
|
---|
149 | JSGlobalData*& instance = sharedInstanceInternal();
|
---|
150 | if (!instance)
|
---|
151 | instance = new JSGlobalData(true);
|
---|
152 | return *instance;
|
---|
153 | }
|
---|
154 |
|
---|
155 | JSGlobalData*& JSGlobalData::sharedInstanceInternal()
|
---|
156 | {
|
---|
157 | ASSERT(JSLock::currentThreadIsHoldingLock());
|
---|
158 | static JSGlobalData* sharedInstance;
|
---|
159 | return sharedInstance;
|
---|
160 | }
|
---|
161 |
|
---|
162 | }
|
---|