Reviewers: danno,
Message:
Danno: Please take a look.
Florian: FYI.
Description:
Always set the callee's context when calling a function from optimized code.
This is necessary even for recursive calls because we're sharing optimized
code
among closures, which could call each other and have distinct contexts.
BUG=138887
TEST=mjsunit/regress/regress-crbug-138887
Please review this at https://chromiumcodereview.appspot.com/10834031/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/arm/lithium-codegen-arm.cc
M src/ia32/lithium-codegen-ia32.cc
M src/mips/lithium-codegen-mips.cc
M src/x64/lithium-codegen-x64.cc
A + test/mjsunit/regress/regress-crbug-138887.js
Index: src/arm/lithium-codegen-arm.cc
diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc
index
d94a1feb238c5e0abef2c1d2f670e30e2c72c6b9..7e138cb260aa570512eeddf29048e6af8a3f5127
100644
--- a/src/arm/lithium-codegen-arm.cc
+++ b/src/arm/lithium-codegen-arm.cc
@@ -3193,14 +3193,8 @@ void LCodeGen::CallKnownFunction(Handle<JSFunction>
function,
__ LoadHeapObject(r1, function);
}
- // Change context if needed.
- bool change_context =
- (info()->closure()->context() != function->context()) ||
- scope()->contains_with() ||
- (scope()->num_heap_slots() > 0);
- if (change_context) {
- __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
- }
+ // Change context.
+ __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
// Set r0 to arguments count if adaption is not needed. Assumes that r0
// is available to write to at this point.
Index: src/ia32/lithium-codegen-ia32.cc
diff --git a/src/ia32/lithium-codegen-ia32.cc
b/src/ia32/lithium-codegen-ia32.cc
index
f3bcf1abc3fc1974af2b7bd55a8aeec35aec8269..36d9146caf4ce9cee0c61d5dd0f9cf9433c7706d
100644
--- a/src/ia32/lithium-codegen-ia32.cc
+++ b/src/ia32/lithium-codegen-ia32.cc
@@ -3013,17 +3013,8 @@ void LCodeGen::CallKnownFunction(Handle<JSFunction>
function,
__ LoadHeapObject(edi, function);
}
- // Change context if needed.
- bool change_context =
- (info()->closure()->context() != function->context()) ||
- scope()->contains_with() ||
- (scope()->num_heap_slots() > 0);
-
- if (change_context) {
- __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
- } else {
- __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
- }
+ // Change context.
+ __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
// Set eax to arguments count if adaption is not needed. Assumes that
eax
// is available to write to at this point.
Index: src/mips/lithium-codegen-mips.cc
diff --git a/src/mips/lithium-codegen-mips.cc
b/src/mips/lithium-codegen-mips.cc
index
e9241591920b011c4b8329d32fefe9eb83baa93f..8863b11eba5a5624083fe2abde58b72fbb521f56
100644
--- a/src/mips/lithium-codegen-mips.cc
+++ b/src/mips/lithium-codegen-mips.cc
@@ -2907,14 +2907,8 @@ void LCodeGen::CallKnownFunction(Handle<JSFunction>
function,
__ LoadHeapObject(a1, function);
}
- // Change context if needed.
- bool change_context =
- (info()->closure()->context() != function->context()) ||
- scope()->contains_with() ||
- (scope()->num_heap_slots() > 0);
- if (change_context) {
- __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
- }
+ // Change context.
+ __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
// Set r0 to arguments count if adaption is not needed. Assumes that r0
// is available to write to at this point.
Index: src/x64/lithium-codegen-x64.cc
diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc
index
3e688dfd004c7bc4aa29dfa2637ce62ba6203bc4..36de28ff19d93261ed00520d46329e9d004c4585
100644
--- a/src/x64/lithium-codegen-x64.cc
+++ b/src/x64/lithium-codegen-x64.cc
@@ -2892,14 +2892,8 @@ void LCodeGen::CallKnownFunction(Handle<JSFunction>
function,
__ LoadHeapObject(rdi, function);
}
- // Change context if needed.
- bool change_context =
- (info()->closure()->context() != function->context()) ||
- scope()->contains_with() ||
- (scope()->num_heap_slots() > 0);
- if (change_context) {
- __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
- }
+ // Change context.
+ __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
// Set rax to arguments count if adaption is not needed. Assumes that
rax
// is available to write to at this point.
Index: test/mjsunit/regress/regress-crbug-138887.js
diff --git a/test/mjsunit/pixel-array-rounding.js
b/test/mjsunit/regress/regress-crbug-138887.js
old mode 100755
new mode 100644
similarity index 75%
copy from test/mjsunit/pixel-array-rounding.js
copy to test/mjsunit/regress/regress-crbug-138887.js
index
0c307e62e55297faefe3e2ae253e7a344f4ee6c6..8d8e1694b620aa36941f4b2e17a90f69f6a17cfa
--- a/test/mjsunit/pixel-array-rounding.js
+++ b/test/mjsunit/regress/regress-crbug-138887.js
@@ -27,18 +27,22 @@
// Flags: --allow-natives-syntax
-var pixels = new Uint8ClampedArray(8);
+function worker1(ignored) {
+ return 100;
+}
-function f() {
- for (var i = 0; i < 8; i++) {
- pixels[i] = (i * 1.1);
+function factory(worker) {
+ return function(call_depth) {
+ if (call_depth == 0) return 10;
+ return 1 + worker(call_depth - 1);
}
- return pixels[1] + pixels[6];
}
-f();
-f();
-assertEquals(6, pixels[5]);
-%OptimizeFunctionOnNextCall(f);
-f();
-assertEquals(6, pixels[5]);
+var f1 = factory(worker1);
+var f2 = factory(f1);
+assertEquals(11, f2(1)); // Result: 1 + f1(0) == 1 + 10.
+assertEquals(11, f2(1));
+%OptimizeFunctionOnNextCall(f1);
+assertEquals(10, f1(0)); // Terminates immediately -> returns 10.
+%OptimizeFunctionOnNextCall(f2);
+assertEquals(102, f2(1000)); // 1 + f1(999) == 1 + 1 + worker1(998) == 102
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev