Bug 1625212 - Give RegExpShared a cell header r=sfink

I had to reorder the fields here to make so the first field was simple to replace.

Differential Revision: https://phabricator.services.mozilla.com/D68837

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jon Coppeard 2020-04-01 09:45:46 +00:00
Родитель 05f7710a8a
Коммит ab358a67a6
3 изменённых файлов: 23 добавлений и 12 удалений

Просмотреть файл

@ -932,7 +932,10 @@ bool js::StringHasRegExpMetaChars(JSLinearString* str) {
/* RegExpShared */
RegExpShared::RegExpShared(JSAtom* source, RegExpFlags flags)
: source(source), parenCount(0), flags(flags), canStringMatch(false) {}
: headerAndSource(source),
parenCount(0),
flags(flags),
canStringMatch(false) {}
void RegExpShared::traceChildren(JSTracer* trc) {
// Discard code to avoid holding onto ExecutablePools.
@ -940,7 +943,7 @@ void RegExpShared::traceChildren(JSTracer* trc) {
discardJitCode();
}
TraceNullableEdge(trc, &source, "RegExpShared source");
TraceNullableEdge(trc, &headerAndSource, "RegExpShared source");
for (auto& comp : compilationArray) {
TraceNullableEdge(trc, &comp.jitCode, "RegExpShared code");
}
@ -972,7 +975,7 @@ bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re,
TraceLoggerThread* logger = TraceLoggerForCurrentThread(cx);
AutoTraceLog logCompile(logger, TraceLogger_IrregexpCompile);
RootedAtom pattern(cx, re->source);
RootedAtom pattern(cx, re->getSource());
return compile(cx, re, pattern, input, mode, force);
}
@ -1079,14 +1082,14 @@ RegExpRunStatus RegExpShared::execute(JSContext* cx,
if (re->canStringMatch) {
MOZ_ASSERT(re->pairCount() == 1);
size_t sourceLength = re->source->length();
size_t sourceLength = re->getSource()->length();
if (re->sticky()) {
// First part checks size_t overflow.
if (sourceLength + start < sourceLength ||
sourceLength + start > length) {
return RegExpRunStatus_Success_NotFound;
}
if (!HasSubstringAt(input, re->source, start)) {
if (!HasSubstringAt(input, re->getSource(), start)) {
return RegExpRunStatus_Success_NotFound;
}
@ -1101,7 +1104,7 @@ RegExpRunStatus RegExpShared::execute(JSContext* cx,
return RegExpRunStatus_Success;
}
int res = StringFindPattern(input, re->source, start);
int res = StringFindPattern(input, re->getSource(), start);
if (res == -1) {
return RegExpRunStatus_Success_NotFound;
}

Просмотреть файл

@ -97,10 +97,11 @@ class RegExpShared : public gc::TenuredCell {
}
};
RegExpCompilation compilationArray[4];
/* Source to the RegExp, for lazy compilation. */
const GCPtrAtom source;
using HeaderWithAtom = gc::CellHeaderWithTenuredGCPointer<JSAtom>;
HeaderWithAtom headerAndSource;
RegExpCompilation compilationArray[4];
uint32_t parenCount;
JS::RegExpFlags flags;
@ -164,7 +165,7 @@ class RegExpShared : public gc::TenuredCell {
/* Accounts for the "0" (whole match) pair. */
size_t pairCount() const { return getParenCount() + 1; }
JSAtom* getSource() const { return source; }
JSAtom* getSource() const { return headerAndSource.ptr(); }
JS::RegExpFlags getFlags() const { return flags; }
bool global() const { return flags.global(); }
@ -187,7 +188,10 @@ class RegExpShared : public gc::TenuredCell {
void discardJitCode();
void finalize(JSFreeOp* fop);
static size_t offsetOfSource() { return offsetof(RegExpShared, source); }
static size_t offsetOfSource() {
return offsetof(RegExpShared, headerAndSource) +
HeaderWithAtom::offsetOfPtr();
}
static size_t offsetOfFlags() { return offsetof(RegExpShared, flags); }
@ -212,6 +216,10 @@ class RegExpShared : public gc::TenuredCell {
static bool dumpBytecode(JSContext* cx, MutableHandleRegExpShared res,
bool match_only, HandleLinearString input);
#endif
public:
static const JS::TraceKind TraceKind = JS::TraceKind::RegExpShared;
const gc::CellHeader& cellHeader() const { return headerAndSource; }
};
class RegExpZone {

Просмотреть файл

@ -243,7 +243,7 @@ inline void RegExpStatics::updateLazily(JSContext* cx, JSLinearString* input,
BarrieredSetPair<JSString, JSLinearString>(cx->zone(), pendingInput, input,
matchesInput, input);
lazySource = shared->source;
lazySource = shared->getSource();
lazyFlags = shared->flags;
lazyIndex = lastIndex;
pendingLazyEvaluation = 1;