Commit 7f1fa30e authored by danno's avatar danno Committed by Commit bot

[stubs] Port CreateWeakCellStub to turbofan

In the process also inline the stub into the appropriate interpreter bytecode
handler and make sure that the context register is preserved in hand-written
assembly code that calls the stub and expects the context register to be
preserved.

BUG=608675

Review-Url: https://codereview.chromium.org/2188993003
Cr-Commit-Position: refs/heads/master@{#38132}
parent da698896
...@@ -1634,9 +1634,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { ...@@ -1634,9 +1634,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
// Number-of-arguments register must be smi-tagged to call out. // Number-of-arguments register must be smi-tagged to call out.
__ SmiTag(r0); __ SmiTag(r0);
__ Push(r3, r2, r1, r0); __ Push(r3, r2, r1, r0);
__ Push(cp);
__ CallStub(stub); __ CallStub(stub);
__ Pop(cp);
__ Pop(r3, r2, r1, r0); __ Pop(r3, r2, r1, r0);
__ SmiUntag(r0); __ SmiUntag(r0);
} }
...@@ -1936,9 +1938,9 @@ void CallICStub::Generate(MacroAssembler* masm) { ...@@ -1936,9 +1938,9 @@ void CallICStub::Generate(MacroAssembler* masm) {
{ {
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
CreateWeakCellStub create_stub(masm->isolate()); CreateWeakCellStub create_stub(masm->isolate());
__ Push(r1); __ Push(cp, r1);
__ CallStub(&create_stub); __ CallStub(&create_stub);
__ Pop(r1); __ Pop(cp, r1);
} }
__ jmp(&call_function); __ jmp(&call_function);
......
...@@ -1826,10 +1826,12 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub, ...@@ -1826,10 +1826,12 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
// Number-of-arguments register must be smi-tagged to call out. // Number-of-arguments register must be smi-tagged to call out.
__ SmiTag(argc); __ SmiTag(argc);
__ Push(argc, function, feedback_vector, index); __ Push(argc, function, feedback_vector, index);
__ Push(cp);
DCHECK(feedback_vector.Is(x2) && index.Is(x3)); DCHECK(feedback_vector.Is(x2) && index.Is(x3));
__ CallStub(stub); __ CallStub(stub);
__ Pop(cp);
__ Pop(index, feedback_vector, function, argc); __ Pop(index, feedback_vector, function, argc);
__ SmiUntag(argc); __ SmiUntag(argc);
} }
...@@ -2161,9 +2163,9 @@ void CallICStub::Generate(MacroAssembler* masm) { ...@@ -2161,9 +2163,9 @@ void CallICStub::Generate(MacroAssembler* masm) {
{ {
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
CreateWeakCellStub create_stub(masm->isolate()); CreateWeakCellStub create_stub(masm->isolate());
__ Push(function); __ Push(cp, function);
__ CallStub(&create_stub); __ CallStub(&create_stub);
__ Pop(function); __ Pop(cp, function);
} }
__ B(&call_function); __ B(&call_function);
......
...@@ -891,6 +891,15 @@ Node* CodeStubAssembler::StoreMapNoWriteBarrier(Node* object, Node* map) { ...@@ -891,6 +891,15 @@ Node* CodeStubAssembler::StoreMapNoWriteBarrier(Node* object, Node* map) {
IntPtrConstant(HeapNumber::kMapOffset - kHeapObjectTag), map); IntPtrConstant(HeapNumber::kMapOffset - kHeapObjectTag), map);
} }
Node* CodeStubAssembler::StoreObjectFieldRoot(Node* object, int offset,
Heap::RootListIndex root_index) {
if (Heap::RootIsImmortalImmovable(root_index)) {
return StoreObjectFieldNoWriteBarrier(object, offset, LoadRoot(root_index));
} else {
return StoreObjectField(object, offset, LoadRoot(root_index));
}
}
Node* CodeStubAssembler::StoreFixedArrayElement(Node* object, Node* index_node, Node* CodeStubAssembler::StoreFixedArrayElement(Node* object, Node* index_node,
Node* value, Node* value,
WriteBarrierMode barrier_mode, WriteBarrierMode barrier_mode,
...@@ -3254,5 +3263,23 @@ void CodeStubAssembler::CheckEnumCache(Node* receiver, Label* use_cache, ...@@ -3254,5 +3263,23 @@ void CodeStubAssembler::CheckEnumCache(Node* receiver, Label* use_cache,
} }
} }
Node* CodeStubAssembler::CreateWeakCellInFeedbackVector(Node* feedback_vector,
Node* slot,
Node* value) {
Node* size = IntPtrConstant(WeakCell::kSize);
Node* cell = Allocate(size, compiler::CodeAssembler::kPretenured);
// Initialize the WeakCell.
StoreObjectFieldRoot(cell, WeakCell::kMapOffset, Heap::kWeakCellMapRootIndex);
StoreObjectField(cell, WeakCell::kValueOffset, value);
StoreObjectFieldRoot(cell, WeakCell::kNextOffset,
Heap::kTheHoleValueRootIndex);
// Store the WeakCell in the feedback vector.
StoreFixedArrayElement(feedback_vector, slot, cell, UPDATE_WRITE_BARRIER,
CodeStubAssembler::SMI_PARAMETERS);
return cell;
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -220,6 +220,8 @@ class CodeStubAssembler : public compiler::CodeAssembler { ...@@ -220,6 +220,8 @@ class CodeStubAssembler : public compiler::CodeAssembler {
// Store the Map of an HeapObject. // Store the Map of an HeapObject.
compiler::Node* StoreMapNoWriteBarrier(compiler::Node* object, compiler::Node* StoreMapNoWriteBarrier(compiler::Node* object,
compiler::Node* map); compiler::Node* map);
compiler::Node* StoreObjectFieldRoot(compiler::Node* object, int offset,
Heap::RootListIndex root);
// Store an array element to a FixedArray. // Store an array element to a FixedArray.
compiler::Node* StoreFixedArrayElement( compiler::Node* StoreFixedArrayElement(
compiler::Node* object, compiler::Node* index, compiler::Node* value, compiler::Node* object, compiler::Node* index, compiler::Node* value,
...@@ -485,6 +487,12 @@ class CodeStubAssembler : public compiler::CodeAssembler { ...@@ -485,6 +487,12 @@ class CodeStubAssembler : public compiler::CodeAssembler {
CodeStubAssembler::Label* use_cache, CodeStubAssembler::Label* use_cache,
CodeStubAssembler::Label* use_runtime); CodeStubAssembler::Label* use_runtime);
// Create a new weak cell with a specified value and install it into a
// feedback vector.
compiler::Node* CreateWeakCellInFeedbackVector(
compiler::Node* feedback_vector, compiler::Node* slot,
compiler::Node* value);
private: private:
compiler::Node* ElementOffsetFromIndex(compiler::Node* index, compiler::Node* ElementOffsetFromIndex(compiler::Node* index,
ElementsKind kind, ParameterMode mode, ElementsKind kind, ParameterMode mode,
......
...@@ -542,37 +542,6 @@ Handle<Code> FastCloneShallowArrayStub::GenerateCode() { ...@@ -542,37 +542,6 @@ Handle<Code> FastCloneShallowArrayStub::GenerateCode() {
return DoGenerateCode(this); return DoGenerateCode(this);
} }
template <>
HValue* CodeStubGraphBuilder<CreateWeakCellStub>::BuildCodeStub() {
// This stub is performance sensitive, the generated code must be tuned
// so that it doesn't build an eager frame.
info()->MarkMustNotHaveEagerFrame();
HValue* size = Add<HConstant>(WeakCell::kSize);
HInstruction* object =
Add<HAllocate>(size, HType::JSObject(), TENURED, JS_OBJECT_TYPE,
graph()->GetConstant0());
Handle<Map> weak_cell_map = isolate()->factory()->weak_cell_map();
AddStoreMapConstant(object, weak_cell_map);
HInstruction* value = GetParameter(Descriptor::kValue);
Add<HStoreNamedField>(object, HObjectAccess::ForWeakCellValue(), value);
Add<HStoreNamedField>(object, HObjectAccess::ForWeakCellNext(),
graph()->GetConstantHole());
HInstruction* feedback_vector = GetParameter(Descriptor::kVector);
HInstruction* slot = GetParameter(Descriptor::kSlot);
Add<HStoreKeyed>(feedback_vector, slot, object, nullptr, FAST_ELEMENTS,
INITIALIZING_STORE);
return graph()->GetConstant0();
}
Handle<Code> CreateWeakCellStub::GenerateCode() { return DoGenerateCode(this); }
template <> template <>
HValue* CodeStubGraphBuilder<LoadScriptContextFieldStub>::BuildCodeStub() { HValue* CodeStubGraphBuilder<LoadScriptContextFieldStub>::BuildCodeStub() {
int context_index = casted_stub()->context_index(); int context_index = casted_stub()->context_index();
......
...@@ -4120,9 +4120,6 @@ void FastCloneShallowArrayStub::InitializeDescriptor( ...@@ -4120,9 +4120,6 @@ void FastCloneShallowArrayStub::InitializeDescriptor(
} }
void CreateWeakCellStub::InitializeDescriptor(CodeStubDescriptor* d) {}
void RegExpConstructResultStub::InitializeDescriptor( void RegExpConstructResultStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) { CodeStubDescriptor* descriptor) {
descriptor->Initialize( descriptor->Initialize(
...@@ -4710,9 +4707,8 @@ void CreateAllocationSiteStub::GenerateAssembly( ...@@ -4710,9 +4707,8 @@ void CreateAllocationSiteStub::GenerateAssembly(
Node* site = assembler->Allocate(size, compiler::CodeAssembler::kPretenured); Node* site = assembler->Allocate(size, compiler::CodeAssembler::kPretenured);
// Store the map // Store the map
Node* map = assembler->StoreObjectFieldRoot(site, AllocationSite::kMapOffset,
assembler->HeapConstant(isolate()->factory()->allocation_site_map()); Heap::kAllocationSiteMapRootIndex);
assembler->StoreMapNoWriteBarrier(site, map);
Node* kind = Node* kind =
assembler->SmiConstant(Smi::FromInt(GetInitialFastElementsKind())); assembler->SmiConstant(Smi::FromInt(GetInitialFastElementsKind()));
...@@ -4733,10 +4729,8 @@ void CreateAllocationSiteStub::GenerateAssembly( ...@@ -4733,10 +4729,8 @@ void CreateAllocationSiteStub::GenerateAssembly(
site, AllocationSite::kPretenureCreateCountOffset, zero); site, AllocationSite::kPretenureCreateCountOffset, zero);
// Store an empty fixed array for the code dependency. // Store an empty fixed array for the code dependency.
Node* empty_fixed_array = assembler->StoreObjectFieldRoot(site, AllocationSite::kDependentCodeOffset,
assembler->HeapConstant(isolate()->factory()->empty_fixed_array()); Heap::kEmptyFixedArrayRootIndex);
assembler->StoreObjectFieldNoWriteBarrier(
site, AllocationSite::kDependentCodeOffset, empty_fixed_array);
// Link the object to the allocation site list // Link the object to the allocation site list
Node* site_list = assembler->ExternalConstant( Node* site_list = assembler->ExternalConstant(
...@@ -4762,6 +4756,13 @@ void CreateAllocationSiteStub::GenerateAssembly( ...@@ -4762,6 +4756,13 @@ void CreateAllocationSiteStub::GenerateAssembly(
assembler->Return(site); assembler->Return(site);
} }
void CreateWeakCellStub::GenerateAssembly(CodeStubAssembler* assembler) const {
assembler->Return(assembler->CreateWeakCellInFeedbackVector(
assembler->Parameter(Descriptor::kVector),
assembler->Parameter(Descriptor::kSlot),
assembler->Parameter(Descriptor::kValue)));
}
void ArrayNoArgumentConstructorStub::GenerateAssembly( void ArrayNoArgumentConstructorStub::GenerateAssembly(
CodeStubAssembler* assembler) const { CodeStubAssembler* assembler) const {
typedef compiler::Node Node; typedef compiler::Node Node;
......
...@@ -63,7 +63,6 @@ namespace internal { ...@@ -63,7 +63,6 @@ namespace internal {
/* HydrogenCodeStubs */ \ /* HydrogenCodeStubs */ \
V(BinaryOpIC) \ V(BinaryOpIC) \
V(BinaryOpWithAllocationSite) \ V(BinaryOpWithAllocationSite) \
V(CreateWeakCell) \
V(ElementsTransitionAndStore) \ V(ElementsTransitionAndStore) \
V(FastArrayPush) \ V(FastArrayPush) \
V(FastCloneRegExp) \ V(FastCloneRegExp) \
...@@ -99,6 +98,7 @@ namespace internal { ...@@ -99,6 +98,7 @@ namespace internal {
V(ArraySingleArgumentConstructor) \ V(ArraySingleArgumentConstructor) \
V(ArrayNArgumentsConstructor) \ V(ArrayNArgumentsConstructor) \
V(CreateAllocationSite) \ V(CreateAllocationSite) \
V(CreateWeakCell) \
V(StringLength) \ V(StringLength) \
V(Add) \ V(Add) \
V(Subtract) \ V(Subtract) \
...@@ -1214,18 +1214,16 @@ class CreateAllocationSiteStub : public TurboFanCodeStub { ...@@ -1214,18 +1214,16 @@ class CreateAllocationSiteStub : public TurboFanCodeStub {
DEFINE_TURBOFAN_CODE_STUB(CreateAllocationSite, TurboFanCodeStub); DEFINE_TURBOFAN_CODE_STUB(CreateAllocationSite, TurboFanCodeStub);
}; };
class CreateWeakCellStub : public TurboFanCodeStub {
class CreateWeakCellStub : public HydrogenCodeStub {
public: public:
explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {} explicit CreateWeakCellStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
static void GenerateAheadOfTime(Isolate* isolate); static void GenerateAheadOfTime(Isolate* isolate);
DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell); DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub); DEFINE_TURBOFAN_CODE_STUB(CreateWeakCell, TurboFanCodeStub);
}; };
class GrowArrayElementsStub : public HydrogenCodeStub { class GrowArrayElementsStub : public HydrogenCodeStub {
public: public:
GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind) GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind)
......
...@@ -1277,9 +1277,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { ...@@ -1277,9 +1277,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
__ push(edi); __ push(edi);
__ push(edx); __ push(edx);
__ push(ebx); __ push(ebx);
__ push(esi);
__ CallStub(stub); __ CallStub(stub);
__ pop(esi);
__ pop(ebx); __ pop(ebx);
__ pop(edx); __ pop(edx);
__ pop(edi); __ pop(edi);
...@@ -1575,7 +1577,9 @@ void CallICStub::Generate(MacroAssembler* masm) { ...@@ -1575,7 +1577,9 @@ void CallICStub::Generate(MacroAssembler* masm) {
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
CreateWeakCellStub create_stub(isolate); CreateWeakCellStub create_stub(isolate);
__ push(edi); __ push(edi);
__ push(esi);
__ CallStub(&create_stub); __ CallStub(&create_stub);
__ pop(esi);
__ pop(edi); __ pop(edi);
} }
......
...@@ -548,10 +548,8 @@ Node* InterpreterAssembler::CallJSWithFeedback(Node* function, Node* context, ...@@ -548,10 +548,8 @@ Node* InterpreterAssembler::CallJSWithFeedback(Node* function, Node* context,
StoreFixedArrayElement(type_feedback_vector, call_count_slot, StoreFixedArrayElement(type_feedback_vector, call_count_slot,
SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER);
CreateWeakCellStub weak_cell_stub(isolate()); CreateWeakCellInFeedbackVector(type_feedback_vector, SmiTag(slot_id),
CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), function);
HeapConstant(weak_cell_stub.GetCode()), context,
type_feedback_vector, SmiTag(slot_id), function);
// Call using call function builtin. // Call using call function builtin.
Callable callable = CodeFactory::InterpreterPushArgsAndCall( Callable callable = CodeFactory::InterpreterPushArgsAndCall(
......
...@@ -1766,7 +1766,8 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { ...@@ -1766,7 +1766,8 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
const RegList kSavedRegs = 1 << 4 | // a0 const RegList kSavedRegs = 1 << 4 | // a0
1 << 5 | // a1 1 << 5 | // a1
1 << 6 | // a2 1 << 6 | // a2
1 << 7; // a3 1 << 7 | // a3
1 << cp.code();
// Number-of-arguments register must be smi-tagged to call out. // Number-of-arguments register must be smi-tagged to call out.
__ SmiTag(a0); __ SmiTag(a0);
...@@ -2064,9 +2065,9 @@ void CallICStub::Generate(MacroAssembler* masm) { ...@@ -2064,9 +2065,9 @@ void CallICStub::Generate(MacroAssembler* masm) {
{ {
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
CreateWeakCellStub create_stub(masm->isolate()); CreateWeakCellStub create_stub(masm->isolate());
__ Push(a1); __ Push(cp, a1);
__ CallStub(&create_stub); __ CallStub(&create_stub);
__ Pop(a1); __ Pop(cp, a1);
} }
__ Branch(&call_function); __ Branch(&call_function);
......
...@@ -1767,8 +1767,8 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { ...@@ -1767,8 +1767,8 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
const RegList kSavedRegs = 1 << 4 | // a0 const RegList kSavedRegs = 1 << 4 | // a0
1 << 5 | // a1 1 << 5 | // a1
1 << 6 | // a2 1 << 6 | // a2
1 << 7; // a3 1 << 7 | // a3
1 << cp.code();
// Number-of-arguments register must be smi-tagged to call out. // Number-of-arguments register must be smi-tagged to call out.
__ SmiTag(a0); __ SmiTag(a0);
...@@ -2118,9 +2118,9 @@ void CallICStub::Generate(MacroAssembler* masm) { ...@@ -2118,9 +2118,9 @@ void CallICStub::Generate(MacroAssembler* masm) {
{ {
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
CreateWeakCellStub create_stub(masm->isolate()); CreateWeakCellStub create_stub(masm->isolate());
__ Push(a1); __ Push(cp, a1);
__ CallStub(&create_stub); __ CallStub(&create_stub);
__ Pop(a1); __ Pop(cp, a1);
} }
__ Branch(&call_function); __ Branch(&call_function);
......
...@@ -1166,9 +1166,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { ...@@ -1166,9 +1166,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
__ Integer32ToSmi(rdx, rdx); __ Integer32ToSmi(rdx, rdx);
__ Push(rdx); __ Push(rdx);
__ Push(rbx); __ Push(rbx);
__ Push(rsi);
__ CallStub(stub); __ CallStub(stub);
__ Pop(rsi);
__ Pop(rbx); __ Pop(rbx);
__ Pop(rdx); __ Pop(rdx);
__ Pop(rdi); __ Pop(rdi);
...@@ -1466,7 +1468,9 @@ void CallICStub::Generate(MacroAssembler* masm) { ...@@ -1466,7 +1468,9 @@ void CallICStub::Generate(MacroAssembler* masm) {
__ Integer32ToSmi(rdx, rdx); __ Integer32ToSmi(rdx, rdx);
__ Push(rdi); __ Push(rdi);
__ Push(rsi);
__ CallStub(&create_stub); __ CallStub(&create_stub);
__ Pop(rsi);
__ Pop(rdi); __ Pop(rdi);
} }
......
...@@ -1106,9 +1106,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { ...@@ -1106,9 +1106,11 @@ static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
__ push(edi); __ push(edi);
__ push(edx); __ push(edx);
__ push(ebx); __ push(ebx);
__ push(esi);
__ CallStub(stub); __ CallStub(stub);
__ pop(esi);
__ pop(ebx); __ pop(ebx);
__ pop(edx); __ pop(edx);
__ pop(edi); __ pop(edi);
...@@ -1404,7 +1406,9 @@ void CallICStub::Generate(MacroAssembler* masm) { ...@@ -1404,7 +1406,9 @@ void CallICStub::Generate(MacroAssembler* masm) {
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
CreateWeakCellStub create_stub(isolate); CreateWeakCellStub create_stub(isolate);
__ push(edi); __ push(edi);
__ push(esi);
__ CallStub(&create_stub); __ CallStub(&create_stub);
__ pop(esi);
__ pop(edi); __ pop(edi);
} }
......
...@@ -30,7 +30,7 @@ function __f_3(x) { ...@@ -30,7 +30,7 @@ function __f_3(x) {
var __v_1 = arguments; var __v_1 = arguments;
__v_1[1000] = 123; __v_1[1000] = 123;
depth++; depth++;
if (depth > 2700) return; if (depth > 2500) return;
function __f_4() { function __f_4() {
++__v_1[0]; ++__v_1[0];
__f_3(0.5); __f_3(0.5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment