Bug 510036 - Convert LabelMap to HashMap<> and Allocator, r=gal.

--HG--
extra : rebase_source : 4f1385922085fe086084c418aa22dcc4cc4c1961
This commit is contained in:
Edwin Smith 2009-08-04 13:56:48 -04:00
parent cf3e9a04dd
commit b0172c9f0a
6 changed files with 48 additions and 51 deletions

View File

@ -3093,7 +3093,7 @@ class RegExpNativeCompiler {
JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx);
Assembler *assm = tm->reAssembler;
Fragmento* fragmento = tm->reFragmento;
VMAllocator *alloc = tm->reAllocator;
VMAllocator& alloc = *tm->reAllocator;
re->source->getCharsAndLength(re_chars, re_length);
/*
@ -3108,7 +3108,7 @@ class RegExpNativeCompiler {
this->cx = cx;
/* At this point we have an empty fragment. */
LirBuffer* lirbuf = fragment->lirbuf;
if (alloc->outOfMemory())
if (alloc.outOfMemory())
goto fail;
/* FIXME Use bug 463260 smart pointer when available. */
lir = lirBufWriter = new (&gc) LirBufWriter(lirbuf);
@ -3117,7 +3117,7 @@ class RegExpNativeCompiler {
#ifdef NJ_VERBOSE
debug_only_stmt(
if (js_LogController.lcbits & LC_TMRegexp) {
lir = new (&gc) VerboseWriter(*alloc, lir, lirbuf->names,
lir = new (&gc) VerboseWriter(alloc, lir, lirbuf->names,
&js_LogController);
}
)
@ -3146,9 +3146,9 @@ class RegExpNativeCompiler {
guard = insertGuard(re_chars, re_length);
if (alloc->outOfMemory())
if (alloc.outOfMemory())
goto fail;
::compile(fragmento, assm, fragment, *alloc);
::compile(fragmento, assm, fragment, alloc);
if (assm->error() != nanojit::None) {
oom = assm->error() == nanojit::OutOMem;
goto fail;
@ -3161,16 +3161,18 @@ class RegExpNativeCompiler {
#endif
return JS_TRUE;
fail:
if (alloc->outOfMemory() || oom ||
if (alloc.outOfMemory() || oom ||
js_OverfullFragmento(tm, fragmento)) {
fragmento->clearFrags();
#ifdef DEBUG
fragmento->labels->clear();
delete lirbuf->names;
lirbuf->names = new (&gc) LirNameMap(&gc, *alloc, fragmento->labels);
delete lirbuf->names;
#endif
tm->reCodeAlloc->sweep();
alloc->reset();
alloc.reset();
#ifdef DEBUG
fragmento->labels = new (alloc) LabelMap(alloc, &js_LogController);
lirbuf->names = new (&gc) LirNameMap(&gc, alloc, fragmento->labels);
#endif
lirbuf->clear();
} else {
if (!guard) insertGuard(re_chars, re_length);

View File

@ -3348,10 +3348,6 @@ FlushJITCache(JSContext* cx)
}
fragmento->clearFrags();
#ifdef DEBUG
JS_ASSERT(fragmento->labels);
fragmento->labels->clear();
#endif
for (size_t i = 0; i < FRAGMENT_TABLE_SIZE; ++i) {
VMFragment* f = tm->vmfragments[i];
@ -3370,10 +3366,19 @@ FlushJITCache(JSContext* cx)
#ifdef DEBUG
delete tm->lirbuf->names;
tm->lirbuf->names = new (&gc) LirNameMap(&gc, *tm->allocator, tm->fragmento->labels);
#endif
tm->allocator->reset();
tm->codeAlloc->sweep();
#ifdef DEBUG
JS_ASSERT(fragmento);
JS_ASSERT(fragmento->labels);
Allocator& alloc = *tm->allocator;
fragmento->labels = new (alloc) LabelMap(alloc, &js_LogController);
tm->lirbuf->names = new (&gc) LirNameMap(&gc, alloc, tm->fragmento->labels);
#endif
tm->lirbuf->clear();
tm->needFlush = JS_FALSE;
}
@ -6411,21 +6416,23 @@ js_InitJIT(JSTraceMonitor *tm)
if (!tm->allocator)
tm->allocator = new VMAllocator();
Allocator& alloc = *tm->allocator;
if (!tm->codeAlloc)
tm->codeAlloc = new CodeAlloc();
if (!tm->assembler)
tm->assembler = new (&gc) Assembler(*tm->codeAlloc, *tm->allocator, core,
tm->assembler = new (&gc) Assembler(*tm->codeAlloc, alloc, core,
&js_LogController);
if (!tm->fragmento) {
JS_ASSERT(!tm->reservedDoublePool);
Fragmento* fragmento = new (&gc) Fragmento(core, &js_LogController, 32, tm->codeAlloc);
verbose_only(fragmento->labels = new (&gc) LabelMap(core, *tm->allocator);)
verbose_only(fragmento->labels = new (alloc) LabelMap(alloc, &js_LogController);)
tm->fragmento = fragmento;
tm->lirbuf = new (&gc) LirBuffer(*tm->allocator);
tm->lirbuf = new (&gc) LirBuffer(alloc);
#ifdef DEBUG
tm->lirbuf->names = new (&gc) LirNameMap(&gc, *tm->allocator, tm->fragmento->labels);
tm->lirbuf->names = new (&gc) LirNameMap(&gc, alloc, tm->fragmento->labels);
#endif
for (size_t i = 0; i < MONITOR_N_GLOBAL_STATES; ++i) {
tm->globalStates[i].globalShape = -1;
@ -6439,20 +6446,22 @@ js_InitJIT(JSTraceMonitor *tm)
if (!tm->reAllocator)
tm->reAllocator = new VMAllocator();
Allocator& reAlloc = *tm->reAllocator;
if (!tm->reCodeAlloc)
tm->reCodeAlloc = new CodeAlloc();
if (!tm->reAssembler)
tm->reAssembler = new (&gc) Assembler(*tm->reCodeAlloc, *tm->reAllocator, core,
tm->reAssembler = new (&gc) Assembler(*tm->reCodeAlloc, reAlloc, core,
&js_LogController);
if (!tm->reFragmento) {
Fragmento* fragmento = new (&gc) Fragmento(core, &js_LogController, 32, tm->reCodeAlloc);
verbose_only(fragmento->labels = new (&gc) LabelMap(core, *tm->reAllocator);)
verbose_only(fragmento->labels = new (reAlloc) LabelMap(reAlloc, &js_LogController);)
tm->reFragmento = fragmento;
tm->reLirBuf = new (&gc) LirBuffer(*tm->reAllocator);
tm->reLirBuf = new (&gc) LirBuffer(reAlloc);
#ifdef DEBUG
tm->reLirBuf->names = new (&gc) LirNameMap(&gc, *tm->reAllocator, fragmento->labels);
tm->reLirBuf->names = new (&gc) LirNameMap(&gc, reAlloc, fragmento->labels);
#endif
}
#if !defined XP_WIN
@ -6481,7 +6490,6 @@ js_FinishJIT(JSTraceMonitor *tm)
#endif
if (tm->fragmento != NULL) {
JS_ASSERT(tm->reservedDoublePool);
verbose_only(delete tm->fragmento->labels;)
#ifdef DEBUG
delete tm->lirbuf->names;
tm->lirbuf->names = NULL;
@ -6512,7 +6520,6 @@ js_FinishJIT(JSTraceMonitor *tm)
}
if (tm->reFragmento != NULL) {
delete tm->reLirBuf;
verbose_only(delete tm->reFragmento->labels;)
delete tm->reFragmento;
delete tm->reAllocator;
delete tm->reAssembler;

View File

@ -167,6 +167,7 @@ namespace nanojit
void printActivationState();
StringList* _outputCache;
LabelMap* _labelMap;
// Log controller object. Contains what-stuff-should-we-print
// bits, and a sink function for debug printing

View File

@ -99,7 +99,7 @@ namespace nanojit
verbose_only( DWB(BlockHist*) enterCounts; )
verbose_only( DWB(BlockHist*) mergeCounts; )
verbose_only( DWB(LabelMap*) labels; )
verbose_only( LabelMap* labels; )
#ifdef AVMPLUS_VERBOSE
void drawTrees(char *fileName);

View File

@ -2199,21 +2199,10 @@ namespace nanojit
#endif /* FEATURE_NANOJIT */
#if defined(NJ_VERBOSE)
LabelMap::LabelMap(AvmCore *core, nanojit::Allocator& a)
: allocator(a), names(core->gc), addrs(core->config.verbose_addrs), end(buf)
LabelMap::LabelMap(nanojit::Allocator& a, LogControl *logc)
: allocator(a), names(a), logc(logc), end(buf)
{}
LabelMap::~LabelMap()
{
clear();
}
void LabelMap::clear()
{
// don't free entries since they're owned by Allocator
names.clear();
}
void LabelMap::add(const void *p, size_t size, size_t align, const char *name)
{
if (!this || names.containsKey(p))
@ -2227,14 +2216,14 @@ namespace nanojit
const char *LabelMap::format(const void *p)
{
char b[200];
int i = names.findNear(p);
if (i >= 0) {
const void *start = names.keyAt(i);
Entry *e = names.at(i);
const void *start = names.findNear(p);
if (start != NULL) {
Entry *e = names.get(start);
const void *end = (const char*)start + e->size;
const char *name = e->name;
if (p == start) {
if (addrs)
if (!(logc->lcbits & LC_NoCodeAddrs))
VMPI_sprintf(b,"%p %s",p,name);
else
VMPI_strcpy(b, name);
@ -2242,7 +2231,7 @@ namespace nanojit
}
else if (p > start && p < end) {
int32_t d = int32_t(intptr_t(p)-intptr_t(start)) >> e->align;
if (addrs)
if (!(logc->lcbits & LC_NoCodeAddrs))
VMPI_sprintf(b, "%p %s+%d", p, name, d);
else
VMPI_sprintf(b,"%s+%d", name, d);

View File

@ -861,7 +861,7 @@ namespace nanojit
/**
* map address ranges to meaningful names.
*/
class LabelMap MMGC_SUBCLASS_DECL
class LabelMap
{
Allocator& allocator;
class Entry
@ -871,17 +871,15 @@ namespace nanojit
char* name;
size_t size:29, align:3;
};
avmplus::SortedMap<const void*, Entry*, avmplus::LIST_NonGCObjects> names;
bool addrs, pad[3];
TreeMap<const void*, Entry*> names;
LogControl *logc;
char buf[1000], *end;
void formatAddr(const void *p, char *buf);
public:
LabelMap(avmplus::AvmCore *, Allocator& allocator);
~LabelMap();
LabelMap(Allocator& allocator, LogControl* logc);
void add(const void *p, size_t size, size_t align, const char *name);
const char *dup(const char *);
const char *format(const void *p);
void clear();
};
class LirNameMap MMGC_SUBCLASS_DECL