Title: [264688] trunk/Source/_javascript_Core
Revision
264688
Author
mark....@apple.com
Date
2020-07-21 18:40:59 -0700 (Tue, 21 Jul 2020)

Log Message

Simplify DisallowScope, DisallowGC, and DisallowVMReentry implementations.
https://bugs.webkit.org/show_bug.cgi?id=214539
<rdar://problem/65795729>

Reviewed by Keith Miller.

Previously, DisallowScope needed to support enabling and disabling.  This was
only needed to enable the implementation of ObjectInitializationScope.  Now, we
can make the DisallowGC and DisallowVMReentry inside ObjectInitializationScope
optional with WTF::Optional.  With that we can simplify these scopes and make
them true RAII scope objects.

This patch also does the following:

1. Renamed DisallowVMReentry to DisallowVMEntry.
   The scope can be used to disable VM entry completely.  There's no need to
   restrict it to only re-entries.

2. Enforcement of DisallowVMReentry is now done in the LLInt's doVMEntry() instead
   of the VMEntryScope's constructor.  This is a stronger guarantee.

   If Options::crashOnDisallowedVMEntry() is true, the VM will crash if it sees
   an attempt to enter the VM while disallowed.

   If Options::crashOnDisallowedVMEntry() is false, an attempt to call into the VM
   while disallowed will return immediately with an undefined result without
   invoking any script.

   By default, Options::crashOnDisallowedVMEntry() is true if ASSERT_ENABLED is
   true.

3. Change DisallowScope and DisallowGC to be based on ASSERT_ENABLED instead of NEBUG.

4. Make DisallowVMEntry always enforceable, not just when ASSERT_ENABLED.
   It's enforcement action depends on Options::crashOnDisallowedVMEntry() as
   described above.

* CMakeLists.txt:
* _javascript_Core.xcodeproj/project.pbxproj:
* Sources.txt:
* heap/DeferGC.cpp:
* heap/DeferGC.h:
(JSC::DisallowGC::DisallowGC):
(JSC::DisallowGC::initialize):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::executeProgram):
(JSC::Interpreter::executeCall):
(JSC::Interpreter::executeConstruct):
(JSC::Interpreter::execute):
(JSC::Interpreter::executeModuleProgram):
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::llint_check_vm_entry_permission):
* llint/LLIntSlowPaths.h:
* llint/LowLevelInterpreter32_64.asm:
* llint/LowLevelInterpreter64.asm:
* runtime/DisallowScope.h:
(JSC::DisallowScope::DisallowScope):
(JSC::DisallowScope::~DisallowScope):
(JSC::DisallowScope::isInEffectOnCurrentThread):
(JSC::DisallowScope::enable): Deleted.
(JSC::DisallowScope::disable): Deleted.
(JSC::DisallowScope::enterScope): Deleted.
(JSC::DisallowScope::exitScope): Deleted.
* runtime/DisallowVMEntry.h: Copied from Source/_javascript_Core/runtime/DisallowVMReentry.h.
(JSC::DisallowVMEntryImpl::DisallowVMEntryImpl):
(JSC::DisallowVMEntryImpl::~DisallowVMEntryImpl):
(JSC::DisallowVMEntryImpl::isEngaged const):
(JSC::DisallowVMEntryImpl::release):
(JSC::DisallowVMReentry::DisallowVMReentry): Deleted.
(JSC::DisallowVMReentry::initialize): Deleted.
(JSC::DisallowVMReentry::scopeReentryCount): Deleted.
(JSC::DisallowVMReentry::setScopeReentryCount): Deleted.
* runtime/DisallowVMReentry.cpp: Removed.
* runtime/DisallowVMReentry.h: Removed.
* runtime/InitializeThreading.cpp:
(JSC::initialize):
* runtime/JSArray.cpp:
(JSC::JSArray::tryCreateUninitializedRestricted):
* runtime/ObjectInitializationScope.cpp:
(JSC::ObjectInitializationScope::ObjectInitializationScope):
(JSC::ObjectInitializationScope::notifyAllocated):
(JSC::ObjectInitializationScope::notifyInitialized):
* runtime/ObjectInitializationScope.h:
(JSC::ObjectInitializationScope::vm const):
(JSC::ObjectInitializationScope::ObjectInitializationScope):
(JSC::ObjectInitializationScope::~ObjectInitializationScope):
(JSC::ObjectInitializationScope::notifyAllocated):
(JSC::ObjectInitializationScope::notifyInitialized):
* runtime/OptionsList.h:
* runtime/RegExpMatchesArray.h:
(JSC::tryCreateUninitializedRegExpMatchesArray):
* runtime/VM.h:
* runtime/VMEntryScope.cpp:
(JSC::VMEntryScope::VMEntryScope):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (264687 => 264688)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2020-07-22 01:40:59 UTC (rev 264688)
@@ -838,7 +838,7 @@
     runtime/DirectArgumentsOffset.h
     runtime/DirectEvalExecutable.h
     runtime/DisallowScope.h
-    runtime/DisallowVMReentry.h
+    runtime/DisallowVMEntry.h
     runtime/DumpContext.h
     runtime/ECMAMode.h
     runtime/EnsureStillAliveHere.h

Modified: trunk/Source/_javascript_Core/ChangeLog (264687 => 264688)


--- trunk/Source/_javascript_Core/ChangeLog	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,102 @@
 2020-07-21  Mark Lam  <mark....@apple.com>
 
+        Simplify DisallowScope, DisallowGC, and DisallowVMReentry implementations.
+        https://bugs.webkit.org/show_bug.cgi?id=214539
+        <rdar://problem/65795729>
+
+        Reviewed by Keith Miller.
+
+        Previously, DisallowScope needed to support enabling and disabling.  This was
+        only needed to enable the implementation of ObjectInitializationScope.  Now, we
+        can make the DisallowGC and DisallowVMReentry inside ObjectInitializationScope
+        optional with WTF::Optional.  With that we can simplify these scopes and make
+        them true RAII scope objects.
+
+        This patch also does the following:
+
+        1. Renamed DisallowVMReentry to DisallowVMEntry.
+           The scope can be used to disable VM entry completely.  There's no need to
+           restrict it to only re-entries.
+
+        2. Enforcement of DisallowVMReentry is now done in the LLInt's doVMEntry() instead
+           of the VMEntryScope's constructor.  This is a stronger guarantee.
+
+           If Options::crashOnDisallowedVMEntry() is true, the VM will crash if it sees
+           an attempt to enter the VM while disallowed.
+
+           If Options::crashOnDisallowedVMEntry() is false, an attempt to call into the VM
+           while disallowed will return immediately with an undefined result without
+           invoking any script.
+
+           By default, Options::crashOnDisallowedVMEntry() is true if ASSERT_ENABLED is
+           true.
+
+        3. Change DisallowScope and DisallowGC to be based on ASSERT_ENABLED instead of NEBUG.
+
+        4. Make DisallowVMEntry always enforceable, not just when ASSERT_ENABLED.
+           It's enforcement action depends on Options::crashOnDisallowedVMEntry() as
+           described above.
+
+        * CMakeLists.txt:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * Sources.txt:
+        * heap/DeferGC.cpp:
+        * heap/DeferGC.h:
+        (JSC::DisallowGC::DisallowGC):
+        (JSC::DisallowGC::initialize):
+        * interpreter/Interpreter.cpp:
+        (JSC::Interpreter::executeProgram):
+        (JSC::Interpreter::executeCall):
+        (JSC::Interpreter::executeConstruct):
+        (JSC::Interpreter::execute):
+        (JSC::Interpreter::executeModuleProgram):
+        * llint/LLIntSlowPaths.cpp:
+        (JSC::LLInt::llint_check_vm_entry_permission):
+        * llint/LLIntSlowPaths.h:
+        * llint/LowLevelInterpreter32_64.asm:
+        * llint/LowLevelInterpreter64.asm:
+        * runtime/DisallowScope.h:
+        (JSC::DisallowScope::DisallowScope):
+        (JSC::DisallowScope::~DisallowScope):
+        (JSC::DisallowScope::isInEffectOnCurrentThread):
+        (JSC::DisallowScope::enable): Deleted.
+        (JSC::DisallowScope::disable): Deleted.
+        (JSC::DisallowScope::enterScope): Deleted.
+        (JSC::DisallowScope::exitScope): Deleted.
+        * runtime/DisallowVMEntry.h: Copied from Source/_javascript_Core/runtime/DisallowVMReentry.h.
+        (JSC::DisallowVMEntryImpl::DisallowVMEntryImpl):
+        (JSC::DisallowVMEntryImpl::~DisallowVMEntryImpl):
+        (JSC::DisallowVMEntryImpl::isEngaged const):
+        (JSC::DisallowVMEntryImpl::release):
+        (JSC::DisallowVMReentry::DisallowVMReentry): Deleted.
+        (JSC::DisallowVMReentry::initialize): Deleted.
+        (JSC::DisallowVMReentry::scopeReentryCount): Deleted.
+        (JSC::DisallowVMReentry::setScopeReentryCount): Deleted.
+        * runtime/DisallowVMReentry.cpp: Removed.
+        * runtime/DisallowVMReentry.h: Removed.
+        * runtime/InitializeThreading.cpp:
+        (JSC::initialize):
+        * runtime/JSArray.cpp:
+        (JSC::JSArray::tryCreateUninitializedRestricted):
+        * runtime/ObjectInitializationScope.cpp:
+        (JSC::ObjectInitializationScope::ObjectInitializationScope):
+        (JSC::ObjectInitializationScope::notifyAllocated):
+        (JSC::ObjectInitializationScope::notifyInitialized):
+        * runtime/ObjectInitializationScope.h:
+        (JSC::ObjectInitializationScope::vm const):
+        (JSC::ObjectInitializationScope::ObjectInitializationScope):
+        (JSC::ObjectInitializationScope::~ObjectInitializationScope):
+        (JSC::ObjectInitializationScope::notifyAllocated):
+        (JSC::ObjectInitializationScope::notifyInitialized):
+        * runtime/OptionsList.h:
+        * runtime/RegExpMatchesArray.h:
+        (JSC::tryCreateUninitializedRegExpMatchesArray):
+        * runtime/VM.h:
+        * runtime/VMEntryScope.cpp:
+        (JSC::VMEntryScope::VMEntryScope):
+
+2020-07-21  Mark Lam  <mark....@apple.com>
+
         llint_slow_path_get_private_name() should not be using PropertySlot::InternalMethodType::VMInquiry.
         https://bugs.webkit.org/show_bug.cgi?id=214603
 

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (264687 => 264688)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1925,7 +1925,7 @@
 		FE533CA51F217DB30016A1FE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */; };
 		FE533CA61F217DB30016A1FE /* _javascript_Core.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932F5BD90822A1C700736975 /* _javascript_Core.framework */; };
 		FE533CAD1F217EA50016A1FE /* testmasm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE533CA01F217C310016A1FE /* testmasm.cpp */; };
-		FE54DEFB1E8C6D8800A892C5 /* DisallowVMReentry.h in Headers */ = {isa = PBXBuildFile; fileRef = FE54DEFA1E8C6D7200A892C5 /* DisallowVMReentry.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		FE54DEFB1E8C6D8800A892C5 /* DisallowVMEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = FE54DEFA1E8C6D7200A892C5 /* DisallowVMEntry.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FE54DEFF1E8D76FA00A892C5 /* DisallowScope.h in Headers */ = {isa = PBXBuildFile; fileRef = FE54DEFE1E8D742800A892C5 /* DisallowScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FE5628CE1E99513200C49E45 /* AirPrintSpecial.h in Headers */ = {isa = PBXBuildFile; fileRef = FE5628CC1E99512400C49E45 /* AirPrintSpecial.h */; };
 		FE5932A8183C5A2600A1ECCC /* VMEntryScope.h in Headers */ = {isa = PBXBuildFile; fileRef = FE5932A6183C5A2600A1ECCC /* VMEntryScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -5225,8 +5225,7 @@
 		FE5068661AE25E280009DAB7 /* DeferredSourceDump.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeferredSourceDump.cpp; sourceTree = "<group>"; };
 		FE533CA01F217C310016A1FE /* testmasm.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = testmasm.cpp; sourceTree = "<group>"; };
 		FE533CAC1F217DB40016A1FE /* testmasm */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testmasm; sourceTree = BUILT_PRODUCTS_DIR; };
-		FE54DEFA1E8C6D7200A892C5 /* DisallowVMReentry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisallowVMReentry.h; sourceTree = "<group>"; };
-		FE54DEFC1E8C6DFF00A892C5 /* DisallowVMReentry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisallowVMReentry.cpp; sourceTree = "<group>"; };
+		FE54DEFA1E8C6D7200A892C5 /* DisallowVMEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisallowVMEntry.h; sourceTree = "<group>"; };
 		FE54DEFE1E8D742800A892C5 /* DisallowScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisallowScope.h; sourceTree = "<group>"; };
 		FE5628CB1E99512400C49E45 /* AirPrintSpecial.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AirPrintSpecial.cpp; path = b3/air/AirPrintSpecial.cpp; sourceTree = "<group>"; };
 		FE5628CC1E99512400C49E45 /* AirPrintSpecial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AirPrintSpecial.h; path = b3/air/AirPrintSpecial.h; sourceTree = "<group>"; };
@@ -7172,8 +7171,7 @@
 				14386A721DD69895008652C4 /* DirectEvalExecutable.cpp */,
 				14386A731DD69895008652C4 /* DirectEvalExecutable.h */,
 				FE54DEFE1E8D742800A892C5 /* DisallowScope.h */,
-				FE54DEFC1E8C6DFF00A892C5 /* DisallowVMReentry.cpp */,
-				FE54DEFA1E8C6D7200A892C5 /* DisallowVMReentry.h */,
+				FE54DEFA1E8C6D7200A892C5 /* DisallowVMEntry.h */,
 				E31618101EC5FE080006A218 /* DOMAnnotation.h */,
 				E31618111EC5FE080006A218 /* DOMAttributeGetterSetter.cpp */,
 				E31618121EC5FE080006A218 /* DOMAttributeGetterSetter.h */,
@@ -9528,7 +9526,7 @@
 				14386A751DD69895008652C4 /* DirectEvalExecutable.h in Headers */,
 				0F37308F1C0CD68500052BFA /* DisallowMacroScratchRegisterUsage.h in Headers */,
 				FE54DEFF1E8D76FA00A892C5 /* DisallowScope.h in Headers */,
-				FE54DEFB1E8C6D8800A892C5 /* DisallowVMReentry.h in Headers */,
+				FE54DEFB1E8C6D8800A892C5 /* DisallowVMEntry.h in Headers */,
 				0FF42731158EBD54004CB9FF /* Disassembler.h in Headers */,
 				E31618131EC5FE170006A218 /* DOMAnnotation.h in Headers */,
 				E31618151EC5FE270006A218 /* DOMAttributeGetterSetter.h in Headers */,

Modified: trunk/Source/_javascript_Core/Sources.txt (264687 => 264688)


--- trunk/Source/_javascript_Core/Sources.txt	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/Sources.txt	2020-07-22 01:40:59 UTC (rev 264688)
@@ -766,7 +766,6 @@
 runtime/DirectArguments.cpp
 runtime/DirectArgumentsOffset.cpp
 runtime/DirectEvalExecutable.cpp
-runtime/DisallowVMReentry.cpp
 runtime/DoublePredictionFuzzerAgent.cpp
 runtime/DumpContext.cpp
 runtime/ECMAMode.cpp

Modified: trunk/Source/_javascript_Core/heap/DeferGC.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/heap/DeferGC.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/heap/DeferGC.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,7 +28,7 @@
 
 namespace JSC {
 
-#ifndef NDEBUG
+#if ASSERT_ENABLED
 LazyNeverDestroyed<ThreadSpecific<unsigned, WTF::CanBeGCThread::True>> DisallowGC::s_scopeReentryCount;
 #endif
 

Modified: trunk/Source/_javascript_Core/heap/DeferGC.h (264687 => 264688)


--- trunk/Source/_javascript_Core/heap/DeferGC.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/heap/DeferGC.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -77,17 +77,9 @@
     WTF_FORBID_HEAP_ALLOCATION;
     typedef DisallowScope<DisallowGC> Base;
 public:
-#ifdef NDEBUG
+#if ASSERT_ENABLED
+    DisallowGC() = default;
 
-    ALWAYS_INLINE DisallowGC(bool = false) { }
-    ALWAYS_INLINE static void initialize() { }
-
-#else // not NDEBUG
-
-    DisallowGC(bool enabled = true)
-        : Base(enabled)
-    { }
-
     static void initialize()
     {
         s_scopeReentryCount.construct();
@@ -105,7 +97,10 @@
     
     JS_EXPORT_PRIVATE static LazyNeverDestroyed<ThreadSpecific<unsigned, WTF::CanBeGCThread::True>> s_scopeReentryCount;
 
-#endif // NDEBUG
+#else
+    ALWAYS_INLINE DisallowGC() { } // We need this to placate Clang due to unused warnings.
+    ALWAYS_INLINE static void initialize() { }
+#endif // ASSERT_ENABLED
     
     friend class DisallowScope<DisallowGC>;
 };

Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2008-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Cameron Zwarich <cwzwar...@uwaterloo.ca>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -825,15 +825,15 @@
         ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'.
     }
 
-    DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
-
-    RefPtr<JITCode> jitCode = program->generatedJITCode();
-
+    RefPtr<JITCode> jitCode;
     ProtoCallFrame protoCallFrame;
-    protoCallFrame.init(codeBlock, globalObject, globalCallee, thisObj, 1);
+    {
+        DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
+        jitCode = program->generatedJITCode();
+        protoCallFrame.init(codeBlock, globalObject, globalCallee, thisObj, 1);
+    }
 
     // Execute the code:
-    disallowGC.disable();
     throwScope.release();
     ASSERT(jitCode == program->generatedJITCode().ptr());
     JSValue result = jitCode->execute(&vm, &protoCallFrame);
@@ -890,27 +890,24 @@
         newCodeBlock->m_shouldAlwaysBeInlined = false;
     }
 
-    DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
-
     RefPtr<JITCode> jitCode;
-    if (isJSCall)
-        jitCode = callData.js.functionExecutable->generatedJITCodeForCall();
-
     ProtoCallFrame protoCallFrame;
-    protoCallFrame.init(newCodeBlock, globalObject, function, thisValue, argsCount, args.data());
+    {
+        DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
+        if (isJSCall)
+            jitCode = callData.js.functionExecutable->generatedJITCodeForCall();
+        protoCallFrame.init(newCodeBlock, globalObject, function, thisValue, argsCount, args.data());
+    }
 
     JSValue result;
-    {
-        // Execute the code:
-        disallowGC.disable();
-        if (isJSCall) {
-            throwScope.release();
-            ASSERT(jitCode == callData.js.functionExecutable->generatedJITCodeForCall().ptr());
-            result = jitCode->execute(&vm, &protoCallFrame);
-        } else {
-            result = JSValue::decode(vmEntryToNative(callData.native.function.rawPointer(), &vm, &protoCallFrame));
-            RETURN_IF_EXCEPTION(throwScope, JSValue());
-        }
+    // Execute the code:
+    if (isJSCall) {
+        throwScope.release();
+        ASSERT(jitCode == callData.js.functionExecutable->generatedJITCodeForCall().ptr());
+        result = jitCode->execute(&vm, &protoCallFrame);
+    } else {
+        result = JSValue::decode(vmEntryToNative(callData.native.function.rawPointer(), &vm, &protoCallFrame));
+        RETURN_IF_EXCEPTION(throwScope, JSValue());
     }
 
     return checkedReturn(result);
@@ -972,28 +969,25 @@
         newCodeBlock->m_shouldAlwaysBeInlined = false;
     }
 
-    DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
-
     RefPtr<JITCode> jitCode;
-    if (isJSConstruct)
-        jitCode = constructData.js.functionExecutable->generatedJITCodeForConstruct();
-
     ProtoCallFrame protoCallFrame;
-    protoCallFrame.init(newCodeBlock, globalObject, constructor, newTarget, argsCount, args.data());
+    {
+        DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
+        if (isJSConstruct)
+            jitCode = constructData.js.functionExecutable->generatedJITCodeForConstruct();
+        protoCallFrame.init(newCodeBlock, globalObject, constructor, newTarget, argsCount, args.data());
+    }
 
     JSValue result;
-    {
-        // Execute the code.
-        disallowGC.disable();
-        if (isJSConstruct) {
-            ASSERT(jitCode == constructData.js.functionExecutable->generatedJITCodeForConstruct().ptr());
-            result = jitCode->execute(&vm, &protoCallFrame);
-        } else {
-            result = JSValue::decode(vmEntryToNative(constructData.native.function.rawPointer(), &vm, &protoCallFrame));
+    // Execute the code.
+    if (isJSConstruct) {
+        ASSERT(jitCode == constructData.js.functionExecutable->generatedJITCodeForConstruct().ptr());
+        result = jitCode->execute(&vm, &protoCallFrame);
+    } else {
+        result = JSValue::decode(vmEntryToNative(constructData.native.function.rawPointer(), &vm, &protoCallFrame));
 
-            if (LIKELY(!throwScope.exception()))
-                RELEASE_ASSERT(result.isObject());
-        }
+        if (LIKELY(!throwScope.exception()))
+            RELEASE_ASSERT(result.isObject());
     }
 
     RETURN_IF_EXCEPTION(throwScope, nullptr);
@@ -1193,15 +1187,15 @@
         ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'.
     }
 
-    DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
-
-    RefPtr<JITCode> jitCode = eval->generatedJITCode();
-
+    RefPtr<JITCode> jitCode;
     ProtoCallFrame protoCallFrame;
-    protoCallFrame.init(codeBlock, globalObject, callee, thisValue, 1);
+    {
+        DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
+        jitCode = eval->generatedJITCode();
+        protoCallFrame.init(codeBlock, globalObject, callee, thisValue, 1);
+    }
 
     // Execute the code:
-    disallowGC.disable();
     throwScope.release();
     ASSERT(jitCode == eval->generatedJITCode().ptr());
     JSValue result = jitCode->execute(&vm, &protoCallFrame);
@@ -1251,18 +1245,18 @@
         ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'.
     }
 
