Commit 9458d625 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

Reland "[offthread] Add a write lock to the string table"

This is a reland of 6af09b1b

Relanding without changes after fixing the root cause in
https://crrev.com/c/2315987

Original change's description:
> [offthread] Add a write lock to the string table
>
> Adds an initial implementation of a concurrency support for the string
> table, allowing it to be read without holding a lock, and written to
> while holding a lock.
>
> This is an initial prototype of _roughly_ how the concurrency would
> work; there are still a few holes (e.g. around deserialization). This
> is predominantly to assess the main-thread runtime impact of the more
> complex string table access.
>
> Bug: v8:10729
> Change-Id: I5c6c35e6fca309efd6ee79804c16972aae1ab3ab
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2306804
> Reviewed-by: Toon Verwaest <verwaest@chromium.org>
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Commit-Queue: Leszek Swirski <leszeks@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#68985}

Tbr: verwaest@chromium.org,ishell@chromium.org,ulan@chromium.org
Bug: v8:10729
Change-Id: I9ce8882cfbdd40fbe1c7478e171c0785bf2e64d6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2315989
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69025}
parent 185389fa
......@@ -16,6 +16,7 @@
#include "include/v8-internal.h"
#include "include/v8.h"
#include "src/base/macros.h"
#include "src/base/platform/mutex.h"
#include "src/builtins/builtins.h"
#include "src/common/globals.h"
#include "src/debug/interface-types.h"
......@@ -613,6 +614,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
return &transition_array_access_;
}
// Mutex for accessing the string table.
base::Mutex* string_table_mutex() { return &string_table_mutex_; }
Address get_address_from_id(IsolateAddressId id);
// Access to top context (where the current function object was created).
......@@ -1654,6 +1658,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
std::shared_ptr<Counters> async_counters_;
base::RecursiveMutex break_access_;
base::SharedMutex transition_array_access_;
base::Mutex string_table_mutex_;
Logger* logger_ = nullptr;
StubCache* load_stub_cache_ = nullptr;
StubCache* store_stub_cache_ = nullptr;
......
......@@ -157,11 +157,10 @@ InternalIndex HashTable<Derived, Shape>::FindEntry(const LocalIsolate* isolate,
Object element = KeyAt(isolate, entry);
// Empty entry. Uses raw unchecked accessors because it is called by the
// string table during bootstrapping.
if (element == undefined) break;
if (element == undefined) return InternalIndex::NotFound();
if (Shape::kMatchNeedsHoleCheck && element == the_hole) continue;
if (Shape::IsMatch(key, element)) return entry;
}
return InternalIndex::NotFound();
}
// static
......
......@@ -223,6 +223,12 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
uint32_t hash);
InternalIndex FindInsertionEntry(Isolate* isolate, uint32_t hash);
// Find either the entry with the given key, or the entry at which to insert
// an element with the given key.
InternalIndex FindEntryOrInsertionEntry(const Isolate* isolate,
ReadOnlyRoots roots, Key key,
uint32_t hash);
// Computes the capacity a table with the given capacity would need to have
// room for the given number of elements, also allowing it to shrink.
static int ComputeCapacityWithShrink(int current_capacity,
......
This diff is collapsed.
......@@ -436,6 +436,12 @@ class RootsTable {
return roots_[index];
}
FullObjectSlot slot(RootIndex root_index) {
size_t index = static_cast<size_t>(root_index);
DCHECK_LT(index, kEntriesCount);
return FullObjectSlot(&roots_[index]);
}
static const char* name(RootIndex root_index) {
size_t index = static_cast<size_t>(root_index);
DCHECK_LT(index, kEntriesCount);
......
......@@ -240,6 +240,7 @@ HeapObject Deserializer::PostProcessNewObject(HeapObject obj,
if (string.IsInternalizedString()) {
// Off-thread internalized strings are canonicalized during off-thread
// isolate publish, so we don't have to canonicalize them here.
// TODO(crbug.com/v8/10729): Add concurrent string table support.
if (local_isolate().is_off_thread()) return string;
// Canonicalize the internalized string. If it already exists in the
......
......@@ -79,6 +79,7 @@ MaybeHandle<HeapObject> ObjectDeserializer::Deserialize(
void ObjectDeserializer::CommitPostProcessedObjects() {
if (is_main_thread()) {
// TODO(crbug.com/v8/10729): Add concurrent string table support.
CHECK_LE(new_internalized_strings().size(), kMaxInt);
StringTable::EnsureCapacityForDeserialization(
isolate(), static_cast<int>(new_internalized_strings().size()));
......
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