Introduce runtime function %OptimizeFunctionOnNextCall to manually trigger optimization.

TEST=existing unit tests still pass

Review URL: http://codereview.chromium.org/6821009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7572 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
jkummerow@chromium.org 2011-04-11 13:24:50 +00:00
parent d8f0b3bea2
commit ed968b1042
39 changed files with 339 additions and 108 deletions

View File

@ -3309,6 +3309,11 @@ bool JSFunction::IsOptimized() {
}
bool JSFunction::IsOptimizable() {
return code()->kind() == Code::FUNCTION && code()->optimizable();
}
bool JSFunction::IsMarkedForLazyRecompilation() {
return code() == GetIsolate()->builtins()->builtin(Builtins::kLazyRecompile);
}

View File

@ -4526,6 +4526,9 @@ class JSFunction: public JSObject {
// Tells whether or not this function has been optimized.
inline bool IsOptimized();
// Tells whether or not this function can be optimized.
inline bool IsOptimizable();
// Mark this function for lazy recompilation. The function will be
// recompiled the next time it is executed.
void MarkForLazyRecompilation();

View File

@ -107,12 +107,6 @@ void PendingListNode::WeakCallback(v8::Persistent<v8::Value>, void* data) {
}
static bool IsOptimizable(JSFunction* function) {
Code* code = function->code();
return code->kind() == Code::FUNCTION && code->optimizable();
}
Atomic32 RuntimeProfiler::state_ = 0;
// TODO(isolates): Create the semaphore lazily and clean it up when no
// longer required.
@ -146,7 +140,7 @@ bool RuntimeProfiler::IsEnabled() {
void RuntimeProfiler::Optimize(JSFunction* function, bool eager, int delay) {
ASSERT(IsOptimizable(function));
ASSERT(function->IsOptimizable());
if (FLAG_trace_opt) {
PrintF("[marking (%s) ", eager ? "eagerly" : "lazily");
function->PrintName();
@ -245,7 +239,7 @@ void RuntimeProfiler::OptimizeNow() {
if (current->IsValid()) {
Handle<JSFunction> function = current->function();
int delay = current->Delay();
if (IsOptimizable(*function)) {
if (function->IsOptimizable()) {
Optimize(*function, true, delay);
}
}
@ -290,7 +284,7 @@ void RuntimeProfiler::OptimizeNow() {
}
// Do not record non-optimizable functions.
if (!IsOptimizable(function)) continue;
if (!function->IsOptimizable()) continue;
samples[sample_count++] = function;
int function_size = function->shared()->SourceSize();
@ -330,7 +324,7 @@ void RuntimeProfiler::OptimizeNow() {
void RuntimeProfiler::OptimizeSoon(JSFunction* function) {
if (!IsOptimizable(function)) return;
if (!function->IsOptimizable()) return;
PendingListNode* node = new PendingListNode(function);
node->set_next(optimize_soon_list_);
optimize_soon_list_ = node;

View File

@ -7405,6 +7405,16 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeoptimizeFunction) {
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_OptimizeFunctionOnNextCall) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(JSFunction, function, 0);
if (!function->IsOptimizable()) return isolate->heap()->undefined_value();
function->MarkForLazyRecompilation();
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileForOnStackReplacement) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);

View File

@ -84,7 +84,8 @@ namespace internal {
F(LazyRecompile, 1, 1) \
F(NotifyDeoptimized, 1, 1) \
F(NotifyOSR, 0, 1) \
F(DeoptimizeFunction, 1, 1) \
F(DeoptimizeFunction, 1, 1) \
F(OptimizeFunctionOnNextCall, 1, 1) \
F(CompileForOnStackReplacement, 1, 1) \
F(SetNewFunctionAttributes, 1, 1) \
F(AllocateInNewSpace, 1, 1) \

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function ArrayLength(a) { return a.length; }
function Test(a0, a2, a5) {
@ -36,7 +38,12 @@ function Test(a0, a2, a5) {
var a0 = [];
var a2 = [1,2];
var a5 = [1,2,3,4,5];
for (var i = 0; i < 100000; i++) Test(a0, a2, a5);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(ArrayLength);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals("undefined", typeof(ArrayLength(0)));
for (var i = 0; i < 100000; i++) Test(a0, a2, a5);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals(4, ArrayLength("hest"));

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test deopt with count operation on parameter.
var max_smi = 1073741823;
var o = {x:0};
@ -44,12 +46,15 @@ o.x = "42";
assign2(o);
assertEquals("421", o.x);
var s = max_smi - 10000;
var s = max_smi - 10;
o.x = s;
for(var i = 0; i < 20000; i++) {
for(var i = 0; i < 20; i++) {
assign2(o);
if (i == 4) {
%OptimizeFunctionOnNextCall(assign2);
}
}
assertEquals(max_smi + 10000, o.x);
assertEquals(max_smi + 10, o.x);
// Test deopt with count operation on keyed property.
@ -59,36 +64,48 @@ o = ["42"];
assign3(o, 0);
assertEquals("421", o[0]);
var s = max_smi - 10000;
var s = max_smi - 10;
o[0] = s;
for(var i = 0; i < 20000; i++) {
for(var i = 0; i < 20; i++) {
assign3(o, 0);
if (i == 4) {
%OptimizeFunctionOnNextCall(assign3);
}
}
assertEquals(max_smi + 10000, o[0]);
assertEquals(max_smi + 10, o[0]);
assign3(o,"0");
assign3(o, "0");
assertEquals(max_smi + 10001, o[0]);
assertEquals(max_smi + 11, o[0]);
// Test bailout when accessing a non-existing array element.
o[0] = 0;
for(var i = 0; i < 10000; i++) {
for(var i = 0; i < 5; i++) {
assign3(o, 0);
}
assign3(o,1);
%OptimizeFunctionOnNextCall(assign3);
assign3(o, 0);
assign3(o, 1);
// Test bailout with count operation in a value context.
function assign5(x,y) { return (x += 1) + y; }
for (var i = 0; i < 10000; ++i) assertEquals(4, assign5(2, 1));
for (var i = 0; i < 5; ++i) assertEquals(4, assign5(2, 1));
%OptimizeFunctionOnNextCall(assign5);
assertEquals(4, assign5(2, 1));
assertEquals(4.1, assign5(2, 1.1));
assertEquals(4.1, assign5(2.1, 1));
function assign7(o,y) { return (o.x += 1) + y; }
o = {x:0};
for (var i = 0; i < 10000; ++i) {
for (var i = 0; i < 5; ++i) {
o.x = 42;
assertEquals(44, assign7(o, 1));
}
%OptimizeFunctionOnNextCall(assign7);
o.x = 42;
assertEquals(44, assign7(o, 1));
o.x = 42;
assertEquals(44.1, assign7(o, 1.1));
o.x = 42.1;
@ -96,10 +113,14 @@ assertEquals(44.1, assign7(o, 1));
function assign9(o,y) { return (o[0] += 1) + y; }
q = [0];
for (var i = 0; i < 10000; ++i) {
for (var i = 0; i < 5; ++i) {
q[0] = 42;
assertEquals(44, assign9(q, 1));
}
%OptimizeFunctionOnNextCall(assign9);
q[0] = 42;
assertEquals(44, assign9(q, 1));
q[0] = 42;
assertEquals(44.1, assign9(q, 1.1));
q[0] = 42.1;
@ -109,11 +130,16 @@ assertEquals(44.1, assign9(q, 1));
function assign10(p) { return p.x += 1 }
var g1 = {x:0};
var g2 = {y:0, x:42};
for (var i = 0; i < 10000; ++i) {
for (var i = 0; i < 5; ++i) {
g1.x = 42;
assertEquals(43, assign10(g1));
assertEquals(43, g1.x);
}
%OptimizeFunctionOnNextCall(assign10);
g1.x = 42;
assertEquals(43, assign10(g1));
assertEquals(43, g1.x);
assertEquals(43, assign10(g2));
assertEquals(43, g2.x);
@ -123,10 +149,14 @@ o = {x:0};
var g3 = { valueOf: function() { o.y = "bar"; return 42; }};
function assign11(p) { return p.x += 1; }
for (var i = 0; i < 10000; i++) {
for (var i = 0; i < 5; i++) {
o.x = "a";
assign11(o);
}
%OptimizeFunctionOnNextCall(assign11);
o.x = "a";
assign11(o);
assertEquals("a11", assign11(o));
o.x = g3;
assertEquals(43, assign11(o));
@ -136,10 +166,14 @@ o = [0];
var g4 = { valueOf: function() { o.y = "bar"; return 42; }};
function assign12(p) { return p[0] += 1; }
for (var i = 0; i < 1000000; i++) {
for (var i = 0; i < 5; i++) {
o[0] = "a";
assign12(o);
}
%OptimizeFunctionOnNextCall(assign12);
o[0] = "a";
assign12(o);
assertEquals("a11", assign12(o));
o[0] = g4;
assertEquals(43, assign12(o));

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test deopt with count operation on parameter.
var max_smi = 1073741823;
var o = {x:0};
@ -44,12 +46,15 @@ o.x = "42";
inc2(o);
assertEquals(43, o.x);
var s = max_smi - 10000;
var s = max_smi - 10;
o.x = s;
for(var i = 0; i < 20000; i++) {
for(var i = 0; i < 20; i++) {
inc2(o);
if (i == 4) {
%OptimizeFunctionOnNextCall(inc2);
}
}
assertEquals(max_smi + 10000, o.x);
assertEquals(max_smi + 10, o.x);
// Test deopt with count operation on keyed property.
@ -59,40 +64,52 @@ o = ["42"];
inc3(o, 0);
assertEquals(43, o[0]);
var s = max_smi - 10000;
var s = max_smi - 10;
o[0] = s;
for(var i = 0; i < 20000; i++) {
for(var i = 0; i < 20; i++) {
inc3(o, 0);
if (i == 4) {
%OptimizeFunctionOnNextCall(inc3);
}
}
assertEquals(max_smi + 10000, o[0]);
assertEquals(max_smi + 10, o[0]);
inc3(o,"0");
assertEquals(max_smi + 10001, o[0]);
assertEquals(max_smi + 11, o[0]);
// Test bailout when accessing a non-existing array element.
o[0] = 0;
for(var i = 0; i < 10000; i++) {
for(var i = 0; i < 5; i++) {
inc3(o, 0);
}
inc3(o,1);
%OptimizeFunctionOnNextCall(inc3);
inc3(o, 0);
inc3(o, 1);
// Test bailout with count operation in a value context.
function inc4(x,y) { return (x++) + y; }
for (var i = 0; i < 100000; ++i) assertEquals(3, inc4(2, 1));
for (var i = 0; i < 5; ++i) assertEquals(3, inc4(2, 1));
%OptimizeFunctionOnNextCall(inc4);
inc4(2, 1);
assertEquals(3.1, inc4(2, 1.1));
function inc5(x,y) { return (++x) + y; }
for (var i = 0; i < 100000; ++i) assertEquals(4, inc5(2, 1));
for (var i = 0; i < 5; ++i) assertEquals(4, inc5(2, 1));
%OptimizeFunctionOnNextCall(inc5);
assertEquals(4, inc5(2, 1));
assertEquals(4.1, inc5(2, 1.1));
assertEquals(4.1, inc5(2.1, 1));
function inc6(o,y) { return (o.x++) + y; }
o = {x:0};
for (var i = 0; i < 10000; ++i) {
for (var i = 0; i < 5; ++i) {
o.x = 42;
assertEquals(43, inc6(o, 1));
}
%OptimizeFunctionOnNextCall(inc6);
o.x = 42;
assertEquals(43, inc6(o, 1));
o.x = 42;
assertEquals(43.1, inc6(o, 1.1));
o.x = 42.1;
@ -100,10 +117,13 @@ assertEquals(43.1, inc6(o, 1));
function inc7(o,y) { return (++o.x) + y; }
o = {x:0};
for (var i = 0; i < 10000; ++i) {
for (var i = 0; i < 5; ++i) {
o.x = 42;
assertEquals(44, inc7(o, 1));
}
%OptimizeFunctionOnNextCall(inc7);
o.x = 42;
assertEquals(44, inc7(o, 1));
o.x = 42;
assertEquals(44.1, inc7(o, 1.1));
o.x = 42.1;
@ -111,10 +131,13 @@ assertEquals(44.1, inc7(o, 1));
function inc8(o,y) { return (o[0]++) + y; }
var q = [0];
for (var i = 0; i < 100000; ++i) {
for (var i = 0; i < 5; ++i) {
q[0] = 42;
assertEquals(43, inc8(q, 1));
}
%OptimizeFunctionOnNextCall(inc8);
q[0] = 42;
assertEquals(43, inc8(q, 1));
q[0] = 42;
assertEquals(43.1, inc8(q, 1.1));
q[0] = 42.1;
@ -122,10 +145,13 @@ assertEquals(43.1, inc8(q, 1));
function inc9(o,y) { return (++o[0]) + y; }
q = [0];
for (var i = 0; i < 100000; ++i) {
for (var i = 0; i < 5; ++i) {
q[0] = 42;
assertEquals(44, inc9(q, 1));
}
%OptimizeFunctionOnNextCall(inc9);
q[0] = 42;
assertEquals(44, inc9(q, 1));
q[0] = 42;
assertEquals(44.1, inc9(q, 1.1));
q[0] = 42.1;
@ -135,11 +161,15 @@ assertEquals(44.1, inc9(q, 1));
function inc10(p) { return p.x++ }
var g1 = {x:0};
var g2 = {y:0, x:42}
for (var i = 0; i < 10000; ++i) {
for (var i = 0; i < 5; ++i) {
g1.x = 42;
assertEquals(42, inc10(g1));
assertEquals(43, g1.x);
}
%OptimizeFunctionOnNextCall(inc10);
g1.x = 42;
assertEquals(42, inc10(g1));
assertEquals(43, g1.x);
assertEquals(42, inc10(g2));
assertEquals(43, g2.x);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function g(x) {
return x.f(0,1,2);
}
@ -35,9 +37,11 @@ function f(a,b,c) {
var object = { };
object.f = f;
for (var i = 0; i < 10000000; i++) {
for (var i = 0; i < 5; i++) {
assertEquals(42, g(object));
}
%OptimizeFunctionOnNextCall(g);
g(object);
object.f = function(a,b,c) { return 87; };
assertEquals(87, g(object));

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test that we can inline a function that returns the result of
// a compare operation.
function TestInlineCompare(o) {
@ -42,5 +44,7 @@ function TestInlineCompare(o) {
var o = {};
o.f = function() { return 0 === 1; };
for (var i = 0; i < 10000000; i++) TestInlineCompare(o);
for (var i = 0; i < 5; i++) TestInlineCompare(o);
%OptimizeFunctionOnNextCall(TestInlineCompare);
TestInlineCompare(o);
TestInlineCompare({f: o.f});

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test that we can inline a function that returns the result of a
// global variable load.
var GLOBAL;
@ -45,5 +47,7 @@ function TestInlineGlobalLoad(o) {
var o = {};
o.f = function() { return GLOBAL; };
for (var i = 0; i < 10000000; i++) TestInlineGlobalLoad(o);
for (var i = 0; i < 5; i++) TestInlineGlobalLoad(o);
%OptimizeFunctionOnNextCall(TestInlineGlobalLoad);
TestInlineGlobalLoad(o);
TestInlineGlobalLoad({f: o.f});

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test that we can inline a call with a parameter.
function TestInlineOneParam(o, p) {
// Effect context.
@ -42,7 +44,9 @@ function TestInlineOneParam(o, p) {
var obj = {x:42};
var o1 = {};
o1.f = function(o) { return o.x; };
for (var i = 0; i < 10000; i++) TestInlineOneParam(o1, obj);
for (var i = 0; i < 5; i++) TestInlineOneParam(o1, obj);
%OptimizeFunctionOnNextCall(TestInlineOneParam);
TestInlineOneParam(o1, obj);
TestInlineOneParam({f: o1.f}, {x:42});
@ -76,5 +80,7 @@ function TestInlineTwoParams(o, p) {
var o2 = {};
o2.h = function(i, j) { return i < j; };
for (var i = 0; i < 10000; i++) TestInlineTwoParams(o2, 42);
for (var i = 0; i < 5; i++) TestInlineTwoParams(o2, 42);
%OptimizeFunctionOnNextCall(TestInlineTwoParams);
TestInlineTwoParams(o2, 42);
TestInlineTwoParams({h: o2.h}, 42);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test that we can inline a function that calls another function.
function TestInlineX(o) {
// Effect context.
@ -42,7 +44,9 @@ function TestInlineX(o) {
var o2 = {};
o2.size = function() { return 42; }
o2.g = function() { return this.size(); };
for (var i = 0; i < 10000; i++) TestInlineX(o2);
for (var i = 0; i < 5; i++) TestInlineX(o2);
%OptimizeFunctionOnNextCall(TestInlineX);
TestInlineX(o2);
TestInlineX({g: o2.g, size:o2.size});
@ -65,7 +69,9 @@ obj.foo = function() { return 42; }
var o3 = {};
o3.v = obj;
o3.h = function() { return this.v.foo(); };
for (var i = 0; i < 10000; i++) TestInlineX2(o3);
for (var i = 0; i < 5; i++) TestInlineX2(o3);
%OptimizeFunctionOnNextCall(TestInlineX2);
TestInlineX2(o3);
TestInlineX2({h: o3.h, v:obj});
@ -89,5 +95,7 @@ var o3 = {};
o3.v = obj;
o3.f = function() { return this.v; }
o3.h = function() { return this.f().g(); };
for (var i = 0; i < 10000; i++) TestInlineFG(o3);
for (var i = 0; i < 5; i++) TestInlineFG(o3);
%OptimizeFunctionOnNextCall(TestInlineFG);
TestInlineFG(o3);
TestInlineFG({h: o3.h, f: o3.f, v:obj});

View File

@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-gc
// Flags: --allow-natives-syntax --expose-gc
function f() {
gc();
@ -48,7 +48,9 @@ delete object.x;
function call_f(o) {
return o.f();
}
for (var i = 0; i < 10000000; i++) call_f(object);
for (var i = 0; i < 5; i++) call_f(object);
%OptimizeFunctionOnNextCall(call_f);
call_f(object);
// Check that nested global function calls work.

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function GetX(o) { return o.x; }
function CallF(o) { return o.f(); }
function SetX(o) { o.x = 42; }
@ -53,11 +55,15 @@ o1.f = o2.f = o3.f = function() { return 99; }
// Run the test until we're fairly sure we've optimized the
// polymorphic property access.
for (var i = 0; i < 100000; i++) {
for (var i = 0; i < 5; i++) {
Test(o1);
Test(o2);
Test(o3);
}
%OptimizeFunctionOnNextCall(Test);
Test(o1);
Test(o2);
Test(o3);
// Make sure that the following doesn't crash.
GetX(0);

View File

@ -25,12 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function f(o) { return o.g(); }
function g() { return 42; }
var object = { };
object.g = g;
for (var i = 0; i < 10000000; i++) f(object);
for (var i = 0; i < 5; i++) f(object);
%OptimizeFunctionOnNextCall(f);
f(object);
assertEquals(42, f(object));
object = { g: function() { return 87; } };

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function Load(o) {
return o.outer.x | o.outer.inner.y;
}
@ -45,7 +47,9 @@ function LoadXY(x, y) {
return Load(object);
}
for (var i = 0; i < 10000; i++) LoadXY(i, i);
for (var i = 0; i < 5; i++) LoadXY(i, i);
%OptimizeFunctionOnNextCall(LoadXY);
LoadXY(6, 6);
assertEquals(42 | 87, LoadXY(42, 87));
assertEquals(42 | 87, LoadXY(42, 87));
assertEquals(42 | 99, LoadXY(42, "99"));

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
var a = 42;
var obj = {x: 0,
@ -33,11 +35,17 @@ var obj = {x: 0,
h: function() { this.x = a; }};
var i;
for (i = 0; i < 10000; i++) { obj.f(); }
for (i = 0; i < 5; i++) { obj.f(); }
%OptimizeFunctionOnNextCall(obj.f);
obj.f();
assertEquals(7, obj.x);
for (i = 0; i < 10000; i++) { obj.g(); }
for (i = 0; i < 5; i++) { obj.g(); }
%OptimizeFunctionOnNextCall(obj.g);
obj.g();
assertEquals(43, obj.x);
for (i = 0; i < 10000; i++) { obj.h(); }
for (i = 0; i < 5; i++) { obj.h(); }
%OptimizeFunctionOnNextCall(obj.h);
obj.h();
assertEquals(42, obj.x);

View File

@ -25,6 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function f(n) {
// Force deopt in both leaf case and when returning. To make
@ -34,15 +35,11 @@ function f(n) {
return f(n - 1) << one;
}
function RunTests() {
assertEquals(1 << 1, f(0));
assertEquals(1 << 2, f(1));
assertEquals(1 << 5, f(4));
}
var one = 1;
for (var i = 0; i < 1000000; i++) RunTests();
for (var i = 0; i < 5; i++) assertEquals(1 << 5, f(4));
%OptimizeFunctionOnNextCall(f);
assertEquals(1 << 5, f(4));
var one = { valueOf: function() { return 1; } };
for (var j = 0; j < 100000; j++) RunTests();
assertEquals(1 << 5, f(4));

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Regression test for failure to deoptimize properly when the most recent
// side effect occurred in a comma expression in an effect context.
@ -40,7 +42,9 @@ function observe(x, y) { try {} finally {} return x; }
function test(x) { return observe(this, ((0, side_effect()), x + 1)); }
// Run test enough times to get it optimized.
for (var i = 0; i < 1000000; ++i) test(0);
for (var i = 0; i < 5; ++i) test(0);
%OptimizeFunctionOnNextCall(test);
test(0);
// Force test to deopt. If it behaves normally, it should return the global
// object. If the value of the call to side_effect() is lingering after the

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Regression test for GVN on field loads.
function bar() {}
@ -58,8 +60,10 @@ a.p9 = "";
a.p10 = "";
a.p11 = "";
a.foo = "foo";
for (var i = 0; i < 100000; i++) {
for (var i = 0; i < 5; i++) {
test(a);
}
%OptimizeFunctionOnNextCall(test);
test(a);
test("");

View File

@ -25,10 +25,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test Math.max with negative zero as input.
function f(x, y) { return Math.max(x, y) }
for (var i = 0; i < 5; i++) Math.max(0, 0);
%OptimizeFunctionOnNextCall(Math.max);
Math.max(0, 0);
for (var i = 0; i < 1000000; i++) f(0, 0);
var r = f(-0, -0);
var r = Math.max(-0, -0);
assertEquals(-Infinity, 1 / r);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test stack traces with method calls.
function Hest() {}
function Svin() {}
@ -39,9 +41,12 @@ var o = new Hest();
var s = new Svin();
var v = 0;
for (var i = 0; i < 1000000; i++) {
for (var i = 0; i < 5; i++) {
o.one(s);
}
%OptimizeFunctionOnNextCall(Hest.prototype.one);
%OptimizeFunctionOnNextCall(Hest.prototype.three);
o.one(s);
v = 42;
@ -57,8 +62,8 @@ try {
assertTrue(p1 != -1);
assertTrue(p3 < p2);
assertTrue(p2 < p1);
assertTrue(stack.indexOf("36:56") != -1);
assertTrue(stack.indexOf("32:51") != -1);
assertTrue(stack.indexOf("34:38") != -1);
assertTrue(stack.indexOf("49:5") != -1);
assertTrue(stack.indexOf("38:56") != -1);
assertTrue(stack.indexOf("34:51") != -1);
assertTrue(stack.indexOf("36:38") != -1);
assertTrue(stack.indexOf("54:5") != -1);
}

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function f(x) {
return ~x;
}
@ -59,7 +61,9 @@ obj.g = g;
function k(o) {
return o.g();
}
for (var i = 0; i < 1000000; i++) k(obj);
for (var i = 0; i < 5; i++) k(obj);
%OptimizeFunctionOnNextCall(k);
k(obj);
assertEquals(42, k(obj));
assertEquals(87, k({g: function() { return 87; }}));
@ -88,9 +92,11 @@ assertEquals('lit[42]', LiteralToStack(42));
var str = "abc";
var r;
function CallCharAt(n) { return str.charAt(n); }
for (var i = 0; i < 1000000; i++) {
for (var i = 0; i < 5; i++) {
r = CallCharAt(0);
}
%OptimizeFunctionOnNextCall(CallCharAt);
r = CallCharAt(0);
assertEquals("a", r);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test that we can inline a function that returns a constant.
function TestInlineConstant(o) {
// Effect context.
@ -41,7 +43,9 @@ function TestInlineConstant(o) {
var o1 = {};
o1.f = function() { return 42; };
for (var i = 0; i < 10000; i++) TestInlineConstant(o1);
for (var i = 0; i < 5; i++) TestInlineConstant(o1);
%OptimizeFunctionOnNextCall(TestInlineConstant);
TestInlineConstant(o1);
TestInlineConstant({f: o1.f});
@ -61,7 +65,9 @@ function TestInlineThis(o) {
var o2 = {};
o2.g = function() { return this; };
for (var i = 0; i < 10000; i++) TestInlineThis(o2);
for (var i = 0; i < 5; i++) TestInlineThis(o2);
%OptimizeFunctionOnNextCall(TestInlineThis);
TestInlineThis(o2);
TestInlineThis({g: o2.g});
@ -81,7 +87,9 @@ function TestInlineThisX(o) {
var o3 = {y:0,x:42};
o3.h = function() { return this.x; };
for (var i = 0; i < 10000; i++) TestInlineThisX(o3);
for (var i = 0; i < 5; i++) TestInlineThisX(o3);
%OptimizeFunctionOnNextCall(TestInlineThisX);
TestInlineThisX(o3);
TestInlineThisX({h: o3.h, x:42});
@ -101,7 +109,9 @@ function TestInlineThisXLength(o) {
var o4 = {x:[1,2,3]};
o4.h = function() { return this.x.length; };
for (var i = 0; i < 10000; i++) TestInlineThisXLength(o4);
for (var i = 0; i < 5; i++) TestInlineThisXLength(o4);
%OptimizeFunctionOnNextCall(TestInlineThisXLength);
TestInlineThisXLength(o4);
TestInlineThisXLength({h: o4.h, x:[1,2,3]});
@ -122,7 +132,9 @@ function TestInlineThisXY(o) {
var o6 = {y:42}
var o5 = {e:o6};
o5.h = function() { return this.e.y; };
for (var i = 0; i < 10000; i++) TestInlineThisXY(o5);
for (var i = 0; i < 5; i++) TestInlineThisXY(o5);
%OptimizeFunctionOnNextCall(TestInlineThisXY);
TestInlineThisXY(o5);
TestInlineThisXY({h: o5.h, e:o6});
@ -142,5 +154,7 @@ function TestInlineThisX0(o) {
var o7 = {x:[42,43,44]};
o7.foo = function() { return this.x[0]; };
for (var i = 0; i < 10000; i++) TestInlineThisX0(o7);
for (var i = 0; i < 5; i++) TestInlineThisX0(o7);
%OptimizeFunctionOnNextCall(TestInlineThisX0);
TestInlineThisX0(o7);
TestInlineThisX0({foo: o7.foo, x:[42,0,0]});

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test that bailing out of the optimized compilation doesn't mess with
// the labels in the AST.
function f(x) {
@ -35,5 +37,7 @@ function f(x) {
return 99;
}
for (var i = 0; i < 10000; i++) f("foo");
for (var i = 0; i < 5; i++) f("foo");
%OptimizeFunctionOnNextCall(f);
f("foo");
assertEquals(42, f("bar"));

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test the handling of initialization of deleted const variables.
// This only makes sense in local scopes since the declaration and
// initialization of consts in the global scope happen at the same
@ -67,9 +69,11 @@ function testAssignmentArgument(x) {
assertEquals(7, x);
}
for (var i = 0; i < 10000; i++) {
for (var i = 0; i < 5; i++) {
testAssignmentArgument();
}
%OptimizeFunctionOnNextCall(testAssignmentArgument);
testAssignmentArgument();
assertEquals(6, x);
__defineSetter__('x', function() { throw 42; });

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// This is a regression test for overlapping key and value registers.
function f(a) {
a[0] = 0;
@ -32,9 +34,11 @@ function f(a) {
}
var a = new Int32Array(2);
for (var i = 0; i < 1000000; i++) {
for (var i = 0; i < 5; i++) {
f(a);
}
%OptimizeFunctionOnNextCall(f);
f(a);
assertEquals(0, a[0]);
assertEquals(0, a[1]);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Getting the arguments property of an optimized function should not crash,
// even if called through our optimized version of Function.prototype.apply.
@ -39,7 +41,8 @@ function unoptimized() {
}
}
for (var i = 0; i < 100000; ++i) {
for (var i = 0; i < 5; ++i) {
assertEquals(3, optimized(1, 2, 3).length);
}
%OptimizeFunctionOnNextCall(optimized);
assertEquals(3, optimized(1, 2, 3).length);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test for issue 1106, where the optimizing compiler broke when accessing
// a property lying on a prototype of the global object, and that prototype
// object was in dictionary mode.
@ -37,14 +39,18 @@ x.foo = 5;
function f() { return foo; }
for (i=0 ; i < 100000; ++i) {
for (i=0 ; i < 5; ++i) {
assertEquals(5, f());
}
%OptimizeFunctionOnNextCall(f);
assertEquals(5, f());
// Test calls on functions defined in the prototype of the global object.
x.gee = function() { return 42; }
function g() { return gee(); }
for (i=0 ; i < 100000; ++i) {
for (i=0 ; i < 5; ++i) {
assertEquals(42, g());
}
%OptimizeFunctionOnNextCall(g);
assertEquals(42, g());

View File

@ -25,11 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Deoptimization after a short-circuit logical operation in an effect
// context should not see the value of the expression.
function observe(x, y) { return x; }
function test(x) { return observe(1, ((false || false), x + 1)); }
for (var i = 0; i < 10000000; ++i) test(0);
for (var i = 0; i < 5; ++i) test(0);
%OptimizeFunctionOnNextCall(test);
test(0);
test("a");

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Deoptimization after a logical not in an effect context should not see a
// value for the logical not expression.
function test0(n) {
@ -68,5 +70,7 @@ function test2(x) {
x + 1));
}
for (var i = 0; i < 1000000; ++i) test2(0);
for (var i = 0; i < 5; ++i) test2(0);
%OptimizeFunctionOnNextCall(test2);
test2(0);
test2(test2);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Deoptimization of the key expression in an arguments access should see
// the arguments object as the value of the receiver.
@ -43,6 +45,8 @@ function test() {
// Run enough to optimize assuming global 'a' is a smi.
for (var i = 0; i < 1000000; ++i) test(0);
%OptimizeFunctionOnNextCall(test);
test(0);
a = "hello";
test(0);

View File

@ -56,11 +56,17 @@ function h(z2, y2) {
return f(local_y, local_z); /* f should be inlined into h */
}
for (var i = 0; i < 100000; i++) f(2, 3);
for (var i = 0; i < 5; i++) f(2, 3);
%OptimizeFunctionOnNextCall(f);
f(2, 3);
for (var i = 0; i < 100000; i++) g(3, 2);
for (var i = 0; i < 5; i++) g(3, 2);
%OptimizeFunctionOnNextCall(g);
g(3, 2);
for (var i = 0; i < 100000; i++) h(6, 4);
for (var i = 0; i < 5; i++) h(6, 4);
%OptimizeFunctionOnNextCall(h);
h(6, 4);
// Check that %_IsConstructCall returns correct value when inlined
var NON_CONSTRUCT_MARKER = {};
@ -76,4 +82,6 @@ function bar(x, y, z) {
assertEquals(construct, CONSTRUCT_MARKER);
}
for (var i = 0; i < 100000; i++) new bar(1, 2, 3);
for (var i = 0; i < 5; i++) new bar(1, 2, 3);
%OptimizeFunctionOnNextCall(bar);
bar(1, 2, 3);

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Deoptimization after a conditional expression in an effect context should
// not see the value of the expression.
function observe(x, y) { return x; }
@ -32,5 +34,8 @@ function test(x) {
return observe(1, ((x? observe(observe.prototype.x): 'c'), x + 1));
}
for (var i = 0; i < 10000000; ++i) test(0);
for (var i = 0; i < 5; ++i) test(0);
%OptimizeFunctionOnNextCall(test);
test(0);
test("a");

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Checks that comma expression in conditional context is processed correctly.
function withCommaExpressionInConditional(x) {
@ -36,7 +38,9 @@ function withCommaExpressionInConditional(x) {
return (y = x + 1, y > 1) ? 'medium' : 'small';
}
for (var i = 0; i < 10000; i++) {
for (var i = 0; i < 5; i++) {
withCommaExpressionInConditional(i);
}
%OptimizeFunctionOnNextCall(withCommaExpressionInConditional);
withCommaExpressionInConditional(i);
withCommaExpressionInConditional("1")

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
function L(scope) { this.s = new Object(); }
L.prototype.c = function() { return true; }
@ -50,4 +52,6 @@ F.prototype.foo = function () {
var ctx = new F;
for (var i = 0; i < 10000; i++) ctx.foo();
for (var i = 0; i < 5; i++) ctx.foo();
%OptimizeFunctionOnNextCall(F.prototype.foo);
ctx.foo();

View File

@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
/**
* @fileoverview Check all sorts of borderline cases for charCodeAt.
*/
@ -159,9 +161,11 @@ function ConsNotSmiIndex() {
assertTrue(isNaN(str.charCodeAt(0x7fffffff)));
}
for (var i = 0; i < 100000; i++) {
for (var i = 0; i < 5; i++) {
ConsNotSmiIndex();
}
%OptimizeFunctionOnNextCall(ConsNotSmiIndex);
ConsNotSmiIndex();
for (var i = 0; i != 10; i++) {
@ -222,6 +226,8 @@ function directlyOnPrototype() {
assertEquals(99, "c".x(0));
}
for (var i = 0; i < 10000; i++) {
for (var i = 0; i < 5; i++) {
directlyOnPrototype();
}
%OptimizeFunctionOnNextCall(directlyOnPrototype);
directlyOnPrototype();

View File

@ -1,4 +1,4 @@
// Copyright 2010 the V8 project authors. All rights reserved.
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
/**
* @fileoverview Test addition of 0 and undefined.
*/
@ -32,9 +34,11 @@
function sum(a, b) { return a + b; }
function test(x, y, expectNaN) {
for (var i = 0; i < 1000; i++) {
for (var i = 0; i < 5; i++) {
assertEquals(expectNaN, isNaN(sum(x, y)));
}
%OptimizeFunctionOnNextCall(sum);
assertEquals(expectNaN, isNaN(sum(x, y)));
}
test(0, 1, false);