Title: [260321] trunk/Source/_javascript_Core
Revision
260321
Author
ysuz...@apple.com
Date
2020-04-18 14:13:58 -0700 (Sat, 18 Apr 2020)

Log Message

[JSC] Replace DFG NewPromise with NewInternalFieldObject
https://bugs.webkit.org/show_bug.cgi?id=210687

Reviewed by Saam Barati.

The feature of DFG::NewPromise can be implemented completely with DFG::NewInternalFieldObject. This reduces code duplication, and furthermore,
this offers Object Allocation Sinking support for free. This patch replaces DFG::NewPromise with DFG::NewInternalFieldObject and remove DFG::NewPromise
completely.

* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::parseBlock):
* dfg/DFGClobberize.h:
(JSC::DFG::clobberize):
* dfg/DFGClobbersExitState.cpp:
(JSC::DFG::clobbersExitState):
* dfg/DFGConstantFoldingPhase.cpp:
(JSC::DFG::ConstantFoldingPhase::foldConstants):
* dfg/DFGDoesGC.cpp:
(JSC::DFG::doesGC):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* dfg/DFGNode.h:
(JSC::DFG::Node::convertToNewInternalFieldObject):
(JSC::DFG::Node::convertToNewInternalFieldObjectWithInlineFields):
(JSC::DFG::Node::hasIsInternalPromise):
(JSC::DFG::Node::hasStructure):
(JSC::DFG::Node::convertToNewPromise): Deleted.
* dfg/DFGNodeType.h:
* dfg/DFGObjectAllocationSinkingPhase.cpp:
* dfg/DFGPredictionPropagationPhase.cpp:
* dfg/DFGSafeToExecute.h:
(JSC::DFG::safeToExecute):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileNewInternalFieldObject):
(JSC::DFG::SpeculativeJIT::compileNewPromise): Deleted.
* dfg/DFGSpeculativeJIT.h:
* dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGStoreBarrierInsertionPhase.cpp:
* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileNode):
(JSC::FTL::DFG::LowerDFGToB3::compileNewInternalFieldObject):
(JSC::FTL::DFG::LowerDFGToB3::compileMaterializeNewInternalFieldObject):
(JSC::FTL::DFG::LowerDFGToB3::compileNewPromise): Deleted.
* ftl/FTLOperations.cpp:
(JSC::FTL::operationPopulateObjectInOSR):
(JSC::FTL::operationMaterializeObjectInOSR):
* runtime/JSInternalPromise.cpp:
(JSC::JSInternalPromise::createWithInitialValues):
* runtime/JSInternalPromise.h:
* runtime/JSPromise.cpp:
(JSC::JSPromise::createWithInitialValues):
(JSC::JSPromise::finishCreation):
(JSC::JSPromise::status const):
(JSC::JSPromise::result const):
(JSC::JSPromise::flags const):
(JSC::JSPromise::resolve):
(JSC::JSPromise::reject):
(JSC::JSPromise::rejectAsHandled):
* runtime/JSPromise.h:
(JSC::JSPromise::initialValues):
(JSC::JSPromise::internalField const):
(JSC::JSPromise::internalField):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (260320 => 260321)


--- trunk/Source/_javascript_Core/ChangeLog	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-04-18 21:13:58 UTC (rev 260321)
@@ -1,5 +1,77 @@
 2020-04-18  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [JSC] Replace DFG NewPromise with NewInternalFieldObject
+        https://bugs.webkit.org/show_bug.cgi?id=210687
+
+        Reviewed by Saam Barati.
+
+        The feature of DFG::NewPromise can be implemented completely with DFG::NewInternalFieldObject. This reduces code duplication, and furthermore,
+        this offers Object Allocation Sinking support for free. This patch replaces DFG::NewPromise with DFG::NewInternalFieldObject and remove DFG::NewPromise
+        completely.
+
+        * dfg/DFGAbstractInterpreterInlines.h:
+        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::parseBlock):
+        * dfg/DFGClobberize.h:
+        (JSC::DFG::clobberize):
+        * dfg/DFGClobbersExitState.cpp:
+        (JSC::DFG::clobbersExitState):
+        * dfg/DFGConstantFoldingPhase.cpp:
+        (JSC::DFG::ConstantFoldingPhase::foldConstants):
+        * dfg/DFGDoesGC.cpp:
+        (JSC::DFG::doesGC):
+        * dfg/DFGFixupPhase.cpp:
+        (JSC::DFG::FixupPhase::fixupNode):
+        * dfg/DFGNode.h:
+        (JSC::DFG::Node::convertToNewInternalFieldObject):
+        (JSC::DFG::Node::convertToNewInternalFieldObjectWithInlineFields):
+        (JSC::DFG::Node::hasIsInternalPromise):
+        (JSC::DFG::Node::hasStructure):
+        (JSC::DFG::Node::convertToNewPromise): Deleted.
+        * dfg/DFGNodeType.h:
+        * dfg/DFGObjectAllocationSinkingPhase.cpp:
+        * dfg/DFGPredictionPropagationPhase.cpp:
+        * dfg/DFGSafeToExecute.h:
+        (JSC::DFG::safeToExecute):
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::compileNewInternalFieldObject):
+        (JSC::DFG::SpeculativeJIT::compileNewPromise): Deleted.
+        * dfg/DFGSpeculativeJIT.h:
+        * dfg/DFGSpeculativeJIT32_64.cpp:
+        (JSC::DFG::SpeculativeJIT::compile):
+        * dfg/DFGSpeculativeJIT64.cpp:
+        (JSC::DFG::SpeculativeJIT::compile):
+        * dfg/DFGStoreBarrierInsertionPhase.cpp:
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        * ftl/FTLLowerDFGToB3.cpp:
+        (JSC::FTL::DFG::LowerDFGToB3::compileNode):
+        (JSC::FTL::DFG::LowerDFGToB3::compileNewInternalFieldObject):
+        (JSC::FTL::DFG::LowerDFGToB3::compileMaterializeNewInternalFieldObject):
+        (JSC::FTL::DFG::LowerDFGToB3::compileNewPromise): Deleted.
+        * ftl/FTLOperations.cpp:
+        (JSC::FTL::operationPopulateObjectInOSR):
+        (JSC::FTL::operationMaterializeObjectInOSR):
+        * runtime/JSInternalPromise.cpp:
+        (JSC::JSInternalPromise::createWithInitialValues):
+        * runtime/JSInternalPromise.h:
+        * runtime/JSPromise.cpp:
+        (JSC::JSPromise::createWithInitialValues):
+        (JSC::JSPromise::finishCreation):
+        (JSC::JSPromise::status const):
+        (JSC::JSPromise::result const):
+        (JSC::JSPromise::flags const):
+        (JSC::JSPromise::resolve):
+        (JSC::JSPromise::reject):
+        (JSC::JSPromise::rejectAsHandled):
+        * runtime/JSPromise.h:
+        (JSC::JSPromise::initialValues):
+        (JSC::JSPromise::internalField const):
+        (JSC::JSPromise::internalField):
+
+2020-04-18  Yusuke Suzuki  <ysuz...@apple.com>
+
         Unreviewed, build fix for ARM64E after r260310
         https://bugs.webkit.org/show_bug.cgi?id=207330
 

Modified: trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -2858,7 +2858,6 @@
         break;
     }
 
-    case NewPromise:
     case NewGenerator:
     case NewAsyncGenerator:    
     case NewInternalFieldObject:

Modified: trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -5240,7 +5240,8 @@
                 }
                 if (promiseConstructor) {
                     addToGraph(Phantom, callee);
-                    set(VirtualRegister(bytecode.m_dst), addToGraph(NewPromise, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())), OpInfo(bytecode.m_isInternalPromise)));
+                    Node* promise = addToGraph(NewInternalFieldObject, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())));
+                    set(VirtualRegister(bytecode.m_dst), promise);
                     alreadyEmitted = true;
                 }
             }
@@ -5273,7 +5274,8 @@
                                 m_graph.freeze(rareData);
                                 m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
 
-                                set(VirtualRegister(bytecode.m_dst), addToGraph(NewPromise, OpInfo(m_graph.registerStructure(structure)), OpInfo(bytecode.m_isInternalPromise)));
+                                Node* promise = addToGraph(NewInternalFieldObject, OpInfo(m_graph.registerStructure(structure)));
+                                set(VirtualRegister(bytecode.m_dst), promise);
                                 // The callee is still live up to this point.
                                 addToGraph(Phantom, callee);
                                 alreadyEmitted = true;
@@ -5308,7 +5310,8 @@
         case op_new_promise: {
             auto bytecode = currentInstruction->as<OpNewPromise>();
             JSGlobalObject* globalObject = m_graph.globalObjectFor(currentNodeOrigin().semantic);
-            set(bytecode.m_dst, addToGraph(NewPromise, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())), OpInfo(bytecode.m_isInternalPromise)));
+            Node* promise = addToGraph(NewInternalFieldObject, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())));
+            set(bytecode.m_dst, promise);
             NEXT_OPCODE(op_new_promise);
         }
 

Modified: trunk/Source/_javascript_Core/dfg/DFGClobberize.h (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGClobberize.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGClobberize.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -1602,7 +1602,6 @@
     }
 
     case NewObject:
-    case NewPromise:
     case NewGenerator:
     case NewAsyncGenerator:
     case NewInternalFieldObject:

Modified: trunk/Source/_javascript_Core/dfg/DFGClobbersExitState.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGClobbersExitState.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGClobbersExitState.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -57,7 +57,6 @@
     case ArrayifyToStructure:
     case Arrayify:
     case NewObject:
-    case NewPromise:
     case NewGenerator:
     case NewAsyncGenerator:
     case NewInternalFieldObject:

Modified: trunk/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -831,7 +831,7 @@
                 JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
                 if (JSValue base = m_state.forNode(node->child1()).m_value) {
                     if (base == (node->isInternalPromise() ? globalObject->internalPromiseConstructor() : globalObject->promiseConstructor())) {
-                        node->convertToNewPromise(m_graph.registerStructure(node->isInternalPromise() ? globalObject->internalPromiseStructure() : globalObject->promiseStructure()));
+                        node->convertToNewInternalFieldObject(m_graph.registerStructure(node->isInternalPromise() ? globalObject->internalPromiseStructure() : globalObject->promiseStructure()));
                         changed = true;
                         break;
                     }
@@ -845,7 +845,7 @@
                                     && rareData->allocationProfileWatchpointSet().isStillValid()) {
                                     m_graph.freeze(rareData);
                                     m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
-                                    node->convertToNewPromise(m_graph.registerStructure(structure));
+                                    node->convertToNewInternalFieldObject(m_graph.registerStructure(structure));
                                     changed = true;
                                     break;
                                 }
@@ -871,7 +871,7 @@
                                         && rareData->allocationProfileWatchpointSet().isStillValid()) {
                                         m_graph.freeze(rareData);
                                         m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
-                                        node->convertToNewInternalFieldObject(newOp, m_graph.registerStructure(structure));
+                                        node->convertToNewInternalFieldObjectWithInlineFields(newOp, m_graph.registerStructure(structure));
                                         changed = true;
                                         return;
                                     }

Modified: trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -353,7 +353,6 @@
     case Arrayify:
     case ArrayifyToStructure:
     case NewObject:
-    case NewPromise:
     case NewGenerator:
     case NewAsyncGenerator:
     case NewArray:

Modified: trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -2533,7 +2533,6 @@
         case VarargsLength:
         case ProfileControlFlow:
         case NewObject:
-        case NewPromise:
         case NewGenerator:
         case NewAsyncGenerator:
         case NewInternalFieldObject:

Modified: trunk/Source/_javascript_Core/dfg/DFGNode.h (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGNode.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGNode.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -784,17 +784,16 @@
         m_opInfo2 = OpInfoWrapper();
     }
 
-    void convertToNewPromise(RegisteredStructure structure)
+    void convertToNewInternalFieldObject(RegisteredStructure structure)
     {
         ASSERT(m_op == CreatePromise);
-        bool internal = isInternalPromise();
-        setOpAndDefaultFlags(NewPromise);
+        setOpAndDefaultFlags(NewInternalFieldObject);
         children.reset();
         m_opInfo = structure;
-        m_opInfo2 = internal;
+        m_opInfo2 = OpInfoWrapper();
     }
 
-    void convertToNewInternalFieldObject(NodeType newOp, RegisteredStructure structure)
+    void convertToNewInternalFieldObjectWithInlineFields(NodeType newOp, RegisteredStructure structure)
     {
         ASSERT(m_op == CreateAsyncGenerator || m_op == CreateGenerator);
         setOpAndDefaultFlags(newOp);
@@ -1312,7 +1311,7 @@
 
     bool hasIsInternalPromise()
     {
-        return op() == CreatePromise || op() == NewPromise;
+        return op() == CreatePromise;
     }
 
     bool isInternalPromise()
@@ -1981,7 +1980,6 @@
         case ArrayifyToStructure:
         case MaterializeNewInternalFieldObject:
         case NewObject:
-        case NewPromise:
         case NewGenerator:
         case NewAsyncGenerator:
         case NewInternalFieldObject:

Modified: trunk/Source/_javascript_Core/dfg/DFGNodeType.h (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGNodeType.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGNodeType.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -352,7 +352,6 @@
     \
     /* Allocations. */\
     macro(NewObject, NodeResultJS) \
-    macro(NewPromise, NodeResultJS) \
     macro(NewGenerator, NodeResultJS) \
     macro(NewAsyncGenerator, NodeResultJS) \
     macro(NewArray, NodeResultJS | NodeHasVarArgs) \

Modified: trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -42,6 +42,7 @@
 #include "DFGValidate.h"
 #include "JSArrayIterator.h"
 #include "JSCInlines.h"
+#include "JSInternalPromise.h"
 #include "JSMapIterator.h"
 #include "JSSetIterator.h"
 #include <wtf/StdList.h>
@@ -974,6 +975,14 @@
             case JSSetIteratorType:
                 target = handleInternalFieldClass<JSSetIterator>(node, writes);
                 break;
+            case JSPromiseType:
+                if (node->structure()->classInfo() == JSInternalPromise::info())
+                    target = handleInternalFieldClass<JSInternalPromise>(node, writes);
+                else {
+                    ASSERT(node->structure()->classInfo() == JSPromise::info());
+                    target = handleInternalFieldClass<JSPromise>(node, writes);
+                }
+                break;
             default:
                 DFG_CRASH(m_graph, node, "Bad structure");
             }

Modified: trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -1053,7 +1053,6 @@
         }
 
         case CreatePromise:
-        case NewPromise:
             setPrediction(SpecPromiseObject);
             break;
 

Modified: trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -542,7 +542,6 @@
     case CallForwardVarargs:
     case ConstructForwardVarargs:
     case NewObject:
-    case NewPromise:
     case NewGenerator:
     case NewAsyncGenerator:
     case NewArray:

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -12948,33 +12948,6 @@
     cellResult(resultGPR, node);
 }
 
-void SpeculativeJIT::compileNewPromise(Node* node)
-{
-    GPRTemporary result(this);
-    GPRTemporary scratch1(this);
-    GPRTemporary scratch2(this);
-
-    GPRReg resultGPR = result.gpr();
-    GPRReg scratch1GPR = scratch1.gpr();
-    GPRReg scratch2GPR = scratch2.gpr();
-
-    MacroAssembler::JumpList slowCases;
-
-    FrozenValue* structure = m_graph.freezeStrong(node->structure().get());
-    auto butterfly = TrustedImmPtr(nullptr);
-    if (node->isInternalPromise())
-        emitAllocateJSObjectWithKnownSize<JSInternalPromise>(resultGPR, TrustedImmPtr(structure), butterfly, scratch1GPR, scratch2GPR, slowCases, sizeof(JSInternalPromise));
-    else
-        emitAllocateJSObjectWithKnownSize<JSPromise>(resultGPR, TrustedImmPtr(structure), butterfly, scratch1GPR, scratch2GPR, slowCases, sizeof(JSPromise));
-    m_jit.storeTrustedValue(jsNumber(static_cast<unsigned>(JSPromise::Status::Pending)), CCallHelpers::Address(resultGPR, JSInternalFieldObjectImpl<>::offsetOfInternalField(static_cast<unsigned>(JSPromise::Field::Flags))));
-    m_jit.storeTrustedValue(jsUndefined(), CCallHelpers::Address(resultGPR, JSInternalFieldObjectImpl<>::offsetOfInternalField(static_cast<unsigned>(JSPromise::Field::ReactionsOrResult))));
-    m_jit.mutatorFence(m_jit.vm());
-
-    addSlowPathGenerator(slowPathCall(slowCases, this, node->isInternalPromise() ? operationNewInternalPromise : operationNewPromise, resultGPR, TrustedImmPtr(&vm()), TrustedImmPtr(structure)));
-
-    cellResult(resultGPR, node);
-}
-
 template<typename JSClass, typename Operation>
 void SpeculativeJIT::compileNewInternalFieldObjectImpl(Node* node, Operation operation)
 {
@@ -13024,6 +12997,15 @@
     case JSSetIteratorType:
         compileNewInternalFieldObjectImpl<JSSetIterator>(node, operationNewSetIterator);
         break;
+    case JSPromiseType: {
+        if (node->structure()->classInfo() == JSInternalPromise::info())
+            compileNewInternalFieldObjectImpl<JSInternalPromise>(node, operationNewInternalPromise);
+        else {
+            ASSERT(node->structure()->classInfo() == JSPromise::info());
+            compileNewInternalFieldObjectImpl<JSPromise>(node, operationNewPromise);
+        }
+        break;
+    }
     default:
         DFG_CRASH(m_graph, node, "Bad structure");
     }

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -1459,7 +1459,6 @@
     void compileCreateGenerator(Node*);
     void compileCreateAsyncGenerator(Node*);
     void compileNewObject(Node*);
-    void compileNewPromise(Node*);
     void compileNewGenerator(Node*);
     void compileNewAsyncGenerator(Node*);
     void compileNewInternalFieldObject(Node*);

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -3246,11 +3246,6 @@
         break;
     }
 
-    case NewPromise: {
-        compileNewPromise(node);
-        break;
-    }
-
     case NewGenerator: {
         compileNewGenerator(node);
         break;

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -3575,11 +3575,6 @@
         break;
     }
 
-    case NewPromise: {
-        compileNewPromise(node);
-        break;
-    }
-
     case NewGenerator: {
         compileNewGenerator(node);
         break;

Modified: trunk/Source/_javascript_Core/dfg/DFGStoreBarrierInsertionPhase.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/dfg/DFGStoreBarrierInsertionPhase.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/dfg/DFGStoreBarrierInsertionPhase.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -332,7 +332,6 @@
             
             switch (m_node->op()) {
             case NewObject:
-            case NewPromise:
             case NewGenerator:
             case NewAsyncGenerator:
             case NewArray:

Modified: trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -74,7 +74,6 @@
     case PutStructure:
     case GetButterfly:
     case NewObject:
-    case NewPromise:
     case NewGenerator:
     case NewAsyncGenerator:
     case NewStringObject:

Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -84,6 +84,7 @@
 #include "JSGenerator.h"
 #include "JSGeneratorFunction.h"
 #include "JSImmutableButterfly.h"
+#include "JSInternalPromise.h"
 #include "JSLexicalEnvironment.h"
 #include "JSMap.h"
 #include "JSMapIterator.h"
@@ -1065,9 +1066,6 @@
         case NewObject:
             compileNewObject();
             break;
-        case NewPromise:
-            compileNewPromise();
-            break;
         case NewGenerator:
             compileNewGenerator();
             break;
@@ -6350,32 +6348,6 @@
         mutatorFence();
     }
 
-    void compileNewPromise()
-    {
-        LBasicBlock slowCase = m_out.newBlock();
-        LBasicBlock continuation = m_out.newBlock();
-
-        LBasicBlock lastNext = m_out.insertNewBlocksBefore(slowCase);
-
-        LValue promise;
-        if (m_node->isInternalPromise())
-            promise = allocateObject<JSInternalPromise>(m_node->structure(), m_out.intPtrZero, slowCase);
-        else
-            promise = allocateObject<JSPromise>(m_node->structure(), m_out.intPtrZero, slowCase);
-        m_out.store64(m_out.constInt64(JSValue::encode(jsNumber(static_cast<unsigned>(JSPromise::Status::Pending)))), promise, m_heaps.JSInternalFieldObjectImpl_internalFields[static_cast<unsigned>(JSPromise::Field::Flags)]);
-        m_out.store64(m_out.constInt64(JSValue::encode(jsUndefined())), promise, m_heaps.JSInternalFieldObjectImpl_internalFields[static_cast<unsigned>(JSPromise::Field::ReactionsOrResult)]);
-        mutatorFence();
-        ValueFromBlock fastResult = m_out.anchor(promise);
-        m_out.jump(continuation);
-
-        m_out.appendTo(slowCase, continuation);
-        ValueFromBlock slowResult = m_out.anchor(vmCall(pointerType(), m_node->isInternalPromise() ? operationNewInternalPromise : operationNewPromise, m_vmValue, frozenPointer(m_graph.freezeStrong(m_node->structure().get()))));
-        m_out.jump(continuation);
-
-        m_out.appendTo(continuation, lastNext);
-        setJSValue(m_out.phi(pointerType(), fastResult, slowResult));
-    }
-
     template<typename JSClass, typename Operation>
     void compileNewInternalFieldObjectImpl(Operation operation)
     {
@@ -6423,6 +6395,14 @@
         case JSSetIteratorType:
             compileNewInternalFieldObjectImpl<JSSetIterator>(operationNewSetIterator);
             break;
+        case JSPromiseType:
+            if (m_node->structure()->classInfo() == JSInternalPromise::info())
+                compileNewInternalFieldObjectImpl<JSInternalPromise>(operationNewInternalPromise);
+            else {
+                ASSERT(m_node->structure()->classInfo() == JSPromise::info());
+                compileNewInternalFieldObjectImpl<JSPromise>(operationNewPromise);
+            }
+            break;
         default:
             DFG_CRASH(m_graph, m_node, "Bad structure");
         }
@@ -12469,6 +12449,14 @@
         case JSSetIteratorType:
             compileMaterializeNewInternalFieldObjectImpl<JSSetIterator>(operationNewSetIterator);
             break;
+        case JSPromiseType:
+            if (m_node->structure()->classInfo() == JSInternalPromise::info())
+                compileMaterializeNewInternalFieldObjectImpl<JSInternalPromise>(operationNewInternalPromise);
+            else {
+                ASSERT(m_node->structure()->classInfo() == JSPromise::info());
+                compileMaterializeNewInternalFieldObjectImpl<JSPromise>(operationNewPromise);
+            }
+            break;
         default:
             DFG_CRASH(m_graph, m_node, "Bad structure");
         }

