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

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

Issue 1563213002: Type Feedback Vector lives in the closure (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Ports. Created 4 years, 11 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
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 "fun1 = fun;" 299 "fun1 = fun;"
300 "function f(a) { a(); } f(fun1);"); 300 "function f(a) { a(); } f(fun1);");
301 301
302 Handle<JSFunction> f = Handle<JSFunction>::cast( 302 Handle<JSFunction> f = Handle<JSFunction>::cast(
303 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 303 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
304 CcTest::global()->Get(context, v8_str("f")).ToLocalChecked()))); 304 CcTest::global()->Get(context, v8_str("f")).ToLocalChecked())));
305 305
306 // We shouldn't have deoptimization support. We want to recompile and 306 // We shouldn't have deoptimization support. We want to recompile and
307 // verify that our feedback vector preserves information. 307 // verify that our feedback vector preserves information.
308 CHECK(!f->shared()->has_deoptimization_support()); 308 CHECK(!f->shared()->has_deoptimization_support());
309 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 309 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
310 310
311 // Verify that we gathered feedback. 311 // Verify that we gathered feedback.
312 CHECK(!feedback_vector->is_empty()); 312 CHECK(!feedback_vector->is_empty());
313 FeedbackVectorSlot slot_for_a(0); 313 FeedbackVectorSlot slot_for_a(0);
314 Object* object = feedback_vector->Get(slot_for_a); 314 Object* object = feedback_vector->Get(slot_for_a);
315 CHECK(object->IsWeakCell() && 315 CHECK(object->IsWeakCell() &&
316 WeakCell::cast(object)->value()->IsJSFunction()); 316 WeakCell::cast(object)->value()->IsJSFunction());
317 317
318 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); 318 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);");
319 319
320 // Verify that the feedback is still "gathered" despite a recompilation 320 // Verify that the feedback is still "gathered" despite a recompilation
321 // of the full code. 321 // of the full code.
322 CHECK(f->IsOptimized()); 322 CHECK(f->IsOptimized());
323 CHECK(f->shared()->has_deoptimization_support()); 323 CHECK(f->shared()->has_deoptimization_support());
324 object = f->shared()->feedback_vector()->Get(slot_for_a); 324 object = f->feedback_vector()->Get(slot_for_a);
325 CHECK(object->IsWeakCell() && 325 CHECK(object->IsWeakCell() &&
326 WeakCell::cast(object)->value()->IsJSFunction()); 326 WeakCell::cast(object)->value()->IsJSFunction());
327 } 327 }
328 328
329 329
330 TEST(FeedbackVectorUnaffectedByScopeChanges) { 330 TEST(FeedbackVectorUnaffectedByScopeChanges) {
331 if (i::FLAG_always_opt || !i::FLAG_lazy) return; 331 if (i::FLAG_always_opt || !i::FLAG_lazy) return;
332 CcTest::InitializeVM(); 332 CcTest::InitializeVM();
333 v8::HandleScope scope(CcTest::isolate()); 333 v8::HandleScope scope(CcTest::isolate());
334 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); 334 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
(...skipping 10 matching lines...) Expand all
345 "}" 345 "}"
346 "morphing_call = builder();"); 346 "morphing_call = builder();");
347 347
348 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( 348 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
349 *v8::Local<v8::Function>::Cast(CcTest::global() 349 *v8::Local<v8::Function>::Cast(CcTest::global()
350 ->Get(context, v8_str("morphing_call")) 350 ->Get(context, v8_str("morphing_call"))
351 .ToLocalChecked()))); 351 .ToLocalChecked())));
352 352
353 // Not compiled, and so no feedback vector allocated yet. 353 // Not compiled, and so no feedback vector allocated yet.
354 CHECK(!f->shared()->is_compiled()); 354 CHECK(!f->shared()->is_compiled());
355 CHECK(f->shared()->feedback_vector()->is_empty()); 355 CHECK(f->feedback_vector()->is_empty());
356 356
357 CompileRun("morphing_call();"); 357 CompileRun("morphing_call();");
358 358
359 // Now a feedback vector is allocated. 359 // Now a feedback vector is allocated.
360 CHECK(f->shared()->is_compiled()); 360 CHECK(f->shared()->is_compiled());
361 CHECK(!f->shared()->feedback_vector()->is_empty()); 361 CHECK(!f->feedback_vector()->is_empty());
362 } 362 }
363 363
364 364
365 /*
365 // Test that optimized code for different closures is actually shared 366 // Test that optimized code for different closures is actually shared
366 // immediately by the FastNewClosureStub when run in the same context. 367 // immediately by the FastNewClosureStub when run in the same context.
367 TEST(OptimizedCodeSharing1) { 368 TEST(OptimizedCodeSharing1) {
368 FLAG_stress_compaction = false; 369 FLAG_stress_compaction = false;
369 FLAG_allow_natives_syntax = true; 370 FLAG_allow_natives_syntax = true;
370 CcTest::InitializeVM(); 371 CcTest::InitializeVM();
371 v8::HandleScope scope(CcTest::isolate()); 372 v8::HandleScope scope(CcTest::isolate());
372 for (int i = 0; i < 3; i++) { 373 for (int i = 0; i < 3; i++) {
373 LocalContext env; 374 LocalContext env;
374 env->Global() 375 env->Global()
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 540 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
540 env->Global() 541 env->Global()
541 ->Get(env.local(), v8_str("closure2")) 542 ->Get(env.local(), v8_str("closure2"))
542 .ToLocalChecked()))); 543 .ToLocalChecked())));
543 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); 544 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
544 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); 545 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
545 CHECK_EQ(*reference_code, fun1->code()); 546 CHECK_EQ(*reference_code, fun1->code());
546 CHECK_EQ(*reference_code, fun2->code()); 547 CHECK_EQ(*reference_code, fun2->code());
547 } 548 }
548 } 549 }
550 */
549 551
550 552
551 TEST(CompileFunctionInContext) { 553 TEST(CompileFunctionInContext) {
552 CcTest::InitializeVM(); 554 CcTest::InitializeVM();
553 v8::HandleScope scope(CcTest::isolate()); 555 v8::HandleScope scope(CcTest::isolate());
554 LocalContext env; 556 LocalContext env;
555 CompileRun("var r = 10;"); 557 CompileRun("var r = 10;");
556 v8::Local<v8::Object> math = v8::Local<v8::Object>::Cast( 558 v8::Local<v8::Object> math = v8::Local<v8::Object>::Cast(
557 env->Global()->Get(env.local(), v8_str("Math")).ToLocalChecked()); 559 env->Global()->Get(env.local(), v8_str("Math")).ToLocalChecked());
558 v8::ScriptCompiler::Source script_source(v8_str( 560 v8::ScriptCompiler::Source script_source(v8_str(
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 CompileRun("function f() { a = 12345678 }; f();"); 755 CompileRun("function f() { a = 12345678 }; f();");
754 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 756 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
755 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 757 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
756 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 758 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
757 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 759 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
758 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 760 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
759 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 761 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
760 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 762 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
761 } 763 }
762 #endif 764 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698