-    DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
-
-    RefPtr<JITCode> jitCode = executable->generatedJITCode();
-
-    // The |this| of the module is always `undefined`.
-    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-environment-records-hasthisbinding
-    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-environment-records-getthisbinding
+    RefPtr<JITCode> jitCode;
     ProtoCallFrame protoCallFrame;
-    protoCallFrame.init(codeBlock, globalObject, callee, jsUndefined(), 1);
+    {
+        DisallowGC disallowGC; // Ensure no GC happens. GC can replace CodeBlock in Executable.
+        jitCode = executable->generatedJITCode();
+        // The |this| of the module is always `undefined`.
+        // http://www.ecma-international.org/ecma-262/6.0/#sec-module-environment-records-hasthisbinding
+        // http://www.ecma-international.org/ecma-262/6.0/#sec-module-environment-records-getthisbinding
+        protoCallFrame.init(codeBlock, globalObject, callee, jsUndefined(), 1);
+    }
 
     // Execute the code:
-    disallowGC.disable();
     throwScope.release();
     ASSERT(jitCode == executable->generatedJITCode().ptr());
     JSValue result = jitCode->execute(&vm, &protoCallFrame);

Modified: trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -2316,6 +2316,16 @@
     vm.heap.writeBarrier(cell);
 }
 
+extern "C" SlowPathReturnType llint_check_vm_entry_permission(VM* vm, ProtoCallFrame*)
+{
+    ASSERT_UNUSED(vm, vm->disallowVMEntryCount);
+    if (Options::crashOnDisallowedVMEntry())
+        CRASH();
+
+    // Else return, and let doVMEntry return undefined.
+    return encodeResult(nullptr, nullptr);
+}
+
 extern "C" void llint_dump_value(EncodedJSValue value);
 extern "C" void llint_dump_value(EncodedJSValue value)
 {

Modified: trunk/Source/_javascript_Core/llint/LLIntSlowPaths.h (264687 => 264688)


--- trunk/Source/_javascript_Core/llint/LLIntSlowPaths.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/llint/LLIntSlowPaths.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2011-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -147,6 +147,7 @@
 #if ENABLE(C_LOOP)
 extern "C" SlowPathReturnType llint_stack_check_at_vm_entry(VM*, Register*) WTF_INTERNAL;
 #endif
+extern "C" SlowPathReturnType llint_check_vm_entry_permission(VM*, ProtoCallFrame*) WTF_INTERNAL;
 extern "C" NO_RETURN_DUE_TO_CRASH void llint_crash() WTF_INTERNAL;
 
 } } // namespace JSC::LLInt

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter32_64.asm (264687 => 264688)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter32_64.asm	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter32_64.asm	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2019 Apple Inc. All rights reserved.
+# Copyright (C) 2011-2020 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -170,6 +170,9 @@
     # Since we have the guarantee that tX != aY when X != Y, we are safe from
     # aliasing problems with our arguments.
 
