2 * Copyright (C) 2008-2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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 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.
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.
32 #include "ConcurrentJSLock.h"
33 #include "ControlFlowProfiler.h"
34 #include "DateInstanceCache.h"
35 #include "DeleteAllCodeEffort.h"
36 #include "ExceptionEventLocation.h"
37 #include "ExecutableAllocator.h"
38 #include "FunctionHasExecutedCache.h"
40 #include "Intrinsic.h"
41 #include "JITThunks.h"
42 #include "JSCJSValue.h"
43 #include "JSDestructibleObjectSubspace.h"
45 #include "JSSegmentedVariableObjectSubspace.h"
46 #include "JSStringSubspace.h"
47 #include "MacroAssemblerCodeRef.h"
48 #include "Microtask.h"
49 #include "NumericStrings.h"
50 #include "PrivateName.h"
51 #include "PrototypeMap.h"
52 #include "SmallStrings.h"
53 #include "SourceCode.h"
56 #include "TemplateRegistryKeyTable.h"
57 #include "ThunkGenerators.h"
58 #include "VMEntryRecord.h"
59 #include "Watchpoint.h"
61 #include <wtf/BumpPointerAllocator.h>
62 #include <wtf/DateMath.h>
63 #include <wtf/Deque.h>
64 #include <wtf/DoublyLinkedList.h>
65 #include <wtf/Forward.h>
66 #include <wtf/HashMap.h>
67 #include <wtf/HashSet.h>
68 #include <wtf/StackBounds.h>
69 #include <wtf/Stopwatch.h>
70 #include <wtf/ThreadSafeRefCounted.h>
71 #include <wtf/ThreadSpecific.h>
72 #include <wtf/WTFThreadData.h>
73 #include <wtf/text/SymbolRegistry.h>
74 #include <wtf/text/WTFString.h>
75 #if ENABLE(REGEXP_TRACING)
76 #include <wtf/ListHashSet.h>
82 using WTF::SimpleStats;
86 class BuiltinExecutables;
87 class BytecodeIntrinsicRegistry;
90 class CommonIdentifiers;
91 class CustomGetterSetter;
97 class TypeProfilerLog;
98 class HasOwnPropertyCache;
102 class JSCustomGetterSetterFunction;
103 class JSGlobalObject;
105 class JSWebAssemblyInstance;
106 class LLIntOffsetsExtractor;
107 class NativeExecutable;
110 class RegisterAtOffsetList;
111 #if ENABLE(SAMPLING_PROFILER)
112 class SamplingProfiler;
115 class ScriptExecutable;
116 class SourceProvider;
117 class SourceProviderCache;
120 #if ENABLE(REGEXP_TRACING)
124 class TypedArrayController;
125 class UnlinkedCodeBlock;
126 class UnlinkedEvalCodeBlock;
127 class UnlinkedFunctionExecutable;
128 class UnlinkedProgramCodeBlock;
129 class UnlinkedModuleProgramCodeBlock;
130 class VirtualRegister;
138 class LongLivedState;
140 #endif // ENABLE(DFG_JIT)
145 #endif // ENABLE(FTL_JIT)
146 namespace CommonSlowPaths {
147 struct ArityCheckData;
155 #if ENABLE(WEBASSEMBLY)
157 class SignatureInformation;
164 struct LocalTimeOffsetCache {
165 LocalTimeOffsetCache()
169 , timeType(WTF::UTCTime)
175 offset = LocalTimeOffset();
179 timeType = WTF::UTCTime;
182 LocalTimeOffset offset;
186 WTF::TimeType timeType;
190 WTF_MAKE_NONCOPYABLE(QueuedTask);
191 WTF_MAKE_FAST_ALLOCATED;
195 QueuedTask(VM& vm, JSGlobalObject* globalObject, Ref<Microtask>&& microtask)
196 : m_globalObject(vm, globalObject)
197 , m_microtask(WTFMove(microtask))
202 Strong<JSGlobalObject> m_globalObject;
203 Ref<Microtask> m_microtask;
206 class ConservativeRoots;
209 #pragma warning(push)
210 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
212 struct ScratchBuffer {
215 u.m_activeLength = 0;
218 static ScratchBuffer* create(size_t size)
220 ScratchBuffer* result = new (fastMalloc(ScratchBuffer::allocationSize(size))) ScratchBuffer;
225 static size_t allocationSize(size_t bufferSize) { return sizeof(ScratchBuffer) + bufferSize; }
226 void setActiveLength(size_t activeLength) { u.m_activeLength = activeLength; }
227 size_t activeLength() const { return u.m_activeLength; };
228 size_t* activeLengthPtr() { return &u.m_activeLength; };
229 void* dataBuffer() { return m_buffer; }
232 size_t m_activeLength;
233 double pad; // Make sure m_buffer is double aligned.
235 #if CPU(MIPS) && (defined WTF_MIPS_ARCH_REV && WTF_MIPS_ARCH_REV == 2)
236 void* m_buffer[0] __attribute__((aligned(8)));
245 class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {
247 // WebCore has a one-to-one mapping of threads to VMs;
248 // either create() or createLeaked() should only be called once
249 // on a thread, this is the 'default' VM (it uses the
250 // thread's default string uniquing table from wtfThreadData).
251 // API contexts created using the new context group aware interface
252 // create APIContextGroup objects which require less locking of JSC
253 // than the old singleton APIShared VM created for use by
255 enum VMType { Default, APIContextGroup, APIShared };
258 JS_EXPORT_PRIVATE virtual ~ClientData() = 0;
261 bool isSharedInstance() { return vmType == APIShared; }
262 bool usingAPI() { return vmType != Default; }
263 JS_EXPORT_PRIVATE static bool sharedInstanceExists();
264 JS_EXPORT_PRIVATE static VM& sharedInstance();
266 JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap);
267 JS_EXPORT_PRIVATE static Ref<VM> createLeaked(HeapType = SmallHeap);
268 static Ref<VM> createContextGroup(HeapType = SmallHeap);
269 JS_EXPORT_PRIVATE ~VM();
271 JS_EXPORT_PRIVATE Watchdog& ensureWatchdog();
272 Watchdog* watchdog() { return m_watchdog.get(); }
274 HeapProfiler* heapProfiler() const { return m_heapProfiler.get(); }
275 JS_EXPORT_PRIVATE HeapProfiler& ensureHeapProfiler();
277 #if ENABLE(SAMPLING_PROFILER)
278 SamplingProfiler* samplingProfiler() { return m_samplingProfiler.get(); }
279 JS_EXPORT_PRIVATE SamplingProfiler& ensureSamplingProfiler(RefPtr<Stopwatch>&&);
283 RefPtr<JSLock> m_apiLock;
286 #if ENABLE(ASSEMBLER)
287 // executableAllocator should be destructed after the heap, as the heap can call executableAllocator
288 // in its destructor.
289 ExecutableAllocator executableAllocator;
292 // The heap should be just after executableAllocator and before other members to ensure that it's
293 // destructed after all the objects that reference it.
296 Subspace auxiliarySpace;
298 // Whenever possible, use subspaceFor<CellType>(vm) to get one of these subspaces.
300 Subspace destructibleCellSpace;
301 JSStringSubspace stringSpace;
302 JSDestructibleObjectSubspace destructibleObjectSpace;
303 JSSegmentedVariableObjectSubspace segmentedVariableObjectSpace;
306 std::unique_ptr<DFG::LongLivedState> dfgState;
307 #endif // ENABLE(DFG_JIT)
310 ClientData* clientData;
311 VMEntryFrame* topVMEntryFrame;
312 // NOTE: When throwing an exception while rolling back the call frame, this may be equal to
314 // FIXME: This should be a void*, because it might not point to a CallFrame.
315 // https://bugs.webkit.org/show_bug.cgi?id=160441
316 ExecState* topCallFrame;
317 JSWebAssemblyInstance* topJSWebAssemblyInstance;
318 Strong<Structure> structureStructure;
319 Strong<Structure> structureRareDataStructure;
320 Strong<Structure> terminatedExecutionErrorStructure;
321 Strong<Structure> stringStructure;
322 Strong<Structure> propertyNameIteratorStructure;
323 Strong<Structure> propertyNameEnumeratorStructure;
324 Strong<Structure> customGetterSetterStructure;
325 Strong<Structure> scopedArgumentsTableStructure;
326 Strong<Structure> apiWrapperStructure;
327 Strong<Structure> JSScopeStructure;
328 Strong<Structure> executableStructure;
329 Strong<Structure> nativeExecutableStructure;
330 Strong<Structure> evalExecutableStructure;
331 Strong<Structure> programExecutableStructure;
332 Strong<Structure> functionExecutableStructure;
333 #if ENABLE(WEBASSEMBLY)
334 Strong<Structure> webAssemblyCalleeStructure;
335 Strong<Structure> webAssemblyToJSCalleeStructure;
336 Strong<JSCell> webAssemblyToJSCallee;
338 Strong<Structure> moduleProgramExecutableStructure;
339 Strong<Structure> regExpStructure;
340 Strong<Structure> symbolStructure;
341 Strong<Structure> symbolTableStructure;
342 Strong<Structure> fixedArrayStructure;
343 Strong<Structure> sourceCodeStructure;
344 Strong<Structure> scriptFetcherStructure;
345 Strong<Structure> structureChainStructure;
346 Strong<Structure> sparseArrayValueMapStructure;
347 Strong<Structure> templateRegistryKeyStructure;
348 Strong<Structure> arrayBufferNeuteringWatchpointStructure;
349 Strong<Structure> unlinkedFunctionExecutableStructure;
350 Strong<Structure> unlinkedProgramCodeBlockStructure;
351 Strong<Structure> unlinkedEvalCodeBlockStructure;
352 Strong<Structure> unlinkedFunctionCodeBlockStructure;
353 Strong<Structure> unlinkedModuleProgramCodeBlockStructure;
354 Strong<Structure> propertyTableStructure;
355 Strong<Structure> weakMapDataStructure;
356 Strong<Structure> inferredValueStructure;
357 Strong<Structure> inferredTypeStructure;
358 Strong<Structure> inferredTypeTableStructure;
359 Strong<Structure> functionRareDataStructure;
360 Strong<Structure> exceptionStructure;
361 Strong<Structure> promiseDeferredStructure;
362 Strong<Structure> internalPromiseDeferredStructure;
363 Strong<Structure> nativeStdFunctionCellStructure;
364 Strong<Structure> programCodeBlockStructure;
365 Strong<Structure> moduleProgramCodeBlockStructure;
366 Strong<Structure> evalCodeBlockStructure;
367 Strong<Structure> functionCodeBlockStructure;
368 Strong<Structure> hashMapBucketSetStructure;
369 Strong<Structure> hashMapBucketMapStructure;
370 Strong<Structure> hashMapImplSetStructure;
371 Strong<Structure> hashMapImplMapStructure;
373 Strong<JSCell> iterationTerminator;
374 Strong<JSCell> emptyPropertyNameEnumerator;
376 #if ENABLE(WEBASSEMBLY)
377 std::once_flag m_wasmSignatureInformationOnceFlag;
378 std::unique_ptr<Wasm::SignatureInformation> m_wasmSignatureInformation;
381 JSCell* currentlyDestructingCallbackObject;
382 const ClassInfo* currentlyDestructingCallbackObjectClassInfo;
384 AtomicStringTable* m_atomicStringTable;
385 WTF::SymbolRegistry m_symbolRegistry;
386 TemplateRegistryKeyTable m_templateRegistryKeytable;
387 CommonIdentifiers* propertyNames;
388 const ArgList* emptyList;
389 SmallStrings smallStrings;
390 NumericStrings numericStrings;
391 DateInstanceCache dateInstanceCache;
392 std::unique_ptr<SimpleStats> machineCodeBytesPerBytecodeWordForBaselineJIT;
393 WeakGCMap<std::pair<CustomGetterSetter*, int>, JSCustomGetterSetterFunction> customGetterSetterFunctionMap;
394 WeakGCMap<StringImpl*, JSString, PtrHash<StringImpl*>> stringCache;
395 Strong<JSString> lastCachedString;
397 AtomicStringTable* atomicStringTable() const { return m_atomicStringTable; }
398 WTF::SymbolRegistry& symbolRegistry() { return m_symbolRegistry; }
400 TemplateRegistryKeyTable& templateRegistryKeyTable() { return m_templateRegistryKeytable; }
402 WeakGCMap<SymbolImpl*, Symbol, PtrHash<SymbolImpl*>> symbolImplToSymbolMap;
404 enum class DeletePropertyMode {
405 // Default behaviour of deleteProperty, matching the spec.
407 // This setting causes deleteProperty to force deletion of all
408 // properties including those that are non-configurable (DontDelete).
412 DeletePropertyMode deletePropertyMode()
414 return m_deletePropertyMode;
417 class DeletePropertyModeScope {
419 DeletePropertyModeScope(VM& vm, DeletePropertyMode mode)
421 , m_previousMode(vm.m_deletePropertyMode)
423 m_vm.m_deletePropertyMode = mode;
426 ~DeletePropertyModeScope()
428 m_vm.m_deletePropertyMode = m_previousMode;
433 DeletePropertyMode m_previousMode;
437 bool canUseJIT() { return m_canUseJIT; }
439 bool canUseJIT() { return false; } // interpreter only
443 bool canUseRegExpJIT() { return m_canUseRegExpJIT; }
445 bool canUseRegExpJIT() { return false; } // interpreter only
448 SourceProviderCache* addSourceProviderCache(SourceProvider*);
449 void clearSourceProviderCaches();
451 PrototypeMap prototypeMap;
453 typedef HashMap<RefPtr<SourceProvider>, RefPtr<SourceProviderCache>> SourceProviderCacheMap;
454 SourceProviderCacheMap sourceProviderCacheMap;
455 Interpreter* interpreter;
457 std::unique_ptr<JITThunks> jitStubs;
458 MacroAssemblerCodeRef getCTIStub(ThunkGenerator generator)
460 return jitStubs->ctiStub(this, generator);
463 std::unique_ptr<RegisterAtOffsetList> allCalleeSaveRegisterOffsets;
465 RegisterAtOffsetList* getAllCalleeSaveRegisterOffsets() { return allCalleeSaveRegisterOffsets.get(); }
467 #endif // ENABLE(JIT)
468 std::unique_ptr<CommonSlowPaths::ArityCheckData> arityCheckData;
470 std::unique_ptr<FTL::Thunks> ftlThunks;
472 NativeExecutable* getHostFunction(NativeFunction, NativeFunction constructor, const String& name);
473 NativeExecutable* getHostFunction(NativeFunction, Intrinsic, NativeFunction constructor, const DOMJIT::Signature*, const String& name);
475 static ptrdiff_t exceptionOffset()
477 return OBJECT_OFFSETOF(VM, m_exception);
480 static ptrdiff_t callFrameForCatchOffset()
482 return OBJECT_OFFSETOF(VM, callFrameForCatch);
485 static ptrdiff_t targetMachinePCForThrowOffset()
487 return OBJECT_OFFSETOF(VM, targetMachinePCForThrow);
490 void restorePreviousException(Exception* exception) { setException(exception); }
492 void clearLastException() { m_lastException = nullptr; }
494 ExecState** addressOfCallFrameForCatch() { return &callFrameForCatch; }
496 JSCell** addressOfException() { return reinterpret_cast<JSCell**>(&m_exception); }
498 Exception* lastException() const { return m_lastException; }
499 JSCell** addressOfLastException() { return reinterpret_cast<JSCell**>(&m_lastException); }
501 void setFailNextNewCodeBlock() { m_failNextNewCodeBlock = true; }
502 bool getAndClearFailNextNewCodeBlock()
504 bool result = m_failNextNewCodeBlock;
505 m_failNextNewCodeBlock = false;
509 ALWAYS_INLINE Structure* getStructure(StructureID id)
511 return heap.structureIDTable().get(decontaminate(id));
514 void* stackPointerAtVMEntry() const { return m_stackPointerAtVMEntry; }
515 void setStackPointerAtVMEntry(void*);
517 size_t softReservedZoneSize() const { return m_currentSoftReservedZoneSize; }
518 size_t updateSoftReservedZoneSize(size_t softReservedZoneSize);
520 static size_t committedStackByteCount();
521 inline bool ensureStackCapacityFor(Register* newTopOfStack);
523 void* stackLimit() { return m_stackLimit; }
524 void* softStackLimit() { return m_softStackLimit; }
525 void** addressOfSoftStackLimit() { return &m_softStackLimit; }
527 void* cloopStackLimit() { return m_cloopStackLimit; }
528 void setCLoopStackLimit(void* limit) { m_cloopStackLimit = limit; }
531 inline bool isSafeToRecurseSoft() const;
532 bool isSafeToRecurse() const
534 return isSafeToRecurse(m_stackLimit);
537 void* lastStackTop() { return m_lastStackTop; }
538 void setLastStackTop(void*);
540 const ClassInfo* const jsArrayClassInfo;
541 const ClassInfo* const jsFinalObjectClassInfo;
543 JSValue hostCallReturnValue;
544 unsigned varargsLength;
545 ExecState* newCallFrameReturnValue;
546 ExecState* callFrameForCatch;
547 void* targetMachinePCForThrow;
548 Instruction* targetInterpreterPCForThrow;
549 uint32_t osrExitIndex;
550 void* osrExitJumpDestination;
551 Vector<ScratchBuffer*> scratchBuffers;
552 size_t sizeOfLastScratchBuffer;
554 bool isExecutingInRegExpJIT { false };
556 ScratchBuffer* scratchBufferForSize(size_t size)
561 if (size > sizeOfLastScratchBuffer) {
562 // Protect against a N^2 memory usage pathology by ensuring
563 // that at worst, we get a geometric series, meaning that the
564 // total memory usage is somewhere around
565 // max(scratch buffer size) * 4.
566 sizeOfLastScratchBuffer = size * 2;
568 ScratchBuffer* newBuffer = ScratchBuffer::create(sizeOfLastScratchBuffer);
569 RELEASE_ASSERT(newBuffer);
570 scratchBuffers.append(newBuffer);
573 ScratchBuffer* result = scratchBuffers.last();
574 result->setActiveLength(0);
578 EncodedJSValue* exceptionFuzzingBuffer(size_t size)
580 ASSERT(Options::useExceptionFuzz());
581 if (!m_exceptionFuzzBuffer)
582 m_exceptionFuzzBuffer = MallocPtr<EncodedJSValue>::malloc(size);
583 return m_exceptionFuzzBuffer.get();
586 void gatherConservativeRoots(ConservativeRoots&);
588 VMEntryScope* entryScope;
590 JSObject* stringRecursionCheckFirstObject { nullptr };
591 HashSet<JSObject*> stringRecursionCheckVisitedObjects;
593 LocalTimeOffsetCache localTimeOffsetCache;
595 String cachedDateString;
596 double cachedDateStringValue;
598 std::unique_ptr<Profiler::Database> m_perBytecodeProfiler;
599 RefPtr<TypedArrayController> m_typedArrayController;
600 RegExpCache* m_regExpCache;
601 BumpPointerAllocator m_regExpAllocator;
602 ConcurrentJSLock m_regExpAllocatorLock;
604 std::unique_ptr<HasOwnPropertyCache> m_hasOwnPropertyCache;
605 ALWAYS_INLINE HasOwnPropertyCache* hasOwnPropertyCache() { return m_hasOwnPropertyCache.get(); }
606 HasOwnPropertyCache* ensureHasOwnPropertyCache();
608 #if ENABLE(REGEXP_TRACING)
609 typedef ListHashSet<RegExp*> RTTraceList;
610 RTTraceList* m_rtTraceList;
613 bool hasExclusiveThread() const { return m_apiLock->hasExclusiveThread(); }
614 std::thread::id exclusiveThread() const { return m_apiLock->exclusiveThread(); }
615 void setExclusiveThread(std::thread::id threadId) { m_apiLock->setExclusiveThread(threadId); }
617 JS_EXPORT_PRIVATE void resetDateCache();
619 RegExpCache* regExpCache() { return m_regExpCache; }
620 #if ENABLE(REGEXP_TRACING)
621 void addRegExpToTrace(RegExp*);
623 JS_EXPORT_PRIVATE void dumpRegExpTrace();
625 bool isCollectorBusyOnCurrentThread() { return heap.isCurrentThreadBusy(); }
627 #if ENABLE(GC_VALIDATION)
628 bool isInitializingObject() const;
629 void setInitializingObjectClass(const ClassInfo*);
632 bool currentThreadIsHoldingAPILock() const { return m_apiLock->currentThreadIsHoldingLock(); }
634 JSLock& apiLock() { return *m_apiLock; }
635 CodeCache* codeCache() { return m_codeCache.get(); }
637 JS_EXPORT_PRIVATE void whenIdle(std::function<void()>);
639 JS_EXPORT_PRIVATE void deleteAllCode(DeleteAllCodeEffort);
640 JS_EXPORT_PRIVATE void deleteAllLinkedCode(DeleteAllCodeEffort);
642 WatchpointSet* ensureWatchpointSetForImpureProperty(const Identifier&);
643 void registerWatchpointForImpureProperty(const Identifier&, Watchpoint*);
645 // FIXME: Use AtomicString once it got merged with Identifier.
646 JS_EXPORT_PRIVATE void addImpureProperty(const String&);
648 BuiltinExecutables* builtinExecutables() { return m_builtinExecutables.get(); }
650 bool enableTypeProfiler();
651 bool disableTypeProfiler();
652 TypeProfilerLog* typeProfilerLog() { return m_typeProfilerLog.get(); }
653 TypeProfiler* typeProfiler() { return m_typeProfiler.get(); }
654 JS_EXPORT_PRIVATE void dumpTypeProfilerData();
656 FunctionHasExecutedCache* functionHasExecutedCache() { return &m_functionHasExecutedCache; }
658 ControlFlowProfiler* controlFlowProfiler() { return m_controlFlowProfiler.get(); }
659 bool enableControlFlowProfiler();
660 bool disableControlFlowProfiler();
662 JS_EXPORT_PRIVATE void queueMicrotask(JSGlobalObject*, Ref<Microtask>&&);
663 JS_EXPORT_PRIVATE void drainMicrotasks();
664 void setGlobalConstRedeclarationShouldThrow(bool globalConstRedeclarationThrow) { m_globalConstRedeclarationShouldThrow = globalConstRedeclarationThrow; }
665 ALWAYS_INLINE bool globalConstRedeclarationShouldThrow() const { return m_globalConstRedeclarationShouldThrow; }
667 inline bool shouldTriggerTermination(ExecState*);
669 void setShouldBuildPCToCodeOriginMapping() { m_shouldBuildPCToCodeOriginMapping = true; }
670 bool shouldBuilderPCToCodeOriginMapping() const { return m_shouldBuildPCToCodeOriginMapping; }
672 BytecodeIntrinsicRegistry& bytecodeIntrinsicRegistry() { return *m_bytecodeIntrinsicRegistry; }
674 ShadowChicken& shadowChicken() { return *m_shadowChicken; }
676 template<typename Func>
677 void logEvent(CodeBlock*, const char* summary, const Func& func);
680 friend class LLIntOffsetsExtractor;
682 VM(VMType, HeapType);
683 static VM*& sharedInstanceInternal();
684 void createNativeThunk();
686 void updateStackLimits();
688 bool isSafeToRecurse(void* stackLimit) const
690 ASSERT(wtfThreadData().stack().isGrowingDownward());
691 void* curr = reinterpret_cast<void*>(&curr);
692 return curr >= stackLimit;
695 void setException(Exception* exception)
697 m_exception = exception;
698 m_lastException = exception;
700 Exception* exception() const
702 #if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
703 m_needExceptionCheck = false;
707 void clearException()
709 #if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
710 m_needExceptionCheck = false;
712 m_exception = nullptr;
716 bool ensureStackCapacityForCLoop(Register* newTopOfStack);
717 bool isSafeToRecurseSoftCLoop() const;
718 #endif // !ENABLE(JIT)
720 JS_EXPORT_PRIVATE void throwException(ExecState*, Exception*);
721 JS_EXPORT_PRIVATE JSValue throwException(ExecState*, JSValue);
722 JS_EXPORT_PRIVATE JSObject* throwException(ExecState*, JSObject*);
724 #if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
725 void verifyExceptionCheckNeedIsSatisfied(unsigned depth, ExceptionEventLocation&);
728 #if ENABLE(ASSEMBLER)
729 bool m_canUseAssembler;
735 bool m_canUseRegExpJIT;
737 #if ENABLE(GC_VALIDATION)
738 const ClassInfo* m_initializingObjectClass;
741 void* m_stackPointerAtVMEntry;
742 size_t m_currentSoftReservedZoneSize;
743 void* m_stackLimit { nullptr };
744 void* m_softStackLimit { nullptr };
746 void* m_cloopStackLimit { nullptr };
748 void* m_lastStackTop;
750 Exception* m_exception { nullptr };
751 Exception* m_lastException { nullptr };
752 #if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
753 ExceptionScope* m_topExceptionScope { nullptr };
754 ExceptionEventLocation m_simulatedThrowPointLocation;
755 unsigned m_simulatedThrowPointRecursionDepth { 0 };
756 mutable bool m_needExceptionCheck { false };
759 bool m_failNextNewCodeBlock { false };
760 DeletePropertyMode m_deletePropertyMode { DeletePropertyMode::Default };
761 bool m_globalConstRedeclarationShouldThrow { true };
762 bool m_shouldBuildPCToCodeOriginMapping { false };
763 std::unique_ptr<CodeCache> m_codeCache;
764 std::unique_ptr<BuiltinExecutables> m_builtinExecutables;
765 HashMap<String, RefPtr<WatchpointSet>> m_impurePropertyWatchpointSets;
766 std::unique_ptr<TypeProfiler> m_typeProfiler;
767 std::unique_ptr<TypeProfilerLog> m_typeProfilerLog;
768 unsigned m_typeProfilerEnabledCount;
769 FunctionHasExecutedCache m_functionHasExecutedCache;
770 std::unique_ptr<ControlFlowProfiler> m_controlFlowProfiler;
771 unsigned m_controlFlowProfilerEnabledCount;
772 Deque<std::unique_ptr<QueuedTask>> m_microtaskQueue;
773 MallocPtr<EncodedJSValue> m_exceptionFuzzBuffer;
774 RefPtr<Watchdog> m_watchdog;
775 std::unique_ptr<HeapProfiler> m_heapProfiler;
776 #if ENABLE(SAMPLING_PROFILER)
777 RefPtr<SamplingProfiler> m_samplingProfiler;
779 std::unique_ptr<ShadowChicken> m_shadowChicken;
780 std::unique_ptr<BytecodeIntrinsicRegistry> m_bytecodeIntrinsicRegistry;
782 VM* m_prev; // Required by DoublyLinkedListNode.
783 VM* m_next; // Required by DoublyLinkedListNode.
785 // Friends for exception checking purpose only.
787 friend class CatchScope;
788 friend class ExceptionScope;
789 friend class ThrowScope;
790 friend class WTF::DoublyLinkedListNode<VM>;
793 #if ENABLE(GC_VALIDATION)
794 inline bool VM::isInitializingObject() const
796 return !!m_initializingObjectClass;
799 inline void VM::setInitializingObjectClass(const ClassInfo* initializingObjectClass)
801 m_initializingObjectClass = initializingObjectClass;
805 inline Heap* WeakSet::heap() const
811 extern "C" void sanitizeStackForVMImpl(VM*);
814 void sanitizeStackForVM(VM*);
815 void logSanitizeStack(VM*);