| 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 14498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14509 | 14509 |
| 14510 static i::HashMap* code_map = NULL; | 14510 static i::HashMap* code_map = NULL; |
| 14511 static i::HashMap* jitcode_line_info = NULL; | 14511 static i::HashMap* jitcode_line_info = NULL; |
| 14512 static int saw_bar = 0; | 14512 static int saw_bar = 0; |
| 14513 static int move_events = 0; | 14513 static int move_events = 0; |
| 14514 | 14514 |
| 14515 | 14515 |
| 14516 static bool FunctionNameIs(const char* expected, | 14516 static bool FunctionNameIs(const char* expected, |
| 14517 const v8::JitCodeEvent* event) { | 14517 const v8::JitCodeEvent* event) { |
| 14518 // Log lines for functions are of the general form: | 14518 // Log lines for functions are of the general form: |
| 14519 // "LazyCompile:<type><function_name>", where the type is one of | 14519 // "LazyCompile:<type><function_name>" or Function:<type><function_name>, |
| 14520 // "*", "~" or "". | 14520 // where the type is one of "*", "~" or "". |
| 14521 static const char kPreamble[] = "LazyCompile:"; | 14521 static const char* kPreamble; |
| 14522 static size_t kPreambleLen = sizeof(kPreamble) - 1; | 14522 if (!i::FLAG_lazy || i::FLAG_ignition) { |
| 14523 kPreamble = "Function:"; |
| 14524 } else { |
| 14525 kPreamble = "LazyCompile:"; |
| 14526 } |
| 14527 static size_t kPreambleLen = strlen(kPreamble); |
| 14523 | 14528 |
| 14524 if (event->name.len < sizeof(kPreamble) - 1 || | 14529 if (event->name.len < kPreambleLen || |
| 14525 strncmp(kPreamble, event->name.str, kPreambleLen) != 0) { | 14530 strncmp(kPreamble, event->name.str, kPreambleLen) != 0) { |
| 14526 return false; | 14531 return false; |
| 14527 } | 14532 } |
| 14528 | 14533 |
| 14529 const char* tail = event->name.str + kPreambleLen; | 14534 const char* tail = event->name.str + kPreambleLen; |
| 14530 size_t tail_len = event->name.len - kPreambleLen; | 14535 size_t tail_len = event->name.len - kPreambleLen; |
| 14531 size_t expected_len = strlen(expected); | 14536 size_t expected_len = strlen(expected); |
| 14532 if (tail_len > 1 && (*tail == '*' || *tail == '~')) { | 14537 if (tail_len > 1 && (*tail == '*' || *tail == '~')) { |
| 14533 --tail_len; | 14538 --tail_len; |
| 14534 ++tail; | 14539 ++tail; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14682 move_events = 0; | 14687 move_events = 0; |
| 14683 | 14688 |
| 14684 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); | 14689 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); |
| 14685 | 14690 |
| 14686 // Generate new code objects sparsely distributed across several | 14691 // Generate new code objects sparsely distributed across several |
| 14687 // different fragmented code-space pages. | 14692 // different fragmented code-space pages. |
| 14688 const int kIterations = 10; | 14693 const int kIterations = 10; |
| 14689 for (int i = 0; i < kIterations; ++i) { | 14694 for (int i = 0; i < kIterations; ++i) { |
| 14690 LocalContext env(isolate); | 14695 LocalContext env(isolate); |
| 14691 i::AlwaysAllocateScope always_allocate(i_isolate); | 14696 i::AlwaysAllocateScope always_allocate(i_isolate); |
| 14692 SimulateFullSpace(heap->code_space()); | 14697 SimulateFullSpace(i::FLAG_ignition ? heap->old_space() |
| 14698 : heap->code_space()); |
| 14693 CompileRun(script); | 14699 CompileRun(script); |
| 14694 | 14700 |
| 14695 // Keep a strong reference to the code object in the handle scope. | 14701 // Keep a strong reference to the code object in the handle scope. |
| 14696 i::Handle<i::Code> bar_code( | 14702 i::Handle<i::Code> bar_code( |
| 14697 i::Handle<i::JSFunction>::cast( | 14703 i::Handle<i::JSFunction>::cast( |
| 14698 v8::Utils::OpenHandle(*env->Global() | 14704 v8::Utils::OpenHandle(*env->Global() |
| 14699 ->Get(env.local(), v8_str("bar")) | 14705 ->Get(env.local(), v8_str("bar")) |
| 14700 .ToLocalChecked())) | 14706 .ToLocalChecked())) |
| 14701 ->code()); | 14707 ->code()); |
| 14702 i::Handle<i::Code> foo_code( | 14708 i::Handle<i::Code> foo_code( |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15123 ->Set(context.local(), v8_str("obj_2"), instance_2) | 15129 ->Set(context.local(), v8_str("obj_2"), instance_2) |
| 15124 .FromJust()); | 15130 .FromJust()); |
| 15125 | 15131 |
| 15126 Local<Value> value_2 = CompileRun("obj_2.a"); | 15132 Local<Value> value_2 = CompileRun("obj_2.a"); |
| 15127 CHECK(value_2.IsEmpty()); | 15133 CHECK(value_2.IsEmpty()); |
| 15128 } | 15134 } |
| 15129 | 15135 |
| 15130 | 15136 |
| 15131 // Tests that ScriptData can be serialized and deserialized. | 15137 // Tests that ScriptData can be serialized and deserialized. |
| 15132 TEST(PreCompileSerialization) { | 15138 TEST(PreCompileSerialization) { |
| 15139 // Producing cached parser data while parsing eagerly is not supported. |
| 15140 if (!i::FLAG_lazy || i::FLAG_ignition) return; |
| 15141 |
| 15133 v8::V8::Initialize(); | 15142 v8::V8::Initialize(); |
| 15134 LocalContext env; | 15143 LocalContext env; |
| 15135 v8::Isolate* isolate = env->GetIsolate(); | 15144 v8::Isolate* isolate = env->GetIsolate(); |
| 15136 HandleScope handle_scope(isolate); | 15145 HandleScope handle_scope(isolate); |
| 15137 | 15146 |
| 15138 i::FLAG_min_preparse_length = 0; | 15147 i::FLAG_min_preparse_length = 0; |
| 15139 const char* script = "function foo(a) { return a+1; }"; | 15148 const char* script = "function foo(a) { return a+1; }"; |
| 15140 v8::ScriptCompiler::Source source(v8_str(script)); | 15149 v8::ScriptCompiler::Source source(v8_str(script)); |
| 15141 v8::ScriptCompiler::Compile(env.local(), &source, | 15150 v8::ScriptCompiler::Compile(env.local(), &source, |
| 15142 v8::ScriptCompiler::kProduceParserCache) | 15151 v8::ScriptCompiler::kProduceParserCache) |
| (...skipping 8911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 24054 CHECK_EQ( | 24063 CHECK_EQ( |
| 24055 42, | 24064 42, |
| 24056 script->Run(context).ToLocalChecked()->Int32Value(context).FromJust()); | 24065 script->Run(context).ToLocalChecked()->Int32Value(context).FromJust()); |
| 24057 } | 24066 } |
| 24058 | 24067 |
| 24059 | 24068 |
| 24060 TEST(InvalidCacheData) { | 24069 TEST(InvalidCacheData) { |
| 24061 v8::V8::Initialize(); | 24070 v8::V8::Initialize(); |
| 24062 v8::HandleScope scope(CcTest::isolate()); | 24071 v8::HandleScope scope(CcTest::isolate()); |
| 24063 LocalContext context; | 24072 LocalContext context; |
| 24064 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); | 24073 if (i::FLAG_lazy && !i::FLAG_ignition) { |
| 24074 // Cached parser data is not consumed while parsing eagerly. |
| 24075 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); |
| 24076 } |
| 24065 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); | 24077 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); |
| 24066 } | 24078 } |
| 24067 | 24079 |
| 24068 | 24080 |
| 24069 TEST(ParserCacheRejectedGracefully) { | 24081 TEST(ParserCacheRejectedGracefully) { |
| 24082 // Producing cached parser data while parsing eagerly is not supported. |
| 24083 if (!i::FLAG_lazy || i::FLAG_ignition) return; |
| 24084 |
| 24070 i::FLAG_min_preparse_length = 0; | 24085 i::FLAG_min_preparse_length = 0; |
| 24071 v8::V8::Initialize(); | 24086 v8::V8::Initialize(); |
| 24072 v8::HandleScope scope(CcTest::isolate()); | 24087 v8::HandleScope scope(CcTest::isolate()); |
| 24073 LocalContext context; | 24088 LocalContext context; |
| 24074 // Produce valid cached data. | 24089 // Produce valid cached data. |
| 24075 v8::ScriptOrigin origin(v8_str("origin")); | 24090 v8::ScriptOrigin origin(v8_str("origin")); |
| 24076 v8::Local<v8::String> source_str = v8_str("function foo() {}"); | 24091 v8::Local<v8::String> source_str = v8_str("function foo() {}"); |
| 24077 v8::ScriptCompiler::Source source(source_str, origin); | 24092 v8::ScriptCompiler::Source source(source_str, origin); |
| 24078 v8::Local<v8::Script> script = | 24093 v8::Local<v8::Script> script = |
| 24079 v8::ScriptCompiler::Compile(context.local(), &source, | 24094 v8::ScriptCompiler::Compile(context.local(), &source, |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 24849 CHECK(proxy->GetTarget()->SameValue(target)); | 24864 CHECK(proxy->GetTarget()->SameValue(target)); |
| 24850 CHECK(proxy->GetHandler()->SameValue(handler)); | 24865 CHECK(proxy->GetHandler()->SameValue(handler)); |
| 24851 | 24866 |
| 24852 proxy->Revoke(); | 24867 proxy->Revoke(); |
| 24853 CHECK(proxy->IsProxy()); | 24868 CHECK(proxy->IsProxy()); |
| 24854 CHECK(!target->IsProxy()); | 24869 CHECK(!target->IsProxy()); |
| 24855 CHECK(proxy->IsRevoked()); | 24870 CHECK(proxy->IsRevoked()); |
| 24856 CHECK(proxy->GetTarget()->SameValue(target)); | 24871 CHECK(proxy->GetTarget()->SameValue(target)); |
| 24857 CHECK(proxy->GetHandler()->IsNull()); | 24872 CHECK(proxy->GetHandler()->IsNull()); |
| 24858 } | 24873 } |
| OLD | NEW |