Commit 98d7bbb4 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[strings] Add --shared-string-table and support in d8

This CL reorders the initialization scheme for shared and client
Isolates such that clients attach to the shared Isolate before
setting up the Heap. This is to support sharing the string table.

Bug: v8:12007
Change-Id: Icb0e40cc5ed84d516c8073a70d0f769f517044c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3039264
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77307}
parent 9e68fc6e
......@@ -281,6 +281,12 @@ class V8_EXPORT Isolate {
*/
int embedder_wrapper_type_index = -1;
int embedder_wrapper_object_index = -1;
/**
* The following parameter is experimental and may change significantly.
* This is currently for internal testing.
*/
Isolate* experimental_attach_to_shared_isolate = nullptr;
};
/**
......
......@@ -8445,6 +8445,12 @@ void Isolate::Initialize(Isolate* isolate,
reinterpret_cast<uintptr_t>(params.constraints.stack_limit());
i_isolate->stack_guard()->SetStackLimit(limit);
}
if (params.experimental_attach_to_shared_isolate != nullptr) {
i_isolate->AttachToSharedIsolate(reinterpret_cast<i::Isolate*>(
params.experimental_attach_to_shared_isolate));
}
// TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
Isolate::Scope isolate_scope(isolate);
if (i_isolate->snapshot_blob() == nullptr) {
......
......@@ -476,6 +476,7 @@ std::atomic<int> Shell::unhandled_promise_rejections_{0};
Global<Context> Shell::evaluation_context_;
ArrayBuffer::Allocator* Shell::array_buffer_allocator;
Isolate* Shell::shared_isolate = nullptr;
bool check_d8_flag_contradictions = true;
ShellOptions Shell::options;
base::OnceType Shell::quit_once_ = V8_ONCE_INIT;
......@@ -3284,6 +3285,9 @@ void Shell::WriteLcovData(v8::Isolate* isolate, const char* file) {
void Shell::OnExit(v8::Isolate* isolate) {
isolate->Dispose();
if (shared_isolate) {
i::Isolate::Delete(reinterpret_cast<i::Isolate*>(shared_isolate));
}
if (i::FLAG_dump_counters || i::FLAG_dump_counters_nvp) {
std::vector<std::pair<std::string, Counter*>> counters(
......@@ -3850,6 +3854,7 @@ SourceGroup::IsolateThread::IsolateThread(SourceGroup* group)
void SourceGroup::ExecuteInThread() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
create_params.experimental_attach_to_shared_isolate = Shell::shared_isolate;
Isolate* isolate = Isolate::New(create_params);
Shell::SetWaitUntilDone(isolate, false);
D8Console console(isolate);
......@@ -4084,6 +4089,7 @@ void Worker::ProcessMessages() {
void Worker::ExecuteInThread() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
create_params.experimental_attach_to_shared_isolate = Shell::shared_isolate;
isolate_ = Isolate::New(create_params);
{
base::MutexGuard lock_guard(&worker_mutex_);
......@@ -4973,6 +4979,12 @@ void Shell::WaitForRunningWorkers() {
allow_new_workers_ = true;
}
namespace {
bool HasFlagThatRequiresSharedIsolate() { return i::FLAG_shared_string_table; }
} // namespace
int Shell::Main(int argc, char* argv[]) {
v8::base::EnsureConsoleOutput();
if (!SetOptions(argc, argv)) return 1;
......@@ -5123,6 +5135,14 @@ int Shell::Main(int argc, char* argv[]) {
}
#endif // V8_ENABLE_WEBASSEMBLY
if (HasFlagThatRequiresSharedIsolate()) {
Isolate::CreateParams shared_create_params;
shared_create_params.array_buffer_allocator = Shell::array_buffer_allocator;
shared_isolate =
reinterpret_cast<Isolate*>(i::Isolate::NewShared(create_params));
create_params.experimental_attach_to_shared_isolate = shared_isolate;
}
Isolate* isolate = Isolate::New(create_params);
{
......@@ -5196,6 +5216,8 @@ int Shell::Main(int argc, char* argv[]) {
// First run to produce the cache
Isolate::CreateParams create_params2;
create_params2.array_buffer_allocator = Shell::array_buffer_allocator;
create_params2.experimental_attach_to_shared_isolate =
Shell::shared_isolate;
i::FLAG_hash_seed ^= 1337; // Use a different hash seed.
Isolate* isolate2 = Isolate::New(create_params2);
i::FLAG_hash_seed ^= 1337; // Restore old hash seed.
......
......@@ -630,6 +630,7 @@ class Shell : public i::AllStatic {
static const char* kPrompt;
static ShellOptions options;
static ArrayBuffer::Allocator* array_buffer_allocator;
static Isolate* shared_isolate;
static void SetWaitUntilDone(Isolate* isolate, bool value);
static void NotifyStartStreamingTask(Isolate* isolate);
......
......@@ -3700,6 +3700,8 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
heap_.InitializeMainThreadLocalHeap(main_thread_local_heap());
if (shared_isolate_) heap()->InitSharedSpaces();
isolate_data_.external_reference_table()->Init(this);
#if V8_ENABLE_WEBASSEMBLY
......@@ -5129,9 +5131,9 @@ Address Isolate::store_to_stack_count_address(const char* function_name) {
void Isolate::AttachToSharedIsolate(Isolate* shared) {
DCHECK(shared->is_shared());
DCHECK_NULL(shared_isolate_);
DCHECK(!heap_.HasBeenSetUp());
shared->AppendAsClientIsolate(this);
shared_isolate_ = shared;
heap()->InitSharedSpaces();
}
void Isolate::DetachFromSharedIsolate() {
......
......@@ -711,6 +711,9 @@ DEFINE_BOOL(trace_baseline_batch_compilation, false,
#undef FLAG
#define FLAG FLAG_FULL
// Internalize into a shared string table in the shared isolate
DEFINE_BOOL(shared_string_table, false, "internalize strings into shared table")
#if !defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64)
DEFINE_BOOL(write_code_using_rwx, true,
"flip permissions to rwx to write page instead of rw")
......
......@@ -28,9 +28,10 @@ void SetupClientIsolateAndRunCallback(Isolate* shared_isolate,
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = allocator.get();
create_params.experimental_attach_to_shared_isolate =
reinterpret_cast<v8::Isolate*>(shared_isolate);
v8::Isolate* client_isolate = v8::Isolate::New(create_params);
Isolate* i_client_isolate = reinterpret_cast<Isolate*>(client_isolate);
i_client_isolate->AttachToSharedIsolate(shared_isolate);
callback(client_isolate, i_client_isolate);
......
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