+    loadi VM::disallowVMEntryCount[vm], t4
+    btinz t4, .checkVMEntryPermission
+
     if ARMv7
         vmEntryRecord(cfr, t3)
         move t3, sp
@@ -319,6 +322,18 @@
     popCalleeSaves()
     functionEpilogue()
     ret
+
+.checkVMEntryPermission:
+    move vm, a0
+    move protoCallFrame, a1
+    cCall2(_llint_check_vm_entry_permission)
+    move UndefinedTag, r0
+    move 0, r1
+
+    subp cfr, CalleeRegisterSaveSize, sp
+    popCalleeSaves()
+    functionEpilogue()
+    ret
 end
 
 # a0, a2, t3, t4

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter64.asm (264687 => 264688)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter64.asm	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter64.asm	2020-07-22 01:40:59 UTC (rev 264688)
@@ -166,6 +166,9 @@
 
     checkStackPointerAlignment(t4, 0xbad0dc01)
 
+    loadi VM::disallowVMEntryCount[vm], t4
+    btinz t4, .checkVMEntryPermission
+
     storep vm, VMEntryRecord::m_vm[sp]
     loadp VM::topCallFrame[vm], t4
     storep t4, VMEntryRecord::m_prevTopCallFrame[sp]
@@ -284,6 +287,17 @@
     popCalleeSaves()
     functionEpilogue()
     ret
+
+.checkVMEntryPermission:
+    move vm, a0
+    move protoCallFrame, a1
+    cCall2(_llint_check_vm_entry_permission)
+    move ValueUndefined, r0
+
+    subp cfr, CalleeRegisterSaveSize, sp
+    popCalleeSaves()
+    functionEpilogue()
+    ret
 end
 
 

Modified: trunk/Source/_javascript_Core/runtime/DisallowScope.h (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/DisallowScope.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/DisallowScope.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -35,27 +35,18 @@
     WTF_MAKE_NONCOPYABLE(DisallowScope);
     WTF_FORBID_HEAP_ALLOCATION;
 public:
-#ifdef NDEBUG
-
-    ALWAYS_INLINE DisallowScope(bool = false) { }
-    ALWAYS_INLINE ~DisallowScope() { }
-    ALWAYS_INLINE static bool isInEffectOnCurrentThread() { return false; }
-    ALWAYS_INLINE void enable() { }
-    ALWAYS_INLINE void disable() { }
-
-#else // not NDEBUG
-
-    DisallowScope(bool enabled = true)
+#if ASSERT_ENABLED
+    DisallowScope()
     {
-        m_isEnabled = enabled;
-        if (m_isEnabled)
-            enterScope();
+        auto count = T::scopeReentryCount();
+        T::setScopeReentryCount(++count);
     }
 
     ~DisallowScope()
     {
-        if (m_isEnabled)
-            exitScope();
+        auto count = T::scopeReentryCount();
+        ASSERT(count);
+        T::setScopeReentryCount(--count);
     }
 
     static bool isInEffectOnCurrentThread()
@@ -63,34 +54,10 @@
         return !!T::scopeReentryCount();
     }
 
-    void enable()
-    {
-        m_isEnabled = true;
-        enterScope();
-    }
-
-    void disable()
-    {
-        m_isEnabled = false;
-        exitScope();
-    }
-
-private:
-    void enterScope()
-    {
-        auto count = T::scopeReentryCount();
-        T::setScopeReentryCount(++count);
-    }
-
-    void exitScope()
-    {
-        auto count = T::scopeReentryCount();
-        ASSERT(count);
-        T::setScopeReentryCount(--count);
-    }
-
-    bool m_isEnabled;
-#endif // NDEBUG
+#else // not ASSERT_ENABLED
+    ALWAYS_INLINE DisallowScope() { } // We need this to placate Clang due to unused warnings.
+    ALWAYS_INLINE static bool isInEffectOnCurrentThread() { return false; }
+#endif // ASSERT_ENABLED
 };
 
 } // namespace JSC

Copied: trunk/Source/_javascript_Core/runtime/DisallowVMEntry.h (from rev 264687, trunk/Source/_javascript_Core/runtime/DisallowVMReentry.h) (0 => 264688)


--- trunk/Source/_javascript_Core/runtime/DisallowVMEntry.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/DisallowVMEntry.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace JSC {
+
+class VM;
+
+// The only reason we implement DisallowVMEntry as specialization of a template
+// is so that we can work around having to #include VM.h, which can hurt build
+// time. This defers the cost of #include'ing VM.h to only the clients that
+// need it.
+
+template<typename VMType = VM>
+class DisallowVMEntryImpl {
+    WTF_MAKE_NONCOPYABLE(DisallowVMEntryImpl);
+public:
+    DisallowVMEntryImpl(VMType& vm)
+        : m_vm(&vm)
+    {
+        m_vm->disallowVMEntryCount++;
+    }
+
+    ~DisallowVMEntryImpl()
+    {
+        RELEASE_ASSERT(m_vm->disallowVMEntryCount);
+        m_vm->disallowVMEntryCount--;
+        m_vm = nullptr;
+    }
+
+private:
+    VMType* m_vm;
+};
+
+using DisallowVMEntry = DisallowVMEntryImpl<VM>;
+
+} // namespace JSC

