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

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

Reviewed by Geoff Garen.

Bring back shared JSGlobalData and implicit locking, because too many clients rely on it.

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