diff options
Diffstat (limited to 'deps/v8/test/cctest/test-serialize.cc')
-rw-r--r-- | deps/v8/test/cctest/test-serialize.cc | 148 |
1 files changed, 76 insertions, 72 deletions
diff --git a/deps/v8/test/cctest/test-serialize.cc b/deps/v8/test/cctest/test-serialize.cc index 70fc8586eb..11a50fa54c 100644 --- a/deps/v8/test/cctest/test-serialize.cc +++ b/deps/v8/test/cctest/test-serialize.cc @@ -1228,13 +1228,31 @@ static Handle<SharedFunctionInfo> CompileScript( Isolate* isolate, Handle<String> source, Handle<String> name, ScriptData** cached_data, v8::ScriptCompiler::CompileOptions options) { return Compiler::GetSharedFunctionInfoForScript( - source, name, 0, 0, v8::ScriptOriginOptions(), Handle<Object>(), - Handle<Context>(isolate->native_context()), nullptr, cached_data, - options, ScriptCompiler::kNoCacheNoReason, NOT_NATIVES_CODE, - Handle<FixedArray>()) + source, Compiler::ScriptDetails(name), v8::ScriptOriginOptions(), + nullptr, cached_data, options, ScriptCompiler::kNoCacheNoReason, + NOT_NATIVES_CODE) .ToHandleChecked(); } +static Handle<SharedFunctionInfo> CompileScriptAndProduceCache( + Isolate* isolate, Handle<String> source, Handle<String> name, + ScriptData** script_data, v8::ScriptCompiler::CompileOptions options) { + Handle<SharedFunctionInfo> sfi = + Compiler::GetSharedFunctionInfoForScript( + source, Compiler::ScriptDetails(name), v8::ScriptOriginOptions(), + nullptr, nullptr, options, ScriptCompiler::kNoCacheNoReason, + NOT_NATIVES_CODE) + .ToHandleChecked(); + std::unique_ptr<ScriptCompiler::CachedData> cached_data( + ScriptCompiler::CreateCodeCache(ToApiHandle<UnboundScript>(sfi), + Utils::ToLocal(source))); + uint8_t* buffer = NewArray<uint8_t>(cached_data->length); + MemCopy(buffer, cached_data->data, cached_data->length); + *script_data = new i::ScriptData(buffer, cached_data->length); + (*script_data)->AcquireDataOwnership(); + return sfi; +} + TEST(CodeSerializerOnePlusOne) { LocalContext context; Isolate* isolate = CcTest::i_isolate(); @@ -1255,9 +1273,9 @@ TEST(CodeSerializerOnePlusOne) { ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, orig_source, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, orig_source, Handle<String>(), &cache, + v8::ScriptCompiler::kNoCompileOptions); int builtins_count = CountBuiltins(); @@ -1297,18 +1315,19 @@ TEST(CodeSerializerPromotedToCompilationCache) { .ToHandleChecked(); ScriptData* cache = nullptr; - CompileScript(isolate, src, src, &cache, - v8::ScriptCompiler::kProduceCodeCache); + CompileScriptAndProduceCache(isolate, src, src, &cache, + v8::ScriptCompiler::kNoCompileOptions); DisallowCompilation no_compile_expected(isolate); Handle<SharedFunctionInfo> copy = CompileScript( isolate, src, src, &cache, v8::ScriptCompiler::kConsumeCodeCache); - InfoVectorPair pair = isolate->compilation_cache()->LookupScript( - src, src, 0, 0, v8::ScriptOriginOptions(), isolate->native_context(), - LanguageMode::kSloppy); + MaybeHandle<SharedFunctionInfo> shared = + isolate->compilation_cache()->LookupScript( + src, src, 0, 0, v8::ScriptOriginOptions(), isolate->native_context(), + LanguageMode::kSloppy); - CHECK(pair.shared() == *copy); + CHECK(*shared.ToHandleChecked() == *copy); delete cache; } @@ -1332,11 +1351,11 @@ TEST(CodeSerializerInternalizedString) { CHECK(orig_source->Equals(*copy_source)); Handle<JSObject> global(isolate->context()->global_object()); - ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, orig_source, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + i::ScriptData* script_data = nullptr; + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, orig_source, Handle<String>(), &script_data, + v8::ScriptCompiler::kNoCompileOptions); Handle<JSFunction> orig_fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( orig, isolate->native_context()); @@ -1349,7 +1368,7 @@ TEST(CodeSerializerInternalizedString) { Handle<SharedFunctionInfo> copy; { DisallowCompilation no_compile_expected(isolate); - copy = CompileScript(isolate, copy_source, Handle<String>(), &cache, + copy = CompileScript(isolate, copy_source, Handle<String>(), &script_data, v8::ScriptCompiler::kConsumeCodeCache); } CHECK_NE(*orig, *copy); @@ -1368,7 +1387,7 @@ TEST(CodeSerializerInternalizedString) { CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); CHECK_EQ(builtins_count, CountBuiltins()); - delete cache; + delete script_data; } TEST(CodeSerializerLargeCodeObject) { @@ -1393,9 +1412,9 @@ TEST(CodeSerializerLargeCodeObject) { Handle<JSObject> global(isolate->context()->global_object()); ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, source_str, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, source_str, Handle<String>(), &cache, + v8::ScriptCompiler::kNoCompileOptions); CHECK(isolate->heap()->InSpace(orig->abstract_code(), LO_SPACE)); @@ -1459,9 +1478,9 @@ TEST(CodeSerializerLargeCodeObjectWithIncrementalMarking) { Handle<JSObject> global(isolate->context()->global_object()); ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, source_str, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, source_str, Handle<String>(), &cache, + v8::ScriptCompiler::kNoCompileOptions); CHECK(heap->InSpace(orig->abstract_code(), LO_SPACE)); @@ -1522,9 +1541,9 @@ TEST(CodeSerializerLargeStrings) { Handle<JSObject> global(isolate->context()->global_object()); ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, source_str, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, source_str, Handle<String>(), &cache, + v8::ScriptCompiler::kNoCompileOptions); Handle<SharedFunctionInfo> copy; { @@ -1590,9 +1609,9 @@ TEST(CodeSerializerThreeBigStrings) { Handle<JSObject> global(isolate->context()->global_object()); ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, source_str, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, source_str, Handle<String>(), &cache, + v8::ScriptCompiler::kNoCompileOptions); Handle<SharedFunctionInfo> copy; { @@ -1708,9 +1727,9 @@ TEST(CodeSerializerExternalString) { Handle<JSObject> global(isolate->context()->global_object()); ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, source_string, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, source_string, Handle<String>(), &cache, + v8::ScriptCompiler::kNoCompileOptions); Handle<SharedFunctionInfo> copy; { @@ -1765,9 +1784,9 @@ TEST(CodeSerializerLargeExternalString) { Handle<JSObject> global(isolate->context()->global_object()); ScriptData* cache = nullptr; - Handle<SharedFunctionInfo> orig = - CompileScript(isolate, source_str, Handle<String>(), &cache, - v8::ScriptCompiler::kProduceCodeCache); + Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( + isolate, source_str, Handle<String>(), &cache, + v8::ScriptCompiler::kNoCompileOptions); Handle<SharedFunctionInfo> copy; { @@ -1815,8 +1834,8 @@ TEST(CodeSerializerExternalScriptName) { ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = - CompileScript(isolate, source_string, name, &cache, - v8::ScriptCompiler::kProduceCodeCache); + CompileScriptAndProduceCache(isolate, source_string, name, &cache, + v8::ScriptCompiler::kNoCompileOptions); Handle<SharedFunctionInfo> copy; { @@ -1848,7 +1867,7 @@ static void SerializerCodeEventListener(const v8::JitCodeEvent* event) { } } -v8::ScriptCompiler::CachedData* ProduceCache( +v8::ScriptCompiler::CachedData* CompileRunAndProduceCache( const char* source, CodeCacheType cacheType = CodeCacheType::kLazy) { v8::ScriptCompiler::CachedData* cache; v8::Isolate::CreateParams create_params; @@ -1865,12 +1884,10 @@ v8::ScriptCompiler::CachedData* ProduceCache( v8::ScriptCompiler::Source source(source_str, origin); v8::ScriptCompiler::CompileOptions options; switch (cacheType) { - case CodeCacheType::kLazy: - options = v8::ScriptCompiler::kProduceCodeCache; - break; case CodeCacheType::kEager: options = v8::ScriptCompiler::kProduceFullCodeCache; break; + case CodeCacheType::kLazy: case CodeCacheType::kAfterExecute: options = v8::ScriptCompiler::kNoCompileOptions; break; @@ -1881,6 +1898,10 @@ v8::ScriptCompiler::CachedData* ProduceCache( v8::ScriptCompiler::CompileUnboundScript(isolate1, &source, options) .ToLocalChecked(); + if (cacheType != CodeCacheType::kAfterExecute) { + cache = ScriptCompiler::CreateCodeCache(script, source_str); + } + v8::Local<v8::Value> result = script->BindToCurrentContext() ->Run(isolate1->GetCurrentContext()) .ToLocalChecked(); @@ -1891,13 +1912,6 @@ v8::ScriptCompiler::CachedData* ProduceCache( if (cacheType == CodeCacheType::kAfterExecute) { cache = ScriptCompiler::CreateCodeCache(script, source_str); - } else { - const ScriptCompiler::CachedData* data = source.GetCachedData(); - CHECK(data); - uint8_t* buffer = NewArray<uint8_t>(data->length); - MemCopy(buffer, data->data, data->length); - cache = new v8::ScriptCompiler::CachedData( - buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); } CHECK(cache); } @@ -1916,7 +1930,7 @@ void CheckDeserializedFlag(v8::Local<v8::UnboundScript> script) { TEST(CodeSerializerIsolates) { const char* source = "function f() { return 'abc'; }; f() + 'def'"; - v8::ScriptCompiler::CachedData* cache = ProduceCache(source); + v8::ScriptCompiler::CachedData* cache = CompileRunAndProduceCache(source); v8::Isolate::CreateParams create_params; create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); @@ -1963,7 +1977,7 @@ TEST(CodeSerializerIsolatesEager) { "}" "f()() + 'def'"; v8::ScriptCompiler::CachedData* cache = - ProduceCache(source, CodeCacheType::kEager); + CompileRunAndProduceCache(source, CodeCacheType::kEager); v8::Isolate::CreateParams create_params; create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); @@ -2010,7 +2024,7 @@ TEST(CodeSerializerAfterExecute) { FLAG_opt = false; const char* source = "function f() { return 'abc'; }; f() + 'def'"; v8::ScriptCompiler::CachedData* cache = - ProduceCache(source, CodeCacheType::kAfterExecute); + CompileRunAndProduceCache(source, CodeCacheType::kAfterExecute); v8::Isolate::CreateParams create_params; create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); @@ -2040,7 +2054,7 @@ TEST(CodeSerializerAfterExecute) { CHECK(sfi->HasBytecodeArray()); BytecodeArray* bytecode = sfi->bytecode_array(); CHECK_EQ(bytecode->interrupt_budget(), - interpreter::Interpreter::kInterruptBudget); + interpreter::Interpreter::InterruptBudget()); CHECK_EQ(bytecode->osr_loop_nesting_level(), 0); { @@ -2065,7 +2079,7 @@ TEST(CodeSerializerAfterExecute) { TEST(CodeSerializerFlagChange) { const char* source = "function f() { return 'abc'; }; f() + 'def'"; - v8::ScriptCompiler::CachedData* cache = ProduceCache(source); + v8::ScriptCompiler::CachedData* cache = CompileRunAndProduceCache(source); v8::Isolate::CreateParams create_params; create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); @@ -2092,7 +2106,7 @@ TEST(CodeSerializerFlagChange) { TEST(CodeSerializerBitFlip) { const char* source = "function f() { return 'abc'; }; f() + 'def'"; - v8::ScriptCompiler::CachedData* cache = ProduceCache(source); + v8::ScriptCompiler::CachedData* cache = CompileRunAndProduceCache(source); // Random bit flip. const_cast<uint8_t*>(cache->data)[337] ^= 0x40; @@ -2141,15 +2155,10 @@ TEST(CodeSerializerWithHarmonyScoping) { v8::ScriptCompiler::Source source(source_str, origin); v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnboundScript( - isolate1, &source, v8::ScriptCompiler::kProduceCodeCache) + isolate1, &source, v8::ScriptCompiler::kNoCompileOptions) .ToLocalChecked(); - const v8::ScriptCompiler::CachedData* data = source.GetCachedData(); - CHECK(data); - // Persist cached data. - uint8_t* buffer = NewArray<uint8_t>(data->length); - MemCopy(buffer, data->data, data->length); - cache = new v8::ScriptCompiler::CachedData( - buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); + cache = v8::ScriptCompiler::CreateCodeCache(script, source_str); + CHECK(cache); v8::Local<v8::Value> result = script->BindToCurrentContext() ->Run(isolate1->GetCurrentContext()) @@ -2205,14 +2214,9 @@ TEST(Regress503552) { Handle<String> source = isolate->factory()->NewStringFromAsciiChecked( "function f() {} function g() {}"); ScriptData* script_data = nullptr; - Handle<SharedFunctionInfo> shared = - Compiler::GetSharedFunctionInfoForScript( - source, MaybeHandle<String>(), 0, 0, v8::ScriptOriginOptions(), - MaybeHandle<Object>(), Handle<Context>(isolate->native_context()), - nullptr, &script_data, v8::ScriptCompiler::kProduceCodeCache, - ScriptCompiler::kNoCacheNoReason, NOT_NATIVES_CODE, - MaybeHandle<FixedArray>()) - .ToHandleChecked(); + Handle<SharedFunctionInfo> shared = CompileScriptAndProduceCache( + isolate, source, Handle<String>(), &script_data, + v8::ScriptCompiler::kNoCompileOptions); delete script_data; heap::SimulateIncrementalMarking(isolate->heap()); |