source: webkit/trunk/JavaScriptCore/runtime/JSGlobalData.h@ 61623

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

Adding regular expression caching to JavaScriptCore
https://bugs.webkit.org/show_bug.cgi?id=38142

Patch by Renata Hodovan <[email protected]> on 2010-06-22
Reviewed by Geoffrey Garen.

The cache is based on Round Robin eviction policy, and
can cache at most 256 character long regular expressions,
and at most 256 of them. These values can be changed at compile time.

(JSC::RegExpNode::emitBytecode):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::~JSGlobalData):

  • runtime/JSGlobalData.h:

(JSC::JSGlobalData::regExpCache):

  • runtime/RegExpCache.cpp: Added.

(JSC::RegExpCache::lookupOrCreate):
(JSC::RegExpCache::create):
(JSC::RegExpCache::RegExpCache):

  • runtime/RegExpCache.h: Added.
  • runtime/RegExpConstructor.cpp:

(JSC::constructRegExp):

  • runtime/RegExpKey.h: Added.

(JSC::RegExpKey::RegExpKey):
(JSC::RegExpKey::getFlagsValue):
(WTF::operator==):
(WTF::):

  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncCompile):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncMatch):
(JSC::stringProtoFuncSearch):

  • Property svn:eol-style set to native
File size: 7.8 KB
Line 
1/*
2 * Copyright (C) 2008, 2009 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#ifndef JSGlobalData_h
30#define JSGlobalData_h
31
32#include "CachedTranscendentalFunction.h"
33#include "Collector.h"
34#include "DateInstanceCache.h"
35#include "ExecutableAllocator.h"
36#include "JITStubs.h"
37#include "JSValue.h"
38#include "MarkStack.h"
39#include "NumericStrings.h"
40#include "SmallStrings.h"
41#include "Terminator.h"
42#include "TimeoutChecker.h"
43#include "WeakRandom.h"
44#include <wtf/Forward.h>
45#include <wtf/HashMap.h>
46#include <wtf/RefCounted.h>
47
48struct OpaqueJSClass;
49struct OpaqueJSClassContextData;
50
51namespace JSC {
52
53 class CodeBlock;
54 class CommonIdentifiers;
55 class IdentifierTable;
56 class Interpreter;
57 class JSGlobalObject;
58 class JSObject;
59 class Lexer;
60 class Parser;
61 class RegExpCache;
62 class Stringifier;
63 class Structure;
64 class UString;
65
66 struct HashTable;
67 struct Instruction;
68
69 struct DSTOffsetCache {
70 DSTOffsetCache()
71 {
72 reset();
73 }
74
75 void reset()
76 {
77 offset = 0.0;
78 start = 0.0;
79 end = -1.0;
80 increment = 0.0;
81 }
82
83 double offset;
84 double start;
85 double end;
86 double increment;
87 };
88
89 enum ThreadStackType {
90 ThreadStackTypeLarge,
91 ThreadStackTypeSmall
92 };
93
94 class JSGlobalData : public RefCounted<JSGlobalData> {
95 public:
96 // WebCore has a one-to-one mapping of threads to JSGlobalDatas;
97 // either create() or createLeaked() should only be called once
98 // on a thread, this is the 'default' JSGlobalData (it uses the
99 // thread's default string uniquing table from wtfThreadData).
100 // API contexts created using the new context group aware interface
101 // create APIContextGroup objects which require less locking of JSC
102 // than the old singleton APIShared JSGlobalData created for use by
103 // the original API.
104 enum GlobalDataType { Default, APIContextGroup, APIShared };
105
106 struct ClientData {
107 virtual ~ClientData() = 0;
108 };
109
110 bool isSharedInstance() { return globalDataType == APIShared; }
111 static bool sharedInstanceExists();
112 static JSGlobalData& sharedInstance();
113
114 static PassRefPtr<JSGlobalData> create(ThreadStackType);
115 static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType);
116 static PassRefPtr<JSGlobalData> createContextGroup(ThreadStackType);
117 ~JSGlobalData();
118
119#if ENABLE(JSC_MULTIPLE_THREADS)
120 // Will start tracking threads that use the heap, which is resource-heavy.
121 void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); }
122#endif
123
124 GlobalDataType globalDataType;
125 ClientData* clientData;
126
127 const HashTable* arrayTable;
128 const HashTable* dateTable;
129 const HashTable* jsonTable;
130 const HashTable* mathTable;
131 const HashTable* numberTable;
132 const HashTable* regExpTable;
133 const HashTable* regExpConstructorTable;
134 const HashTable* stringTable;
135
136 RefPtr<Structure> activationStructure;
137 RefPtr<Structure> interruptedExecutionErrorStructure;
138 RefPtr<Structure> terminatedExecutionErrorStructure;
139 RefPtr<Structure> staticScopeStructure;
140 RefPtr<Structure> stringStructure;
141 RefPtr<Structure> notAnObjectErrorStubStructure;
142 RefPtr<Structure> notAnObjectStructure;
143 RefPtr<Structure> propertyNameIteratorStructure;
144 RefPtr<Structure> getterSetterStructure;
145 RefPtr<Structure> apiWrapperStructure;
146 RefPtr<Structure> dummyMarkableCellStructure;
147
148#if USE(JSVALUE32)
149 RefPtr<Structure> numberStructure;
150#endif
151
152 static void storeVPtrs();
153 static JS_EXPORTDATA void* jsArrayVPtr;
154 static JS_EXPORTDATA void* jsByteArrayVPtr;
155 static JS_EXPORTDATA void* jsStringVPtr;
156 static JS_EXPORTDATA void* jsFunctionVPtr;
157
158 IdentifierTable* identifierTable;
159 CommonIdentifiers* propertyNames;
160 const MarkedArgumentBuffer* emptyList; // Lists are supposed to be allocated on the stack to have their elements properly marked, which is not the case here - but this list has nothing to mark.
161 SmallStrings smallStrings;
162 NumericStrings numericStrings;
163 DateInstanceCache dateInstanceCache;
164
165#if ENABLE(ASSEMBLER)
166 ExecutableAllocator executableAllocator;
167#endif
168
169 Lexer* lexer;
170 Parser* parser;
171 Interpreter* interpreter;
172#if ENABLE(JIT)
173 JITThunks jitStubs;
174 MacroAssemblerCodePtr getCTIStub(ThunkGenerator generator)
175 {
176 return jitStubs.ctiStub(this, generator);
177 }
178 PassRefPtr<NativeExecutable> getHostFunction(NativeFunction function);
179 PassRefPtr<NativeExecutable> getHostFunction(NativeFunction function, ThunkGenerator generator);
180#endif
181 TimeoutChecker timeoutChecker;
182 Terminator terminator;
183 Heap heap;
184
185 JSValue exception;
186#if ENABLE(JIT)
187 ReturnAddressPtr exceptionLocation;
188#endif
189
190 const Vector<Instruction>& numericCompareFunction(ExecState*);
191 Vector<Instruction> lazyNumericCompareFunction;
192 bool initializingLazyNumericCompareFunction;
193
194 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
195
196 JSGlobalObject* head;
197 JSGlobalObject* dynamicGlobalObject;
198
199 HashSet<JSObject*> arrayVisitedElements;
200
201 CodeBlock* functionCodeBlockBeingReparsed;
202 Stringifier* firstStringifierToMark;
203
204 MarkStack markStack;
205
206 double cachedUTCOffset;
207 DSTOffsetCache dstOffsetCache;
208
209 UString cachedDateString;
210 double cachedDateStringValue;
211
212 WeakRandom weakRandom;
213
214 int maxReentryDepth;
215
216 RegExpCache* m_regExpCache;
217
218#ifndef NDEBUG
219 ThreadIdentifier exclusiveThread;
220#endif
221
222 CachedTranscendentalFunction<sin> cachedSin;
223
224 void resetDateCache();
225
226 void startSampling();
227 void stopSampling();
228 void dumpSampleData(ExecState* exec);
229 RegExpCache* regExpCache() { return m_regExpCache; }
230 private:
231 JSGlobalData(GlobalDataType, ThreadStackType);
232 static JSGlobalData*& sharedInstanceInternal();
233 void createNativeThunk();
234 };
235
236} // namespace JSC
237
238#endif // JSGlobalData_h
Note: See TracBrowser for help on using the repository browser.