From ef445b445bc2cdded10eebfd6e102f7c41a58dc3 Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Fri, 22 Aug 2008 16:37:37 -0700 Subject: [PATCH] Allocate nanojit code cache incrementally (bug 443111). --- js/src/jstracer.cpp | 1 - js/src/nanojit/Fragmento.cpp | 13 +++++++++++-- js/src/nanojit/Fragmento.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/js/src/jstracer.cpp b/js/src/jstracer.cpp index a15eae45a425..d3e05da03322 100644 --- a/js/src/jstracer.cpp +++ b/js/src/jstracer.cpp @@ -2211,7 +2211,6 @@ js_InitJIT(JSTraceMonitor *tm) Fragmento* fragmento = new (&gc) Fragmento(core, 24); verbose_only(fragmento->labels = new (&gc) LabelMap(core, NULL);) fragmento->assm()->setCallTable(builtins); - fragmento->pageFree(fragmento->pageAlloc()); // FIXME: prime page cache tm->fragmento = fragmento; tm->globalSlots = new (&gc) SlotList(); tm->globalTypeMap = new (&gc) TypeMap(); diff --git a/js/src/nanojit/Fragmento.cpp b/js/src/nanojit/Fragmento.cpp index 8de38cea2ee7..bfb27e25ec8b 100644 --- a/js/src/nanojit/Fragmento.cpp +++ b/js/src/nanojit/Fragmento.cpp @@ -65,6 +65,7 @@ namespace nanojit GC *gc = core->GetGC(); _frags = new (gc) FragmentMap(gc, 128); _assm = new (gc) nanojit::Assembler(this); + _pageGrowth = 1; verbose_only( enterCounts = new (gc) BlockHist(gc); ) verbose_only( mergeCounts = new (gc) BlockHist(gc); ) } @@ -101,8 +102,11 @@ namespace nanojit Page* Fragmento::pageAlloc() { NanoAssert(sizeof(Page) == NJ_PAGE_SIZE); - if (!_pageList) - pagesGrow(_max_pages); // try to get more mem + if (!_pageList) { + pagesGrow(_pageGrowth); // try to get more mem + if ((_pageGrowth << 1) < _max_pages) + _pageGrowth <<= 1; + } Page *page = _pageList; if (page) { @@ -132,6 +136,11 @@ namespace nanojit Page* memory = 0; if (_stats.pages < _max_pages) { + // make sure we don't grow beyond _max_pages + if (_stats.pages + count > _max_pages) + count = _max_pages - _stats.pages; + if (count < 0) + count = 0; // @todo nastiness that needs a fix'n _gcHeap = _core->GetGC()->GetGCHeap(); NanoAssert(int32_t(NJ_PAGE_SIZE)<=_gcHeap->kNativePageSize); diff --git a/js/src/nanojit/Fragmento.h b/js/src/nanojit/Fragmento.h index d0e0c3c54355..cab2f6e2acc0 100644 --- a/js/src/nanojit/Fragmento.h +++ b/js/src/nanojit/Fragmento.h @@ -138,6 +138,7 @@ namespace nanojit DWB(Assembler*) _assm; DWB(FragmentMap*) _frags; /* map from ip -> Fragment ptr */ Page* _pageList; + uint32_t _pageGrowth; /* unmanaged mem */ AllocList _allocList;