Commit 6d392516 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

Reland "[protectors] Add use counters to track invalidations"

This is a reland of 52412058

Original change's description:
> [protectors] Add use counters to track invalidations
> 
> ... to make real world protector invalidations measurable.
> 
> Chromium CL: https://crrev.com/c/2149324
> 
> Drive-by: Add missing newline in protector tracing.
> Drive-by: Consistent naming for the regexp species protector.
> 
> Bug: v8:9496
> Change-Id: I3c7238aa8024e03ea9e89daf83345b8ec4f0d768
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2149428
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Commit-Queue: Jakob Gruber <jgruber@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#67149}

Bug: v8:9496
Change-Id: I3c97bfa747e8429569eaa09ea909de73fc377efa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2151363Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67261}
parent 4536bb2e
......@@ -8463,6 +8463,22 @@ class V8_EXPORT Isolate {
kDateTimeFormatDateTimeStyle = 87,
kBreakIteratorTypeWord = 88,
kBreakIteratorTypeLine = 89,
kInvalidatedArrayBufferDetachingProtector = 90,
kInvalidatedArrayConstructorProtector = 91,
kInvalidatedArrayIteratorLookupChainProtector = 92,
kInvalidatedArraySpeciesLookupChainProtector = 93,
kInvalidatedIsConcatSpreadableLookupChainProtector = 94,
kInvalidatedMapIteratorLookupChainProtector = 95,
kInvalidatedNoElementsProtector = 96,
kInvalidatedPromiseHookProtector = 97,
kInvalidatedPromiseResolveLookupChainProtector = 98,
kInvalidatedPromiseSpeciesLookupChainProtector = 99,
kInvalidatedPromiseThenLookupChainProtector = 100,
kInvalidatedRegExpSpeciesLookupChainProtector = 101,
kInvalidatedSetIteratorLookupChainProtector = 102,
kInvalidatedStringIteratorLookupChainProtector = 103,
kInvalidatedStringLengthOverflowLookupChainProtector = 104,
kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
// If you add new values here, you'll also need to update Chromium's:
// web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
......
......@@ -17,6 +17,7 @@ namespace v8 {
namespace internal {
namespace {
void TraceProtectorInvalidation(const char* protector_name) {
DCHECK(FLAG_trace_protector_invalidation);
static constexpr char kInvalidateProtectorTracingCategory[] =
......@@ -26,11 +27,23 @@ void TraceProtectorInvalidation(const char* protector_name) {
DCHECK(FLAG_trace_protector_invalidation);
// TODO(jgruber): Remove the PrintF once tracing can output to stdout.
i::PrintF("Invalidating protector cell %s", protector_name);
i::PrintF("Invalidating protector cell %s\n", protector_name);
TRACE_EVENT_INSTANT1("v8", kInvalidateProtectorTracingCategory,
TRACE_EVENT_SCOPE_THREAD, kInvalidateProtectorTracingArg,
protector_name);
}
// Static asserts to ensure we have a use counter for every protector. If this
// fails, add the use counter in V8 and chromium. Note: IsDefined is not
// strictly needed but clarifies the intent of the static assert.
constexpr bool IsDefined(v8::Isolate::UseCounterFeature) { return true; }
#define V(Name, ...) \
STATIC_ASSERT(IsDefined(v8::Isolate::kInvalidated##Name##Protector));
DECLARED_PROTECTORS_ON_ISOLATE(V)
DECLARED_PROTECTORS_ON_NATIVE_CONTEXT(V)
#undef V
} // namespace
#define INVALIDATE_PROTECTOR_ON_NATIVE_CONTEXT_DEFINITION(name, cell) \
......@@ -58,6 +71,7 @@ DECLARED_PROTECTORS_ON_NATIVE_CONTEXT(
if (FLAG_trace_protector_invalidation) { \
TraceProtectorInvalidation(#name); \
} \
isolate->CountUsage(v8::Isolate::kInvalidated##name##Protector); \
PropertyCell::SetValueWithInvalidation( \
isolate, #cell, isolate->factory()->cell(), \
handle(Smi::FromInt(kProtectorInvalid), isolate)); \
......
......@@ -16,7 +16,7 @@ class Protectors : public AllStatic {
static const int kProtectorInvalid = 0;
#define DECLARED_PROTECTORS_ON_NATIVE_CONTEXT(V) \
V(RegExpSpeciesLookupChainProtector, regexp_species_protector)
V(RegExpSpeciesLookupChain, regexp_species_protector)
#define DECLARED_PROTECTORS_ON_ISOLATE(V) \
V(ArrayBufferDetaching, ArrayBufferDetachingProtector, \
......
......@@ -205,8 +205,7 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate,
if (!Protectors::IsArraySpeciesLookupChainIntact(isolate) &&
!Protectors::IsPromiseSpeciesLookupChainIntact(isolate) &&
!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
native_context) &&
!Protectors::IsRegExpSpeciesLookupChainIntact(native_context) &&
!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) {
return;
}
......@@ -222,12 +221,10 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate,
Protectors::InvalidatePromiseSpeciesLookupChain(isolate);
return;
} else if (receiver->IsJSRegExp(isolate)) {
if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
native_context)) {
if (!Protectors::IsRegExpSpeciesLookupChainIntact(native_context)) {
return;
}
Protectors::InvalidateRegExpSpeciesLookupChainProtector(isolate,
native_context);
Protectors::InvalidateRegExpSpeciesLookupChain(isolate, native_context);
return;
} else if (receiver->IsJSTypedArray(isolate)) {
if (!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) return;
......@@ -253,12 +250,10 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate,
Protectors::InvalidatePromiseSpeciesLookupChain(isolate);
} else if (isolate->IsInAnyContext(*receiver,
Context::REGEXP_PROTOTYPE_INDEX)) {
if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
native_context)) {
if (!Protectors::IsRegExpSpeciesLookupChainIntact(native_context)) {
return;
}
Protectors::InvalidateRegExpSpeciesLookupChainProtector(isolate,
native_context);
Protectors::InvalidateRegExpSpeciesLookupChain(isolate, native_context);
} else if (isolate->IsInAnyContext(
receiver->map(isolate).prototype(isolate),
Context::TYPED_ARRAY_PROTOTYPE_INDEX)) {
......@@ -301,8 +296,7 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate,
if (!Protectors::IsArraySpeciesLookupChainIntact(isolate) &&
!Protectors::IsPromiseSpeciesLookupChainIntact(isolate) &&
!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
native_context) &&
!Protectors::IsRegExpSpeciesLookupChainIntact(native_context) &&
!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) {
return;
}
......@@ -319,12 +313,10 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate,
Protectors::InvalidatePromiseSpeciesLookupChain(isolate);
} else if (isolate->IsInAnyContext(*receiver,
Context::REGEXP_FUNCTION_INDEX)) {
if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
native_context)) {
if (!Protectors::IsRegExpSpeciesLookupChainIntact(native_context)) {
return;
}
Protectors::InvalidateRegExpSpeciesLookupChainProtector(isolate,
native_context);
Protectors::InvalidateRegExpSpeciesLookupChain(isolate, native_context);
} else if (IsTypedArrayFunctionInAnyContext(isolate, *receiver)) {
if (!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) return;
Protectors::InvalidateTypedArraySpeciesLookupChain(isolate);
......
......@@ -185,7 +185,7 @@ bool RegExpUtils::IsUnmodifiedRegExp(Isolate* isolate, Handle<Object> obj) {
// property. Similar spots in CSA would use BranchIfFastRegExp_Strict in this
// case.
if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
if (!Protectors::IsRegExpSpeciesLookupChainIntact(
recv.GetCreationContext())) {
return false;
}
......
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