Modified: trunk/Source/_javascript_Core/ftl/FTLOperations.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/ftl/FTLOperations.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/ftl/FTLOperations.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -43,6 +43,7 @@
 #include "JSCInlines.h"
 #include "JSGeneratorFunction.h"
 #include "JSImmutableButterfly.h"
+#include "JSInternalPromise.h"
 #include "JSLexicalEnvironment.h"
 #include "JSMapIterator.h"
 #include "JSSetIterator.h"
@@ -144,6 +145,14 @@
         case JSSetIteratorType:
             materialize(jsCast<JSSetIterator*>(target));
             break;
+        case JSPromiseType:
+            if (target->classInfo(vm) == JSInternalPromise::info())
+                materialize(jsCast<JSInternalPromise*>(target));
+            else {
+                ASSERT(target->classInfo(vm) == JSPromise::info());
+                materialize(jsCast<JSPromise*>(target));
+            }
+            break;
         default:
             RELEASE_ASSERT_NOT_REACHED();
             break;
@@ -344,6 +353,17 @@
             RELEASE_ASSERT(materialization->properties().size() - 1 == JSSetIterator::numberOfInternalFields);
             return result;
         }
+        case JSPromiseType: {
+            if (structure->classInfo() == JSInternalPromise::info()) {
+                JSInternalPromise* result = JSInternalPromise::createWithInitialValues(vm, structure);
+                RELEASE_ASSERT(materialization->properties().size() - 1 == JSInternalPromise::numberOfInternalFields);
+                return result;
+            }
+            ASSERT(structure->classInfo() == JSPromise::info());
+            JSPromise* result = JSPromise::createWithInitialValues(vm, structure);
+            RELEASE_ASSERT(materialization->properties().size() - 1 == JSPromise::numberOfInternalFields);
+            return result;
+        }
         default:
             RELEASE_ASSERT_NOT_REACHED();
             return nullptr;

Modified: trunk/Source/_javascript_Core/runtime/JSInternalPromise.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/runtime/JSInternalPromise.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/runtime/JSInternalPromise.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -40,6 +40,11 @@
     return promise;
 }
 
+JSInternalPromise* JSInternalPromise::createWithInitialValues(VM& vm, Structure* structure)
+{
+    return create(vm, structure);
+}
+
 Structure* JSInternalPromise::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
 {
     return Structure::create(vm, globalObject, prototype, TypeInfo(JSPromiseType, StructureFlags), info());

Modified: trunk/Source/_javascript_Core/runtime/JSInternalPromise.h (260320 => 260321)


--- trunk/Source/_javascript_Core/runtime/JSInternalPromise.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/runtime/JSInternalPromise.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -44,6 +44,7 @@
     typedef JSPromise Base;
 
     JS_EXPORT_PRIVATE static JSInternalPromise* create(VM&, Structure*);
+    static JSInternalPromise* createWithInitialValues(VM&, Structure*);
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
 
     DECLARE_EXPORT_INFO;

Modified: trunk/Source/_javascript_Core/runtime/JSPromise.cpp (260320 => 260321)


--- trunk/Source/_javascript_Core/runtime/JSPromise.cpp	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/runtime/JSPromise.cpp	2020-04-18 21:13:58 UTC (rev 260321)
@@ -45,6 +45,11 @@
     return promise;
 }
 
+JSPromise* JSPromise::createWithInitialValues(VM& vm, Structure* structure)
+{
+    return create(vm, structure);
+}
+
 Structure* JSPromise::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
 {
     return Structure::create(vm, globalObject, prototype, TypeInfo(JSPromiseType, StructureFlags), info());
@@ -58,8 +63,9 @@
 void JSPromise::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
-    internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(static_cast<unsigned>(Status::Pending)));
-    internalField(static_cast<unsigned>(Field::ReactionsOrResult)).set(vm, this, jsUndefined());
+    auto values = initialValues();
+    for (unsigned index = 0; index < values.size(); ++index)
+        Base::internalField(index).set(vm, this, values[index]);
 }
 
 void JSPromise::visitChildren(JSCell* cell, SlotVisitor& visitor)
