Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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}
  • Loading branch information
hashseed committed Jun 4, 2018
commit 1e18fc46b045f70267b089856526796b7a2b61a9
6 changes: 6 additions & 0 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,9 @@ class V8_EXPORT ScriptCompiler {
* This will return nullptr if the script cannot be serialized. The
* 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,
Local<String> source);

Expand All @@ -1587,6 +1590,9 @@ class V8_EXPORT ScriptCompiler {
* This will return nullptr if the script cannot be serialized. The
* CachedData returned by this function should be owned by the caller.
*/
static CachedData* CreateCodeCacheForFunction(Local<Function> function);

// Deprecated.
static CachedData* CreateCodeCacheForFunction(Local<Function> function,
Local<String> source);

Expand Down
14 changes: 12 additions & 2 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2626,21 +2626,31 @@ uint32_t ScriptCompiler::CachedDataVersionTag() {

ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
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>::cast(
Utils::OpenHandle(*unbound_script));
i::Handle<i::String> source_str = Utils::OpenHandle(*source);
DCHECK(shared->is_toplevel());
return i::CodeSerializer::Serialize(shared, source_str);
return i::CodeSerializer::Serialize(shared);
}

ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
Local<Function> function, Local<String> source) {
return CreateCodeCacheForFunction(function);
}

ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
Local<Function> function) {
i::Handle<i::SharedFunctionInfo> shared(
i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*function))->shared());
i::Handle<i::String> source_str = Utils::OpenHandle(*source);
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,
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/d8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
ShellOptions::CodeCacheOptions::kProduceCache) {
// Serialize and store it in memory for the next execution.
ScriptCompiler::CachedData* cached_data =
ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
StoreInCodeCache(isolate, source, cached_data);
delete cached_data;
}
Expand All @@ -645,7 +645,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
ShellOptions::CodeCacheOptions::kProduceCacheAfterExecute) {
// Serialize and store it in memory for the next execution.
ScriptCompiler::CachedData* cached_data =
ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
StoreInCodeCache(isolate, source, cached_data);
delete cached_data;
}
Expand Down
14 changes: 8 additions & 6 deletions deps/v8/src/snapshot/code-serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ ScriptData::ScriptData(const byte* data, int length)
}
}

<<<<<<< HEAD
// static
ScriptCompiler::CachedData* CodeSerializer::Serialize(
Handle<SharedFunctionInfo> info, Handle<String> source) {
Handle<SharedFunctionInfo> info) {
Isolate* isolate = info->GetIsolate();
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
HistogramTimerScope histogram_timer(isolate->counters()->compile_serialize());
Expand All @@ -45,8 +46,7 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
Handle<Script> script(Script::cast(info->script()), isolate);
if (FLAG_trace_serializer) {
PrintF("[Serializing from");
Object* script = info->script();
Script::cast(script)->name()->ShortPrint();
script->name()->ShortPrint();
PrintF("]\n");
}
// TODO(7110): Enable serialization of Asm modules once the AsmWasmData is
Expand All @@ -55,10 +55,11 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
if (isolate->debug()->is_loaded()) return nullptr;

// Serialize code object.
Handle<String> source(String::cast(script->source()), isolate);
CodeSerializer cs(isolate, SerializedCodeData::SourceHash(source));
DisallowHeapAllocation no_gc;
cs.reference_map()->AddAttachedReference(*source);
ScriptData* script_data = cs.Serialize(info);
ScriptData* script_data = cs.SerializeSharedFunctionInfo(info);

Copy link
Copy Markdown
Member

@jdalton jdalton Jun 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hashseed RE #20300 (comment). Can you double-check that this produces buffers with more data (after script execution) than say those with the legacy Node API (before execution).

Update:

NM I goofed my test.

if (FLAG_profile_deserialization) {
double ms = timer.Elapsed().InMillisecondsF();
Expand All @@ -75,11 +76,12 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
return result;
}

ScriptData* CodeSerializer::Serialize(Handle<HeapObject> obj) {
ScriptData* CodeSerializer::SerializeSharedFunctionInfo(
Handle<SharedFunctionInfo> info) {
DisallowHeapAllocation no_gc;

VisitRootPointer(Root::kHandleScope, nullptr,
Handle<Object>::cast(obj).location());
Handle<Object>::cast(info).location());
SerializeDeferredObjects();
Pad();

Expand Down
5 changes: 2 additions & 3 deletions deps/v8/src/snapshot/code-serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class ScriptData {

class CodeSerializer : public Serializer<> {
public:
static ScriptCompiler::CachedData* Serialize(Handle<SharedFunctionInfo> info,
Handle<String> source);

static ScriptCompiler::CachedData* Serialize(Handle<SharedFunctionInfo> info);
static ScriptData* SerializeSharedFunctionInfo(Handle<SharedFunctionInfo> info);
ScriptData* Serialize(Handle<HeapObject> obj);

V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize(
Expand Down
3 changes: 1 addition & 2 deletions deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25485,8 +25485,7 @@ TEST(CodeCache) {
v8::ScriptCompiler::kNoCompileOptions;
v8::Local<v8::Script> script =
v8::ScriptCompiler::Compile(context, &source, option).ToLocalChecked();
cache = v8::ScriptCompiler::CreateCodeCache(script->GetUnboundScript(),
source_string);
cache = v8::ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
}
isolate1->Dispose();

Expand Down
11 changes: 5 additions & 6 deletions deps/v8/test/cctest/test-serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,7 @@ static Handle<SharedFunctionInfo> CompileScriptAndProduceCache(
NOT_NATIVES_CODE)
.ToHandleChecked();
std::unique_ptr<ScriptCompiler::CachedData> cached_data(
ScriptCompiler::CreateCodeCache(ToApiHandle<UnboundScript>(sfi),
Utils::ToLocal(source)));
ScriptCompiler::CreateCodeCache(ToApiHandle<UnboundScript>(sfi)));
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);
Expand Down Expand Up @@ -1895,7 +1894,7 @@ v8::ScriptCompiler::CachedData* CompileRunAndProduceCache(
.ToLocalChecked();

if (cacheType != CodeCacheType::kAfterExecute) {
cache = ScriptCompiler::CreateCodeCache(script, source_str);
cache = ScriptCompiler::CreateCodeCache(script);
}

v8::Local<v8::Value> result = script->BindToCurrentContext()
Expand All @@ -1907,7 +1906,7 @@ v8::ScriptCompiler::CachedData* CompileRunAndProduceCache(
.FromJust());

if (cacheType == CodeCacheType::kAfterExecute) {
cache = ScriptCompiler::CreateCodeCache(script, source_str);
cache = ScriptCompiler::CreateCodeCache(script);
}
CHECK(cache);
}
Expand Down Expand Up @@ -2153,7 +2152,7 @@ TEST(CodeSerializerWithHarmonyScoping) {
v8::ScriptCompiler::CompileUnboundScript(
isolate1, &source, v8::ScriptCompiler::kNoCompileOptions)
.ToLocalChecked();
cache = v8::ScriptCompiler::CreateCodeCache(script, source_str);
cache = v8::ScriptCompiler::CreateCodeCache(script);
CHECK(cache);

v8::Local<v8::Value> result = script->BindToCurrentContext()
Expand Down Expand Up @@ -2218,7 +2217,7 @@ TEST(Regress503552) {
heap::SimulateIncrementalMarking(isolate->heap());

v8::ScriptCompiler::CachedData* cache_data =
CodeSerializer::Serialize(shared, source);
CodeSerializer::Serialize(shared);
delete cache_data;
}

Expand Down