| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 static void SetGlobalProperty(const char* name, Object* value) { | 47 static void SetGlobalProperty(const char* name, Object* value) { |
| 48 Isolate* isolate = CcTest::i_isolate(); | 48 Isolate* isolate = CcTest::i_isolate(); |
| 49 Handle<Object> object(value, isolate); | 49 Handle<Object> object(value, isolate); |
| 50 Handle<String> internalized_name = | 50 Handle<String> internalized_name = |
| 51 isolate->factory()->InternalizeUtf8String(name); | 51 isolate->factory()->InternalizeUtf8String(name); |
| 52 Handle<JSObject> global(isolate->context()->global_object()); | 52 Handle<JSObject> global(isolate->context()->global_object()); |
| 53 Runtime::SetObjectProperty(isolate, global, internalized_name, object, NONE, | 53 Runtime::SetObjectProperty(isolate, global, internalized_name, object, NONE, |
| 54 kNonStrictMode); | 54 SLOPPY); |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 static Handle<JSFunction> Compile(const char* source) { | 58 static Handle<JSFunction> Compile(const char* source) { |
| 59 Isolate* isolate = CcTest::i_isolate(); | 59 Isolate* isolate = CcTest::i_isolate(); |
| 60 Handle<String> source_code( | 60 Handle<String> source_code( |
| 61 isolate->factory()->NewStringFromUtf8(CStrVector(source))); | 61 isolate->factory()->NewStringFromUtf8(CStrVector(source))); |
| 62 Handle<SharedFunctionInfo> shared_function = | 62 Handle<SharedFunctionInfo> shared_function = |
| 63 Compiler::CompileScript(source_code, | 63 Compiler::CompileScript(source_code, |
| 64 Handle<String>(), | 64 Handle<String>(), |
| 65 0, | 65 0, |
| 66 0, | 66 0, |
| 67 false, | 67 false, |
| 68 Handle<Context>(isolate->native_context()), | 68 Handle<Context>(isolate->native_context()), |
| 69 NULL, NULL, | 69 NULL, NULL, |
| 70 Handle<String>::null(), | |
| 71 NOT_NATIVES_CODE); | 70 NOT_NATIVES_CODE); |
| 72 return isolate->factory()->NewFunctionFromSharedFunctionInfo( | 71 return isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 73 shared_function, isolate->native_context()); | 72 shared_function, isolate->native_context()); |
| 74 } | 73 } |
| 75 | 74 |
| 76 | 75 |
| 77 static double Inc(Isolate* isolate, int x) { | 76 static double Inc(Isolate* isolate, int x) { |
| 78 const char* source = "result = %d + 1;"; | 77 const char* source = "result = %d + 1;"; |
| 79 EmbeddedVector<char, 512> buffer; | 78 EmbeddedVector<char, 512> buffer; |
| 80 OS::SNPrintF(buffer, source, x); | 79 OS::SNPrintF(buffer, source, x); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 v8::String::NewFromUtf8(CcTest::isolate(), buffer.start()); | 305 v8::String::NewFromUtf8(CcTest::isolate(), buffer.start()); |
| 307 v8::Script::Compile(script_body, &origin)->Run(); | 306 v8::Script::Compile(script_body, &origin)->Run(); |
| 308 v8::Local<v8::Function> f = | 307 v8::Local<v8::Function> f = |
| 309 v8::Local<v8::Function>::Cast(context->Global()->Get( | 308 v8::Local<v8::Function>::Cast(context->Global()->Get( |
| 310 v8::String::NewFromUtf8(CcTest::isolate(), "f"))); | 309 v8::String::NewFromUtf8(CcTest::isolate(), "f"))); |
| 311 CHECK_EQ(i, f->GetScriptLineNumber()); | 310 CHECK_EQ(i, f->GetScriptLineNumber()); |
| 312 } | 311 } |
| 313 } | 312 } |
| 314 | 313 |
| 315 | 314 |
| 315 TEST(FeedbackVectorRecreatedOnScopeChanges) { |
| 316 if (i::FLAG_always_opt || !i::FLAG_lazy) return; |
| 317 CcTest::InitializeVM(); |
| 318 v8::HandleScope scope(CcTest::isolate()); |
| 319 |
| 320 CompileRun("function builder() {" |
| 321 " call_target = function() { return 3; };" |
| 322 " return (function() {" |
| 323 " eval('');" |
| 324 " return function() {" |
| 325 " 'use strict';" |
| 326 " call_target();" |
| 327 " }" |
| 328 " })();" |
| 329 "}" |
| 330 "morphing_call = builder();"); |
| 331 |
| 332 Handle<JSFunction> f = |
| 333 v8::Utils::OpenHandle( |
| 334 *v8::Handle<v8::Function>::Cast( |
| 335 CcTest::global()->Get(v8_str("morphing_call")))); |
| 336 |
| 337 // morphing_call should have one feedback vector slot for the call to |
| 338 // call_target(), scoping analysis having been performed. |
| 339 CHECK_EQ(1, f->shared()->feedback_vector()->length()); |
| 340 // And yet it's not compiled. |
| 341 CHECK(!f->shared()->is_compiled()); |
| 342 |
| 343 CompileRun("morphing_call();"); |
| 344 |
| 345 // On scoping analysis after lazy compile, the call is now a global |
| 346 // call which needs no feedback vector slot. |
| 347 CHECK_EQ(0, f->shared()->feedback_vector()->length()); |
| 348 CHECK(f->shared()->is_compiled()); |
| 349 } |
| 350 |
| 351 |
| 316 // Test that optimized code for different closures is actually shared | 352 // Test that optimized code for different closures is actually shared |
| 317 // immediately by the FastNewClosureStub when run in the same context. | 353 // immediately by the FastNewClosureStub when run in the same context. |
| 318 TEST(OptimizedCodeSharing) { | 354 TEST(OptimizedCodeSharing) { |
| 319 // Skip test if --cache-optimized-code is not activated by default because | 355 // Skip test if --cache-optimized-code is not activated by default because |
| 320 // FastNewClosureStub that is baked into the snapshot is incorrect. | 356 // FastNewClosureStub that is baked into the snapshot is incorrect. |
| 321 if (!FLAG_cache_optimized_code) return; | 357 if (!FLAG_cache_optimized_code) return; |
| 322 FLAG_stress_compaction = false; | 358 FLAG_stress_compaction = false; |
| 323 FLAG_allow_natives_syntax = true; | 359 FLAG_allow_natives_syntax = true; |
| 324 CcTest::InitializeVM(); | 360 CcTest::InitializeVM(); |
| 325 v8::HandleScope scope(CcTest::isolate()); | 361 v8::HandleScope scope(CcTest::isolate()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 CompileRun("function f() { a = 12345678 }; f();"); | 430 CompileRun("function f() { a = 12345678 }; f();"); |
| 395 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 431 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 396 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 432 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 397 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 433 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 398 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 434 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 399 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 435 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 400 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 436 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 401 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 437 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 402 } | 438 } |
| 403 #endif | 439 #endif |
| OLD | NEW |