]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
81345200 | 2 | * Copyright (C) 2008, 2009, 2013, 2014 Apple Inc. All rights reserved. |
9dae56ea A |
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. | |
81345200 | 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
9dae56ea A |
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 | ||
93a37866 A |
29 | #ifndef VM_h |
30 | #define VM_h | |
9dae56ea | 31 | |
f9bf01c6 | 32 | #include "DateInstanceCache.h" |
9dae56ea | 33 | #include "ExecutableAllocator.h" |
6fe7ccc8 A |
34 | #include "Heap.h" |
35 | #include "Intrinsic.h" | |
93a37866 | 36 | #include "JITThunks.h" |
93a37866 | 37 | #include "JSCJSValue.h" |
6fe7ccc8 | 38 | #include "JSLock.h" |
6fe7ccc8 | 39 | #include "LLIntData.h" |
93a37866 | 40 | #include "MacroAssemblerCodeRef.h" |
f9bf01c6 | 41 | #include "NumericStrings.h" |
93a37866 A |
42 | #include "PrivateName.h" |
43 | #include "PrototypeMap.h" | |
ba379fdc | 44 | #include "SmallStrings.h" |
81345200 | 45 | #include "SourceCode.h" |
6fe7ccc8 | 46 | #include "Strong.h" |
93a37866 | 47 | #include "ThunkGenerators.h" |
81345200 | 48 | #include "TypedArrayController.h" |
93a37866 | 49 | #include "Watchdog.h" |
81345200 | 50 | #include "Watchpoint.h" |
f9bf01c6 | 51 | #include "WeakRandom.h" |
14957cd0 | 52 | #include <wtf/BumpPointerAllocator.h> |
93a37866 | 53 | #include <wtf/DateMath.h> |
ba379fdc A |
54 | #include <wtf/Forward.h> |
55 | #include <wtf/HashMap.h> | |
81345200 | 56 | #include <wtf/HashSet.h> |
93a37866 | 57 | #include <wtf/RefCountedArray.h> |
6fe7ccc8 | 58 | #include <wtf/SimpleStats.h> |
81345200 | 59 | #include <wtf/StackBounds.h> |
6fe7ccc8 | 60 | #include <wtf/ThreadSafeRefCounted.h> |
14957cd0 A |
61 | #include <wtf/ThreadSpecific.h> |
62 | #include <wtf/WTFThreadData.h> | |
81345200 | 63 | #include <wtf/text/WTFString.h> |
14957cd0 A |
64 | #if ENABLE(REGEXP_TRACING) |
65 | #include <wtf/ListHashSet.h> | |
66 | #endif | |
9dae56ea | 67 | |
9dae56ea A |
68 | namespace JSC { |
69 | ||
81345200 A |
70 | class ArityCheckFailReturnThunks; |
71 | class BuiltinExecutables; | |
f9bf01c6 | 72 | class CodeBlock; |
93a37866 | 73 | class CodeCache; |
9dae56ea | 74 | class CommonIdentifiers; |
93a37866 | 75 | class ExecState; |
14957cd0 | 76 | class HandleStack; |
81345200 | 77 | class Identifier; |
9dae56ea A |
78 | class Interpreter; |
79 | class JSGlobalObject; | |
80 | class JSObject; | |
6fe7ccc8 A |
81 | class Keywords; |
82 | class LLIntOffsetsExtractor; | |
93a37866 | 83 | class LegacyProfiler; |
14957cd0 | 84 | class NativeExecutable; |
6fe7ccc8 | 85 | class ParserArena; |
4e4e5a6f | 86 | class RegExpCache; |
93a37866 A |
87 | class SourceProvider; |
88 | class SourceProviderCache; | |
89 | struct StackFrame; | |
ba379fdc | 90 | class Stringifier; |
9dae56ea | 91 | class Structure; |
14957cd0 A |
92 | #if ENABLE(REGEXP_TRACING) |
93 | class RegExp; | |
94 | #endif | |
93a37866 A |
95 | class UnlinkedCodeBlock; |
96 | class UnlinkedEvalCodeBlock; | |
97 | class UnlinkedFunctionExecutable; | |
98 | class UnlinkedProgramCodeBlock; | |
81345200 A |
99 | class VMEntryScope; |
100 | class Watchpoint; | |
101 | class WatchpointSet; | |
93a37866 A |
102 | |
103 | #if ENABLE(DFG_JIT) | |
104 | namespace DFG { | |
105 | class LongLivedState; | |
106 | } | |
107 | #endif // ENABLE(DFG_JIT) | |
81345200 A |
108 | #if ENABLE(FTL_JIT) |
109 | namespace FTL { | |
110 | class Thunks; | |
111 | } | |
112 | #endif // ENABLE(FTL_JIT) | |
113 | namespace CommonSlowPaths { | |
114 | struct ArityCheckData; | |
115 | } | |
116 | namespace Profiler { | |
117 | class Database; | |
118 | } | |
ba379fdc | 119 | |
9dae56ea | 120 | struct HashTable; |
14957cd0 | 121 | struct Instruction; |
f9bf01c6 | 122 | |
93a37866 A |
123 | struct LocalTimeOffsetCache { |
124 | LocalTimeOffsetCache() | |
125 | : start(0.0) | |
126 | , end(-1.0) | |
127 | , increment(0.0) | |
f9bf01c6 | 128 | { |
f9bf01c6 A |
129 | } |
130 | ||
131 | void reset() | |
132 | { | |
93a37866 | 133 | offset = LocalTimeOffset(); |
f9bf01c6 A |
134 | start = 0.0; |
135 | end = -1.0; | |
136 | increment = 0.0; | |
137 | } | |
138 | ||
93a37866 | 139 | LocalTimeOffset offset; |
f9bf01c6 A |
140 | double start; |
141 | double end; | |
142 | double increment; | |
143 | }; | |
9dae56ea | 144 | |
6fe7ccc8 A |
145 | class ConservativeRoots; |
146 | ||
93a37866 A |
147 | #if COMPILER(MSVC) |
148 | #pragma warning(push) | |
149 | #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning | |
150 | #endif | |
6fe7ccc8 A |
151 | struct ScratchBuffer { |
152 | ScratchBuffer() | |
6fe7ccc8 | 153 | { |
93a37866 | 154 | u.m_activeLength = 0; |
6fe7ccc8 A |
155 | } |
156 | ||
157 | static ScratchBuffer* create(size_t size) | |
158 | { | |
159 | ScratchBuffer* result = new (fastMalloc(ScratchBuffer::allocationSize(size))) ScratchBuffer; | |
160 | ||
161 | return result; | |
162 | } | |
163 | ||
93a37866 A |
164 | static size_t allocationSize(size_t bufferSize) { return sizeof(ScratchBuffer) + bufferSize; } |
165 | void setActiveLength(size_t activeLength) { u.m_activeLength = activeLength; } | |
166 | size_t activeLength() const { return u.m_activeLength; }; | |
167 | size_t* activeLengthPtr() { return &u.m_activeLength; }; | |
6fe7ccc8 A |
168 | void* dataBuffer() { return m_buffer; } |
169 | ||
93a37866 A |
170 | union { |
171 | size_t m_activeLength; | |
172 | double pad; // Make sure m_buffer is double aligned. | |
173 | } u; | |
174 | #if CPU(MIPS) && (defined WTF_MIPS_ARCH_REV && WTF_MIPS_ARCH_REV == 2) | |
175 | void* m_buffer[0] __attribute__((aligned(8))); | |
176 | #else | |
6fe7ccc8 | 177 | void* m_buffer[0]; |
93a37866 | 178 | #endif |
6fe7ccc8 | 179 | }; |
93a37866 A |
180 | #if COMPILER(MSVC) |
181 | #pragma warning(pop) | |
6fe7ccc8 A |
182 | #endif |
183 | ||
93a37866 | 184 | class VM : public ThreadSafeRefCounted<VM> { |
9dae56ea | 185 | public: |
93a37866 | 186 | // WebCore has a one-to-one mapping of threads to VMs; |
4e4e5a6f | 187 | // either create() or createLeaked() should only be called once |
93a37866 | 188 | // on a thread, this is the 'default' VM (it uses the |
4e4e5a6f A |
189 | // thread's default string uniquing table from wtfThreadData). |
190 | // API contexts created using the new context group aware interface | |
191 | // create APIContextGroup objects which require less locking of JSC | |
93a37866 | 192 | // than the old singleton APIShared VM created for use by |
4e4e5a6f | 193 | // the original API. |
93a37866 | 194 | enum VMType { Default, APIContextGroup, APIShared }; |
6fe7ccc8 | 195 | |
ba379fdc | 196 | struct ClientData { |
6fe7ccc8 | 197 | JS_EXPORT_PRIVATE virtual ~ClientData() = 0; |
ba379fdc A |
198 | }; |
199 | ||
93a37866 A |
200 | bool isSharedInstance() { return vmType == APIShared; } |
201 | bool usingAPI() { return vmType != Default; } | |
6fe7ccc8 | 202 | JS_EXPORT_PRIVATE static bool sharedInstanceExists(); |
93a37866 | 203 | JS_EXPORT_PRIVATE static VM& sharedInstance(); |
9dae56ea | 204 | |
93a37866 A |
205 | JS_EXPORT_PRIVATE static PassRefPtr<VM> create(HeapType = SmallHeap); |
206 | JS_EXPORT_PRIVATE static PassRefPtr<VM> createLeaked(HeapType = SmallHeap); | |
207 | static PassRefPtr<VM> createContextGroup(HeapType = SmallHeap); | |
208 | JS_EXPORT_PRIVATE ~VM(); | |
9dae56ea | 209 | |
14957cd0 | 210 | void makeUsableFromMultipleThreads() { heap.machineThreads().makeUsableFromMultipleThreads(); } |
81345200 | 211 | |
6fe7ccc8 | 212 | private: |
93a37866 | 213 | RefPtr<JSLock> m_apiLock; |
6fe7ccc8 A |
214 | |
215 | public: | |
93a37866 A |
216 | #if ENABLE(ASSEMBLER) |
217 | // executableAllocator should be destructed after the heap, as the heap can call executableAllocator | |
218 | // in its destructor. | |
219 | ExecutableAllocator executableAllocator; | |
220 | #endif | |
9dae56ea | 221 | |
93a37866 A |
222 | // The heap should be just after executableAllocator and before other members to ensure that it's |
223 | // destructed after all the objects that reference it. | |
224 | Heap heap; | |
225 | ||
226 | #if ENABLE(DFG_JIT) | |
81345200 | 227 | OwnPtr<DFG::LongLivedState> dfgState; |
93a37866 A |
228 | #endif // ENABLE(DFG_JIT) |
229 | ||
230 | VMType vmType; | |
ba379fdc | 231 | ClientData* clientData; |
93a37866 | 232 | ExecState* topCallFrame; |
81345200 A |
233 | std::unique_ptr<Watchdog> watchdog; |
234 | ||
235 | const OwnPtr<const HashTable> arrayConstructorTable; | |
236 | const OwnPtr<const HashTable> arrayPrototypeTable; | |
237 | const OwnPtr<const HashTable> booleanPrototypeTable; | |
238 | const OwnPtr<const HashTable> dataViewTable; | |
239 | const OwnPtr<const HashTable> dateTable; | |
240 | const OwnPtr<const HashTable> dateConstructorTable; | |
241 | const OwnPtr<const HashTable> errorPrototypeTable; | |
242 | const OwnPtr<const HashTable> globalObjectTable; | |
243 | const OwnPtr<const HashTable> jsonTable; | |
244 | const OwnPtr<const HashTable> numberConstructorTable; | |
245 | const OwnPtr<const HashTable> numberPrototypeTable; | |
246 | const OwnPtr<const HashTable> objectConstructorTable; | |
247 | const OwnPtr<const HashTable> privateNamePrototypeTable; | |
248 | const OwnPtr<const HashTable> regExpTable; | |
249 | const OwnPtr<const HashTable> regExpConstructorTable; | |
250 | const OwnPtr<const HashTable> regExpPrototypeTable; | |
251 | const OwnPtr<const HashTable> stringConstructorTable; | |
252 | #if ENABLE(PROMISES) | |
253 | const OwnPtr<const HashTable> promisePrototypeTable; | |
254 | const OwnPtr<const HashTable> promiseConstructorTable; | |
255 | #endif | |
256 | ||
14957cd0 | 257 | Strong<Structure> structureStructure; |
93a37866 | 258 | Strong<Structure> structureRareDataStructure; |
14957cd0 | 259 | Strong<Structure> debuggerActivationStructure; |
14957cd0 | 260 | Strong<Structure> terminatedExecutionErrorStructure; |
14957cd0 A |
261 | Strong<Structure> stringStructure; |
262 | Strong<Structure> notAnObjectStructure; | |
263 | Strong<Structure> propertyNameIteratorStructure; | |
264 | Strong<Structure> getterSetterStructure; | |
81345200 | 265 | Strong<Structure> customGetterSetterStructure; |
14957cd0 | 266 | Strong<Structure> apiWrapperStructure; |
93a37866 | 267 | Strong<Structure> JSScopeStructure; |
14957cd0 A |
268 | Strong<Structure> executableStructure; |
269 | Strong<Structure> nativeExecutableStructure; | |
270 | Strong<Structure> evalExecutableStructure; | |
271 | Strong<Structure> programExecutableStructure; | |
272 | Strong<Structure> functionExecutableStructure; | |
14957cd0 | 273 | Strong<Structure> regExpStructure; |
81345200 | 274 | Strong<Structure> symbolTableStructure; |
14957cd0 | 275 | Strong<Structure> structureChainStructure; |
93a37866 | 276 | Strong<Structure> sparseArrayValueMapStructure; |
81345200 | 277 | Strong<Structure> arrayBufferNeuteringWatchpointStructure; |
93a37866 A |
278 | Strong<Structure> withScopeStructure; |
279 | Strong<Structure> unlinkedFunctionExecutableStructure; | |
280 | Strong<Structure> unlinkedProgramCodeBlockStructure; | |
281 | Strong<Structure> unlinkedEvalCodeBlockStructure; | |
282 | Strong<Structure> unlinkedFunctionCodeBlockStructure; | |
283 | Strong<Structure> propertyTableStructure; | |
81345200 A |
284 | Strong<Structure> mapDataStructure; |
285 | Strong<Structure> weakMapDataStructure; | |
286 | #if ENABLE(PROMISES) | |
287 | Strong<Structure> promiseDeferredStructure; | |
288 | Strong<Structure> promiseReactionStructure; | |
289 | #endif | |
290 | Strong<JSCell> iterationTerminator; | |
14957cd0 | 291 | |
81345200 | 292 | AtomicStringTable* m_atomicStringTable; |
9dae56ea | 293 | CommonIdentifiers* propertyNames; |
ba379fdc | 294 | 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. |
9dae56ea | 295 | SmallStrings smallStrings; |
f9bf01c6 A |
296 | NumericStrings numericStrings; |
297 | DateInstanceCache dateInstanceCache; | |
6fe7ccc8 | 298 | WTF::SimpleStats machineCodeBytesPerBytecodeWordForBaselineJIT; |
81345200 A |
299 | WeakGCMap<StringImpl*, JSString, PtrHash<StringImpl*>> stringCache; |
300 | Strong<JSString> lastCachedString; | |
6fe7ccc8 | 301 | |
81345200 | 302 | AtomicStringTable* atomicStringTable() const { return m_atomicStringTable; } |
6fe7ccc8 A |
303 | |
304 | void setInDefineOwnProperty(bool inDefineOwnProperty) | |
305 | { | |
306 | m_inDefineOwnProperty = inDefineOwnProperty; | |
307 | } | |
308 | ||
309 | bool isInDefineOwnProperty() | |
310 | { | |
311 | return m_inDefineOwnProperty; | |
312 | } | |
313 | ||
81345200 A |
314 | LegacyProfiler* enabledProfiler() { return m_enabledProfiler; } |
315 | void setEnabledProfiler(LegacyProfiler*); | |
316 | ||
317 | void* enabledProfilerAddress() { return &m_enabledProfiler; } | |
9dae56ea | 318 | |
81345200 | 319 | #if ENABLE(JIT) |
93a37866 | 320 | bool canUseJIT() { return m_canUseJIT; } |
4e4e5a6f | 321 | #else |
93a37866 | 322 | bool canUseJIT() { return false; } // interpreter only |
4e4e5a6f | 323 | #endif |
14957cd0 | 324 | |
93a37866 A |
325 | #if ENABLE(YARR_JIT) |
326 | bool canUseRegExpJIT() { return m_canUseRegExpJIT; } | |
6fe7ccc8 | 327 | #else |
93a37866 | 328 | bool canUseRegExpJIT() { return false; } // interpreter only |
6fe7ccc8 | 329 | #endif |
14957cd0 | 330 | |
93a37866 A |
331 | SourceProviderCache* addSourceProviderCache(SourceProvider*); |
332 | void clearSourceProviderCaches(); | |
333 | ||
334 | PrototypeMap prototypeMap; | |
335 | ||
6fe7ccc8 | 336 | OwnPtr<ParserArena> parserArena; |
81345200 | 337 | typedef HashMap<RefPtr<SourceProvider>, RefPtr<SourceProviderCache>> SourceProviderCacheMap; |
93a37866 | 338 | SourceProviderCacheMap sourceProviderCacheMap; |
6fe7ccc8 | 339 | OwnPtr<Keywords> keywords; |
ba379fdc A |
340 | Interpreter* interpreter; |
341 | #if ENABLE(JIT) | |
4e4e5a6f | 342 | OwnPtr<JITThunks> jitStubs; |
6fe7ccc8 | 343 | MacroAssemblerCodeRef getCTIStub(ThunkGenerator generator) |
4e4e5a6f | 344 | { |
14957cd0 | 345 | return jitStubs->ctiStub(this, generator); |
4e4e5a6f | 346 | } |
6fe7ccc8 | 347 | NativeExecutable* getHostFunction(NativeFunction, Intrinsic); |
81345200 A |
348 | |
349 | std::unique_ptr<ArityCheckFailReturnThunks> arityCheckFailReturnThunks; | |
350 | #endif // ENABLE(JIT) | |
351 | std::unique_ptr<CommonSlowPaths::ArityCheckData> arityCheckData; | |
352 | #if ENABLE(FTL_JIT) | |
353 | std::unique_ptr<FTL::Thunks> ftlThunks; | |
ba379fdc | 354 | #endif |
6fe7ccc8 | 355 | NativeExecutable* getHostFunction(NativeFunction, NativeFunction constructor); |
14957cd0 | 356 | |
81345200 A |
357 | static ptrdiff_t exceptionOffset() |
358 | { | |
359 | return OBJECT_OFFSETOF(VM, m_exception); | |
360 | } | |
361 | ||
362 | static ptrdiff_t callFrameForThrowOffset() | |
363 | { | |
364 | return OBJECT_OFFSETOF(VM, callFrameForThrow); | |
365 | } | |
366 | ||
367 | static ptrdiff_t targetMachinePCForThrowOffset() | |
368 | { | |
369 | return OBJECT_OFFSETOF(VM, targetMachinePCForThrow); | |
370 | } | |
371 | ||
372 | JS_EXPORT_PRIVATE void clearException(); | |
93a37866 | 373 | JS_EXPORT_PRIVATE void clearExceptionStack(); |
81345200 A |
374 | void getExceptionInfo(JSValue& exception, RefCountedArray<StackFrame>& exceptionStack); |
375 | void setExceptionInfo(JSValue& exception, RefCountedArray<StackFrame>& exceptionStack); | |
376 | JSValue exception() const { return m_exception; } | |
377 | JSValue* addressOfException() { return &m_exception; } | |
378 | const RefCountedArray<StackFrame>& exceptionStack() const { return m_exceptionStack; } | |
379 | ||
380 | JS_EXPORT_PRIVATE JSValue throwException(ExecState*, JSValue); | |
381 | JS_EXPORT_PRIVATE JSObject* throwException(ExecState*, JSObject*); | |
382 | ||
383 | void* stackPointerAtVMEntry() const { return m_stackPointerAtVMEntry; } | |
384 | void setStackPointerAtVMEntry(void*); | |
385 | ||
386 | size_t reservedZoneSize() const { return m_reservedZoneSize; } | |
387 | size_t updateReservedZoneSize(size_t reservedZoneSize); | |
388 | ||
389 | #if ENABLE(FTL_JIT) | |
390 | void updateFTLLargestStackSize(size_t); | |
391 | void** addressOfFTLStackLimit() { return &m_ftlStackLimit; } | |
392 | #endif | |
393 | ||
394 | #if !ENABLE(JIT) | |
395 | void* jsStackLimit() { return m_jsStackLimit; } | |
396 | void setJSStackLimit(void* limit) { m_jsStackLimit = limit; } | |
397 | #endif | |
398 | void* stackLimit() { return m_stackLimit; } | |
399 | void** addressOfStackLimit() { return &m_stackLimit; } | |
400 | ||
401 | bool isSafeToRecurse(size_t neededStackInBytes = 0) const | |
402 | { | |
403 | ASSERT(wtfThreadData().stack().isGrowingDownward()); | |
404 | int8_t* curr = reinterpret_cast<int8_t*>(&curr); | |
405 | int8_t* limit = reinterpret_cast<int8_t*>(m_stackLimit); | |
406 | return curr >= limit && static_cast<size_t>(curr - limit) >= neededStackInBytes; | |
407 | } | |
408 | ||
409 | void* lastStackTop() { return m_lastStackTop; } | |
410 | void setLastStackTop(void* lastStackTop) { m_lastStackTop = lastStackTop; } | |
6fe7ccc8 A |
411 | |
412 | const ClassInfo* const jsArrayClassInfo; | |
413 | const ClassInfo* const jsFinalObjectClassInfo; | |
414 | ||
6fe7ccc8 | 415 | JSValue hostCallReturnValue; |
81345200 | 416 | ExecState* newCallFrameReturnValue; |
40a37d08 | 417 | unsigned varargsLength; |
93a37866 | 418 | ExecState* callFrameForThrow; |
6fe7ccc8 A |
419 | void* targetMachinePCForThrow; |
420 | Instruction* targetInterpreterPCForThrow; | |
6fe7ccc8 A |
421 | uint32_t osrExitIndex; |
422 | void* osrExitJumpDestination; | |
423 | Vector<ScratchBuffer*> scratchBuffers; | |
424 | size_t sizeOfLastScratchBuffer; | |
425 | ||
426 | ScratchBuffer* scratchBufferForSize(size_t size) | |
427 | { | |
428 | if (!size) | |
429 | return 0; | |
430 | ||
431 | if (size > sizeOfLastScratchBuffer) { | |
432 | // Protect against a N^2 memory usage pathology by ensuring | |
433 | // that at worst, we get a geometric series, meaning that the | |
434 | // total memory usage is somewhere around | |
435 | // max(scratch buffer size) * 4. | |
436 | sizeOfLastScratchBuffer = size * 2; | |
437 | ||
81345200 A |
438 | ScratchBuffer* newBuffer = ScratchBuffer::create(sizeOfLastScratchBuffer); |
439 | RELEASE_ASSERT(newBuffer); | |
440 | scratchBuffers.append(newBuffer); | |
6fe7ccc8 A |
441 | } |
442 | ||
443 | ScratchBuffer* result = scratchBuffers.last(); | |
444 | result->setActiveLength(0); | |
445 | return result; | |
446 | } | |
447 | ||
448 | void gatherConservativeRoots(ConservativeRoots&); | |
9dae56ea | 449 | |
81345200 | 450 | VMEntryScope* entryScope; |
9dae56ea | 451 | |
14957cd0 | 452 | HashSet<JSObject*> stringRecursionCheckVisitedObjects; |
f9bf01c6 | 453 | |
93a37866 | 454 | LocalTimeOffsetCache localTimeOffsetCache; |
f9bf01c6 | 455 | |
93a37866 | 456 | String cachedDateString; |
f9bf01c6 | 457 | double cachedDateStringValue; |
4e4e5a6f | 458 | |
93a37866 | 459 | OwnPtr<Profiler::Database> m_perBytecodeProfiler; |
81345200 | 460 | RefPtr<TypedArrayController> m_typedArrayController; |
4e4e5a6f | 461 | RegExpCache* m_regExpCache; |
14957cd0 A |
462 | BumpPointerAllocator m_regExpAllocator; |
463 | ||
464 | #if ENABLE(REGEXP_TRACING) | |
81345200 | 465 | typedef ListHashSet<RegExp*> RTTraceList; |
14957cd0 A |
466 | RTTraceList* m_rtTraceList; |
467 | #endif | |
f9bf01c6 | 468 | |
81345200 A |
469 | bool hasExclusiveThread() const { return m_apiLock->hasExclusiveThread(); } |
470 | std::thread::id exclusiveThread() const { return m_apiLock->exclusiveThread(); } | |
471 | void setExclusiveThread(std::thread::id threadId) { m_apiLock->setExclusiveThread(threadId); } | |
4e4e5a6f | 472 | |
6fe7ccc8 | 473 | JS_EXPORT_PRIVATE void resetDateCache(); |
f9bf01c6 | 474 | |
6fe7ccc8 A |
475 | JS_EXPORT_PRIVATE void startSampling(); |
476 | JS_EXPORT_PRIVATE void stopSampling(); | |
477 | JS_EXPORT_PRIVATE void dumpSampleData(ExecState* exec); | |
4e4e5a6f | 478 | RegExpCache* regExpCache() { return m_regExpCache; } |
14957cd0 | 479 | #if ENABLE(REGEXP_TRACING) |
81345200 | 480 | void addRegExpToTrace(RegExp*); |
14957cd0 | 481 | #endif |
6fe7ccc8 | 482 | JS_EXPORT_PRIVATE void dumpRegExpTrace(); |
14957cd0 A |
483 | |
484 | bool isCollectorBusy() { return heap.isBusy(); } | |
6fe7ccc8 A |
485 | JS_EXPORT_PRIVATE void releaseExecutableMemory(); |
486 | ||
487 | #if ENABLE(GC_VALIDATION) | |
488 | bool isInitializingObject() const; | |
489 | void setInitializingObjectClass(const ClassInfo*); | |
490 | #endif | |
491 | ||
93a37866 A |
492 | unsigned m_newStringsSinceLastHashCons; |
493 | ||
494 | static const unsigned s_minNumberOfNewStringsToHashCons = 100; | |
495 | ||
496 | bool haveEnoughNewStringsToHashCons() { return m_newStringsSinceLastHashCons > s_minNumberOfNewStringsToHashCons; } | |
497 | void resetNewStringsSinceLastHashCons() { m_newStringsSinceLastHashCons = 0; } | |
6fe7ccc8 | 498 | |
81345200 | 499 | bool currentThreadIsHoldingAPILock() const { return m_apiLock->currentThreadIsHoldingLock(); } |
93a37866 A |
500 | |
501 | JSLock& apiLock() { return *m_apiLock; } | |
502 | CodeCache* codeCache() { return m_codeCache.get(); } | |
6fe7ccc8 | 503 | |
81345200 A |
504 | void waitForCompilationsToComplete(); |
505 | ||
93a37866 | 506 | JS_EXPORT_PRIVATE void discardAllCode(); |
14957cd0 | 507 | |
81345200 A |
508 | void registerWatchpointForImpureProperty(const Identifier&, Watchpoint*); |
509 | // FIXME: Use AtomicString once it got merged with Identifier. | |
510 | JS_EXPORT_PRIVATE void addImpureProperty(const String&); | |
511 | ||
512 | BuiltinExecutables* builtinExecutables() { return m_builtinExecutables.get(); } | |
513 | ||
9dae56ea | 514 | private: |
6fe7ccc8 | 515 | friend class LLIntOffsetsExtractor; |
81345200 A |
516 | friend class ClearExceptionScope; |
517 | friend class RecursiveAllocationScope; | |
6fe7ccc8 | 518 | |
93a37866 A |
519 | VM(VMType, HeapType); |
520 | static VM*& sharedInstanceInternal(); | |
ba379fdc | 521 | void createNativeThunk(); |
81345200 A |
522 | |
523 | void updateStackLimit(); | |
524 | ||
93a37866 | 525 | #if ENABLE(ASSEMBLER) |
6fe7ccc8 A |
526 | bool m_canUseAssembler; |
527 | #endif | |
93a37866 A |
528 | #if ENABLE(JIT) |
529 | bool m_canUseJIT; | |
530 | #endif | |
531 | #if ENABLE(YARR_JIT) | |
532 | bool m_canUseRegExpJIT; | |
533 | #endif | |
6fe7ccc8 A |
534 | #if ENABLE(GC_VALIDATION) |
535 | const ClassInfo* m_initializingObjectClass; | |
4e4e5a6f | 536 | #endif |
81345200 A |
537 | void* m_stackPointerAtVMEntry; |
538 | size_t m_reservedZoneSize; | |
539 | #if !ENABLE(JIT) | |
540 | struct { | |
541 | void* m_stackLimit; | |
542 | void* m_jsStackLimit; | |
543 | }; | |
544 | #else | |
545 | union { | |
546 | void* m_stackLimit; | |
547 | void* m_jsStackLimit; | |
548 | }; | |
549 | #if ENABLE(FTL_JIT) | |
550 | void* m_ftlStackLimit; | |
551 | size_t m_largestFTLStackSize; | |
552 | #endif | |
553 | #endif | |
554 | void* m_lastStackTop; | |
555 | JSValue m_exception; | |
6fe7ccc8 | 556 | bool m_inDefineOwnProperty; |
81345200 A |
557 | OwnPtr<CodeCache> m_codeCache; |
558 | LegacyProfiler* m_enabledProfiler; | |
559 | OwnPtr<BuiltinExecutables> m_builtinExecutables; | |
93a37866 | 560 | RefCountedArray<StackFrame> m_exceptionStack; |
81345200 | 561 | HashMap<String, RefPtr<WatchpointSet>> m_impurePropertyWatchpointSets; |
9dae56ea | 562 | }; |
4e4e5a6f | 563 | |
6fe7ccc8 | 564 | #if ENABLE(GC_VALIDATION) |
93a37866 | 565 | inline bool VM::isInitializingObject() const |
14957cd0 | 566 | { |
6fe7ccc8 | 567 | return !!m_initializingObjectClass; |
14957cd0 A |
568 | } |
569 | ||
93a37866 | 570 | inline void VM::setInitializingObjectClass(const ClassInfo* initializingObjectClass) |
6fe7ccc8 A |
571 | { |
572 | m_initializingObjectClass = initializingObjectClass; | |
573 | } | |
574 | #endif | |
575 | ||
93a37866 A |
576 | inline Heap* WeakSet::heap() const |
577 | { | |
578 | return &m_vm->heap; | |
579 | } | |
580 | ||
81345200 A |
581 | #if ENABLE(JIT) |
582 | extern "C" void sanitizeStackForVMImpl(VM*); | |
583 | #endif | |
584 | ||
585 | void sanitizeStackForVM(VM*); | |
586 | void logSanitizeStack(VM*); | |
587 | ||
ba379fdc | 588 | } // namespace JSC |
9dae56ea | 589 | |
93a37866 | 590 | #endif // VM_h |