[regexp] Add use counters for slow exec and replace calls

These counters track how often the slow path of these two builtins is
hit. Exec is very permissive, its fast-path check doesn't look at the
regexp prototype at all. Replace is strict; any change on the
prototype will trigger the slow path.

Chromium CL: https://crrev.com/c/1875250

Bug: v8:5577
Change-Id: I9807f43829981445b75b5c5d29800cbdac9bc26a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1873698
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Peter Marshall <petermarshall@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64496}
This commit is contained in:
Jakob Gruber 2019-10-22 15:47:40 +02:00 committed by Commit Bot
parent 4f52630b0a
commit 6f1de28834
3 changed files with 9 additions and 0 deletions

View File

@ -8141,6 +8141,8 @@ class V8_EXPORT Isolate {
kCallSiteAPIGetFunctionSloppyCall = 76,
kCallSiteAPIGetThisSloppyCall = 77,
kRegExpMatchAllWithNonGlobalRegExp = 78,
kRegExpExecCalledOnSlowRegExp = 79,
kRegExpReplaceCalledOnSlowRegExp = 80,
// 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

View File

@ -701,6 +701,8 @@ RegExpBuiltinsAssembler::RegExpPrototypeExecBodyWithoutResult(
TNode<Context> context, TNode<JSReceiver> maybe_regexp,
TNode<String> string, const bool is_fastpath, Label* if_didnotmatch) {
if (!is_fastpath) {
CallRuntime(Runtime::kIncrementUseCounter, context,
SmiConstant(v8::Isolate::kRegExpExecCalledOnSlowRegExp));
ThrowIfNotInstanceType(context, maybe_regexp, JS_REG_EXP_TYPE,
"RegExp.prototype.exec");
}

View File

@ -211,6 +211,9 @@ namespace regexp {
}
}
const kRegExpReplaceCalledOnSlowRegExp: constexpr int31
generates 'v8::Isolate::kRegExpReplaceCalledOnSlowRegExp';
transitioning javascript builtin RegExpPrototypeReplace(
js-implicit context: Context, receiver: JSAny)(...arguments): JSAny {
const methodName: constexpr string = 'RegExp.prototype.@@replace';
@ -250,6 +253,8 @@ namespace regexp {
return RegExpReplace(fastRx, s, replaceValue);
}
label Runtime deferred {
IncrementUseCounter(
context, SmiConstant(kRegExpReplaceCalledOnSlowRegExp));
return RegExpReplaceRT(context, rx, s, replaceValue);
}
}