Bug 820124, Part 1/2 - Use RegExpShared for lazy RegExpStatics. r=dvander

This commit is contained in:
Sean Stangl committed 2012-12-14 16:07:35 -08:00
1 parent 22074d68d7
commit 1267526f02
9 files changed
+68 -51

No files matched your search

+4 -4
View File
@@ -114,7 +114,7 @@ js::CreateRegExpMatchResult(JSContext *cx, HandleString string, MatchPairs &matc
}
RegExpRunStatus
ExecuteRegExpImpl(JSContext *cx, RegExpStatics *res, RegExpShared &re, RegExpObject &regexp,
ExecuteRegExpImpl(JSContext *cx, RegExpStatics *res, RegExpShared &re,
JSLinearString *input, StableCharPtr chars, size_t length,
size_t *lastIndex, MatchConduit &matches)
{
@@ -126,7 +126,7 @@ ExecuteRegExpImpl(JSContext *cx, RegExpStatics *res, RegExpShared &re, RegExpObj
/* Only one MatchPair slot provided: execute short-circuiting regexp. */
status = re.executeMatchOnly(cx, chars, length, lastIndex, *matches.u.pair);
if (status == RegExpRunStatus_Success && res)
res->updateLazily(cx, input, &regexp, lastIndex_orig);
res->updateLazily(cx, input, &re, lastIndex_orig);
} else {
/* Vector of MatchPairs provided: execute full regexp. */
status = re.execute(cx, chars, length, lastIndex, *matches.u.pairs);
@@ -151,7 +151,7 @@ js::ExecuteRegExpLegacy(JSContext *cx, RegExpStatics *res, RegExpObject &reobj,
MatchConduit conduit(&matches);
RegExpRunStatus status =
ExecuteRegExpImpl(cx, res, *shared, reobj, input, chars, length, lastIndex, conduit);
ExecuteRegExpImpl(cx, res, *shared, input, chars, length, lastIndex, conduit);
if (status == RegExpRunStatus_Error)
return false;
@@ -591,7 +591,7 @@ js::ExecuteRegExp(JSContext *cx, HandleObject regexp, HandleString string, Match
/* Steps 8-21. */
size_t lastIndexInt(i);
RegExpRunStatus status =
ExecuteRegExpImpl(cx, res, *re, *reobj, stableInput, chars, length, &lastIndexInt, matches);
ExecuteRegExpImpl(cx, res, *re, stableInput, chars, length, &lastIndexInt, matches);
if (status == RegExpRunStatus_Error)
return RegExpRunStatus_Error;
-1
View File
@@ -332,7 +332,6 @@ DeclMarkerImpl(Object, DebugScopeObject)
DeclMarkerImpl(Object, GlobalObject)
DeclMarkerImpl(Object, JSObject)
DeclMarkerImpl(Object, JSFunction)
DeclMarkerImpl(Object, RegExpObject)
DeclMarkerImpl(Object, ScopeObject)
DeclMarkerImpl(Script, JSScript)
DeclMarkerImpl(Shape, Shape)
-1
View File
@@ -97,7 +97,6 @@ DeclMarker(Object, DebugScopeObject)
DeclMarker(Object, GlobalObject)
DeclMarker(Object, JSObject)
DeclMarker(Object, JSFunction)
DeclMarker(Object, RegExpObject)
DeclMarker(Object, ScopeObject)
DeclMarker(Script, JSScript)
DeclMarker(Shape, Shape)
-3
View File
@@ -674,9 +674,6 @@ Shape::Range::AutoRooter::trace(JSTracer *trc)
void
RegExpStatics::AutoRooter::trace(JSTracer *trc)
{
if (statics->regexp)
MarkObjectRoot(trc, reinterpret_cast<JSObject**>(&statics->regexp),
"RegExpStatics::AutoRooter regexp");
if (statics->matchesInput)
MarkStringRoot(trc, reinterpret_cast<JSString**>(&statics->matchesInput),
"RegExpStatics::AutoRooter matchesInput");
+12
View File
@@ -645,6 +645,18 @@ RegExpCompartment::RegExpCompartment(JSRuntime *rt)
RegExpCompartment::~RegExpCompartment()
{
JS_ASSERT(map_.empty());
/*
* RegExpStatics may have prevented a single RegExpShared from
* being collected during RegExpCompartment::sweep().
*/
if (!inUse_.empty()) {
PendingSet::Enum e(inUse_);
RegExpShared *shared = e.front();
JS_ASSERT(shared->activeUseCount == 0);
js_delete(shared);
e.removeFront();
}
JS_ASSERT(inUse_.empty());
}
+16 -4
View File
@@ -198,22 +198,31 @@ class RegExpShared
class RegExpGuard
{
RegExpShared *re_;
private:
RegExpGuard(const RegExpGuard &) MOZ_DELETE;
void operator=(const RegExpGuard &) MOZ_DELETE;
public:
RegExpGuard() : re_(NULL) {}
RegExpGuard(RegExpShared &re) : re_(&re) {
re_->incRef();
}
~RegExpGuard() { release(); }
public:
void init(RegExpShared &re) {
JS_ASSERT(!re_);
JS_ASSERT(!initialized());
re_ = &re;
re_->incRef();
}
~RegExpGuard() {
if (re_)
void release() {
if (re_) {
re_->decRef();
re_ = NULL;
}
}
bool initialized() const { return !!re_; }
RegExpShared *re() const { JS_ASSERT(initialized()); return re_; }
RegExpShared *operator->() { return re(); }
@@ -225,9 +234,12 @@ class RegExpCompartment
struct Key {
JSAtom *atom;
uint16_t flag;
Key() {}
Key(JSAtom *atom, RegExpFlag flag)
: atom(atom), flag(flag) {}
: atom(atom), flag(flag)
{ }
typedef Key Lookup;
static HashNumber hash(const Lookup &l) {
return DefaultHasher<JSAtom *>::hash(l.atom) ^ (l.flag << 1);
+24 -21
View File
@@ -27,15 +27,6 @@ SizeOfRegExpStaticsData(const JSObject *obj, JSMallocSizeOfFun mallocSizeOf)
return mallocSizeOf(obj->getPrivate());
}
inline
RegExpStatics::RegExpStatics()
: pendingLazyEvaluation(false),
bufferLink(NULL),
copied(false)
{
clear();
}
inline bool
RegExpStatics::createDependent(JSContext *cx, size_t start, size_t end, Value *out)
{
@@ -231,15 +222,20 @@ RegExpStatics::copyTo(RegExpStatics &dst)
if (!pendingLazyEvaluation)
dst.matches.initArrayFrom(matches);
if (regexpGuard.initialized())
dst.regexpGuard.init(*regexpGuard);
else
dst.regexpGuard.release();
dst.matchesInput = matchesInput;
dst.regexp = regexp;
dst.lastIndex = lastIndex;
dst.pendingInput = pendingInput;
dst.flags = flags;
dst.pendingLazyEvaluation = pendingLazyEvaluation;
JS_ASSERT_IF(pendingLazyEvaluation, regexp);
JS_ASSERT_IF(pendingLazyEvaluation, regexpGuard.initialized());
JS_ASSERT_IF(pendingLazyEvaluation, matchesInput);
JS_ASSERT(regexpGuard.initialized() == dst.regexpGuard.initialized());
}
inline void
@@ -261,17 +257,20 @@ RegExpStatics::restore()
inline void
RegExpStatics::updateLazily(JSContext *cx, JSLinearString *input,
RegExpObject *regexp, size_t lastIndex)
RegExpShared *shared, size_t lastIndex)
{
JS_ASSERT(input && regexp);
JS_ASSERT(input && shared);
aboutToWrite();
BarrieredSetPair<JSString, JSLinearString>(cx->compartment,
pendingInput, input,
matchesInput, input);
pendingLazyEvaluation = true;
this->regexp = regexp;
if (regexpGuard.initialized())
regexpGuard.release();
regexpGuard.init(*shared);
this->lastIndex = lastIndex;
pendingLazyEvaluation = true;
}
inline bool
@@ -282,7 +281,7 @@ RegExpStatics::updateFromMatchPairs(JSContext *cx, JSLinearString *input, MatchP
/* Unset all lazy state. */
pendingLazyEvaluation = false;
this->regexp = NULL;
this->regexpGuard.release();
this->lastIndex = size_t(-1);
BarrieredSetPair<JSString, JSLinearString>(cx->compartment,
@@ -301,11 +300,14 @@ inline void
RegExpStatics::clear()
{
aboutToWrite();
flags = RegExpFlag(0);
pendingInput = NULL;
pendingLazyEvaluation = false;
matchesInput = NULL;
matches.forgetArray();
matchesInput = NULL;
regexpGuard.release();
lastIndex = size_t(-1);
pendingInput = NULL;
flags = RegExpFlag(0);
pendingLazyEvaluation = false;
}
inline void
@@ -363,8 +365,9 @@ RegExpStatics::checkInvariants()
{
#ifdef DEBUG
if (pendingLazyEvaluation) {
JS_ASSERT(regexp);
JS_ASSERT(regexpGuard.initialized());
JS_ASSERT(pendingInput);
JS_ASSERT(lastIndex != size_t(-1));
return;
}
+4 -7
View File
@@ -74,7 +74,7 @@ RegExpStatics::executeLazy(JSContext *cx)
if (!pendingLazyEvaluation)
return true;
JS_ASSERT(regexp);
JS_ASSERT(regexpGuard.initialized());
JS_ASSERT(matchesInput);
JS_ASSERT(lastIndex != size_t(-1));
@@ -87,17 +87,14 @@ RegExpStatics::executeLazy(JSContext *cx)
StableCharPtr chars(matchesInput->chars(), length);
/* Execute the full regular expression. */
RegExpGuard shared;
if (!regexp->getShared(cx, &shared))
return false;
RegExpRunStatus status = shared->execute(cx, chars, length, &this->lastIndex, this->matches);
RegExpRunStatus status = regexpGuard->execute(cx, chars, length, &this->lastIndex, this->matches);
if (status == RegExpRunStatus_Error)
return false;
/* Unset lazy state and remove rooted values that now have no use. */
pendingLazyEvaluation = false;
regexp = NULL;
regexpGuard.release();
lastIndex = size_t(-1);
return true;
}
+8 -10
View File
@@ -15,6 +15,7 @@
#include "js/Vector.h"
#include "vm/MatchPairs.h"
#include "vm/RegExpObject.h"
namespace js {
@@ -25,7 +26,7 @@ class RegExpStatics
HeapPtr<JSLinearString> matchesInput;
/* The previous RegExp input, used to resolve lazy state. */
HeapPtr<RegExpObject> regexp;
RegExpGuard regexpGuard; /* Strong reference to RegExpShared. */
size_t lastIndex;
/* The latest RegExp input, set before execution. */
@@ -33,7 +34,7 @@ class RegExpStatics
RegExpFlag flags;
/*
* If true, |matchesInput|, |regexp|, and |lastIndex| may be used
* If true, |matchesInput|, |regexpGuard|, and |lastIndex| may be used
* to replay the last executed RegExp, and |matches| is invalid.
*/
bool pendingLazyEvaluation;
@@ -42,6 +43,10 @@ class RegExpStatics
RegExpStatics *bufferLink;
bool copied;
public:
RegExpStatics() : bufferLink(NULL), copied(false) { clear(); }
static JSObject *create(JSContext *cx, GlobalObject *parent);
private:
bool executeLazy(JSContext *cx);
@@ -78,14 +83,9 @@ class RegExpStatics
friend class PreserveRegExpStatics;
public:
inline RegExpStatics();
static JSObject *create(JSContext *cx, GlobalObject *parent);
/* Mutators. */
inline void updateLazily(JSContext *cx, JSLinearString *input,
RegExpObject *regexp, size_t lastIndex);
RegExpShared *shared, size_t lastIndex);
inline bool updateFromMatchPairs(JSContext *cx, JSLinearString *input, MatchPairs &newPairs);
inline void setMultiline(JSContext *cx, bool enabled);
@@ -118,8 +118,6 @@ class RegExpStatics
}
void mark(JSTracer *trc) {
if (regexp)
gc::MarkObject(trc, &regexp, "res->regexp");
if (pendingInput)
MarkString(trc, &pendingInput, "res->pendingInput");
if (matchesInput)