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

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: Code comments 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
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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->IsOptimized());
324 CHECK(f->shared()->has_deoptimization_support());
325 CHECK(f->shared()->feedback_vector()->get(0)->IsJSFunction());
326 }
327
328
329 TEST(FeedbackVectorUnaffectedByScopeChanges) {
330 if (i::FLAG_always_opt || !i::FLAG_lazy) return;
331 CcTest::InitializeVM();
332 v8::HandleScope scope(CcTest::isolate());
333
334 CompileRun("function builder() {"
335 " call_target = function() { return 3; };"
336 " return (function() {"
337 " eval('');"
338 " return function() {"
339 " 'use strict';"
340 " call_target();"
341 " }"
342 " })();"
343 "}"
344 "morphing_call = builder();");
345
346 Handle<JSFunction> f =
347 v8::Utils::OpenHandle(
348 *v8::Handle<v8::Function>::Cast(
349 CcTest::global()->Get(v8_str("morphing_call"))));
350
351 // morphing_call should have one feedback vector slot for the call to
352 // call_target().
353 CHECK_EQ(1, f->shared()->feedback_vector()->length());
354 // And yet it's not compiled.
355 CHECK(!f->shared()->is_compiled());
356
357 CompileRun("morphing_call();");
358
359 // The vector should have the same size despite the new scoping.
360 CHECK_EQ(1, f->shared()->feedback_vector()->length());
361 CHECK(f->shared()->is_compiled());
362 }
363
364
293 // Test that optimized code for different closures is actually shared 365 // Test that optimized code for different closures is actually shared
294 // immediately by the FastNewClosureStub when run in the same context. 366 // immediately by the FastNewClosureStub when run in the same context.
295 TEST(OptimizedCodeSharing) { 367 TEST(OptimizedCodeSharing) {
296 // Skip test if --cache-optimized-code is not activated by default because 368 // Skip test if --cache-optimized-code is not activated by default because
297 // FastNewClosureStub that is baked into the snapshot is incorrect. 369 // FastNewClosureStub that is baked into the snapshot is incorrect.
298 if (!FLAG_cache_optimized_code) return; 370 if (!FLAG_cache_optimized_code) return;
299 FLAG_stress_compaction = false; 371 FLAG_stress_compaction = false;
300 FLAG_allow_natives_syntax = true; 372 FLAG_allow_natives_syntax = true;
301 CcTest::InitializeVM(); 373 CcTest::InitializeVM();
302 v8::HandleScope scope(CcTest::isolate()); 374 v8::HandleScope scope(CcTest::isolate());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 CompileRun("function f() { a = 12345678 }; f();"); 443 CompileRun("function f() { a = 12345678 }; f();");
372 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 444 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
373 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 445 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
374 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 446 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
375 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 447 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
376 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 448 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
377 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 449 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
378 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 450 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
379 } 451 }
380 #endif 452 #endif
OLDNEW
« no previous file with comments | « 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