@@ -71,7 +77,7 @@
 
 auto JSPromise::status(VM&) const -> Status
 {
-    JSValue value = internalField(static_cast<unsigned>(Field::Flags)).get();
+    JSValue value = internalField(Field::Flags).get();
     uint32_t flags = value.asUInt32AsAnyInt();
     return static_cast<Status>(flags & stateMask);
 }
@@ -81,12 +87,12 @@
     Status status = this->status(vm);
     if (status == Status::Pending)
         return jsUndefined();
-    return internalField(static_cast<unsigned>(Field::ReactionsOrResult)).get();
+    return internalField(Field::ReactionsOrResult).get();
 }
 
 uint32_t JSPromise::flags() const
 {
-    JSValue value = internalField(static_cast<unsigned>(Field::Flags)).get();
+    JSValue value = internalField(Field::Flags).get();
     return value.asUInt32AsAnyInt();
 }
 
@@ -160,7 +166,7 @@
     auto scope = DECLARE_THROW_SCOPE(vm);
     uint32_t flags = this->flags();
     if (!(flags & isFirstResolvingFunctionCalledFlag)) {
-        internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
+        internalField(Field::Flags).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
         JSGlobalObject* globalObject = this->globalObject(vm);
         callFunction(lexicalGlobalObject, globalObject->resolvePromiseFunction(), this, value);
         RETURN_IF_EXCEPTION(scope, void());
@@ -174,7 +180,7 @@
     auto scope = DECLARE_THROW_SCOPE(vm);
     uint32_t flags = this->flags();
     if (!(flags & isFirstResolvingFunctionCalledFlag)) {
-        internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
+        internalField(Field::Flags).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
         JSGlobalObject* globalObject = this->globalObject(vm);
         callFunction(lexicalGlobalObject, globalObject->rejectPromiseFunction(), this, value);
         RETURN_IF_EXCEPTION(scope, void());
@@ -188,7 +194,7 @@
     VM& vm = lexicalGlobalObject->vm();
     uint32_t flags = this->flags();
     if (!(flags & isFirstResolvingFunctionCalledFlag))
-        internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isHandledFlag));
+        internalField(Field::Flags).set(vm, this, jsNumber(flags | isHandledFlag));
     reject(lexicalGlobalObject, value);
 }
 

Modified: trunk/Source/_javascript_Core/runtime/JSPromise.h (260320 => 260321)


--- trunk/Source/_javascript_Core/runtime/JSPromise.h	2020-04-18 21:08:36 UTC (rev 260320)
+++ trunk/Source/_javascript_Core/runtime/JSPromise.h	2020-04-18 21:13:58 UTC (rev 260321)
@@ -41,6 +41,7 @@
     }
 
     JS_EXPORT_PRIVATE static JSPromise* create(VM&, Structure*);
+    static JSPromise* createWithInitialValues(VM&, Structure*);
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
 
     DECLARE_EXPORT_INFO;
@@ -60,6 +61,17 @@
     };
     static_assert(numberOfInternalFields == 2);
 
+    static std::array<JSValue, numberOfInternalFields> initialValues()
+    {
+        return { {
+            jsNumber(static_cast<unsigned>(Status::Pending)),
+            jsUndefined(),
+        } };
+    }
+
+    const WriteBarrier<Unknown>& internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); }
+    WriteBarrier<Unknown>& internalField(Field field) { return Base::internalField(static_cast<uint32_t>(field)); }
+
     JS_EXPORT_PRIVATE Status status(VM&) const;
     JS_EXPORT_PRIVATE JSValue result(VM&) const;
     JS_EXPORT_PRIVATE bool isHandled(VM&) const;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to