deps: V8: cherry-pick a440efb27f from upstream
Original commit message: [api] do not require source string for producing code cache. The embedder should not need to keep track of the source string. R=jgruber@chromium.org Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: Ie27df755a22fbcae7b6e87a435419d2d8f545558 Reviewed-on: https://chromium-review.googlesource.com/1013482 Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#52614} PR-URL: https://github.com/nodejs/node/pull/21022 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This commit is contained in:
parent
44d1a46a42
commit
8d27477acf
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
# Reset this number to 0 on major V8 upgrades.
|
# Reset this number to 0 on major V8 upgrades.
|
||||||
# Increment by one for each non-official patch applied to deps/v8.
|
# Increment by one for each non-official patch applied to deps/v8.
|
||||||
'v8_embedder_string': '-node.7',
|
'v8_embedder_string': '-node.8',
|
||||||
|
|
||||||
# Enable disassembler for `--print-code` v8 options
|
# Enable disassembler for `--print-code` v8 options
|
||||||
'v8_enable_disassembler': 1,
|
'v8_enable_disassembler': 1,
|
||||||
|
6
deps/v8/include/v8.h
vendored
6
deps/v8/include/v8.h
vendored
@ -1578,6 +1578,9 @@ class V8_EXPORT ScriptCompiler {
|
|||||||
* This will return nullptr if the script cannot be serialized. The
|
* This will return nullptr if the script cannot be serialized. The
|
||||||
* CachedData returned by this function should be owned by the caller.
|
* CachedData returned by this function should be owned by the caller.
|
||||||
*/
|
*/
|
||||||
|
static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
|
||||||
|
|
||||||
|
// Deprecated.
|
||||||
static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script,
|
static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script,
|
||||||
Local<String> source);
|
Local<String> source);
|
||||||
|
|
||||||
@ -1587,6 +1590,9 @@ class V8_EXPORT ScriptCompiler {
|
|||||||
* This will return nullptr if the script cannot be serialized. The
|
* This will return nullptr if the script cannot be serialized. The
|
||||||
* CachedData returned by this function should be owned by the caller.
|
* CachedData returned by this function should be owned by the caller.
|
||||||
*/
|
*/
|
||||||
|
static CachedData* CreateCodeCacheForFunction(Local<Function> function);
|
||||||
|
|
||||||
|
// Deprecated.
|
||||||
static CachedData* CreateCodeCacheForFunction(Local<Function> function,
|
static CachedData* CreateCodeCacheForFunction(Local<Function> function,
|
||||||
Local<String> source);
|
Local<String> source);
|
||||||
|
|
||||||
|
16
deps/v8/src/api.cc
vendored
16
deps/v8/src/api.cc
vendored
@ -2626,21 +2626,29 @@ uint32_t ScriptCompiler::CachedDataVersionTag() {
|
|||||||
|
|
||||||
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
|
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
|
||||||
Local<UnboundScript> unbound_script, Local<String> source) {
|
Local<UnboundScript> unbound_script, Local<String> source) {
|
||||||
|
return CreateCodeCache(unbound_script);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
|
||||||
|
Local<UnboundScript> unbound_script) {
|
||||||
i::Handle<i::SharedFunctionInfo> shared =
|
i::Handle<i::SharedFunctionInfo> shared =
|
||||||
i::Handle<i::SharedFunctionInfo>::cast(
|
i::Handle<i::SharedFunctionInfo>::cast(
|
||||||
Utils::OpenHandle(*unbound_script));
|
Utils::OpenHandle(*unbound_script));
|
||||||
i::Handle<i::String> source_str = Utils::OpenHandle(*source);
|
|
||||||
DCHECK(shared->is_toplevel());
|
DCHECK(shared->is_toplevel());
|
||||||
return i::CodeSerializer::Serialize(shared, source_str);
|
return i::CodeSerializer::Serialize(shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
|
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
|
||||||
Local<Function> function, Local<String> source) {
|
Local<Function> function, Local<String> source) {
|
||||||
|
return CreateCodeCacheForFunction(function);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
|
||||||
|
Local<Function> function) {
|
||||||
i::Handle<i::SharedFunctionInfo> shared(
|
i::Handle<i::SharedFunctionInfo> shared(
|
||||||
i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*function))->shared());
|
i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*function))->shared());
|
||||||
i::Handle<i::String> source_str = Utils::OpenHandle(*source);
|
|
||||||
CHECK(shared->is_wrapped());
|
CHECK(shared->is_wrapped());
|
||||||
return i::CodeSerializer::Serialize(shared, source_str);
|
return i::CodeSerializer::Serialize(shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeLocal<Script> Script::Compile(Local<Context> context, Local<String> source,
|
MaybeLocal<Script> Script::Compile(Local<Context> context, Local<String> source,
|
||||||
|
4
deps/v8/src/d8.cc
vendored
4
deps/v8/src/d8.cc
vendored
@ -636,7 +636,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
|
|||||||
ShellOptions::CodeCacheOptions::kProduceCache) {
|
ShellOptions::CodeCacheOptions::kProduceCache) {
|
||||||
// Serialize and store it in memory for the next execution.
|
// Serialize and store it in memory for the next execution.
|
||||||
ScriptCompiler::CachedData* cached_data =
|
ScriptCompiler::CachedData* cached_data =
|
||||||
ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
|
ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
|
||||||
StoreInCodeCache(isolate, source, cached_data);
|
StoreInCodeCache(isolate, source, cached_data);
|
||||||
delete cached_data;
|
delete cached_data;
|
||||||
}
|
}
|
||||||
@ -645,7 +645,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
|
|||||||
ShellOptions::CodeCacheOptions::kProduceCacheAfterExecute) {
|
ShellOptions::CodeCacheOptions::kProduceCacheAfterExecute) {
|
||||||
// Serialize and store it in memory for the next execution.
|
// Serialize and store it in memory for the next execution.
|
||||||
ScriptCompiler::CachedData* cached_data =
|
ScriptCompiler::CachedData* cached_data =
|
||||||
ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
|
ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
|
||||||
StoreInCodeCache(isolate, source, cached_data);
|
StoreInCodeCache(isolate, source, cached_data);
|
||||||
delete cached_data;
|
delete cached_data;
|
||||||
}
|
}
|
||||||
|
13
deps/v8/src/snapshot/code-serializer.cc
vendored
13
deps/v8/src/snapshot/code-serializer.cc
vendored
@ -32,7 +32,7 @@ ScriptData::ScriptData(const byte* data, int length)
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
ScriptCompiler::CachedData* CodeSerializer::Serialize(
|
ScriptCompiler::CachedData* CodeSerializer::Serialize(
|
||||||
Handle<SharedFunctionInfo> info, Handle<String> source) {
|
Handle<SharedFunctionInfo> info) {
|
||||||
Isolate* isolate = info->GetIsolate();
|
Isolate* isolate = info->GetIsolate();
|
||||||
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
|
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
|
||||||
HistogramTimerScope histogram_timer(isolate->counters()->compile_serialize());
|
HistogramTimerScope histogram_timer(isolate->counters()->compile_serialize());
|
||||||
@ -45,8 +45,7 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
|
|||||||
Handle<Script> script(Script::cast(info->script()), isolate);
|
Handle<Script> script(Script::cast(info->script()), isolate);
|
||||||
if (FLAG_trace_serializer) {
|
if (FLAG_trace_serializer) {
|
||||||
PrintF("[Serializing from");
|
PrintF("[Serializing from");
|
||||||
Object* script = info->script();
|
script->name()->ShortPrint();
|
||||||
Script::cast(script)->name()->ShortPrint();
|
|
||||||
PrintF("]\n");
|
PrintF("]\n");
|
||||||
}
|
}
|
||||||
// TODO(7110): Enable serialization of Asm modules once the AsmWasmData is
|
// TODO(7110): Enable serialization of Asm modules once the AsmWasmData is
|
||||||
@ -55,10 +54,11 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
|
|||||||
if (isolate->debug()->is_loaded()) return nullptr;
|
if (isolate->debug()->is_loaded()) return nullptr;
|
||||||
|
|
||||||
// Serialize code object.
|
// Serialize code object.
|
||||||
|
Handle<String> source(String::cast(script->source()), isolate);
|
||||||
CodeSerializer cs(isolate, SerializedCodeData::SourceHash(source));
|
CodeSerializer cs(isolate, SerializedCodeData::SourceHash(source));
|
||||||
DisallowHeapAllocation no_gc;
|
DisallowHeapAllocation no_gc;
|
||||||
cs.reference_map()->AddAttachedReference(*source);
|
cs.reference_map()->AddAttachedReference(*source);
|
||||||
ScriptData* script_data = cs.Serialize(info);
|
ScriptData* script_data = cs.SerializeSharedFunctionInfo(info);
|
||||||
|
|
||||||
if (FLAG_profile_deserialization) {
|
if (FLAG_profile_deserialization) {
|
||||||
double ms = timer.Elapsed().InMillisecondsF();
|
double ms = timer.Elapsed().InMillisecondsF();
|
||||||
@ -75,11 +75,12 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptData* CodeSerializer::Serialize(Handle<HeapObject> obj) {
|
ScriptData* CodeSerializer::SerializeSharedFunctionInfo(
|
||||||
|
Handle<SharedFunctionInfo> info) {
|
||||||
DisallowHeapAllocation no_gc;
|
DisallowHeapAllocation no_gc;
|
||||||
|
|
||||||
VisitRootPointer(Root::kHandleScope, nullptr,
|
VisitRootPointer(Root::kHandleScope, nullptr,
|
||||||
Handle<Object>::cast(obj).location());
|
Handle<Object>::cast(info).location());
|
||||||
SerializeDeferredObjects();
|
SerializeDeferredObjects();
|
||||||
Pad();
|
Pad();
|
||||||
|
|
||||||
|
5
deps/v8/src/snapshot/code-serializer.h
vendored
5
deps/v8/src/snapshot/code-serializer.h
vendored
@ -45,10 +45,9 @@ class ScriptData {
|
|||||||
|
|
||||||
class CodeSerializer : public Serializer<> {
|
class CodeSerializer : public Serializer<> {
|
||||||
public:
|
public:
|
||||||
static ScriptCompiler::CachedData* Serialize(Handle<SharedFunctionInfo> info,
|
static ScriptCompiler::CachedData* Serialize(Handle<SharedFunctionInfo> info);
|
||||||
Handle<String> source);
|
|
||||||
|
|
||||||
ScriptData* Serialize(Handle<HeapObject> obj);
|
ScriptData* SerializeSharedFunctionInfo(Handle<SharedFunctionInfo> info);
|
||||||
|
|
||||||
V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize(
|
V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize(
|
||||||
Isolate* isolate, ScriptData* cached_data, Handle<String> source);
|
Isolate* isolate, ScriptData* cached_data, Handle<String> source);
|
||||||
|
3
deps/v8/test/cctest/test-api.cc
vendored
3
deps/v8/test/cctest/test-api.cc
vendored
@ -25485,8 +25485,7 @@ TEST(CodeCache) {
|
|||||||
v8::ScriptCompiler::kNoCompileOptions;
|
v8::ScriptCompiler::kNoCompileOptions;
|
||||||
v8::Local<v8::Script> script =
|
v8::Local<v8::Script> script =
|
||||||
v8::ScriptCompiler::Compile(context, &source, option).ToLocalChecked();
|
v8::ScriptCompiler::Compile(context, &source, option).ToLocalChecked();
|
||||||
cache = v8::ScriptCompiler::CreateCodeCache(script->GetUnboundScript(),
|
cache = v8::ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
|
||||||
source_string);
|
|
||||||
}
|
}
|
||||||
isolate1->Dispose();
|
isolate1->Dispose();
|
||||||
|
|
||||||
|
11
deps/v8/test/cctest/test-serialize.cc
vendored
11
deps/v8/test/cctest/test-serialize.cc
vendored
@ -1240,8 +1240,7 @@ static Handle<SharedFunctionInfo> CompileScriptAndProduceCache(
|
|||||||
NOT_NATIVES_CODE)
|
NOT_NATIVES_CODE)
|
||||||
.ToHandleChecked();
|
.ToHandleChecked();
|
||||||
std::unique_ptr<ScriptCompiler::CachedData> cached_data(
|
std::unique_ptr<ScriptCompiler::CachedData> cached_data(
|
||||||
ScriptCompiler::CreateCodeCache(ToApiHandle<UnboundScript>(sfi),
|
ScriptCompiler::CreateCodeCache(ToApiHandle<UnboundScript>(sfi)));
|
||||||
Utils::ToLocal(source)));
|
|
||||||
uint8_t* buffer = NewArray<uint8_t>(cached_data->length);
|
uint8_t* buffer = NewArray<uint8_t>(cached_data->length);
|
||||||
MemCopy(buffer, cached_data->data, cached_data->length);
|
MemCopy(buffer, cached_data->data, cached_data->length);
|
||||||
*script_data = new i::ScriptData(buffer, cached_data->length);
|
*script_data = new i::ScriptData(buffer, cached_data->length);
|
||||||
@ -1895,7 +1894,7 @@ v8::ScriptCompiler::CachedData* CompileRunAndProduceCache(
|
|||||||
.ToLocalChecked();
|
.ToLocalChecked();
|
||||||
|
|
||||||
if (cacheType != CodeCacheType::kAfterExecute) {
|
if (cacheType != CodeCacheType::kAfterExecute) {
|
||||||
cache = ScriptCompiler::CreateCodeCache(script, source_str);
|
cache = ScriptCompiler::CreateCodeCache(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> result = script->BindToCurrentContext()
|
v8::Local<v8::Value> result = script->BindToCurrentContext()
|
||||||
@ -1907,7 +1906,7 @@ v8::ScriptCompiler::CachedData* CompileRunAndProduceCache(
|
|||||||
.FromJust());
|
.FromJust());
|
||||||
|
|
||||||
if (cacheType == CodeCacheType::kAfterExecute) {
|
if (cacheType == CodeCacheType::kAfterExecute) {
|
||||||
cache = ScriptCompiler::CreateCodeCache(script, source_str);
|
cache = ScriptCompiler::CreateCodeCache(script);
|
||||||
}
|
}
|
||||||
CHECK(cache);
|
CHECK(cache);
|
||||||
}
|
}
|
||||||
@ -2153,7 +2152,7 @@ TEST(CodeSerializerWithHarmonyScoping) {
|
|||||||
v8::ScriptCompiler::CompileUnboundScript(
|
v8::ScriptCompiler::CompileUnboundScript(
|
||||||
isolate1, &source, v8::ScriptCompiler::kNoCompileOptions)
|
isolate1, &source, v8::ScriptCompiler::kNoCompileOptions)
|
||||||
.ToLocalChecked();
|
.ToLocalChecked();
|
||||||
cache = v8::ScriptCompiler::CreateCodeCache(script, source_str);
|
cache = v8::ScriptCompiler::CreateCodeCache(script);
|
||||||
CHECK(cache);
|
CHECK(cache);
|
||||||
|
|
||||||
v8::Local<v8::Value> result = script->BindToCurrentContext()
|
v8::Local<v8::Value> result = script->BindToCurrentContext()
|
||||||
@ -2218,7 +2217,7 @@ TEST(Regress503552) {
|
|||||||
heap::SimulateIncrementalMarking(isolate->heap());
|
heap::SimulateIncrementalMarking(isolate->heap());
|
||||||
|
|
||||||
v8::ScriptCompiler::CachedData* cache_data =
|
v8::ScriptCompiler::CachedData* cache_data =
|
||||||
CodeSerializer::Serialize(shared, source);
|
CodeSerializer::Serialize(shared);
|
||||||
delete cache_data;
|
delete cache_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user