Deleted: trunk/Source/_javascript_Core/runtime/DisallowVMReentry.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/DisallowVMReentry.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/DisallowVMReentry.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "DisallowVMReentry.h"
-
-namespace JSC {
-    
-#ifndef NDEBUG
-LazyNeverDestroyed<ThreadSpecific<unsigned, WTF::CanBeGCThread::True>> DisallowVMReentry::s_scopeReentryCount;
-#endif
-    
-} // namespace JSC

Deleted: trunk/Source/_javascript_Core/runtime/DisallowVMReentry.h (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/DisallowVMReentry.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/DisallowVMReentry.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "DisallowScope.h"
-#include <wtf/NeverDestroyed.h>
-#include <wtf/ThreadSpecific.h>
-
-namespace JSC {
-
-class DisallowVMReentry : public DisallowScope<DisallowVMReentry> {
-    WTF_MAKE_NONCOPYABLE(DisallowVMReentry);
-    typedef DisallowScope<DisallowVMReentry> Base;
-public:
-#ifdef NDEBUG
-
-    ALWAYS_INLINE DisallowVMReentry(bool = false) { }
-    ALWAYS_INLINE static void initialize() { }
-
-#else // not NDEBUG
-
-    DisallowVMReentry(bool enabled = true)
-        : Base(enabled)
-    { }
-
-    static void initialize()
-    {
-        s_scopeReentryCount.construct();
-    }
-
-private:
-    static unsigned scopeReentryCount()
-    {
-        return *s_scopeReentryCount.get();
-    }
-    static void setScopeReentryCount(unsigned value)
-    {
-        *s_scopeReentryCount.get() = value;
-    }
-
-    JS_EXPORT_PRIVATE static LazyNeverDestroyed<ThreadSpecific<unsigned, WTF::CanBeGCThread::True>> s_scopeReentryCount;
-
-#endif // NDEBUG
-
-    friend class DisallowScope<DisallowVMReentry>;
-};
-
-} // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -29,7 +29,6 @@
 #include "config.h"
 #include "InitializeThreading.h"
 
-#include "DisallowVMReentry.h"
 #include "ExecutableAllocator.h"
 #include "JSCConfig.h"
 #include "JSCPtrTag.h"
@@ -78,10 +77,8 @@
             enableSigillCrashAnalyzer();
 
         LLInt::initialize();
-#ifndef NDEBUG
         DisallowGC::initialize();
-        DisallowVMReentry::initialize();
-#endif
+
         initializeSuperSampler();
         Thread& thread = Thread::current();
         thread.setSavedLastStackTop(thread.stack().origin());

Modified: trunk/Source/_javascript_Core/runtime/JSArray.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/JSArray.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/JSArray.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 1999-2000 Harri Porten (por...@kde.org)
- *  Copyright (C) 2003-2019 Apple Inc. All rights reserved.
+ *  Copyright (C) 2003-2020 Apple Inc. All rights reserved.
  *  Copyright (C) 2003 Peter Kelly (p...@post.com)
  *  Copyright (C) 2006 Alexey Proskuryakov (a...@nypop.com)
  *
@@ -96,8 +96,7 @@
 
     JSArray* result = createWithButterfly(vm, deferralContext, structure, butterfly);
 
-    const bool createUninitialized = true;
-    scope.notifyAllocated(result, createUninitialized);
+    scope.notifyAllocated(result);
     return result;
 }
 

Modified: trunk/Source/_javascript_Core/runtime/ObjectInitializationScope.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/ObjectInitializationScope.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/ObjectInitializationScope.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -34,11 +34,10 @@
 
 namespace JSC {
 
-#ifndef NDEBUG
+#if ASSERT_ENABLED
+
 ObjectInitializationScope::ObjectInitializationScope(VM& vm)
     : m_vm(vm)
-    , m_disallowGC(false)
-    , m_disallowVMReentry(false)
 {
 }
 
@@ -50,21 +49,20 @@
     verifyPropertiesAreInitialized(m_object);
 }
 
-void ObjectInitializationScope::notifyAllocated(JSObject* object, bool wasCreatedUninitialized)
+void ObjectInitializationScope::notifyAllocated(JSObject* object)
 {
-    if (wasCreatedUninitialized) {
-        m_disallowGC.enable();
-        m_disallowVMReentry.enable();
-        m_object = object;
-    } else
-        verifyPropertiesAreInitialized(object);
+    ASSERT(!m_disallowGC);
+    ASSERT(!m_disallowVMEntry);
+    m_disallowGC.emplace();
+    m_disallowVMEntry.emplace(m_vm);
+    m_object = object;
 }
 
 void ObjectInitializationScope::notifyInitialized(JSObject* object)
 {
     if (m_object) {
-        m_disallowGC.disable();
-        m_disallowVMReentry.disable();
+        m_disallowGC.reset();
+        m_disallowVMEntry.reset();
         m_object = nullptr;
     }
     verifyPropertiesAreInitialized(object);
@@ -114,6 +112,7 @@
         }
     }
 }
-#endif
 
+#endif // ASSERT_ENABLED
+
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/ObjectInitializationScope.h (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/ObjectInitializationScope.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/ObjectInitializationScope.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,8 +26,9 @@
 #pragma once
 
 #include "DeferGC.h"
-#include "DisallowVMReentry.h"
+#include "DisallowVMEntry.h"
 #include "VM.h"
+#include <wtf/Optional.h>
 
 namespace JSC {
 
@@ -34,10 +35,30 @@
 class VM;
 class JSObject;
 
-#ifdef NDEBUG
+#if ASSERT_ENABLED
 
 class ObjectInitializationScope {
 public:
+    JS_EXPORT_PRIVATE ObjectInitializationScope(VM&);
+    JS_EXPORT_PRIVATE ~ObjectInitializationScope();
+
+    VM& vm() const { return m_vm; }
+    void notifyAllocated(JSObject*);
+    void notifyInitialized(JSObject*);
+
+private:
+    void verifyPropertiesAreInitialized(JSObject*);
+
+    VM& m_vm;
+    Optional<DisallowGC> m_disallowGC;
+    Optional<DisallowVMEntry> m_disallowVMEntry;
+    JSObject* m_object { nullptr };
+};
+
+#else // not ASSERT_ENABLED
+
+class ObjectInitializationScope {
+public:
     ALWAYS_INLINE ObjectInitializationScope(VM& vm)
         : m_vm(vm)
     { }
@@ -47,7 +68,7 @@
     }
 
     ALWAYS_INLINE VM& vm() const { return m_vm; }
-    ALWAYS_INLINE void notifyAllocated(JSObject*, bool) { }
+    ALWAYS_INLINE void notifyAllocated(JSObject*) { }
     ALWAYS_INLINE void notifyInitialized(JSObject*) { }
 
 private:
@@ -54,26 +75,6 @@
     VM& m_vm;
 };
 
-#else // not NDEBUG
+#endif // ASSERT_ENABLED
 
-class ObjectInitializationScope {
-public:
-    JS_EXPORT_PRIVATE ObjectInitializationScope(VM&);
-    JS_EXPORT_PRIVATE ~ObjectInitializationScope();
-
-    VM& vm() const { return m_vm; }
-    void notifyAllocated(JSObject*, bool wasCreatedUninitialized);
-    void notifyInitialized(JSObject*);
-
-private:
-    void verifyPropertiesAreInitialized(JSObject*);
-
-    VM& m_vm;
-    DisallowGC m_disallowGC;
-    DisallowVMReentry m_disallowVMReentry;
-    JSObject* m_object { nullptr };
-};
-
-#endif // NDEBUG
-
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/OptionsList.h (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/OptionsList.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/OptionsList.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -94,6 +94,7 @@
     v(Unsigned, softReservedZoneSize, 128 * KB, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
     v(Unsigned, reservedZoneSize, 64 * KB, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \
     \
+    v(Bool, crashOnDisallowedVMEntry, ASSERT_ENABLED, Normal, "Forces a crash if we attempt to enter the VM when disallowed") \
     v(Bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \
     v(Unsigned, jitMemoryReservationSize, 0, Normal, "Set this number to change the executable allocation size in ExecutableAllocatorFixedVMPool. (In bytes.)") \
     \

Modified: trunk/Source/_javascript_Core/runtime/RegExpMatchesArray.h (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/RegExpMatchesArray.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/RegExpMatchesArray.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -54,8 +54,7 @@
 
     JSArray* result = JSArray::createWithButterfly(vm, deferralContext, structure, butterfly);
 
-    const bool createUninitialized = true;
-    scope.notifyAllocated(result, createUninitialized);
+    scope.notifyAllocated(result);
     return result;
 }
 

Modified: trunk/Source/_javascript_Core/runtime/VM.h (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/VM.h	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2020-07-22 01:40:59 UTC (rev 264688)
@@ -35,6 +35,7 @@
 #include "ControlFlowProfiler.h"
 #include "DateInstanceCache.h"
 #include "DeleteAllCodeEffort.h"
+#include "DisallowVMEntry.h"
 #include "ExceptionEventLocation.h"
 #include "ExecutableAllocator.h"
 #include "FunctionHasExecutedCache.h"
@@ -952,6 +953,7 @@
     bool hasCheckpointOSRSideState() const { return m_checkpointSideState.size(); }
     void scanSideState(ConservativeRoots&) const;
 
+    unsigned disallowVMEntryCount { 0 };
     VMEntryScope* entryScope;
 
     JSObject* stringRecursionCheckFirstObject { nullptr };

Modified: trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp (264687 => 264688)


--- trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp	2020-07-22 01:11:14 UTC (rev 264687)
+++ trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp	2020-07-22 01:40:59 UTC (rev 264688)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "VMEntryScope.h"
 
-#include "DisallowVMReentry.h"
 #include "Options.h"
 #include "SamplingProfiler.h"
 #include "VM.h"
@@ -39,7 +38,6 @@
     : m_vm(vm)
     , m_globalObject(globalObject)
 {
-    ASSERT(!DisallowVMReentry::isInEffectOnCurrentThread());
     if (!vm.entryScope) {
         vm.entryScope = this;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to