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