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

[strings] Accomodate shared strings in externalizeString()

This is a testing function used by d8 to test string externalization.

Bug: v8:12007
Change-Id: Ic19f28a42e1f9681ab08c00106788c569639fe7e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3888378
Commit-Queue: Adam Klein <adamk@chromium.org>
Auto-Submit: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83117}
parent 4ec5bb4f
......@@ -57,6 +57,15 @@ ExternalizeStringExtension::GetNativeFunctionTemplate(
}
}
namespace {
bool HasExternalForwardingIndex(Isolate* isolate, Handle<String> string) {
if (!string->IsShared(isolate)) return false;
uint32_t raw_hash = string->raw_hash_field(kAcquireLoad);
return Name::IsExternalForwardingIndex(raw_hash);
}
} // namespace
void ExternalizeStringExtension::Externalize(
const v8::FunctionCallbackInfo<v8::Value>& args) {
......@@ -96,7 +105,13 @@ void ExternalizeStringExtension::Externalize(
result = Utils::ToLocal(string)->MakeExternal(resource);
if (!result) delete resource;
}
if (!result) {
// If the string is shared, testing with the combination of
// --shared-string-table and --isolate in d8 may result in races to
// externalize the same string. Those races manifest as externalization
// sometimes failing if another thread won and already forwarded the string to
// the external resource. Don't consider those races as failures.
if (!result && !HasExternalForwardingIndex(
reinterpret_cast<Isolate*>(args.GetIsolate()), string)) {
args.GetIsolate()->ThrowError("externalizeString() failed.");
return;
}
......
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