Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: test/cctest/test-compiler.cc

Issue 254623002: Simplify feedback vector creation and store in SharedFunctionInfo. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 v8::String::NewFromUtf8(CcTest::isolate(), buffer.start()); 283 v8::String::NewFromUtf8(CcTest::isolate(), buffer.start());
284 v8::Script::Compile(script_body, &origin)->Run(); 284 v8::Script::Compile(script_body, &origin)->Run();
285 v8::Local<v8::Function> f = 285 v8::Local<v8::Function> f =
286 v8::Local<v8::Function>::Cast(context->Global()->Get( 286 v8::Local<v8::Function>::Cast(context->Global()->Get(
287 v8::String::NewFromUtf8(CcTest::isolate(), "f"))); 287 v8::String::NewFromUtf8(CcTest::isolate(), "f")));
288 CHECK_EQ(i, f->GetScriptLineNumber()); 288 CHECK_EQ(i, f->GetScriptLineNumber());
289 } 289 }
290 } 290 }
291 291
292 292
293 TEST(FeedbackVectorPreservedAcrossRecompiles) {
294 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return;
295 i::FLAG_allow_natives_syntax = true;
296 CcTest::InitializeVM();
297 if (!CcTest::i_isolate()->use_crankshaft()) return;
298 v8::HandleScope scope(CcTest::isolate());
299
300 // Make sure function f has a call that uses a type feedback slot.
301 CompileRun("function fun() {};"
302 "fun1 = fun;"
303 "function f(a) { a(); } f(fun1);");
304
305 Handle<JSFunction> f =
306 v8::Utils::OpenHandle(
307 *v8::Handle<v8::Function>::Cast(
308 CcTest::global()->Get(v8_str("f"))));
309
310 // We shouldn't have deoptimization support. We want to recompile and
311 // verify that our feedback vector preserves information.
312 CHECK(!f->shared()->has_deoptimization_support());
313 Handle<FixedArray> feedback_vector(f->shared()->feedback_vector());
314
315 // Verify that we gathered feedback.
316 CHECK_EQ(1, feedback_vector->length());
317 CHECK(feedback_vector->get(0)->IsJSFunction());
318
319 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);");
320
321 // Verify that the feedback is still "gathered" despite a recompilation
322 // of the full code.
323 CHECK(f->shared()->has_deoptimization_support());
Benedikt Meurer 2014/04/28 19:17:00 Nit: Please also CHECK() that f is actually optimi
mvstanton 2014/04/30 08:31:18 Done.
324 CHECK(f->shared()->feedback_vector()->get(0)->IsJSFunction());
325 }
326
327
328 TEST(FeedbackVectorUnaffectedByScopeChanges) {
329 if (i::FLAG_always_opt || !i::FLAG_lazy) return;
330 CcTest::InitializeVM();
331 v8::HandleScope scope(CcTest::isolate());
332
333 CompileRun("function builder() {"
334 " call_target = function() { return 3; };"
335 " return (function() {"
336 " eval('');"
337 " return function() {"
338 " 'use strict';"
339 " call_target();"
340 " }"
341 " })();"
342 "}"
343 "morphing_call = builder();");
344
345 Handle<JSFunction> f =
346 v8::Utils::OpenHandle(
347 *v8::Handle<v8::Function>::Cast(
348 CcTest::global()->Get(v8_str("morphing_call"))));
349
350 // morphing_call should have one feedback vector slot for the call to
351 // call_target().
352 CHECK_EQ(1, f->shared()->feedback_vector()->length());
353 // And yet it's not compiled.
354 CHECK(!f->shared()->is_compiled());
355
356 CompileRun("morphing_call();");
357
358 // The vector should have the same size despite the new scoping.
359 CHECK_EQ(1, f->shared()->feedback_vector()->length());
360 CHECK(f->shared()->is_compiled());
361 }
362
363
293 // Test that optimized code for different closures is actually shared 364 // Test that optimized code for different closures is actually shared
294 // immediately by the FastNewClosureStub when run in the same context. 365 // immediately by the FastNewClosureStub when run in the same context.
295 TEST(OptimizedCodeSharing) { 366 TEST(OptimizedCodeSharing) {
296 // Skip test if --cache-optimized-code is not activated by default because 367 // Skip test if --cache-optimized-code is not activated by default because
297 // FastNewClosureStub that is baked into the snapshot is incorrect. 368 // FastNewClosureStub that is baked into the snapshot is incorrect.
298 if (!FLAG_cache_optimized_code) return; 369 if (!FLAG_cache_optimized_code) return;
299 FLAG_stress_compaction = false; 370 FLAG_stress_compaction = false;
300 FLAG_allow_natives_syntax = true; 371 FLAG_allow_natives_syntax = true;
301 CcTest::InitializeVM(); 372 CcTest::InitializeVM();
302 v8::HandleScope scope(CcTest::isolate()); 373 v8::HandleScope scope(CcTest::isolate());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 CompileRun("function f() { a = 12345678 }; f();"); 442 CompileRun("function f() { a = 12345678 }; f();");
372 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 443 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
373 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 444 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
374 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 445 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
375 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 446 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
376 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 447 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
377 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 448 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
378 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 449 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
379 } 450 }
380 #endif 451 #endif
OLDNEW
« src/typing.cc ('K') | « src/x64/full-codegen-x64.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698