| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 "fun1 = fun;" | 298 "fun1 = fun;" |
| 299 "function f(a) { a(); } f(fun1);"); | 299 "function f(a) { a(); } f(fun1);"); |
| 300 | 300 |
| 301 Handle<JSFunction> f = Handle<JSFunction>::cast( | 301 Handle<JSFunction> f = Handle<JSFunction>::cast( |
| 302 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 302 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 303 CcTest::global()->Get(context, v8_str("f")).ToLocalChecked()))); | 303 CcTest::global()->Get(context, v8_str("f")).ToLocalChecked()))); |
| 304 | 304 |
| 305 // We shouldn't have deoptimization support. We want to recompile and | 305 // We shouldn't have deoptimization support. We want to recompile and |
| 306 // verify that our feedback vector preserves information. | 306 // verify that our feedback vector preserves information. |
| 307 CHECK(!f->shared()->has_deoptimization_support()); | 307 CHECK(!f->shared()->has_deoptimization_support()); |
| 308 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); | 308 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); |
| 309 | 309 |
| 310 // Verify that we gathered feedback. | 310 // Verify that we gathered feedback. |
| 311 CHECK(!feedback_vector->is_empty()); | 311 CHECK(!feedback_vector->is_empty()); |
| 312 FeedbackVectorSlot slot_for_a(0); | 312 FeedbackVectorSlot slot_for_a(0); |
| 313 Object* object = feedback_vector->Get(slot_for_a); | 313 Object* object = feedback_vector->Get(slot_for_a); |
| 314 CHECK(object->IsWeakCell() && | 314 CHECK(object->IsWeakCell() && |
| 315 WeakCell::cast(object)->value()->IsJSFunction()); | 315 WeakCell::cast(object)->value()->IsJSFunction()); |
| 316 | 316 |
| 317 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); | 317 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); |
| 318 | 318 |
| 319 // Verify that the feedback is still "gathered" despite a recompilation | 319 // Verify that the feedback is still "gathered" despite a recompilation |
| 320 // of the full code. | 320 // of the full code. |
| 321 CHECK(f->IsOptimized()); | 321 CHECK(f->IsOptimized()); |
| 322 CHECK(f->shared()->has_deoptimization_support()); | 322 CHECK(f->shared()->has_deoptimization_support()); |
| 323 object = f->shared()->feedback_vector()->Get(slot_for_a); | 323 object = f->feedback_vector()->Get(slot_for_a); |
| 324 CHECK(object->IsWeakCell() && | 324 CHECK(object->IsWeakCell() && |
| 325 WeakCell::cast(object)->value()->IsJSFunction()); | 325 WeakCell::cast(object)->value()->IsJSFunction()); |
| 326 } | 326 } |
| 327 | 327 |
| 328 | 328 |
| 329 TEST(FeedbackVectorUnaffectedByScopeChanges) { | 329 TEST(FeedbackVectorUnaffectedByScopeChanges) { |
| 330 if (i::FLAG_always_opt || !i::FLAG_lazy || | 330 if (i::FLAG_always_opt || !i::FLAG_lazy || |
| 331 (FLAG_ignition && FLAG_ignition_eager)) { | 331 (FLAG_ignition && FLAG_ignition_eager)) { |
| 332 return; | 332 return; |
| 333 } | 333 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 348 "morphing_call = builder();"); | 348 "morphing_call = builder();"); |
| 349 | 349 |
| 350 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 350 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 351 *v8::Local<v8::Function>::Cast(CcTest::global() | 351 *v8::Local<v8::Function>::Cast(CcTest::global() |
| 352 ->Get(context, v8_str("morphing_call")) | 352 ->Get(context, v8_str("morphing_call")) |
| 353 .ToLocalChecked()))); | 353 .ToLocalChecked()))); |
| 354 | 354 |
| 355 // If we are compiling lazily then it should not be compiled, and so no | 355 // If we are compiling lazily then it should not be compiled, and so no |
| 356 // feedback vector allocated yet. | 356 // feedback vector allocated yet. |
| 357 CHECK(!f->shared()->is_compiled()); | 357 CHECK(!f->shared()->is_compiled()); |
| 358 CHECK(f->shared()->feedback_vector()->is_empty()); | 358 CHECK(f->feedback_vector()->is_empty()); |
| 359 | 359 |
| 360 CompileRun("morphing_call();"); | 360 CompileRun("morphing_call();"); |
| 361 | 361 |
| 362 // Now a feedback vector is allocated. | 362 // Now a feedback vector is allocated. |
| 363 CHECK(f->shared()->is_compiled()); | 363 CHECK(f->shared()->is_compiled()); |
| 364 CHECK(!f->shared()->feedback_vector()->is_empty()); | 364 CHECK(!f->feedback_vector()->is_empty()); |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Test that optimized code for different closures is actually shared. | 367 // Test that optimized code for different closures is actually shared. |
| 368 TEST(OptimizedCodeSharing1) { | 368 TEST(OptimizedCodeSharing1) { |
| 369 FLAG_stress_compaction = false; | 369 FLAG_stress_compaction = false; |
| 370 FLAG_allow_natives_syntax = true; | 370 FLAG_allow_natives_syntax = true; |
| 371 CcTest::InitializeVM(); | 371 CcTest::InitializeVM(); |
| 372 v8::HandleScope scope(CcTest::isolate()); | 372 v8::HandleScope scope(CcTest::isolate()); |
| 373 for (int i = 0; i < 3; i++) { | 373 for (int i = 0; i < 3; i++) { |
| 374 LocalContext env; | 374 LocalContext env; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 CompileRun("function f() { a = 12345678 }; f();"); | 750 CompileRun("function f() { a = 12345678 }; f();"); |
| 751 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 751 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 752 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 752 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 753 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 753 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 754 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 754 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 755 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 755 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 756 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 756 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 757 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 757 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 758 } | 758 } |
| 759 #endif | 759 #endif |
| OLD | NEW |