OLD | NEW |
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 Loading... |
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 || | 331 if (i::FLAG_always_opt || !i::FLAG_lazy || |
332 (FLAG_ignition && FLAG_ignition_eager)) { | 332 (FLAG_ignition && FLAG_ignition_eager)) { |
333 return; | 333 return; |
334 } | 334 } |
(...skipping 14 matching lines...) Expand all Loading... |
349 "morphing_call = builder();"); | 349 "morphing_call = builder();"); |
350 | 350 |
351 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 351 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
352 *v8::Local<v8::Function>::Cast(CcTest::global() | 352 *v8::Local<v8::Function>::Cast(CcTest::global() |
353 ->Get(context, v8_str("morphing_call")) | 353 ->Get(context, v8_str("morphing_call")) |
354 .ToLocalChecked()))); | 354 .ToLocalChecked()))); |
355 | 355 |
356 // If we are compiling lazily then it should not be compiled, and so no | 356 // If we are compiling lazily then it should not be compiled, and so no |
357 // feedback vector allocated yet. | 357 // feedback vector allocated yet. |
358 CHECK(!f->shared()->is_compiled()); | 358 CHECK(!f->shared()->is_compiled()); |
359 CHECK(f->shared()->feedback_vector()->is_empty()); | 359 CHECK(f->feedback_vector()->is_empty()); |
360 | 360 |
361 CompileRun("morphing_call();"); | 361 CompileRun("morphing_call();"); |
362 | 362 |
363 // Now a feedback vector is allocated. | 363 // Now a feedback vector is allocated. |
364 CHECK(f->shared()->is_compiled()); | 364 CHECK(f->shared()->is_compiled()); |
365 CHECK(!f->shared()->feedback_vector()->is_empty()); | 365 CHECK(!f->feedback_vector()->is_empty()); |
366 } | 366 } |
367 | 367 |
368 // Test that optimized code for different closures is actually shared. | 368 // Test that optimized code for different closures is actually shared. |
369 TEST(OptimizedCodeSharing1) { | 369 TEST(OptimizedCodeSharing1) { |
370 FLAG_stress_compaction = false; | 370 FLAG_stress_compaction = false; |
371 FLAG_allow_natives_syntax = true; | 371 FLAG_allow_natives_syntax = true; |
372 CcTest::InitializeVM(); | 372 CcTest::InitializeVM(); |
373 v8::HandleScope scope(CcTest::isolate()); | 373 v8::HandleScope scope(CcTest::isolate()); |
374 for (int i = 0; i < 3; i++) { | 374 for (int i = 0; i < 3; i++) { |
375 LocalContext env; | 375 LocalContext env; |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 " %CompileBaseline(f);\n" | 793 " %CompileBaseline(f);\n" |
794 " is_baseline_in_function = IsBaselineCompiled(f);\n" | 794 " is_baseline_in_function = IsBaselineCompiled(f);\n" |
795 " return 1234;\n" | 795 " return 1234;\n" |
796 "};\n" | 796 "};\n" |
797 "return_val = f();\n" | 797 "return_val = f();\n" |
798 "is_baseline_after_return = IsBaselineCompiled(f);\n"); | 798 "is_baseline_after_return = IsBaselineCompiled(f);\n"); |
799 CHECK_EQ(false, GetGlobalProperty("is_baseline_in_function")->BooleanValue()); | 799 CHECK_EQ(false, GetGlobalProperty("is_baseline_in_function")->BooleanValue()); |
800 CHECK_EQ(true, GetGlobalProperty("is_baseline_after_return")->BooleanValue()); | 800 CHECK_EQ(true, GetGlobalProperty("is_baseline_after_return")->BooleanValue()); |
801 CHECK_EQ(1234.0, GetGlobalProperty("return_val")->Number()); | 801 CHECK_EQ(1234.0, GetGlobalProperty("return_val")->Number()); |
802 } | 802 } |
OLD | NEW |