Commit 80575e28 authored by Seth Brenith's avatar Seth Brenith Committed by V8 LUCI CQ

Allow embedder to provide source text during code cache deserialization

This change is only to get the API in place; the newly added functions
don't yet do anything.

Bug: v8:12808
Change-Id: Ic6a697d4f62c2b61761b2545dae6fcdf37653bbf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3681880Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#81418}
parent b0ccc6ad
......@@ -506,7 +506,7 @@ class V8_EXPORT ScriptCompiler {
/**
* A task which the embedder must run on a background thread to
* consume a V8 code cache. Returned by
* ScriptCompiler::StarConsumingCodeCache.
* ScriptCompiler::StartConsumingCodeCache.
*/
class V8_EXPORT ConsumeCodeCacheTask final {
public:
......@@ -514,6 +514,36 @@ class V8_EXPORT ScriptCompiler {
void Run();
/**
* Provides the source text string and origin information to the consumption
* task. May be called before, during, or after Run(). This step checks
* whether the script matches an existing script in the Isolate's
* compilation cache. To check whether such a script was found, call
* ShouldMergeWithExistingScript.
*
* The Isolate provided must be the same one used during
* StartConsumingCodeCache and must be currently entered on the thread that
* calls this function. The source text and origin provided in this step
* must precisely match those used later in the ScriptCompiler::Source that
* will contain this ConsumeCodeCacheTask.
*/
void SourceTextAvailable(Isolate* isolate, Local<String> source_text,
const ScriptOrigin& origin);
/**
* Returns whether the embedder should call MergeWithExistingScript. This
* function may be called from any thread, any number of times, but its
* return value is only meaningful after SourceTextAvailable has completed.
*/
bool ShouldMergeWithExistingScript() const;
/**
* Merges newly deserialized data into an existing script which was found
* during SourceTextAvailable. May be called only after Run() has completed.
* Can execute on any thread, like Run().
*/
void MergeWithExistingScript();
private:
friend class ScriptCompiler;
......
......@@ -2753,6 +2753,32 @@ ScriptCompiler::ConsumeCodeCacheTask::~ConsumeCodeCacheTask() = default;
void ScriptCompiler::ConsumeCodeCacheTask::Run() { impl_->Run(); }
void ScriptCompiler::ConsumeCodeCacheTask::SourceTextAvailable(
Isolate* v8_isolate, Local<String> source_text,
const ScriptOrigin& origin) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
DCHECK_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::String> str = Utils::OpenHandle(*(source_text));
i::ScriptDetails script_details =
GetScriptDetails(i_isolate, origin.ResourceName(), origin.LineOffset(),
origin.ColumnOffset(), origin.SourceMapUrl(),
origin.GetHostDefinedOptions(), origin.Options());
impl_->SourceTextAvailable(i_isolate, str, script_details);
}
bool ScriptCompiler::ConsumeCodeCacheTask::ShouldMergeWithExistingScript()
const {
if (!i::FLAG_merge_background_deserialized_script_with_compilation_cache) {
return false;
}
return impl_->ShouldMergeWithExistingScript();
}
void ScriptCompiler::ConsumeCodeCacheTask::MergeWithExistingScript() {
DCHECK(i::FLAG_merge_background_deserialized_script_with_compilation_cache);
impl_->MergeWithExistingScript();
}
ScriptCompiler::ConsumeCodeCacheTask* ScriptCompiler::StartConsumingCodeCache(
Isolate* v8_isolate, std::unique_ptr<CachedData> cached_data) {
if (!i::FLAG_concurrent_cache_deserialization) return nullptr;
......
......@@ -1861,6 +1861,24 @@ void BackgroundDeserializeTask::Run() {
CodeSerializer::StartDeserializeOffThread(&isolate, &cached_data_);
}
void BackgroundDeserializeTask::SourceTextAvailable(
Isolate* isolate, Handle<String> source_text,
const ScriptDetails& script_details) {
DCHECK_EQ(isolate, isolate_for_local_isolate_);
// TODO(v8:12808): Implement this.
}
bool BackgroundDeserializeTask::ShouldMergeWithExistingScript() const {
DCHECK(FLAG_merge_background_deserialized_script_with_compilation_cache);
// TODO(v8:12808): Implement this.
return true;
}
void BackgroundDeserializeTask::MergeWithExistingScript() {
DCHECK(FLAG_merge_background_deserialized_script_with_compilation_cache);
// TODO(v8:12808): Implement this.
}
MaybeHandle<SharedFunctionInfo> BackgroundDeserializeTask::Finish(
Isolate* isolate, Handle<String> source,
ScriptOriginOptions origin_options) {
......
......@@ -606,6 +606,25 @@ class V8_EXPORT_PRIVATE BackgroundDeserializeTask {
void Run();
// Checks the Isolate compilation cache to see whether it will be necessary to
// merge the newly deserialized objects into an existing Script. This can
// change the value of ShouldMergeWithExistingScript, and embedders should
// check the latter after calling this. May only be called on a thread where
// the Isolate is currently entered.
void SourceTextAvailable(Isolate* isolate, Handle<String> source_text,
const ScriptDetails& script_details);
// Returns whether the embedder should call MergeWithExistingScript. This
// function may be called from any thread, any number of times, but its return
// value is only meaningful after SourceTextAvailable has completed.
bool ShouldMergeWithExistingScript() const;
// Partially merges newly deserialized objects into an existing Script with
// the same source, as provided by SourceTextAvailable, and generates a list
// of follow-up work for the main thread. May be called from any thread, only
// once.
void MergeWithExistingScript();
MaybeHandle<SharedFunctionInfo> Finish(Isolate* isolate,
Handle<String> source,
ScriptOriginOptions origin_options);
......
......@@ -1530,6 +1530,10 @@ DEFINE_BOOL(stress_background_compile, false,
"stress test parsing on background")
DEFINE_BOOL(concurrent_cache_deserialization, true,
"enable deserializing code caches on background")
DEFINE_BOOL(
merge_background_deserialized_script_with_compilation_cache, false,
"After deserializing code cache data on a background thread, merge it into "
"an existing Script if one is found in the Isolate compilation cache")
DEFINE_BOOL(disable_old_api_accessors, false,
"Disable old-style API accessors whose setters trigger through the "
"prototype chain")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment