Bug 878293 - Remove Parser::init, cleanup parse maps pool, r=waldo.

This commit is contained in:
Brian Hackett 2013-06-04 15:53:29 -06:00
parent 3f6e332136
commit dd12c2726c
14 changed files with 40 additions and 106 deletions

View File

@ -22,7 +22,7 @@ template <typename K, typename V, size_t InlineElems>
class InlineMap
{
public:
typedef HashMap<K, V, DefaultHasher<K>, TempAllocPolicy> WordMap;
typedef HashMap<K, V, DefaultHasher<K>, SystemAllocPolicy> WordMap;
struct InlineElem
{
@ -79,8 +79,8 @@ class InlineMap
}
public:
explicit InlineMap(JSContext *cx)
: inlNext(0), inlCount(0), map(cx) {
explicit InlineMap()
: inlNext(0), inlCount(0) {
checkStaticInvariants(); /* Force the template to instantiate the static invariants. */
}

View File

@ -131,8 +131,6 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain,
Parser<FullParseHandler> parser(cx, options, chars, length, /* foldConstants = */ true,
options.canLazilyParse ? &syntaxParser.ref() : NULL, NULL);
if (!parser.init())
return NULL;
parser.sct = sct;
GlobalSharedContext globalsc(cx, scopeChain, StrictModeFromContext(cx));
@ -329,8 +327,6 @@ frontend::CompileLazyFunction(JSContext *cx, HandleFunction fun, LazyScript *laz
Parser<FullParseHandler> parser(cx, options, chars, length,
/* foldConstants = */ true, NULL, lazy);
if (!parser.init())
return false;
RootedObject enclosingScope(cx, lazy->parent()->function());
@ -402,8 +398,6 @@ frontend::CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, CompileO
Parser<FullParseHandler> parser(cx, options, chars, length, /* foldConstants = */ true,
options.canLazilyParse ? &syntaxParser.ref() : NULL, NULL);
if (!parser.init())
return false;
parser.sct = &sct;
JS_ASSERT(fun);

View File

@ -87,7 +87,7 @@ AtomThingMapPtr<Map>::ensureMap(JSContext *cx)
{
if (map_)
return true;
map_ = cx->parseMapPool().acquire<Map>();
map_ = cx->runtime->parseMapPool.acquire<Map>();
return !!map_;
}
@ -97,7 +97,7 @@ AtomThingMapPtr<Map>::releaseMap(JSContext *cx)
{
if (!map_)
return;
cx->parseMapPool().release(map_);
cx->runtime->parseMapPool.release(map_);
map_ = NULL;
}
@ -105,7 +105,7 @@ template <typename ParseHandler>
inline bool
AtomDecls<ParseHandler>::init()
{
map = cx->parseMapPool().acquire<AtomDefnListMap>();
map = cx->runtime->parseMapPool.acquire<AtomDefnListMap>();
return map;
}
@ -114,7 +114,7 @@ inline
AtomDecls<ParseHandler>::~AtomDecls()
{
if (map)
cx->parseMapPool().release(map);
cx->runtime->parseMapPool.release(map);
}
} /* namespace frontend */

View File

@ -50,7 +50,7 @@ ParseMapPool::allocateFresh()
if (!all.reserve(newAllLength) || !recyclable.reserve(newAllLength))
return NULL;
AtomMapT *map = cx->new_<AtomMapT>(cx);
AtomMapT *map = js_new<AtomMapT>();
if (!map)
return NULL;

View File

@ -45,7 +45,6 @@ class ParseMapPool
RecyclableMaps all;
RecyclableMaps recyclable;
JSContext *cx;
void checkInvariants();
@ -79,8 +78,6 @@ class ParseMapPool
}
public:
explicit ParseMapPool(JSContext *cx) : cx(cx) {}
~ParseMapPool() {
purgeAll();
}

View File

@ -422,24 +422,15 @@ Parser<ParseHandler>::Parser(JSContext *cx, const CompileOptions &options,
// XXX bug 678037 always disable syntax parsing for now.
handler.disableSyntaxParser();
cx->activeCompilations++;
cx->runtime->activeCompilations++;
// The Mozilla specific 'strict' option adds extra warnings which are not
// generated if functions are parsed lazily. Note that the standard
// "use strict" does not inhibit lazy parsing.
if (context->hasStrictOption())
handler.disableSyntaxParser();
}
template <typename ParseHandler>
bool
Parser<ParseHandler>::init()
{
if (!context->ensureParseMapPool())
return false;
tempPoolMark = context->tempLifoAlloc().mark();
return true;
tempPoolMark = cx->tempLifoAlloc().mark();
}
template <typename ParseHandler>
@ -447,7 +438,7 @@ Parser<ParseHandler>::~Parser()
{
JSContext *cx = context;
cx->tempLifoAlloc().release(tempPoolMark);
cx->activeCompilations--;
cx->runtime->activeCompilations--;
/*
* The parser can allocate enormous amounts of memory for large functions.
@ -6720,7 +6711,7 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
* A map from property names we've seen thus far to a mask of property
* assignment types, stored and retrieved with ALE_SET_INDEX/ALE_INDEX.
*/
AtomIndexMap seen(context);
AtomIndexMap seen;
enum AssignmentType {
GET = 0x1,

View File

@ -331,14 +331,6 @@ struct Parser : private AutoGCRooter, public StrictModeGetter
friend void AutoGCRooter::trace(JSTracer *trc);
/*
* Initialize a parser. The compiler owns the arena pool "tops-of-stack"
* space above the current JSContext.tempLifoAlloc mark. This means you
* cannot allocate from tempLifoAlloc and save the pointer beyond the next
* Parser destructor invocation.
*/
bool init();
const char *getFilename() const { return tokenStream.getFilename(); }
JSVersion versionNumber() const { return tokenStream.versionNumber(); }

View File

@ -879,6 +879,7 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
#endif
mathCache_(NULL),
dtoaState(NULL),
activeCompilations(0),
trustedPrincipals_(NULL),
wrapObjectCallback(TransparentObjectWrapper),
sameCompartmentWrapObjectCallback(NULL),
@ -5439,19 +5440,16 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *objArg, const char *utf8, siz
options.setCompileAndGo(false);
Parser<frontend::FullParseHandler> parser(cx, options, chars, length,
/* foldConstants = */ true, NULL, NULL);
if (parser.init()) {
older = JS_SetErrorReporter(cx, NULL);
if (!parser.parse(obj) &&
parser.tokenStream.isUnexpectedEOF()) {
/*
* We ran into an error. If it was because we ran out of
* source, we return false so our caller knows to try to
* collect more buffered source.
*/
result = JS_FALSE;
}
JS_SetErrorReporter(cx, older);
older = JS_SetErrorReporter(cx, NULL);
if (!parser.parse(obj) && parser.tokenStream.isUnexpectedEOF()) {
/*
* We ran into an error. If it was because we ran out of
* source, we return false so our caller knows to try to
* collect more buffered source.
*/
result = JS_FALSE;
}
JS_SetErrorReporter(cx, older);
}
js_free(chars);
JS_RestoreExceptionState(cx, exnState);

View File

@ -1132,7 +1132,6 @@ JSContext::JSContext(JSRuntime *rt)
savedFrameChains_(),
defaultCompartmentObject_(NULL),
stack(thisDuringConstruction()),
parseMapPool_(NULL),
cycleDetectorSet(thisDuringConstruction()),
errorReporter(NULL),
operationCallback(NULL),
@ -1147,12 +1146,12 @@ JSContext::JSContext(JSRuntime *rt)
#ifdef MOZ_TRACE_JSCALLS
functionCallback(NULL),
#endif
innermostGenerator_(NULL),
#ifdef DEBUG
stackIterAssertionEnabled(true),
#endif
activeCompilations(0)
innermostGenerator_(NULL)
{
#ifdef DEBUG
stackIterAssertionEnabled = true;
#endif
JS_ASSERT(static_cast<ContextFriendFields*>(this) ==
ContextFriendFields::get(this));
@ -1167,9 +1166,6 @@ JSContext::JSContext(JSRuntime *rt)
JSContext::~JSContext()
{
/* Free the stuff hanging off of cx. */
if (parseMapPool_)
js_delete(parseMapPool_);
JS_ASSERT(!resolvingList);
}
@ -1358,15 +1354,6 @@ JSRuntime::onOutOfMemory(void *p, size_t nbytes, JSContext *cx)
return NULL;
}
void
JSContext::purge()
{
if (!activeCompilations) {
js_delete(parseMapPool_);
parseMapPool_ = NULL;
}
}
static bool
ComputeIsJITBroken()
{

View File

@ -29,6 +29,7 @@
#include "prmjtime.h"
#include "ds/LifoAlloc.h"
#include "frontend/ParseMaps.h"
#include "gc/Nursery.h"
#include "gc/Statistics.h"
#include "gc/StoreBuffer.h"
@ -1257,6 +1258,16 @@ struct JSRuntime : public JS::shadow::Runtime,
js::ConservativeGCData conservativeGC;
/* Pool of maps used during parse/emit. */
js::frontend::ParseMapPool parseMapPool;
/*
* Count of currently active compilations.
* When there are compilations active for the context, the GC must not
* purge the ParseMapPool.
*/
unsigned activeCompilations;
private:
JSPrincipals *trustedPrincipals_;
public:
@ -1601,11 +1612,6 @@ struct JSContext : js::ContextFriendFields,
/* Wrap cx->exception for the current compartment. */
void wrapPendingException();
private:
/* Lazily initialized pool of maps used during parse/emit. */
js::frontend::ParseMapPool *parseMapPool_;
public:
/* State for object and array toSource conversion. */
js::ObjectSet cycleDetectorSet;
@ -1622,13 +1628,6 @@ struct JSContext : js::ContextFriendFields,
inline js::RegExpStatics *regExpStatics();
public:
js::frontend::ParseMapPool &parseMapPool() {
JS_ASSERT(parseMapPool_);
return *parseMapPool_;
}
inline bool ensureParseMapPool();
/*
* The default script compilation version can be set iff there is no code running.
* This typically occurs via the JSAPI right after a context is constructed.
@ -1750,8 +1749,6 @@ struct JSContext : js::ContextFriendFields,
js_ReportAllocationOverflow(this);
}
void purge();
bool isExceptionPending() {
return throwing;
}
@ -1778,13 +1775,6 @@ struct JSContext : js::ContextFriendFields,
bool stackIterAssertionEnabled;
#endif
/*
* Count of currently active compilations.
* When there are compilations active for the context, the GC must not
* purge the ParseMapPool.
*/
unsigned activeCompilations;
/*
* See JS_SetTrustedPrincipals in jsapi.h.
* Note: !cx->compartment is treated as trusted.

View File

@ -520,15 +520,6 @@ JSContext::setPendingException(js::Value v) {
js::assertSameCompartment(this, v);
}
inline bool
JSContext::ensureParseMapPool()
{
if (parseMapPool_)
return true;
parseMapPool_ = js_new<js::frontend::ParseMapPool>(this);
return parseMapPool_;
}
inline js::PropertyTree&
JSContext::propertyTree()
{

View File

@ -2577,8 +2577,8 @@ PurgeRuntime(JSRuntime *rt)
rt->sourceDataCache.purge();
rt->evalCache.clear();
for (ContextIter acx(rt); !acx.done(); acx.next())
acx->purge();
if (!rt->activeCompilations)
rt->parseMapPool.purgeAll();
}
static bool

View File

@ -3072,8 +3072,6 @@ reflect_parse(JSContext *cx, uint32_t argc, jsval *vp)
options.setCanLazilyParse(false);
Parser<FullParseHandler> parser(cx, options, chars.get(), length,
/* foldConstants = */ false, NULL, NULL);
if (!parser.init())
return JS_FALSE;
serialize.setParser(&parser);

View File

@ -3178,8 +3178,6 @@ Parse(JSContext *cx, unsigned argc, jsval *vp)
JS_GetStringCharsZ(cx, scriptContents),
JS_GetStringLength(scriptContents),
/* foldConstants = */ true, NULL, NULL);
if (!parser.init())
return false;
ParseNode *pn = parser.parse(NULL);
if (!pn)
@ -3218,8 +3216,6 @@ SyntaxParse(JSContext *cx, unsigned argc, jsval *vp)
const jschar *chars = JS_GetStringCharsZ(cx, scriptContents);
size_t length = JS_GetStringLength(scriptContents);
Parser<frontend::SyntaxParseHandler> parser(cx, options, chars, length, false, NULL, NULL);
if (!parser.init())
return false;
bool succeeded = parser.parse(NULL);
if (cx->isExceptionPending())