Reviewers: Toon Verwaest,
Message:
Hi Toon, here is the change we discussed (sans ports). I'm not that happy
with
EmitMapCode() at the moment, esp. the way it's used as a helper in the keyed
array call stub. I'll chat in the morning with you.
thx,
--michael
Description:
Array constructor can be simplified by loading context from JSFunction.
BUG=
Please review this at https://codereview.chromium.org/128683002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+32, -64 lines):
M src/code-stubs-hydrogen.cc
M src/code-stubs.h
M src/hydrogen.h
M src/hydrogen.cc
M src/ia32/code-stubs-ia32.cc
M src/ia32/lithium-codegen-ia32.cc
Index: src/code-stubs-hydrogen.cc
diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc
index
374f55f06879ffe12ecf7685f39f450d4eaa98dc..783384d45285f3e5325038a34ea6d3705e45042e
100644
--- a/src/code-stubs-hydrogen.cc
+++ b/src/code-stubs-hydrogen.cc
@@ -81,24 +81,6 @@ class CodeStubGraphBuilderBase : public HGraphBuilder {
HContext* context() { return context_; }
Isolate* isolate() { return info_.isolate(); }
- class ArrayContextChecker {
- public:
- ArrayContextChecker(HGraphBuilder* builder, HValue* constructor,
- HValue* array_function)
- : checker_(builder) {
- checker_.If<HCompareObjectEqAndBranch, HValue*>(constructor,
- array_function);
- checker_.Then();
- }
-
- ~ArrayContextChecker() {
- checker_.ElseDeopt("Array constructor called from different
context");
- checker_.End();
- }
- private:
- IfBuilder checker_;
- };
-
enum ArgumentClass {
NONE,
SINGLE,
@@ -106,7 +88,6 @@ class CodeStubGraphBuilderBase : public HGraphBuilder {
};
HValue* BuildArrayConstructor(ElementsKind kind,
- ContextCheckMode context_mode,
AllocationSiteOverrideMode override_mode,
ArgumentClass argument_class);
HValue* BuildInternalArrayConstructor(ElementsKind kind,
@@ -672,15 +653,9 @@ Handle<Code>
TransitionElementsKindStub::GenerateCode(Isolate* isolate) {
HValue* CodeStubGraphBuilderBase::BuildArrayConstructor(
ElementsKind kind,
- ContextCheckMode context_mode,
AllocationSiteOverrideMode override_mode,
ArgumentClass argument_class) {
HValue* constructor =
GetParameter(ArrayConstructorStubBase::kConstructor);
- if (context_mode == CONTEXT_CHECK_REQUIRED) {
- HInstruction* array_function = BuildGetArrayFunction();
- ArrayContextChecker checker(this, constructor, array_function);
- }
-
HValue* property_cell =
GetParameter(ArrayConstructorStubBase::kPropertyCell);
// Walk through the property cell to the AllocationSite
HValue* alloc_site = Add<HLoadNamedField>(property_cell,
@@ -787,9 +762,8 @@ HValue*
CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor(
template <>
HValue*
CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() {
ElementsKind kind = casted_stub()->elements_kind();
- ContextCheckMode context_mode = casted_stub()->context_mode();
AllocationSiteOverrideMode override_mode =
casted_stub()->override_mode();
- return BuildArrayConstructor(kind, context_mode, override_mode, NONE);
+ return BuildArrayConstructor(kind, override_mode, NONE);
}
@@ -802,9 +776,8 @@ template <>
HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::
BuildCodeStub() {
ElementsKind kind = casted_stub()->elements_kind();
- ContextCheckMode context_mode = casted_stub()->context_mode();
AllocationSiteOverrideMode override_mode =
casted_stub()->override_mode();
- return BuildArrayConstructor(kind, context_mode, override_mode, SINGLE);
+ return BuildArrayConstructor(kind, override_mode, SINGLE);
}
@@ -817,9 +790,8 @@ Handle<Code>
ArraySingleArgumentConstructorStub::GenerateCode(
template <>
HValue*
CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() {
ElementsKind kind = casted_stub()->elements_kind();
- ContextCheckMode context_mode = casted_stub()->context_mode();
AllocationSiteOverrideMode override_mode =
casted_stub()->override_mode();
- return BuildArrayConstructor(kind, context_mode, override_mode,
MULTIPLE);
+ return BuildArrayConstructor(kind, override_mode, MULTIPLE);
}
Index: src/code-stubs.h
diff --git a/src/code-stubs.h b/src/code-stubs.h
index
7e6c00060fff1f033d563b5b53c992aa14401435..cf9a40c261ff74846cc5e01a6b9895f8ace2dff0
100644
--- a/src/code-stubs.h
+++ b/src/code-stubs.h
@@ -1984,16 +1984,9 @@ class TransitionElementsKindStub : public
HydrogenCodeStub {
};
-enum ContextCheckMode {
- CONTEXT_CHECK_REQUIRED,
- CONTEXT_CHECK_NOT_REQUIRED,
- LAST_CONTEXT_CHECK_MODE = CONTEXT_CHECK_NOT_REQUIRED
-};
-
-
class ArrayConstructorStubBase : public HydrogenCodeStub {
public:
- ArrayConstructorStubBase(ElementsKind kind, ContextCheckMode
context_mode,
+ ArrayConstructorStubBase(ElementsKind kind,
AllocationSiteOverrideMode override_mode) {
// It only makes sense to override local allocation site behavior
// if there is a difference between the global allocation site policy
@@ -2001,8 +1994,7 @@ class ArrayConstructorStubBase : public
HydrogenCodeStub {
ASSERT(override_mode != DISABLE_ALLOCATION_SITES ||
AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
bit_field_ = ElementsKindBits::encode(kind) |
- AllocationSiteOverrideModeBits::encode(override_mode) |
- ContextCheckModeBits::encode(context_mode);
+ AllocationSiteOverrideModeBits::encode(override_mode);
}
ElementsKind elements_kind() const {
@@ -2013,10 +2005,6 @@ class ArrayConstructorStubBase : public
HydrogenCodeStub {
return AllocationSiteOverrideModeBits::decode(bit_field_);
}
- ContextCheckMode context_mode() const {
- return ContextCheckModeBits::decode(bit_field_);
- }
-
static void GenerateStubsAheadOfTime(Isolate* isolate);
static void InstallDescriptors(Isolate* isolate);
@@ -2032,12 +2020,10 @@ class ArrayConstructorStubBase : public
HydrogenCodeStub {
// Ensure data fits within available bits.
STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
- STATIC_ASSERT(LAST_CONTEXT_CHECK_MODE == 1);
class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
class AllocationSiteOverrideModeBits: public
BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
- class ContextCheckModeBits: public BitField<ContextCheckMode, 9, 1> {};
uint32_t bit_field_;
DISALLOW_COPY_AND_ASSIGN(ArrayConstructorStubBase);
@@ -2048,9 +2034,8 @@ class ArrayNoArgumentConstructorStub : public
ArrayConstructorStubBase {
public:
ArrayNoArgumentConstructorStub(
ElementsKind kind,
- ContextCheckMode context_mode = CONTEXT_CHECK_REQUIRED,
AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
- : ArrayConstructorStubBase(kind, context_mode, override_mode) {
+ : ArrayConstructorStubBase(kind, override_mode) {
}
virtual Handle<Code> GenerateCode(Isolate* isolate);
@@ -2074,9 +2059,8 @@ class ArraySingleArgumentConstructorStub : public
ArrayConstructorStubBase {
public:
ArraySingleArgumentConstructorStub(
ElementsKind kind,
- ContextCheckMode context_mode = CONTEXT_CHECK_REQUIRED,
AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
- : ArrayConstructorStubBase(kind, context_mode, override_mode) {
+ : ArrayConstructorStubBase(kind, override_mode) {
}
virtual Handle<Code> GenerateCode(Isolate* isolate);
@@ -2100,9 +2084,8 @@ class ArrayNArgumentsConstructorStub : public
ArrayConstructorStubBase {
public:
ArrayNArgumentsConstructorStub(
ElementsKind kind,
- ContextCheckMode context_mode = CONTEXT_CHECK_REQUIRED,
AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
- : ArrayConstructorStubBase(kind, context_mode, override_mode) {
+ : ArrayConstructorStubBase(kind, override_mode) {
}
virtual Handle<Code> GenerateCode(Isolate* isolate);
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index
529ebd2f4f066288b0281ee11353b50645656596..c8276e703ffd2b097b27914d08d62192c4730832
100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -2657,6 +2657,18 @@ void HGraphBuilder::BuildCreateAllocationMemento(
}
+HInstruction* HGraphBuilder::BuildGetNativeContext(HValue* closure) {
+ // Get the global context, then the native context
+ HInstruction* context =
+ Add<HLoadNamedField>(closure,
HObjectAccess::ForFunctionContextPointer());
+ HInstruction* global_object = Add<HLoadNamedField>(context,
+ HObjectAccess::ForContextSlot(Context::GLOBAL_OBJECT_INDEX));
+ HObjectAccess access = HObjectAccess::ForJSObjectOffset(
+ GlobalObject::kNativeContextOffset);
+ return Add<HLoadNamedField>(global_object, access);
+}
+
+
HInstruction* HGraphBuilder::BuildGetNativeContext() {
// Get the global context, then the native context
HInstruction* global_object = Add<HGlobalObject>();
@@ -2716,7 +2728,12 @@ HValue* HGraphBuilder::JSArrayBuilder::EmitMapCode()
{
return builder()->AddLoadNamedField(constructor_function_, access);
}
- HInstruction* native_context = builder()->BuildGetNativeContext();
+ // TODO(mvstanton): we should always have a constructor function if we
+ // are creating a stub.
+ HInstruction* native_context = constructor_function_ != NULL
+ ? builder()->BuildGetNativeContext(constructor_function_)
+ : builder()->BuildGetNativeContext();
+
HInstruction* index = builder()->Add<HConstant>(
static_cast<int32_t>(Context::JS_ARRAY_MAPS_INDEX));
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index
2af24696c158d2e090bf44a2169911f3b5784515..9658e8341faab9202e61cf0b332aec9b9a16b32b
100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -1774,6 +1774,7 @@ class HGraphBuilder {
HInstruction* BuildCheckPrototypeMaps(Handle<JSObject> prototype,
Handle<JSObject> holder);
+ HInstruction* BuildGetNativeContext(HValue* closure);
HInstruction* BuildGetNativeContext();
HInstruction* BuildGetArrayFunction();
Index: src/ia32/code-stubs-ia32.cc
diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc
index
86f2b159a22f497562f92a0ec15105285749b113..c76d60715472bc0e08cb8ba719d3c87d7a633c98
100644
--- a/src/ia32/code-stubs-ia32.cc
+++ b/src/ia32/code-stubs-ia32.cc
@@ -5409,7 +5409,6 @@ static void CreateArrayDispatch(MacroAssembler* masm,
AllocationSiteOverrideMode mode) {
if (mode == DISABLE_ALLOCATION_SITES) {
T stub(GetInitialFastElementsKind(),
- CONTEXT_CHECK_REQUIRED,
mode);
__ TailCallStub(&stub);
} else if (mode == DONT_OVERRIDE) {
@@ -5465,13 +5464,11 @@ static void
CreateArrayDispatchOneArgument(MacroAssembler* masm,
ElementsKind holey_initial = GetHoleyElementsKind(initial);
ArraySingleArgumentConstructorStub stub_holey(holey_initial,
- CONTEXT_CHECK_REQUIRED,
DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub_holey);
__ bind(&normal_sequence);
ArraySingleArgumentConstructorStub stub(initial,
- CONTEXT_CHECK_REQUIRED,
DISABLE_ALLOCATION_SITES);
__ TailCallStub(&stub);
} else if (mode == DONT_OVERRIDE) {
@@ -5523,7 +5520,7 @@ static void
ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
T stub(kind);
stub.GetCode(isolate);
if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
- T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES);
+ T stub1(kind, DISABLE_ALLOCATION_SITES);
stub1.GetCode(isolate);
}
}
Index: src/ia32/lithium-codegen-ia32.cc
diff --git a/src/ia32/lithium-codegen-ia32.cc
b/src/ia32/lithium-codegen-ia32.cc
index
bec4924f98ce4ccf2048f8a3e24f1b490d45434b..2a217c3404f07a120a1099dfa4fd76cfe2baea43
100644
--- a/src/ia32/lithium-codegen-ia32.cc
+++ b/src/ia32/lithium-codegen-ia32.cc
@@ -4302,10 +4302,9 @@ void LCodeGen::DoCallNewArray(LCallNewArray* instr) {
(AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE)
? DISABLE_ALLOCATION_SITES
: DONT_OVERRIDE;
- ContextCheckMode context_mode = CONTEXT_CHECK_NOT_REQUIRED;
if (instr->arity() == 0) {
- ArrayNoArgumentConstructorStub stub(kind, context_mode, override_mode);
+ ArrayNoArgumentConstructorStub stub(kind, override_mode);
CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr);
} else if (instr->arity() == 1) {
Label done;
@@ -4318,18 +4317,17 @@ void LCodeGen::DoCallNewArray(LCallNewArray* instr)
{
__ j(zero, &packed_case, Label::kNear);
ElementsKind holey_kind = GetHoleyElementsKind(kind);
- ArraySingleArgumentConstructorStub stub(holey_kind, context_mode,
- override_mode);
+ ArraySingleArgumentConstructorStub stub(holey_kind, override_mode);
CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr);
__ jmp(&done, Label::kNear);
__ bind(&packed_case);
}
- ArraySingleArgumentConstructorStub stub(kind, context_mode,
override_mode);
+ ArraySingleArgumentConstructorStub stub(kind, override_mode);
CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr);
__ bind(&done);
} else {
- ArrayNArgumentsConstructorStub stub(kind, context_mode, override_mode);
+ ArrayNArgumentsConstructorStub stub(kind, override_mode);
CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr);
}
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.