v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
background-merge-task.h
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_CODEGEN_BACKGROUND_MERGE_TASK_H_
6#define V8_CODEGEN_BACKGROUND_MERGE_TASK_H_
7
8#include <vector>
9
11
12namespace v8 {
13namespace internal {
14
15class FeedbackMetadata;
16class PersistentHandles;
17class Script;
18class SharedFunctionInfo;
19class String;
20
21struct ScriptDetails;
22
23// Contains data transferred between threads for background merging between a
24// newly compiled or deserialized script and an existing script from the Isolate
25// compilation cache.
27 public:
28 // Step 1: on the main thread, check whether the Isolate compilation cache
29 // contains the script.
30 void SetUpOnMainThread(Isolate* isolate, Handle<String> source_text,
31 const ScriptDetails& script_details,
32 LanguageMode language_mode);
33
34 // Alternative step 1: on the main thread, if the caller has already looked up
35 // the script in the Isolate compilation cache, set up the necessary
36 // persistent data for the background merge.
37 void SetUpOnMainThread(Isolate* isolate, DirectHandle<Script> cached_script);
38
39 // Step 2: on the background thread, update pointers in the new Script's
40 // object graph to point to corresponding objects from the cached Script where
41 // appropriate. May only be called if HasPendingBackgroundWork returned true.
42 void BeginMergeInBackground(LocalIsolate* isolate,
43 DirectHandle<Script> new_script);
44
45 // Step 3: on the main thread again, complete the merge so that all relevant
46 // objects are reachable from the cached Script. May only be called if
47 // HasPendingForegroundWork returned true. Returns the top-level
48 // SharedFunctionInfo that should be used.
49 Handle<SharedFunctionInfo> CompleteMergeInForeground(
50 Isolate* isolate, DirectHandle<Script> new_script);
51
53 return state_ == kPendingBackgroundWork;
54 }
56 return state_ == kPendingForegroundWork;
57 }
58
59 static void ForceGCDuringNextMergeForTesting();
60
61 private:
62 std::unique_ptr<PersistentHandles> persistent_handles_;
63
64 // Data from main thread:
65
67
68 // Data from background thread:
69
70 // The top-level SharedFunctionInfo from the cached script, if one existed,
71 // just to keep it alive.
73
74 // New SharedFunctionInfos which are used because there was no corresponding
75 // SharedFunctionInfo in the cached script. The main thread must:
76 // 1. Check whether the cached script gained corresponding SharedFunctionInfos
77 // for any of these, and if so, redo the merge.
78 // 2. Update the cached script's infos list to refer to these.
79 std::vector<Handle<SharedFunctionInfo>> used_new_sfis_;
80
81 // SharedFunctionInfos from the cached script which were not compiled, with
82 // the corresponding new SharedFunctionInfo. If the SharedFunctionInfo from
83 // the cached script is still uncompiled when finishing, the main thread must
84 // copy all fields from the new SharedFunctionInfo to the SharedFunctionInfo
85 // from the cached script.
90 std::vector<NewCompiledDataForCachedSfi> new_compiled_data_for_cached_sfis_;
91
98 State state_ = kNotStarted;
99};
100
101} // namespace internal
102} // namespace v8
103
104#endif // V8_CODEGEN_BACKGROUND_MERGE_TASK_H_
std::vector< NewCompiledDataForCachedSfi > new_compiled_data_for_cached_sfis_
std::unique_ptr< PersistentHandles > persistent_handles_
std::vector< Handle< SharedFunctionInfo > > used_new_sfis_
MaybeHandle< SharedFunctionInfo > toplevel_sfi_from_cached_script_
enum v8::internal::@1270::DeoptimizableCodeIterator::@67 state_
v8_inspector::String16 String
Definition string-util.h:26
#define V8_EXPORT_PRIVATE
Definition macros.h:460