Revision: 24367
Author: [email protected]
Date: Wed Oct 1 14:03:02 2014 UTC
Log: Implement inlined stack-check guards in TurboFan.
[email protected]
TEST=cctest/test-run-stackcheck/TerminateAtMethodEntry
Review URL: https://codereview.chromium.org/621833003
https://code.google.com/p/v8/source/detail?r=24367
Added:
/branches/bleeding_edge/test/cctest/compiler/test-run-stackcheck.cc
Modified:
/branches/bleeding_edge/src/compiler/arm/code-generator-arm.cc
/branches/bleeding_edge/src/compiler/arm/instruction-selector-arm.cc
/branches/bleeding_edge/src/compiler/arm64/code-generator-arm64.cc
/branches/bleeding_edge/src/compiler/ast-graph-builder.cc
/branches/bleeding_edge/src/compiler/ast-graph-builder.h
/branches/bleeding_edge/src/compiler/ia32/code-generator-ia32.cc
/branches/bleeding_edge/src/compiler/instruction-codes.h
/branches/bleeding_edge/src/compiler/instruction-selector.cc
/branches/bleeding_edge/src/compiler/machine-operator.cc
/branches/bleeding_edge/src/compiler/machine-operator.h
/branches/bleeding_edge/src/compiler/opcodes.h
/branches/bleeding_edge/src/compiler/simplified-lowering.cc
/branches/bleeding_edge/src/compiler/x64/code-generator-x64.cc
/branches/bleeding_edge/test/cctest/cctest.gyp
/branches/bleeding_edge/test/unittests/compiler/machine-operator-unittest.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/cctest/compiler/test-run-stackcheck.cc Wed
Oct 1 14:03:02 2014 UTC
@@ -0,0 +1,18 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/v8.h"
+
+#include "test/cctest/compiler/function-tester.h"
+
+using namespace v8::internal;
+using namespace v8::internal::compiler;
+
+TEST(TerminateAtMethodEntry) {
+ FunctionTester T("(function(a,b) { return 23; })");
+
+ T.CheckCall(T.Val(23));
+ T.isolate->stack_guard()->RequestTerminateExecution();
+ T.CheckThrows(T.undefined(), T.undefined());
+}
=======================================
--- /branches/bleeding_edge/src/compiler/arm/code-generator-arm.cc Thu Sep
25 08:56:02 2014 UTC
+++ /branches/bleeding_edge/src/compiler/arm/code-generator-arm.cc Wed Oct
1 14:03:02 2014 UTC
@@ -204,6 +204,10 @@
AssembleReturn();
DCHECK_EQ(LeaveCC, i.OutputSBit());
break;
+ case kArchStackPointer:
+ __ mov(i.OutputRegister(), sp);
+ DCHECK_EQ(LeaveCC, i.OutputSBit());
+ break;
case kArchTruncateDoubleToI:
__ TruncateDoubleToI(i.OutputRegister(), i.InputFloat64Register(0));
DCHECK_EQ(LeaveCC, i.OutputSBit());
=======================================
--- /branches/bleeding_edge/src/compiler/arm/instruction-selector-arm.cc
Wed Oct 1 10:39:11 2014 UTC
+++ /branches/bleeding_edge/src/compiler/arm/instruction-selector-arm.cc
Wed Oct 1 14:03:02 2014 UTC
@@ -73,6 +73,7 @@
case kArchJmp:
case kArchNop:
case kArchRet:
+ case kArchStackPointer:
case kArchTruncateDoubleToI:
case kArmMul:
case kArmMla:
=======================================
--- /branches/bleeding_edge/src/compiler/arm64/code-generator-arm64.cc Mon
Sep 29 10:08:04 2014 UTC
+++ /branches/bleeding_edge/src/compiler/arm64/code-generator-arm64.cc Wed
Oct 1 14:03:02 2014 UTC
@@ -172,6 +172,9 @@
case kArchRet:
AssembleReturn();
break;
+ case kArchStackPointer:
+ __ mov(i.OutputRegister(), masm()->StackPointer());
+ break;
case kArchTruncateDoubleToI:
__ TruncateDoubleToI(i.OutputRegister(), i.InputDoubleRegister(0));
break;
=======================================
--- /branches/bleeding_edge/src/compiler/ast-graph-builder.cc Wed Oct 1
11:08:37 2014 UTC
+++ /branches/bleeding_edge/src/compiler/ast-graph-builder.cc Wed Oct 1
14:03:02 2014 UTC
@@ -86,8 +86,8 @@
// Visit declarations within the function scope.
VisitDeclarations(scope->declarations());
- // TODO(mstarzinger): This should do an inlined stack check.
- Node* node = NewNode(javascript()->CallRuntime(Runtime::kStackGuard, 0));
+ // Build a stack-check before the body.
+ Node* node = BuildStackCheck();
PrepareFrameState(node, BailoutId::FunctionEntry());
// Visit statements in the function body.
@@ -2057,6 +2057,24 @@
}
return NewNode(js_op, left, right);
}
+
+
+Node* AstGraphBuilder::BuildStackCheck() {
+ IfBuilder stack_check(this);
+ Node* limit =
+ NewNode(jsgraph()->machine()->Load(kMachPtr),
+ jsgraph()->ExternalConstant(
+ ExternalReference::address_of_stack_limit(isolate())),
+ jsgraph()->ZeroConstant());
+ Node* stack = NewNode(jsgraph()->machine()->LoadStackPointer());
+ Node* tag = NewNode(jsgraph()->machine()->UintLessThan(), limit, stack);
+ stack_check.If(tag);
+ stack_check.Then();
+ stack_check.Else();
+ Node* guard = NewNode(javascript()->CallRuntime(Runtime::kStackGuard,
0));
+ stack_check.End();
+ return guard;
+}
void AstGraphBuilder::PrepareFrameState(Node* node, BailoutId ast_id,
=======================================
--- /branches/bleeding_edge/src/compiler/ast-graph-builder.h Tue Sep 30
10:42:44 2014 UTC
+++ /branches/bleeding_edge/src/compiler/ast-graph-builder.h Wed Oct 1
14:03:02 2014 UTC
@@ -105,6 +105,9 @@
// Builders for binary operations.
Node* BuildBinaryOp(Node* left, Node* right, Token::Value op);
+ // Builder for stack-check guards.
+ Node* BuildStackCheck();
+
#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
// Visiting functions for AST nodes make this an AstVisitor.
AST_NODE_LIST(DECLARE_VISIT)
=======================================
--- /branches/bleeding_edge/src/compiler/ia32/code-generator-ia32.cc Tue
Sep 30 11:22:14 2014 UTC
+++ /branches/bleeding_edge/src/compiler/ia32/code-generator-ia32.cc Wed
Oct 1 14:03:02 2014 UTC
@@ -205,6 +205,9 @@
case kArchRet:
AssembleReturn();
break;
+ case kArchStackPointer:
+ __ mov(i.OutputRegister(), esp);
+ break;
case kArchTruncateDoubleToI:
__ TruncateDoubleToI(i.OutputRegister(), i.InputDoubleRegister(0));
break;
=======================================
--- /branches/bleeding_edge/src/compiler/instruction-codes.h Tue Sep 30
10:29:32 2014 UTC
+++ /branches/bleeding_edge/src/compiler/instruction-codes.h Wed Oct 1
14:03:02 2014 UTC
@@ -33,6 +33,7 @@
V(ArchJmp) \
V(ArchNop) \
V(ArchRet) \
+ V(ArchStackPointer) \
V(ArchTruncateDoubleToI) \
TARGET_ARCH_OPCODE_LIST(V)
=======================================
--- /branches/bleeding_edge/src/compiler/instruction-selector.cc Wed Oct 1
10:39:11 2014 UTC
+++ /branches/bleeding_edge/src/compiler/instruction-selector.cc Wed Oct 1
14:03:02 2014 UTC
@@ -612,6 +612,8 @@
return VisitFloat64LessThan(node);
case IrOpcode::kFloat64LessThanOrEqual:
return VisitFloat64LessThanOrEqual(node);
+ case IrOpcode::kLoadStackPointer:
+ return VisitLoadStackPointer(node);
default:
V8_Fatal(__FILE__, __LINE__, "Unexpected operator #%d:%s @ node #%d",
node->opcode(), node->op()->mnemonic(), node->id());
@@ -726,6 +728,12 @@
FlagsContinuation cont(kUnorderedLessThanOrEqual, node);
VisitFloat64Compare(node, &cont);
}
+
+
+void InstructionSelector::VisitLoadStackPointer(Node* node) {
+ OperandGenerator g(this);
+ Emit(kArchStackPointer, g.DefineAsRegister(node));
+}
#endif // V8_TURBOFAN_BACKEND
=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator.cc Wed Oct 1
10:39:11 2014 UTC
+++ /branches/bleeding_edge/src/compiler/machine-operator.cc Wed Oct 1
14:03:02 2014 UTC
@@ -119,7 +119,8 @@
V(Float64Sqrt, Operator::kNoProperties, 1,
1) \
V(Float64Equal, Operator::kCommutative, 2,
1) \
V(Float64LessThan, Operator::kNoProperties, 2,
1) \
- V(Float64LessThanOrEqual, Operator::kNoProperties, 2, 1)
+ V(Float64LessThanOrEqual, Operator::kNoProperties, 2,
1) \
+ V(LoadStackPointer, Operator::kNoProperties, 0, 1)
#define MACHINE_TYPE_LIST(V) \
=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator.h Wed Oct 1
10:39:11 2014 UTC
+++ /branches/bleeding_edge/src/compiler/machine-operator.h Wed Oct 1
14:03:02 2014 UTC
@@ -144,6 +144,9 @@
// store [base + index], value
const Operator* Store(StoreRepresentation rep);
+ // Access to the machine stack.
+ const Operator* LoadStackPointer();
+
// Target machine word-size assumed by this builder.
bool Is32() const { return word() == kRepWord32; }
bool Is64() const { return word() == kRepWord64; }
=======================================
--- /branches/bleeding_edge/src/compiler/opcodes.h Wed Oct 1 11:08:37 2014
UTC
+++ /branches/bleeding_edge/src/compiler/opcodes.h Wed Oct 1 14:03:02 2014
UTC
@@ -221,7 +221,8 @@
V(Float64Sqrt) \
V(Float64Equal) \
V(Float64LessThan) \
- V(Float64LessThanOrEqual)
+ V(Float64LessThanOrEqual) \
+ V(LoadStackPointer)
#define VALUE_OP_LIST(V) \
COMMON_OP_LIST(V) \
=======================================
--- /branches/bleeding_edge/src/compiler/simplified-lowering.cc Wed Oct 1
11:08:37 2014 UTC
+++ /branches/bleeding_edge/src/compiler/simplified-lowering.cc Wed Oct 1
14:03:02 2014 UTC
@@ -612,7 +612,7 @@
//------------------------------------------------------------------
case IrOpcode::kLoad: {
// TODO(titzer): machine loads/stores need to know BaseTaggedness!?
- MachineType tBase = kRepTagged;
+ MachineTypeUnion tBase = kRepTagged | kMachPtr;
LoadRepresentation rep = OpParameter<LoadRepresentation>(node);
ProcessInput(node, 0, tBase); // pointer or object
ProcessInput(node, 1, kMachInt32); // index
@@ -622,7 +622,7 @@
}
case IrOpcode::kStore: {
// TODO(titzer): machine loads/stores need to know BaseTaggedness!?
- MachineType tBase = kRepTagged;
+ MachineTypeUnion tBase = kRepTagged | kMachPtr;
StoreRepresentation rep = OpParameter<StoreRepresentation>(node);
ProcessInput(node, 0, tBase); // pointer or object
ProcessInput(node, 1, kMachInt32); // index
@@ -732,6 +732,8 @@
case IrOpcode::kFloat64LessThan:
case IrOpcode::kFloat64LessThanOrEqual:
return VisitFloat64Cmp(node);
+ case IrOpcode::kLoadStackPointer:
+ return VisitLeaf(node, kMachPtr);
default:
VisitInputs(node);
break;
=======================================
--- /branches/bleeding_edge/src/compiler/x64/code-generator-x64.cc Tue Sep
30 10:24:11 2014 UTC
+++ /branches/bleeding_edge/src/compiler/x64/code-generator-x64.cc Wed Oct
1 14:03:02 2014 UTC
@@ -233,6 +233,9 @@
case kArchRet:
AssembleReturn();
break;
+ case kArchStackPointer:
+ __ movq(i.OutputRegister(), rsp);
+ break;
case kArchTruncateDoubleToI:
__ TruncateDoubleToI(i.OutputRegister(), i.InputDoubleRegister(0));
break;
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.gyp Tue Sep 30 10:29:32 2014
UTC
+++ /branches/bleeding_edge/test/cctest/cctest.gyp Wed Oct 1 14:03:02 2014
UTC
@@ -81,6 +81,7 @@
'compiler/test-run-jsops.cc',
'compiler/test-run-machops.cc',
'compiler/test-run-properties.cc',
+ 'compiler/test-run-stackcheck.cc',
'compiler/test-run-variables.cc',
'compiler/test-schedule.cc',
'compiler/test-scheduler.cc',
=======================================
---
/branches/bleeding_edge/test/unittests/compiler/machine-operator-unittest.cc
Wed Oct 1 11:08:37 2014 UTC
+++
/branches/bleeding_edge/test/unittests/compiler/machine-operator-unittest.cc
Wed Oct 1 14:03:02 2014 UTC
@@ -201,7 +201,7 @@
PURE(Float64Mul, 2, 1), PURE(Float64Div, 2, 1),
PURE(Float64Mod, 2, 1), PURE(Float64Sqrt, 1, 1),
PURE(Float64Equal, 2, 1), PURE(Float64LessThan, 2, 1),
- PURE(Float64LessThanOrEqual, 2, 1)
+ PURE(Float64LessThanOrEqual, 2, 1), PURE(LoadStackPointer, 0, 1)
#undef PURE
};
--
--
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/d/optout.