From 76b8fb7891354343d10cc2957a9cee6010df4fd9 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Fri, 31 Aug 2012 15:01:33 -0700 Subject: [PATCH] Bug 787246 - rm OffTheBooks/Foreground/UnwantedForeground gunk (r=billm) --- js/jsd/jshash.cpp | 8 +- js/public/Utility.h | 226 +++++---------------- js/src/Makefile.in | 31 --- js/src/assembler/jit/ExecutableAllocator.h | 22 +- js/src/builtin/MapObject.cpp | 8 +- js/src/ctypes/CTypes.cpp | 28 +-- js/src/ctypes/CTypes.h | 29 +-- js/src/ds/LifoAlloc.h | 2 +- js/src/frontend/BytecodeEmitter.cpp | 12 +- js/src/frontend/FoldConstants.cpp | 2 +- js/src/frontend/ParseMaps.cpp | 2 +- js/src/frontend/Parser-inl.h | 4 +- js/src/frontend/Parser.h | 2 +- js/src/frontend/TokenStream.cpp | 22 +- js/src/jsanalyze.cpp | 14 +- js/src/jsapi.cpp | 46 ++--- js/src/jsapi.h | 12 +- js/src/jsarray.cpp | 10 +- js/src/jsatom.cpp | 4 +- js/src/jsclone.cpp | 2 +- js/src/jscntxt.cpp | 62 +++--- js/src/jscntxt.h | 46 ++--- js/src/jscntxtinlines.h | 4 +- js/src/jscompartment.cpp | 6 +- js/src/jsdbgapi.cpp | 14 +- js/src/jsdhash.cpp | 12 +- js/src/jsdtoa.cpp | 10 +- js/src/jsdtoa.h | 2 +- js/src/jsexn.cpp | 20 +- js/src/jsgc.cpp | 10 +- js/src/jsgc.h | 4 +- js/src/jsinfer.cpp | 22 +- js/src/jsiter.cpp | 2 +- js/src/jsnum.cpp | 20 +- js/src/jsobj.cpp | 12 +- js/src/jsopcode.cpp | 43 ++-- js/src/jsprf.cpp | 20 +- js/src/jspropertytree.cpp | 6 +- js/src/jsreflect.cpp | 2 +- js/src/jsscope.cpp | 4 +- js/src/jsscope.h | 2 +- js/src/jsscript.cpp | 46 ++--- js/src/jsstr.cpp | 20 +- js/src/jstypedarray.cpp | 4 +- js/src/jsutil.cpp | 4 +- js/src/jsweakmap.cpp | 2 +- js/src/jsxml.cpp | 22 +- js/src/methodjit/Compiler.cpp | 37 ++-- js/src/methodjit/FrameState.cpp | 14 +- js/src/methodjit/ImmutableSync.cpp | 4 +- js/src/methodjit/LoopState.cpp | 2 +- js/src/methodjit/MethodJIT.cpp | 2 +- js/src/methodjit/PolyIC.cpp | 2 +- js/src/methodjit/PolyIC.h | 6 +- js/src/perf/pm_linux.cpp | 4 +- js/src/shell/jsheaptools.cpp | 2 +- js/src/shell/jsoptparse.cpp | 19 +- js/src/vm/Debugger.cpp | 2 +- js/src/vm/GlobalObject.cpp | 4 +- js/src/vm/RegExpObject.cpp | 2 +- js/src/vm/RegExpObject.h | 8 +- js/src/vm/SPSProfiler.cpp | 12 +- js/src/vm/String.cpp | 2 +- js/src/vm/StringBuffer.cpp | 4 +- js/src/vm/Xdr.cpp | 4 +- js/src/yarr/RegExpJitTables.h | 14 +- js/src/yarr/YarrInterpreter.cpp | 6 +- js/src/yarr/YarrPattern.cpp | 12 +- js/src/yarr/YarrPattern.h | 8 +- js/src/yarr/wtfbridge.h | 6 +- 70 files changed, 444 insertions(+), 639 deletions(-) diff --git a/js/jsd/jshash.cpp b/js/jsd/jshash.cpp index dbd7de3a469e..6ae4e549ea34 100644 --- a/js/jsd/jshash.cpp +++ b/js/jsd/jshash.cpp @@ -34,26 +34,26 @@ using namespace js; static void * DefaultAllocTable(void *pool, size_t size) { - return OffTheBooks::malloc_(size); + return js_malloc(size); } static void DefaultFreeTable(void *pool, void *item, size_t size) { - UnwantedForeground::free_(item); + js_free(item); } static JSHashEntry * DefaultAllocEntry(void *pool, const void *key) { - return (JSHashEntry*) OffTheBooks::malloc_(sizeof(JSHashEntry)); + return (JSHashEntry*) js_malloc(sizeof(JSHashEntry)); } static void DefaultFreeEntry(void *pool, JSHashEntry *he, unsigned flag) { if (flag == HT_FREE_ENTRY) - UnwantedForeground::free_(he); + js_free(he); } static JSHashAllocOps defaultHashAllocOps = { diff --git a/js/public/Utility.h b/js/public/Utility.h index 5c845e1183a8..fb319db02861 100644 --- a/js/public/Utility.h +++ b/js/public/Utility.h @@ -146,11 +146,6 @@ PrintBacktrace() # define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0) # endif /* DEBUG */ -/* - * SpiderMonkey code should not be calling these allocation functions directly. - * Instead, all calls should go through JSRuntime, JSContext or OffTheBooks. - * However, js_free() can be called directly. - */ static JS_INLINE void* js_malloc(size_t bytes) { JS_OOM_POSSIBLY_FAIL(); @@ -381,82 +376,45 @@ JS_END_EXTERN_C #include /* - * User guide to memory management within SpiderMonkey: + * Low-level memory management in SpiderMonkey: * - * Quick tips: + * ** Do not use the standard malloc/free/realloc: SpiderMonkey allows these + * to be redefined (via JS_USE_CUSTOM_ALLOCATOR) and Gecko even #define's + * these symbols. * - * Allocation: - * - Prefer to allocate using JSContext: - * cx->{malloc_,realloc_,calloc_,new_,array_new} + * ** Do not use the builtin C++ operator new and delete: these throw on + * error and we cannot override them not to. * - * - If no JSContext is available, use a JSRuntime: - * rt->{malloc_,realloc_,calloc_,new_,array_new} + * Allocation: * - * - As a last resort, use unaccounted allocation ("OffTheBooks"): - * js::OffTheBooks::{malloc_,realloc_,calloc_,new_,array_new} + * - If the lifetime of the allocation is tied to the lifetime of a GC-thing + * (that is, finalizing the GC-thing will free the allocation), call one of + * the following functions: * - * Deallocation: - * - When the deallocation occurs on a slow path, use: - * Foreground::{free_,delete_,array_delete} + * JSContext::{malloc_,realloc_,calloc_,new_} + * JSRuntime::{malloc_,realloc_,calloc_,new_} * - * - Otherwise deallocate on a background thread using a JSContext: - * cx->{free_,delete_,array_delete} + * These functions accumulate the number of bytes allocated which is used as + * part of the GC-triggering heuristic. * - * - If no JSContext is available, use a JSRuntime: - * rt->{free_,delete_,array_delete} + * The difference between the JSContext and JSRuntime versions is that the + * cx version reports an out-of-memory error on OOM. (This follows from the + * general SpiderMonkey idiom that a JSContext-taking function reports its + * own errors.) * - * - As a last resort, use UnwantedForeground deallocation: - * js::UnwantedForeground::{free_,delete_,array_delete} + * - Otherwise, use js_malloc/js_realloc/js_calloc/js_free/js_new * - * General tips: + * Deallocation: * - * - Mixing and matching these allocators is allowed (you may free memory - * allocated by any allocator, with any deallocator). + * - Ordinarily, use js_free/js_delete. * - * - Never, ever use normal C/C++ memory management: - * malloc, free, new, new[], delete, operator new, etc. + * - For deallocations during GC finalization, use one of the following + * operations on the FreeOp provided to the finalizer: * - * - Never, ever use low-level SpiderMonkey allocators: - * js_malloc(), js_free(), js_calloc(), js_realloc() - * Their use is reserved for the other memory managers. + * FreeOp::{free_,delete_} * - * - Classes which have private constructors or destructors should have - * JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR added to their - * declaration. - * - * Details: - * - * Using vanilla new/new[] is unsafe in SpiderMonkey because they throw on - * failure instead of returning NULL, which is what SpiderMonkey expects. - * (Even overriding them is unsafe, as the system's C++ runtime library may - * throw, which we do not support. We also can't just use the 'nothrow' - * variant of new/new[], because we want to mediate *all* allocations - * within SpiderMonkey, to satisfy any embedders using - * JS_USE_CUSTOM_ALLOCATOR.) - * - * JSContexts and JSRuntimes keep track of memory allocated, and use this - * accounting to schedule GC. OffTheBooks does not. We'd like to remove - * OffTheBooks allocations as much as possible (bug 636558). - * - * On allocation failure, a JSContext correctly reports an error, which a - * JSRuntime and OffTheBooks does not. - * - * A JSContext deallocates in a background thread. A JSRuntime might - * deallocate in the background in the future, but does not now. Foreground - * deallocation is preferable on slow paths. UnwantedForeground deallocations - * occur where we have no JSContext or JSRuntime, and the deallocation is not - * on a slow path. We want to remove UnwantedForeground deallocations (bug - * 636561). - * - * JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR makes the allocation - * classes friends with your class, giving them access to private - * constructors and destructors. - * - * |make check| does a source level check on the number of uses OffTheBooks, - * UnwantedForeground, js_malloc, js_free etc, to prevent regressions. If you - * really must add one, update Makefile.in, and run |make check|. - * - * |make check| also statically prevents the use of vanilla new/new[]. + * The advantage of these operations is that the memory is batched and freed + * on another thread. */ #define JS_NEW_BODY(allocator, t, parms) \ @@ -464,190 +422,112 @@ JS_END_EXTERN_C return memory ? new(memory) t parms : NULL; /* - * Given a class which should provide new_() methods, add + * Given a class which should provide 'new' methods, add * JS_DECLARE_NEW_METHODS (see JSContext for a usage example). This - * adds new_()s with up to 12 parameters. Add more versions of new_ below if + * adds news with up to 12 parameters. Add more versions of new below if * you need more than 12 parameters. * * Note: Do not add a ; at the end of a use of JS_DECLARE_NEW_METHODS, * or the build will break. */ -#define JS_DECLARE_NEW_METHODS(ALLOCATOR, QUALIFIERS)\ +#define JS_DECLARE_NEW_METHODS(NEWNAME, ALLOCATOR, QUALIFIERS)\ template \ - QUALIFIERS T *new_() {\ + QUALIFIERS T *NEWNAME() {\ JS_NEW_BODY(ALLOCATOR, T, ())\ }\ \ template \ - QUALIFIERS T *new_(P1 p1) {\ + QUALIFIERS T *NEWNAME(P1 p1) {\ JS_NEW_BODY(ALLOCATOR, T, (p1))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11))\ }\ \ template \ - QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11, P12 p12) {\ + QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11, P12 p12) {\ JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12))\ }\ - static const int JSMinAlignment = 8;\ - template \ - QUALIFIERS T *array_new(size_t n) {\ - /* The length is stored just before the vector memory. */\ - uint64_t numBytes64 = uint64_t(JSMinAlignment) + uint64_t(sizeof(T)) * uint64_t(n);\ - size_t numBytes = size_t(numBytes64);\ - if (numBytes64 != numBytes) {\ - JS_ASSERT(0); /* we want to know if this happens in debug builds */\ - return NULL;\ - }\ - void *memory = ALLOCATOR(numBytes);\ - if (!memory)\ - return NULL;\ - *(size_t *)memory = n;\ - memory = (void*)(uintptr_t(memory) + JSMinAlignment);\ - return new(memory) T[n];\ - }\ +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static JS_ALWAYS_INLINE) -#define JS_DECLARE_DELETE_METHODS(DEALLOCATOR, QUALIFIERS)\ - template \ - QUALIFIERS void delete_(T *p) {\ - if (p) {\ - p->~T();\ - DEALLOCATOR(p);\ - }\ - }\ -\ - template \ - QUALIFIERS void array_delete(T *p) {\ - if (p) {\ - void* p0 = (void *)(uintptr_t(p) - js::OffTheBooks::JSMinAlignment);\ - size_t n = *(size_t *)p0;\ - for (size_t i = 0; i < n; i++)\ - (p + i)->~T();\ - DEALLOCATOR(p0);\ - }\ +template +static JS_ALWAYS_INLINE void +js_delete(T *p) +{ + if (p) { + p->~T(); + js_free(p); } +} - -/* - * In general, all allocations should go through a JSContext or JSRuntime, so - * that the garbage collector knows how much memory has been allocated. In - * cases where it is difficult to use a JSContext or JSRuntime, OffTheBooks can - * be used, though this is undesirable. - */ namespace js { -class OffTheBooks { -public: - JS_DECLARE_NEW_METHODS(::js_malloc, JS_ALWAYS_INLINE static) - - static JS_INLINE void* malloc_(size_t bytes) { - return ::js_malloc(bytes); - } - - static JS_INLINE void* calloc_(size_t bytes) { - return ::js_calloc(bytes); - } - - static JS_INLINE void* realloc_(void* p, size_t bytes) { - return ::js_realloc(p, bytes); - } -}; - -/* - * We generally prefer deallocating using JSContext because it can happen in - * the background. On slow paths, we may prefer foreground allocation. - */ -class Foreground { -public: - /* See parentheses comment above. */ - static JS_ALWAYS_INLINE void free_(void* p) { - ::js_free(p); - } - - JS_DECLARE_DELETE_METHODS(::js_free, JS_ALWAYS_INLINE static) -}; - -class UnwantedForeground : public Foreground { -}; - template struct ScopedFreePtrTraits { typedef T* type; static T* empty() { return NULL; } - static void release(T* ptr) { Foreground::free_(ptr); } + static void release(T* ptr) { js_free(ptr); } }; SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) template struct ScopedDeletePtrTraits : public ScopedFreePtrTraits { - static void release(T *ptr) { Foreground::delete_(ptr); } + static void release(T *ptr) { js_delete(ptr); } }; SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) } /* namespace js */ -/* - * Note lack of ; in JSRuntime below. This is intentional so "calling" this - * looks "normal". - */ -#define JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR \ - friend class js::OffTheBooks;\ - friend class js::Foreground;\ - friend class js::UnwantedForeground;\ - friend struct ::JSContext;\ - friend struct ::JSRuntime - /* * The following classes are designed to cause assertions to detect * inadvertent use of guard objects as temporaries. In other words, diff --git a/js/src/Makefile.in b/js/src/Makefile.in index cfaa12664652..b98259ff5043 100644 --- a/js/src/Makefile.in +++ b/js/src/Makefile.in @@ -512,37 +512,6 @@ ifeq ($(MOZ_DEBUG),1) #check:: check-ooms endif -## Prevent regressing in our deprecation of non-preferred memory management functions. -# We use all the files in the distribution so that different configurations -# don't give different results. We skip the contents of objdirs using |find| -# (it can't be done with %-expansion, because the files we want to skip aren't -# in the vpath). -ALL_FILES=$(shell find $(srcdir) \( -name "*.cpp" -o -name "*.h" \) ! -path "*/dist/*" ! -path "*/config/*") -check-malloc-function-usage: $(filter-out %jsalloc.h %jscntxt.h %jsutil.h, $(ALL_FILES)) - - # js_malloc and friends are only used by other memory managers, and should - # never be used elsewhere directly. - $(srcdir)/config/check_source_count.py "\bjs_malloc\b" 0 \ - "in Makefile.in" "cx->malloc_ or rt->malloc_" $^ - $(srcdir)/config/check_source_count.py "\bjs_calloc\b" 0 \ - "in Makefile.in" "cx->calloc_ or rt->calloc_" $^ - $(srcdir)/config/check_source_count.py "\bjs_realloc\b" 0 \ - "in Makefile.in" "cx->realloc_ or rt->realloc_" $^ - $(srcdir)/config/check_source_count.py "\bjs_free\b" 0 \ - "in Makefile.in" "cx->free_" $^ - - # We desire these numbers to go down, not up. See "User guide to memory - # management within SpiderMonkey" in jsutil.h. - $(srcdir)/config/check_source_count.py OffTheBooks:: 71 \ - "in Makefile.in" "{cx,rt}->{new_,array_new,malloc_,calloc_,realloc_}" $^ - # This should go to zero, if possible. - $(srcdir)/config/check_source_count.py UnwantedForeground:: 31 \ - "in Makefile.in" "{cx,rt}->{free_,delete_,array_delete}" $^ - -ifneq ($(OS_ARCH),WINNT) # FIXME: this should be made work on Windows too. -#check:: check-malloc-function-usage FIXME: disable on JM until closer to merge time. -endif - ifdef MOZ_VALGRIND ifndef MOZ_ASAN JITTEST_VALGRIND_FLAG = --valgrind diff --git a/js/src/assembler/jit/ExecutableAllocator.h b/js/src/assembler/jit/ExecutableAllocator.h index c071c33f232c..b4325f52e185 100644 --- a/js/src/assembler/jit/ExecutableAllocator.h +++ b/js/src/assembler/jit/ExecutableAllocator.h @@ -87,7 +87,6 @@ namespace JSC { // These are reference-counted. A new one starts with a count of 1. class ExecutablePool { - JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR; friend class ExecutableAllocator; private: struct Allocation { @@ -123,11 +122,17 @@ public: JS_ASSERT(m_refCount != 0); // XXX: disabled, see bug 654820. //JS_ASSERT_IF(willDestroy, m_refCount == 1); - if (--m_refCount == 0) { - js::UnwantedForeground::delete_(this); - } + if (--m_refCount == 0) + js_delete(this); } + ExecutablePool(ExecutableAllocator* allocator, Allocation a) + : m_allocator(allocator), m_freePtr(a.pages), m_end(m_freePtr + a.size), m_allocation(a), + m_refCount(1), m_mjitCodeMethod(0), m_mjitCodeRegexp(0), m_destroy(false), m_gcNumber(0) + { } + + ~ExecutablePool(); + private: // It should be impossible for us to roll over, because only small // pools have multiple holders, and they have one holder per chunk @@ -138,13 +143,6 @@ private: ++m_refCount; } - ExecutablePool(ExecutableAllocator* allocator, Allocation a) - : m_allocator(allocator), m_freePtr(a.pages), m_end(m_freePtr + a.size), m_allocation(a), - m_refCount(1), m_mjitCodeMethod(0), m_mjitCodeRegexp(0), m_destroy(false), m_gcNumber(0) - { } - - ~ExecutablePool(); - void* alloc(size_t n, CodeKind kind) { JS_ASSERT(n <= available()); @@ -304,7 +302,7 @@ private: if (!a.pages) return NULL; - ExecutablePool *pool = js::OffTheBooks::new_(this, a); + ExecutablePool *pool = js_new(this, a); if (!pool) { systemRelease(a); return NULL; diff --git a/js/src/builtin/MapObject.cpp b/js/src/builtin/MapObject.cpp index d1deed8aab51..a904d9196587 100644 --- a/js/src/builtin/MapObject.cpp +++ b/js/src/builtin/MapObject.cpp @@ -789,7 +789,7 @@ MapIteratorObject::create(JSContext *cx, HandleObject mapobj, ValueMap *data) JSObject *iterobj = NewObjectWithGivenProto(cx, &MapIteratorClass, proto, global); if (!iterobj) { - cx->delete_(range); + js_delete(range); return NULL; } iterobj->setSlot(TargetSlot, ObjectValue(*mapobj)); @@ -817,7 +817,7 @@ MapIteratorObject::next_impl(JSContext *cx, CallArgs args) if (!range) return js_ThrowStopIteration(cx); if (range->empty()) { - cx->delete_(range); + js_delete(range); thisobj.setReservedSlot(RangeSlot, PrivateValue(NULL)); return js_ThrowStopIteration(cx); } @@ -1236,7 +1236,7 @@ SetIteratorObject::create(JSContext *cx, HandleObject setobj, ValueSet *data) JSObject *iterobj = NewObjectWithGivenProto(cx, &SetIteratorClass, proto, global); if (!iterobj) { - cx->delete_(range); + js_delete(range); return NULL; } iterobj->setSlot(TargetSlot, ObjectValue(*setobj)); @@ -1264,7 +1264,7 @@ SetIteratorObject::next_impl(JSContext *cx, CallArgs args) if (!range) return js_ThrowStopIteration(cx); if (range->empty()) { - cx->delete_(range); + js_delete(range); thisobj.setReservedSlot(RangeSlot, PrivateValue(NULL)); return js_ThrowStopIteration(cx); } diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index c4e82e120324..f87e60e18a02 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -2149,7 +2149,7 @@ ImplicitConvert(JSContext* cx, return false; char** charBuffer = static_cast(buffer); - *charBuffer = cx->array_new(nbytes + 1); + *charBuffer = (char*)cx->malloc_(nbytes + 1); if (!*charBuffer) { JS_ReportAllocationOverflow(cx); return false; @@ -2166,7 +2166,7 @@ ImplicitConvert(JSContext* cx, // JSString's buffer, but this approach is safer if the caller happens // to modify the string.) jschar** jscharBuffer = static_cast(buffer); - *jscharBuffer = cx->array_new(sourceLength + 1); + *jscharBuffer = (jschar*)cx->malloc_((sourceLength + 1) * sizeof(jschar)); if (!*jscharBuffer) { JS_ReportAllocationOverflow(cx); return false; @@ -2255,7 +2255,7 @@ ImplicitConvert(JSContext* cx, // Convert into an intermediate, in case of failure. size_t elementSize = CType::GetSize(baseType); size_t arraySize = elementSize * targetLength; - AutoPtr::Array intermediate(cx->array_new(arraySize)); + AutoPtr intermediate((char*)cx->malloc_(arraySize)); if (!intermediate) { JS_ReportAllocationOverflow(cx); return false; @@ -2306,7 +2306,7 @@ ImplicitConvert(JSContext* cx, // Convert into an intermediate, in case of failure. size_t structSize = CType::GetSize(targetType); - AutoPtr::Array intermediate(cx->array_new(structSize)); + AutoPtr intermediate((char*)cx->malloc_(structSize)); if (!intermediate) { JS_ReportAllocationOverflow(cx); return false; @@ -3067,7 +3067,7 @@ CType::Finalize(JSFreeOp *fop, JSObject* obj) slot = JS_GetReservedSlot(obj, SLOT_FFITYPE); if (!JSVAL_IS_VOID(slot)) { ffi_type* ffiType = static_cast(JSVAL_TO_PRIVATE(slot)); - FreeOp::get(fop)->array_delete(ffiType->elements); + FreeOp::get(fop)->free_(ffiType->elements); FreeOp::get(fop)->delete_(ffiType); } @@ -4202,7 +4202,7 @@ ArrayType::BuildFFIType(JSContext* cx, JSObject* obj) ffiType->type = FFI_TYPE_STRUCT; ffiType->size = CType::GetSize(obj); ffiType->alignment = CType::GetAlignment(obj); - ffiType->elements = cx->array_new(length + 1); + ffiType->elements = (ffi_type**)cx->malloc_((length + 1) * sizeof(ffi_type*)); if (!ffiType->elements) { JS_ReportAllocationOverflow(cx); return NULL; @@ -4644,9 +4644,9 @@ StructType::BuildFFIType(JSContext* cx, JSObject* obj) } ffiType->type = FFI_TYPE_STRUCT; - AutoPtr::Array elements; + AutoPtr elements; if (len != 0) { - elements = cx->array_new(len + 1); + elements = (ffi_type**)cx->malloc_((len + 1) * sizeof(ffi_type*)); if (!elements) { JS_ReportOutOfMemory(cx); return NULL; @@ -4665,7 +4665,7 @@ StructType::BuildFFIType(JSContext* cx, JSObject* obj) // Represent an empty struct as having a size of 1 byte, just like C++. JS_ASSERT(structSize == 1); JS_ASSERT(structAlign == 1); - elements = cx->array_new(2); + elements = (ffi_type**)cx->malloc_(2 * sizeof(ffi_type*)); if (!elements) { JS_ReportOutOfMemory(cx); return NULL; @@ -5012,14 +5012,14 @@ struct AutoValue ~AutoValue() { - UnwantedForeground::array_delete(static_cast(mData)); + js_free(mData); } bool SizeToType(JSContext* cx, JSObject* type) { // Allocate a minimum of sizeof(ffi_arg) to handle small integers. size_t size = Align(CType::GetSize(type), sizeof(ffi_arg)); - mData = cx->array_new(size); + mData = js_malloc(size); if (mData) memset(mData, 0, size); return mData != NULL; @@ -6068,11 +6068,11 @@ CData::Create(JSContext* cx, } else { // Initialize our own buffer. size_t size = CType::GetSize(typeObj); - data = cx->array_new(size); + data = (char*)cx->malloc_(size); if (!data) { // Report a catchable allocation error. JS_ReportAllocationOverflow(cx); - Foreground::delete_(buffer); + js_free(buffer); return NULL; } @@ -6104,7 +6104,7 @@ CData::Finalize(JSFreeOp *fop, JSObject* obj) char** buffer = static_cast(JSVAL_TO_PRIVATE(slot)); if (owns) - FreeOp::get(fop)->array_delete(*buffer); + FreeOp::get(fop)->free_(*buffer); FreeOp::get(fop)->delete_(buffer); } diff --git a/js/src/ctypes/CTypes.h b/js/src/ctypes/CTypes.h index 0e1b6ad8d7dc..763f50b2d021 100644 --- a/js/src/ctypes/CTypes.h +++ b/js/src/ctypes/CTypes.h @@ -20,34 +20,17 @@ namespace ctypes { ** Utility classes *******************************************************************************/ -template -class OperatorDelete -{ -public: - static void destroy(T* ptr) { UnwantedForeground::delete_(ptr); } -}; - -template -class OperatorArrayDelete -{ -public: - static void destroy(T* ptr) { UnwantedForeground::array_delete(ptr); } -}; - // Class that takes ownership of a pointer T*, and calls cx->delete_() or // cx->array_delete() upon destruction. -template > +template class AutoPtr { private: - typedef AutoPtr self_type; + typedef AutoPtr self_type; public: - // An AutoPtr variant that calls js_array_delete() instead. - typedef AutoPtr > Array; - AutoPtr() : mPtr(NULL) { } explicit AutoPtr(T* ptr) : mPtr(ptr) { } - ~AutoPtr() { DeleteTraits::destroy(mPtr); } + ~AutoPtr() { js_delete(mPtr); } T* operator->() { return mPtr; } bool operator!() { return mPtr == NULL; } @@ -64,8 +47,8 @@ public: private: // Do not allow copy construction or assignment from another AutoPtr. - template AutoPtr(AutoPtr&); - template self_type& operator=(AutoPtr& rhs); + AutoPtr(AutoPtr&); + self_type& operator=(AutoPtr& rhs); T* mPtr; }; @@ -311,7 +294,7 @@ struct ClosureInfo if (closure) ffi_closure_free(closure); if (errResult) - rt->free_(errResult); + js_free(errResult); }; }; diff --git a/js/src/ds/LifoAlloc.h b/js/src/ds/LifoAlloc.h index 697afd0c6ab1..9b3ea34246fe 100644 --- a/js/src/ds/LifoAlloc.h +++ b/js/src/ds/LifoAlloc.h @@ -306,7 +306,7 @@ class LifoAlloc return static_cast(alloc(sizeof(T))); } - JS_DECLARE_NEW_METHODS(alloc, JS_ALWAYS_INLINE) + JS_DECLARE_NEW_METHODS(new_, alloc, JS_ALWAYS_INLINE) }; class LifoAllocScope diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 4786269a3ee7..8ff3aaba02ef 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -139,12 +139,10 @@ BytecodeEmitter::init() BytecodeEmitter::~BytecodeEmitter() { - JSContext *cx = sc->context; - - cx->free_(prolog.base); - cx->free_(prolog.notes); - cx->free_(main.base); - cx->free_(main.notes); + js_free(prolog.base); + js_free(prolog.notes); + js_free(main.base); + js_free(main.notes); } static ptrdiff_t @@ -2391,7 +2389,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) release: if (intmap && intmap != intmap_space) - cx->free_(intmap); + js_free(intmap); if (!ok) return false; diff --git a/js/src/frontend/FoldConstants.cpp b/js/src/frontend/FoldConstants.cpp index 6d5db9ca1301..015a03d443f8 100644 --- a/js/src/frontend/FoldConstants.cpp +++ b/js/src/frontend/FoldConstants.cpp @@ -678,7 +678,7 @@ frontend::FoldConstants(JSContext *cx, ParseNode *pn, Parser *parser, bool inGen chars[length] = 0; JSString *str = js_NewString(cx, chars, length); if (!str) { - cx->free_(chars); + js_free(chars); return false; } diff --git a/js/src/frontend/ParseMaps.cpp b/js/src/frontend/ParseMaps.cpp index b7442452ba47..102565bbdcd4 100644 --- a/js/src/frontend/ParseMaps.cpp +++ b/js/src/frontend/ParseMaps.cpp @@ -36,7 +36,7 @@ void ParseMapPool::purgeAll() { for (void **it = all.begin(), **end = all.end(); it != end; ++it) - cx->delete_(asAtomMap(*it)); + js_delete(asAtomMap(*it)); all.clearAndFree(); recyclable.clearAndFree(); diff --git a/js/src/frontend/Parser-inl.h b/js/src/frontend/Parser-inl.h index 20aa66ac6d55..2d7a9b046807 100644 --- a/js/src/frontend/Parser-inl.h +++ b/js/src/frontend/Parser-inl.h @@ -79,7 +79,7 @@ ParseContext::~ParseContext() // die, make |*parserPC| point to this object's parent. JS_ASSERT(*parserPC == this); *parserPC = this->parent; - sc->context->delete_(funcStmts); + js_delete(funcStmts); if (queuedStrictModeError) { // If the parent context is looking for strict mode violations, pass // ours up. Otherwise, free it. @@ -87,7 +87,7 @@ ParseContext::~ParseContext() !parent->queuedStrictModeError) parent->queuedStrictModeError = queuedStrictModeError; else - sc->context->delete_(queuedStrictModeError); + js_delete(queuedStrictModeError); } } diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index de4d62787b9c..17c409aa6703 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -342,7 +342,7 @@ struct Parser : private AutoGCRooter void prepareNodeForMutation(ParseNode *pn) { return allocator.prepareNodeForMutation(pn); } /* new_ methods for creating parse nodes. These report OOM on context. */ - JS_DECLARE_NEW_METHODS(allocParseNode, inline) + JS_DECLARE_NEW_METHODS(new_, allocParseNode, inline) ParseNode *cloneNode(const ParseNode &other) { ParseNode *node = allocParseNode(sizeof(ParseNode)); diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index 22c4a66675dc..bf69fec49350 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -218,9 +218,9 @@ TokenStream::TokenStream(JSContext *cx, const CompileOptions &options, TokenStream::~TokenStream() { if (flags & TSF_OWNFILENAME) - cx->free_((void *) filename); + js_free((void *) filename); if (sourceMap) - cx->free_(sourceMap); + js_free(sourceMap); if (originPrincipals) JS_DropPrincipals(cx->runtime, originPrincipals); } @@ -441,19 +441,19 @@ CompileError::throwError() CompileError::~CompileError() { - cx->free_((void*)report.uclinebuf); - cx->free_((void*)report.linebuf); - cx->free_((void*)report.ucmessage); - cx->free_(message); + js_free((void*)report.uclinebuf); + js_free((void*)report.linebuf); + js_free((void*)report.ucmessage); + js_free(message); message = NULL; if (report.messageArgs) { if (hasCharArgs) { unsigned i = 0; while (report.messageArgs[i]) - cx->free_((void*)report.messageArgs[i++]); + js_free((void*)report.messageArgs[i++]); } - cx->free_(report.messageArgs); + js_free(report.messageArgs); } PodZero(&report); @@ -725,7 +725,7 @@ TokenStream::getXMLEntity() bytes = DeflateString(cx, bp + 1, (tb.end() - bp) - 1); if (bytes) { reportError(msg, bytes); - cx->free_(bytes); + js_free(bytes); } return false; } @@ -1211,7 +1211,7 @@ TokenStream::getAtLine() if (c == EOF || c == '\n') { if (i > 0) { if (flags & TSF_OWNFILENAME) - cx->free_((void *) filename); + js_free((void *) filename); filename = JS_strdup(cx, filenameBuf); if (!filename) return false; @@ -1250,7 +1250,7 @@ TokenStream::getAtSourceMappingURL() size_t sourceMapLength = tokenbuf.length(); if (sourceMap) - cx->free_(sourceMap); + js_free(sourceMap); sourceMap = static_cast(cx->malloc_(sizeof(jschar) * (sourceMapLength + 1))); if (!sourceMap) return false; diff --git a/js/src/jsanalyze.cpp b/js/src/jsanalyze.cpp index 7add1ecc9183..64937ae0becb 100644 --- a/js/src/jsanalyze.cpp +++ b/js/src/jsanalyze.cpp @@ -799,7 +799,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx) LifetimeVariable &var = *saved[i]; var.lifetime = alloc.new_(offset, var.savedEnd, var.saved); if (!var.lifetime) { - cx->free_(saved); + js_free(saved); setOOM(cx); return; } @@ -866,7 +866,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx) LoopAnalysis *nloop = alloc.new_(); if (!nloop) { - cx->free_(saved); + js_free(saved); setOOM(cx); return; } @@ -916,7 +916,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx) */ var.lifetime = alloc.new_(offset, var.savedEnd, var.saved); if (!var.lifetime) { - cx->free_(saved); + js_free(saved); setOOM(cx); return; } @@ -939,7 +939,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx) offset--; } - cx->free_(saved); + js_free(saved); ranLifetimes_ = true; } @@ -1207,7 +1207,7 @@ ScriptAnalysis::analyzeSSA(JSContext *cx) JSContext *cx; SSAValueInfo *values; FreeSSAValues(JSContext *cx, SSAValueInfo *values) : cx(cx), values(values) {} - ~FreeSSAValues() { cx->free_(values); } + ~FreeSSAValues() { js_free(values); } } free(cx, values); SSAValueInfo *stack = values + numSlots; @@ -1853,7 +1853,7 @@ ScriptAnalysis::freezeNewValues(JSContext *cx, uint32_t offset) unsigned count = pending->length(); if (count == 0) { - cx->delete_(pending); + js_delete(pending); return; } @@ -1868,7 +1868,7 @@ ScriptAnalysis::freezeNewValues(JSContext *cx, uint32_t offset) code.newValues[count].slot = 0; code.newValues[count].value.clear(); - cx->delete_(pending); + js_delete(pending); } bool diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 42348df9da60..6055f845eae0 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -436,7 +436,7 @@ JS_RemoveArgumentFormatter(JSContext *cx, const char *format) while ((map = *mpp) != NULL) { if (map->length == length && !strcmp(map->format, format)) { *mpp = map->next; - cx->free_(map); + js_free(map); return; } mpp = &map->next; @@ -905,7 +905,7 @@ JSRuntime::init(uint32_t maxbytes) !atomsCompartment->init(NULL) || !compartments.append(atomsCompartment)) { - Foreground::delete_(atomsCompartment); + js_delete(atomsCompartment); return false; } @@ -938,7 +938,7 @@ JSRuntime::init(uint32_t maxbytes) debugScopes = this->new_(this); if (!debugScopes || !debugScopes->init()) { - Foreground::delete_(debugScopes); + js_delete(debugScopes); return false; } @@ -952,7 +952,7 @@ JSRuntime::~JSRuntime() clearOwnerThread(); #endif - delete_(debugScopes); + js_delete(debugScopes); /* * Even though all objects in the compartment are dead, we may have keep @@ -992,12 +992,12 @@ JSRuntime::~JSRuntime() PR_DestroyLock(gcLock); #endif - delete_(bumpAlloc_); - delete_(mathCache_); + js_delete(bumpAlloc_); + js_delete(mathCache_); #ifdef JS_METHODJIT - delete_(jaegerRuntime_); + js_delete(jaegerRuntime_); #endif - delete_(execAlloc_); /* Delete after jaegerRuntime_. */ + js_delete(execAlloc_); /* Delete after jaegerRuntime_. */ } #ifdef JS_THREADSAFE @@ -1087,7 +1087,7 @@ JS_NewRuntime(uint32_t maxbytes) js_NewRuntimeWasCalled = JS_TRUE; } - JSRuntime *rt = OffTheBooks::new_(); + JSRuntime *rt = js_new(); if (!rt) return NULL; @@ -1104,7 +1104,7 @@ JS_PUBLIC_API(void) JS_DestroyRuntime(JSRuntime *rt) { Probes::destroyRuntime(rt); - Foreground::delete_(rt); + js_delete(rt); } JS_PUBLIC_API(void) @@ -2310,7 +2310,7 @@ JS_realloc(JSContext *cx, void *p, size_t nbytes) JS_PUBLIC_API(void) JS_free(JSContext *cx, void *p) { - return cx->free_(p); + return js_free(p); } JS_PUBLIC_API(void) @@ -2772,7 +2772,7 @@ DumpNotify(JSTracer *trc, void **thingp, JSGCTraceKind kind) const char *edgeName = JS_GetTraceEdgeName(&dtrc->base, dtrc->buffer, sizeof(dtrc->buffer)); size_t edgeNameSize = strlen(edgeName) + 1; size_t bytes = offsetof(JSHeapDumpNode, edgeName) + edgeNameSize; - JSHeapDumpNode *node = (JSHeapDumpNode *) OffTheBooks::malloc_(bytes); + JSHeapDumpNode *node = (JSHeapDumpNode *) js_malloc(bytes); if (!node) { dtrc->ok = false; return; @@ -2916,7 +2916,7 @@ JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind startKind, for (;;) { next = node->next; parent = node->parent; - Foreground::free_(node); + js_free(node); node = next; if (node) break; @@ -5227,7 +5227,7 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options, return NULL; JSScript *script = Compile(cx, obj, options, chars, length); - cx->free_(chars); + js_free(chars); return script; } @@ -5395,7 +5395,7 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8, JSObject *objArg JS_SetErrorReporter(cx, older); } } - cx->free_(chars); + js_free(chars); JS_RestoreExceptionState(cx, exnState); return result; } @@ -5519,7 +5519,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options, return NULL; JSFunction *fun = CompileFunction(cx, obj, options, name, nargs, argnames, chars, length); - cx->free_(chars); + js_free(chars); return fun; } @@ -5715,7 +5715,7 @@ JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options, return false; bool ok = Evaluate(cx, obj, options, chars, length, rval); - cx->free_(chars); + js_free(chars); return ok; } @@ -6020,7 +6020,7 @@ JS_NewStringCopyZ(JSContext *cx, const char *s) return NULL; str = js_NewString(cx, js, n); if (!str) - cx->free_(js); + js_free(js); return str; } @@ -6461,7 +6461,7 @@ void JSAutoStructuredCloneBuffer::clear() { if (data_) { - Foreground::free_(data_); + js_free(data_); data_ = NULL; nbytes_ = 0; version_ = 0; @@ -6480,7 +6480,7 @@ JSAutoStructuredCloneBuffer::adopt(uint64_t *data, size_t nbytes, uint32_t versi bool JSAutoStructuredCloneBuffer::copy(const uint64_t *srcData, size_t nbytes, uint32_t version) { - uint64_t *newData = static_cast(OffTheBooks::malloc_(nbytes)); + uint64_t *newData = static_cast(js_malloc(nbytes)); if (!newData) return false; @@ -6776,7 +6776,7 @@ JS_NewRegExpObject(JSContext *cx, JSObject *objArg, char *bytes, size_t length, RegExpStatics *res = obj->asGlobal().getRegExpStatics(); RegExpObject *reobj = RegExpObject::create(cx, res, chars, length, RegExpFlag(flags), NULL); - cx->free_(chars); + js_free(chars); return reobj; } @@ -6835,7 +6835,7 @@ JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned if (!chars) return NULL; RegExpObject *reobj = RegExpObject::createNoStatics(cx, chars, length, RegExpFlag(flags), NULL); - cx->free_(chars); + js_free(chars); return reobj; } @@ -6995,7 +6995,7 @@ JS_DropExceptionState(JSContext *cx, JSExceptionState *state) assertSameCompartment(cx, state->exception); JS_RemoveValueRoot(cx, &state->exception); } - cx->free_(state); + js_free(state); } } diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 3f062eda7c0b..b6b246d51b04 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -5762,7 +5762,7 @@ class JSAutoByteString { } ~JSAutoByteString() { - js::UnwantedForeground::free_(mBytes); + js_free(mBytes); } /* Take ownership of the given byte array. */ @@ -5779,7 +5779,7 @@ class JSAutoByteString { } void clear() { - js::UnwantedForeground::free_(mBytes); + js_free(mBytes); mBytes = NULL; } @@ -6038,17 +6038,17 @@ JS_ReportAllocationOverflow(JSContext *cx); struct JSErrorReport { const char *filename; /* source file name, URL, etc., or null */ JSPrincipals *originPrincipals; /* see 'originPrincipals' comment above */ - unsigned lineno; /* source line number */ + unsigned lineno; /* source line number */ const char *linebuf; /* offending source line without final \n */ const char *tokenptr; /* pointer to error token in linebuf */ const jschar *uclinebuf; /* unicode (original) line buffer */ const jschar *uctokenptr; /* unicode (original) token pointer */ - unsigned flags; /* error/warning, etc. */ - unsigned errorNumber; /* the error number, e.g. see js.msg */ + unsigned flags; /* error/warning, etc. */ + unsigned errorNumber; /* the error number, e.g. see js.msg */ const jschar *ucmessage; /* the (default) error message */ const jschar **messageArgs; /* arguments for the error message */ int16_t exnType; /* One of the JSExnType constants */ - unsigned column; /* zero-based column index in line */ + unsigned column; /* zero-based column index in line */ }; /* diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 312f298e05e4..094c8ef9f247 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -1325,7 +1325,7 @@ JSObject::makeDenseArraySlow(JSContext *cx, HandleObject obj) if (!AddLengthProperty(cx, obj)) { obj->shape_ = oldShape; if (obj->elements != emptyObjectElements) - cx->free_(obj->getElementsHeader()); + js_free(obj->getElementsHeader()); obj->elements = elems; return false; } @@ -1345,7 +1345,7 @@ JSObject::makeDenseArraySlow(JSContext *cx, HandleObject obj) if (!obj->addDataProperty(cx, id, next, JSPROP_ENUMERATE)) { obj->shape_ = oldShape; - cx->free_(obj->getElementsHeader()); + js_free(obj->getElementsHeader()); obj->elements = elems; return false; } @@ -1358,7 +1358,7 @@ JSObject::makeDenseArraySlow(JSContext *cx, HandleObject obj) ObjectElements *oldheader = ObjectElements::fromElements(elems); obj->getElementsHeader()->length = oldheader->length; - cx->free_(oldheader); + js_free(oldheader); return true; } @@ -3737,7 +3737,7 @@ js_ArrayInfo(JSContext *cx, unsigned argc, Value *vp) if (arg.isPrimitive() || !(array = arg.toObjectOrNull())->isArray()) { fprintf(stderr, "%s: not array\n", bytes); - cx->free_(bytes); + js_free(bytes); continue; } fprintf(stderr, "%s: %s (len %u", bytes, @@ -3748,7 +3748,7 @@ js_ArrayInfo(JSContext *cx, unsigned argc, Value *vp) array->getDenseArrayCapacity()); } fputs(")\n", stderr); - cx->free_(bytes); + js_free(bytes); } args.rval().setUndefined(); diff --git a/js/src/jsatom.cpp b/js/src/jsatom.cpp index d6bb1660773b..df0aaf70054e 100644 --- a/js/src/jsatom.cpp +++ b/js/src/jsatom.cpp @@ -384,7 +384,7 @@ js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, JSAtom *atom = AtomizeInline(cx, &chars, inflatedLength, ib, ocb); if (ocb == TakeCharOwnership && chars) - cx->free_((void *)chars); + js_free((void *)chars); return atom; } @@ -506,7 +506,7 @@ js::XDRAtom(XDRState *xdr, JSAtom **atomp) JS_ALWAYS_TRUE(xdr->codeChars(chars, nchars)); atom = AtomizeChars(cx, chars, nchars); if (chars != stackChars) - Foreground::free_(chars); + js_free(chars); #endif /* !IS_LITTLE_ENDIAN */ if (!atom) diff --git a/js/src/jsclone.cpp b/js/src/jsclone.cpp index 5d5a9911b741..13e8000014c3 100644 --- a/js/src/jsclone.cpp +++ b/js/src/jsclone.cpp @@ -607,7 +607,7 @@ class Chars { jschar *p; public: Chars(JSContext *cx) : cx(cx), p(NULL) {} - ~Chars() { if (p) cx->free_(p); } + ~Chars() { if (p) js_free(p); } bool allocate(size_t len) { JS_ASSERT(!p); diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 7cbf7dd73e3e..5c374725407e 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -185,7 +185,7 @@ JSRuntime::createExecutableAllocator(JSContext *cx) JSC::AllocationBehavior randomize = jitHardening ? JSC::AllocationCanRandomize : JSC::AllocationDeterministic; - execAlloc_ = new_(randomize); + execAlloc_ = js_new(randomize); if (!execAlloc_) js_ReportOutOfMemory(cx); return execAlloc_; @@ -197,7 +197,7 @@ JSRuntime::createBumpPointerAllocator(JSContext *cx) JS_ASSERT(!bumpAlloc_); JS_ASSERT(cx->runtime == this); - bumpAlloc_ = new_(); + bumpAlloc_ = js_new(); if (!bumpAlloc_) js_ReportOutOfMemory(cx); return bumpAlloc_; @@ -209,7 +209,7 @@ JSRuntime::createMathCache(JSContext *cx) JS_ASSERT(!mathCache_); JS_ASSERT(cx->runtime == this); - MathCache *newMathCache = new_(); + MathCache *newMathCache = js_new(); if (!newMathCache) { js_ReportOutOfMemory(cx); return NULL; @@ -226,10 +226,10 @@ JSRuntime::createJaegerRuntime(JSContext *cx) JS_ASSERT(!jaegerRuntime_); JS_ASSERT(cx->runtime == this); - mjit::JaegerRuntime *jr = new_(); + mjit::JaegerRuntime *jr = js_new(); if (!jr || !jr->init(cx)) { js_ReportOutOfMemory(cx); - delete_(jr); + js_delete(jr); return NULL; } @@ -334,14 +334,14 @@ js::NewContext(JSRuntime *rt, size_t stackChunkSize) { JS_AbortIfWrongThread(rt); - JSContext *cx = OffTheBooks::new_(rt); + JSContext *cx = js_new(rt); if (!cx) return NULL; JS_ASSERT(cx->findVersion() == JSVERSION_DEFAULT); if (!cx->cycleDetectorSet.init()) { - Foreground::delete_(cx); + js_delete(cx); return NULL; } @@ -439,7 +439,7 @@ js::DestroyContext(JSContext *cx, DestroyContextMode mode) PrepareForFullGC(rt); GC(rt, GC_NORMAL, gcreason::DESTROY_CONTEXT); } - Foreground::delete_(cx); + js_delete(cx); } namespace js { @@ -653,8 +653,8 @@ js_ReportErrorVA(JSContext *cx, unsigned flags, const char *format, va_list ap) warning = JSREPORT_IS_WARNING(report.flags); ReportError(cx, message, &report, NULL, NULL); - Foreground::free_(message); - Foreground::free_(ucmessage); + js_free(message); + js_free(ucmessage); return warning; } @@ -849,7 +849,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback, reportp->ucmessage = out = (jschar *) cx->malloc_((expandedLength + 1) * sizeof(jschar)); if (!out) { - cx->free_(buffer); + js_free(buffer); goto error; } while (*fmt) { @@ -869,7 +869,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback, } JS_ASSERT(expandedArgs == argCount); *out = 0; - cx->free_(buffer); + js_free(buffer); *messagep = DeflateString(cx, reportp->ucmessage, size_t(out - reportp->ucmessage)); if (!*messagep) @@ -910,17 +910,17 @@ error: if (charArgs) { i = 0; while (reportp->messageArgs[i]) - cx->free_((void *)reportp->messageArgs[i++]); + js_free((void *)reportp->messageArgs[i++]); } - cx->free_((void *)reportp->messageArgs); + js_free((void *)reportp->messageArgs); reportp->messageArgs = NULL; } if (reportp->ucmessage) { - cx->free_((void *)reportp->ucmessage); + js_free((void *)reportp->ucmessage); reportp->ucmessage = NULL; } if (*messagep) { - cx->free_((void *)*messagep); + js_free((void *)*messagep); *messagep = NULL; } return JS_FALSE; @@ -952,7 +952,7 @@ js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback, ReportError(cx, message, &report, callback, userRef); if (message) - cx->free_(message); + js_free(message); if (report.messageArgs) { /* * js_ExpandErrorArguments owns its messageArgs only if it had to @@ -961,12 +961,12 @@ js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback, if (charArgs) { int i = 0; while (report.messageArgs[i]) - cx->free_((void *)report.messageArgs[i++]); + js_free((void *)report.messageArgs[i++]); } - cx->free_((void *)report.messageArgs); + js_free((void *)report.messageArgs); } if (report.ucmessage) - cx->free_((void *)report.ucmessage); + js_free((void *)report.ucmessage); return warning; } @@ -980,7 +980,7 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *reportp) return; if (cx->lastMessage) - Foreground::free_(cx->lastMessage); + js_free(cx->lastMessage); cx->lastMessage = JS_strdup(cx, message); if (!cx->lastMessage) return; @@ -1035,7 +1035,7 @@ js_ReportIsNullOrUndefined(JSContext *cx, int spindex, HandleValue v, js_null_str, NULL); } - cx->free_(bytes); + js_free(bytes); return ok; } @@ -1058,7 +1058,7 @@ js_ReportMissingArg(JSContext *cx, HandleValue v, unsigned arg) JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MISSING_FUN_ARG, argbuf, bytes ? bytes : ""); - cx->free_(bytes); + js_free(bytes); } JSBool @@ -1077,7 +1077,7 @@ js_ReportValueErrorFlags(JSContext *cx, unsigned flags, const unsigned errorNumb ok = JS_ReportErrorFlagsAndNumber(cx, flags, js_GetErrorMessage, NULL, errorNumber, bytes, arg1, arg2); - cx->free_(bytes); + js_free(bytes); return ok; } @@ -1224,17 +1224,17 @@ JSContext::~JSContext() { /* Free the stuff hanging off of cx. */ if (parseMapPool_) - Foreground::delete_(parseMapPool_); + js_delete(parseMapPool_); if (lastMessage) - Foreground::free_(lastMessage); + js_free(lastMessage); /* Remove any argument formatters. */ JSArgumentFormatMap *map = argumentFormatMap; while (map) { JSArgumentFormatMap *temp = map; map = map->next; - Foreground::free_(temp); + js_free(temp); } JS_ASSERT(!resolvingList); @@ -1382,11 +1382,11 @@ JSRuntime::onOutOfMemory(void *p, size_t nbytes, JSContext *cx) ShrinkGCBuffers(this); gcHelperThread.waitBackgroundSweepOrAllocEnd(); if (!p) - p = OffTheBooks::malloc_(nbytes); + p = js_malloc(nbytes); else if (p == reinterpret_cast(1)) - p = OffTheBooks::calloc_(nbytes); + p = js_calloc(nbytes); else - p = OffTheBooks::realloc_(p, nbytes); + p = js_realloc(p, nbytes); if (p) return p; if (cx) @@ -1398,7 +1398,7 @@ void JSContext::purge() { if (!activeCompilations) { - Foreground::delete_(parseMapPool_); + js_delete(parseMapPool_); parseMapPool_ = NULL; } } diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 2d844a1bc7d7..53ddb97093dc 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -341,7 +341,13 @@ class FreeOp : public JSFreeOp { inline void free_(void* p); - JS_DECLARE_DELETE_METHODS(free_, inline) + template + inline void delete_(T *p) { + if (p) { + p->~T(); + free_(p); + } + } static void staticAsserts() { /* @@ -934,13 +940,7 @@ struct JSRuntime : js::RuntimeFriendFields return JS_LIKELY(!!p2) ? p2 : onOutOfMemory(p, bytes, cx); } - inline void free_(void* p) { - /* FIXME: Making this free in the background is buggy. Can it work? */ - js::Foreground::free_(p); - } - - JS_DECLARE_NEW_METHODS(malloc_, JS_ALWAYS_INLINE) - JS_DECLARE_DELETE_METHODS(free_, JS_ALWAYS_INLINE) + JS_DECLARE_NEW_METHODS(new_, malloc_, JS_ALWAYS_INLINE) void setGCMaxMallocBytes(size_t value); @@ -1120,7 +1120,7 @@ FreeOp::free_(void* p) { runtime()->gcHelperThread.freeLater(p); return; } - runtime()->free_(p); + js_free(p); } } /* namespace js */ @@ -1416,12 +1416,7 @@ struct JSContext : js::ContextFriendFields return runtime->realloc_(p, oldBytes, newBytes, this); } - inline void free_(void* p) { - runtime->free_(p); - } - - JS_DECLARE_NEW_METHODS(malloc_, inline) - JS_DECLARE_DELETE_METHODS(free_, inline) + JS_DECLARE_NEW_METHODS(new_, malloc_, JS_ALWAYS_INLINE) void purge(); @@ -1617,7 +1612,6 @@ class AutoKeepAtoms { }; class AutoReleasePtr { - JSContext *cx; void *ptr; JS_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1625,20 +1619,20 @@ class AutoReleasePtr { AutoReleasePtr operator=(const AutoReleasePtr &other) MOZ_DELETE; public: - explicit AutoReleasePtr(JSContext *cx, void *ptr + explicit AutoReleasePtr(void *ptr JS_GUARD_OBJECT_NOTIFIER_PARAM) - : cx(cx), ptr(ptr) + : ptr(ptr) { JS_GUARD_OBJECT_NOTIFIER_INIT; } - ~AutoReleasePtr() { cx->free_(ptr); } + void forget() { ptr = NULL; } + ~AutoReleasePtr() { js_free(ptr); } }; /* * FIXME: bug 602774: cleaner API for AutoReleaseNullablePtr */ class AutoReleaseNullablePtr { - JSContext *cx; void *ptr; JS_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1646,18 +1640,18 @@ class AutoReleaseNullablePtr { AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other) MOZ_DELETE; public: - explicit AutoReleaseNullablePtr(JSContext *cx, void *ptr + explicit AutoReleaseNullablePtr(void *ptr JS_GUARD_OBJECT_NOTIFIER_PARAM) - : cx(cx), ptr(ptr) + : ptr(ptr) { JS_GUARD_OBJECT_NOTIFIER_INIT; } void reset(void *ptr2) { if (ptr) - cx->free_(ptr); + js_free(ptr); ptr = ptr2; } - ~AutoReleaseNullablePtr() { if (ptr) cx->free_(ptr); } + ~AutoReleaseNullablePtr() { if (ptr) js_free(ptr); } }; } /* namespace js */ @@ -2013,7 +2007,7 @@ class RuntimeAllocPolicy RuntimeAllocPolicy(JSContext *cx) : runtime(cx->runtime) {} void *malloc_(size_t bytes) { return runtime->malloc_(bytes); } void *realloc_(void *p, size_t bytes) { return runtime->realloc_(p, bytes); } - void free_(void *p) { runtime->free_(p); } + void free_(void *p) { js_free(p); } void reportAllocOverflow() const {} }; @@ -2029,7 +2023,7 @@ class ContextAllocPolicy JSContext *context() const { return cx; } void *malloc_(size_t bytes) { return cx->malloc_(bytes); } void *realloc_(void *p, size_t oldBytes, size_t bytes) { return cx->realloc_(p, oldBytes, bytes); } - void free_(void *p) { cx->free_(p); } + void free_(void *p) { js_free(p); } void reportAllocOverflow() const { js_ReportAllocationOverflow(cx); } }; diff --git a/js/src/jscntxtinlines.h b/js/src/jscntxtinlines.h index 424148dfb744..5afa69195d20 100644 --- a/js/src/jscntxtinlines.h +++ b/js/src/jscntxtinlines.h @@ -176,7 +176,7 @@ class AutoPtr public: explicit AutoPtr(JSContext *cx) : cx(cx), value(NULL) {} ~AutoPtr() { - cx->delete_(value); + js_delete(value); } void operator=(T *ptr) { value = ptr; } @@ -551,7 +551,7 @@ JSContext::ensureParseMapPool() { if (parseMapPool_) return true; - parseMapPool_ = js::OffTheBooks::new_(this); + parseMapPool_ = js_new(this); return parseMapPool_; } diff --git a/js/src/jscompartment.cpp b/js/src/jscompartment.cpp index b653c2bbaa42..f006cf7a3ede 100644 --- a/js/src/jscompartment.cpp +++ b/js/src/jscompartment.cpp @@ -76,9 +76,9 @@ JSCompartment::JSCompartment(JSRuntime *rt) JSCompartment::~JSCompartment() { - Foreground::delete_(watchpointMap); - Foreground::delete_(scriptCountsMap); - Foreground::delete_(debugScriptMap); + js_delete(watchpointMap); + js_delete(scriptCountsMap); + js_delete(debugScriptMap); } bool diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index 0163e57bbd7d..a3fc674be330 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -362,7 +362,7 @@ JS_GetLinePCs(JSContext *cx, JSScript *script, pcs = (jsbytecode**) cx->malloc_(len * sizeof(jsbytecode*)); if (!pcs) { - cx->free_(lines); + js_free(lines); return JS_FALSE; } @@ -391,12 +391,12 @@ JS_GetLinePCs(JSContext *cx, JSScript *script, if (retLines) *retLines = lines; else - cx->free_(lines); + js_free(lines); if (retPCs) *retPCs = pcs; else - cx->free_(pcs); + js_free(pcs); return JS_TRUE; } @@ -751,7 +751,7 @@ JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp, length = (unsigned) len; ok = JS_EvaluateUCInStackFrame(cx, fp, chars, length, filename, lineno, rval); - cx->free_(chars); + js_free(chars); return ok; } @@ -896,7 +896,7 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda) if (pd[i].flags & JSPD_ALIAS) js_RemoveRoot(cx->runtime, &pd[i].alias); } - cx->free_(pd); + js_free(pd); pda->array = NULL; pda->length = 0; } @@ -1227,7 +1227,7 @@ struct RequiredStringArg { } ~RequiredStringArg() { if (mBytes) - mCx->free_(mBytes); + js_free(mBytes); } }; @@ -1536,7 +1536,7 @@ js_StartVtune(const char *profileName) status = VTStartSampling(¶ms); if (params.tb5Filename != default_filename) - Foreground::free_(params.tb5Filename); + js_free(params.tb5Filename); if (status != 0) { if (status == VTAPI_MULTIPLE_RUNS) diff --git a/js/src/jsdhash.cpp b/js/src/jsdhash.cpp index 44e69bc329b7..5c61a4f25aa4 100644 --- a/js/src/jsdhash.cpp +++ b/js/src/jsdhash.cpp @@ -78,13 +78,13 @@ using namespace js; JS_PUBLIC_API(void *) JS_DHashAllocTable(JSDHashTable *table, uint32_t nbytes) { - return OffTheBooks::malloc_(nbytes); + return js_malloc(nbytes); } JS_PUBLIC_API(void) JS_DHashFreeTable(JSDHashTable *table, void *ptr) { - UnwantedForeground::free_(ptr); + js_free(ptr); } JS_PUBLIC_API(JSDHashNumber) @@ -147,7 +147,7 @@ JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry) { const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry; - UnwantedForeground::free_((void *) stub->key); + js_free((void *) stub->key); memset(entry, 0, table->entrySize); } @@ -179,11 +179,11 @@ JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32_t entrySize, { JSDHashTable *table; - table = (JSDHashTable *) OffTheBooks::malloc_(sizeof *table); + table = (JSDHashTable *) js_malloc(sizeof *table); if (!table) return NULL; if (!JS_DHashTableInit(table, ops, data, entrySize, capacity)) { - Foreground::free_(table); + js_free(table); return NULL; } return table; @@ -193,7 +193,7 @@ JS_PUBLIC_API(void) JS_DHashTableDestroy(JSDHashTable *table) { JS_DHashTableFinish(table); - UnwantedForeground::free_(table); + js_free(table); } JS_PUBLIC_API(JSBool) diff --git a/js/src/jsdtoa.cpp b/js/src/jsdtoa.cpp index 784ee89b825e..b8b57eb3f368 100644 --- a/js/src/jsdtoa.cpp +++ b/js/src/jsdtoa.cpp @@ -48,8 +48,8 @@ using namespace js; * MALLOC gets declared external, and that doesn't work for class members, so * wrap. */ -inline void* dtoa_malloc(size_t size) { return OffTheBooks::malloc_(size); } -inline void dtoa_free(void* p) { return UnwantedForeground::free_(p); } +inline void* dtoa_malloc(size_t size) { return js_malloc(size); } +inline void dtoa_free(void* p) { return js_free(p); } #define NO_GLOBAL_STATE #define MALLOC dtoa_malloc @@ -301,7 +301,7 @@ js_dtobasestr(DtoaState *state, int base, double dinput) JS_ASSERT(base >= 2 && base <= 36); dval(d) = dinput; - buffer = (char*) OffTheBooks::malloc_(DTOBASESTR_BUFFER_SIZE); + buffer = (char*) js_malloc(DTOBASESTR_BUFFER_SIZE); if (!buffer) return NULL; p = buffer; @@ -345,7 +345,7 @@ js_dtobasestr(DtoaState *state, int base, double dinput) if (!b) { nomem1: Bfree(PASS_STATE b); - UnwantedForeground::free_(buffer); + js_free(buffer); return NULL; } do { @@ -381,7 +381,7 @@ js_dtobasestr(DtoaState *state, int base, double dinput) if (mlo != mhi) Bfree(PASS_STATE mlo); Bfree(PASS_STATE mhi); - UnwantedForeground::free_(buffer); + js_free(buffer); return NULL; } JS_ASSERT(e < 0); diff --git a/js/src/jsdtoa.h b/js/src/jsdtoa.h index f79bd7256c97..0f4824abe8fb 100644 --- a/js/src/jsdtoa.h +++ b/js/src/jsdtoa.h @@ -103,7 +103,7 @@ js_dtostr(DtoaState *state, char *buffer, size_t bufferSize, JSDToStrMode mode, * not equal to itself). * * Return NULL if out of memory. If the result is not NULL, it must be - * released via cx->free_(). + * released via js_free(). */ char * js_dtobasestr(DtoaState *state, int base, double d); diff --git a/js/src/jsexn.cpp b/js/src/jsexn.cpp index 2cb38b48b8eb..400522383a1c 100644 --- a/js/src/jsexn.cpp +++ b/js/src/jsexn.cpp @@ -321,7 +321,7 @@ InitExnPrivate(JSContext *cx, HandleObject exnObject, HandleString message, */ priv->errorReport = CopyErrorReport(cx, report); if (!priv->errorReport) { - cx->free_(priv); + js_free(priv); return false; } } else { @@ -1179,19 +1179,8 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope) JSExnPrivate *copy = (JSExnPrivate *)cx->malloc_(size); if (!copy) return NULL; + AutoReleasePtr autoFreePrivate(copy); - struct AutoFree { - JSContext *cx; - JSExnPrivate *p; - ~AutoFree() { - if (p) { - cx->free_(p->errorReport); - cx->free_(p); - } - } - } autoFree = {cx, copy}; - - // Copy each field. Don't bother copying the stack elements. if (priv->errorReport) { copy->errorReport = CopyErrorReport(cx, priv->errorReport); if (!copy->errorReport) @@ -1199,6 +1188,8 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope) } else { copy->errorReport = NULL; } + AutoReleasePtr autoFreeErrorReport(copy->errorReport); + copy->message.init(priv->message); if (!cx->compartment->wrap(cx, ©->message)) return NULL; @@ -1220,6 +1211,7 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope) if (!copyobj) return NULL; SetExnPrivate(cx, copyobj, copy); - autoFree.p = NULL; + autoFreePrivate.forget(); + autoFreeErrorReport.forget(); return copyobj; } diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index b66c1c29d5c0..beb091b3341a 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -1273,7 +1273,7 @@ js_FinishGC(JSRuntime *rt) /* Delete all remaining Compartments. */ for (CompartmentsIter c(rt); !c.done(); c.next()) - Foreground::delete_(c.get()); + js_delete(c.get()); rt->compartments.clear(); rt->atomsCompartment = NULL; @@ -3083,7 +3083,7 @@ GCHelperThread::replenishAndFreeLater(void *ptr) do { if (freeCursor && !freeVector.append(freeCursorEnd - FREE_ARRAY_LENGTH)) break; - freeCursor = (void **) OffTheBooks::malloc_(FREE_ARRAY_SIZE); + freeCursor = (void **) js_malloc(FREE_ARRAY_SIZE); if (!freeCursor) { freeCursorEnd = NULL; break; @@ -3092,7 +3092,7 @@ GCHelperThread::replenishAndFreeLater(void *ptr) *freeCursor++ = ptr; return; } while (false); - Foreground::free_(ptr); + js_free(ptr); } #ifdef JS_THREADSAFE @@ -4748,7 +4748,7 @@ NewCompartment(JSContext *cx, JSPrincipals *principals) js_ReportOutOfMemory(cx); } - Foreground::delete_(compartment); + js_delete(compartment); return NULL; } @@ -4942,7 +4942,7 @@ JS::CheckStackRoots(JSContext *cx) * stack was last scanned, and update the last scanned state. */ if (stackEnd != oldStackEnd) { - rt->free_(oldStackData); + js_free(oldStackData); oldStackCapacity = rt->nativeStackQuota / sizeof(uintptr_t); oldStackData = (uintptr_t *) rt->malloc_(oldStackCapacity * sizeof(uintptr_t)); if (!oldStackData) { diff --git a/js/src/jsgc.h b/js/src/jsgc.h index 0945db4cdb31..40f002165b8f 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -633,8 +633,8 @@ class GCHelperThread { static void freeElementsAndArray(void **array, void **end) { JS_ASSERT(array <= end); for (void **p = array; p != end; ++p) - js::Foreground::free_(*p); - js::Foreground::free_(array); + js_free(*p); + js_free(array); } static void threadMain(void* arg); diff --git a/js/src/jsinfer.cpp b/js/src/jsinfer.cpp index 293ee0cde6bf..70fcf2a03ee8 100644 --- a/js/src/jsinfer.cpp +++ b/js/src/jsinfer.cpp @@ -2165,14 +2165,14 @@ bool TypeCompartment::growPendingArray(JSContext *cx) { unsigned newCapacity = js::Max(unsigned(100), pendingCapacity * 2); - PendingWork *newArray = (PendingWork *) OffTheBooks::calloc_(newCapacity * sizeof(PendingWork)); + PendingWork *newArray = (PendingWork *) js_calloc(newCapacity * sizeof(PendingWork)); if (!newArray) { cx->compartment->types.setPendingNukeTypes(cx); return false; } PodCopy(newArray, pendingArray, pendingCount); - cx->free_(pendingArray); + js_free(pendingArray); pendingArray = newArray; pendingCapacity = newCapacity; @@ -3241,7 +3241,7 @@ TypeObject::clearNewScript(JSContext *cx) /* We NULL out newScript *before* freeing it so the write barrier works. */ TypeNewScript *savedNewScript = newScript; newScript = NULL; - cx->free_(savedNewScript); + js_free(savedNewScript); markStateChange(cx); } @@ -5930,8 +5930,8 @@ TypeCompartment::sweep(FreeOp *fop) } if (remove) { - Foreground::free_(key.ids); - Foreground::free_(entry.types); + js_free(key.ids); + js_free(entry.types); e.removeFront(); } } @@ -6015,16 +6015,16 @@ JSCompartment::sweepNewTypeObjectTable(TypeObjectSet &table) TypeCompartment::~TypeCompartment() { if (pendingArray) - Foreground::free_(pendingArray); + js_free(pendingArray); if (arrayTypeTable) - Foreground::delete_(arrayTypeTable); + js_delete(arrayTypeTable); if (objectTypeTable) - Foreground::delete_(objectTypeTable); + js_delete(objectTypeTable); if (allocationSiteTable) - Foreground::delete_(allocationSiteTable); + js_delete(allocationSiteTable); } /* static */ void @@ -6067,11 +6067,11 @@ TypeScript::destroy() { while (dynamicList) { TypeResult *next = dynamicList->next; - Foreground::delete_(dynamicList); + js_delete(dynamicList); dynamicList = next; } - Foreground::free_(this); + js_free(this); } /* static */ void diff --git a/js/src/jsiter.cpp b/js/src/jsiter.cpp index 7982b33118df..0915eb7d01e8 100644 --- a/js/src/jsiter.cpp +++ b/js/src/jsiter.cpp @@ -595,7 +595,7 @@ GetIterator(JSContext *cx, HandleObject obj, unsigned flags, MutableHandleValue if (!bytes) return false; JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_ITERABLE, bytes); - cx->free_(bytes); + js_free(bytes); return false; } diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index f0634a5884d7..9ffc496d89c1 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -83,12 +83,12 @@ ComputeAccurateDecimalInteger(JSContext *cx, const jschar *start, const jschar * *dp = js_strtod_harder(cx->runtime->dtoaState, cstr, &estr, &err); if (err == JS_DTOA_ENOMEM) { JS_ReportOutOfMemory(cx); - cx->free_(cstr); + js_free(cstr); return false; } if (err == JS_DTOA_ERANGE && *dp == HUGE_VAL) *dp = js_PositiveInfinity; - cx->free_(cstr); + js_free(cstr); return true; } @@ -514,7 +514,7 @@ ToCStringBuf::ToCStringBuf() :dbuf(NULL) ToCStringBuf::~ToCStringBuf() { if (dbuf) - UnwantedForeground::free_(dbuf); + js_free(dbuf); } JSFixedString * @@ -741,12 +741,12 @@ num_toLocaleString_impl(JSContext *cx, CallArgs args) bool ok = !!cx->localeCallbacks->localeToUnicode(cx, buf, v.address()); if (ok) args.rval().set(v); - cx->free_(buf); + js_free(buf); return ok; } str = js_NewStringCopyN(cx, buf, buflen); - cx->free_(buf); + js_free(buf); if (!str) return false; @@ -1089,9 +1089,9 @@ InitRuntimeNumberState(JSRuntime *rt) size_t decimalPointSize = strlen(decimalPoint) + 1; size_t groupingSize = strlen(grouping) + 1; - char *storage = static_cast(OffTheBooks::malloc_(thousandsSeparatorSize + - decimalPointSize + - groupingSize)); + char *storage = static_cast(js_malloc(thousandsSeparatorSize + + decimalPointSize + + groupingSize)); if (!storage) return false; @@ -1116,7 +1116,7 @@ FinishRuntimeNumberState(JSRuntime *rt) * strings. */ char *storage = const_cast(rt->thousandsSeparator); - Foreground::free_(storage); + js_free(storage); } } /* namespace js */ @@ -1547,7 +1547,7 @@ js_strtod(JSContext *cx, const jschar *s, const jschar *send, i = estr - cstr; if (cstr != cbuf) - cx->free_(cstr); + js_free(cstr); *ep = i ? s1 + i : s; *dp = d; return JS_TRUE; diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index c895c9d64add..512cf27ff678 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -2126,7 +2126,7 @@ NewObject(JSContext *cx, Class *clasp, types::TypeObject *type_, JSObject *paren JSObject *obj = JSObject::create(cx, kind, shape, type, slots); if (!obj) { - cx->free_(slots); + js_free(slots); return NULL; } @@ -2650,9 +2650,9 @@ struct JSObject::TradeGutsReserved { ~TradeGutsReserved() { if (newaslots) - cx->free_(newaslots); + js_free(newaslots); if (newbslots) - cx->free_(newbslots); + js_free(newbslots); } }; @@ -2840,9 +2840,9 @@ JSObject::TradeGuts(JSContext *cx, JSObject *a, JSObject *b, TradeGutsReserved & /* Done with the dynamic slots. */ if (a->hasDynamicSlots()) - cx->free_(a->slots); + js_free(a->slots); if (b->hasDynamicSlots()) - cx->free_(b->slots); + js_free(b->slots); void *apriv = a->hasPrivate() ? a->getPrivate() : NULL; void *bpriv = b->hasPrivate() ? b->getPrivate() : NULL; @@ -3375,7 +3375,7 @@ JSObject::shrinkSlots(JSContext *cx, uint32_t oldCount, uint32_t newCount) size_t newSize = oldSize - (oldCount - newCount) * sizeof(Value); if (newCount == 0) { - cx->free_(slots); + js_free(slots); slots = NULL; if (Probes::objectResizeActive()) Probes::resizeObject(cx, this, oldSize, newSize); diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp index 13ef72790092..71b80e3255c4 100644 --- a/js/src/jsopcode.cpp +++ b/js/src/jsopcode.cpp @@ -713,7 +713,7 @@ Sprinter::~Sprinter() if (initialized) checkInvariants(); #endif - context->free_(base); + js_free(base); } bool @@ -915,7 +915,7 @@ js::Sprint(Sprinter *sp, const char *format, ...) return -1; } offset = sp->put(bp); - sp->context->free_(bp); + js_free(bp); return offset; } @@ -1106,11 +1106,10 @@ js_NewPrinter(JSContext *cx, const char *name, JSFunction *fun, void js_DestroyPrinter(JSPrinter *jp) { - JSContext *cx = jp->sprinter.context; jp->pool.freeAll(); - Foreground::delete_(jp->localNames); + js_delete(jp->localNames); jp->sprinter.Sprinter::~Sprinter(); - cx->free_(jp); + js_free(jp); } JSString * @@ -1182,7 +1181,7 @@ js_printf(JSPrinter *jp, const char *format, ...) /* Allocate temp space, convert format, and put. */ bp = JS_vsmprintf(format, ap); /* XXX vsaprintf */ if (fp) { - jp->sprinter.context->free_(fp); + js_free(fp); format = NULL; } if (!bp) { @@ -1194,7 +1193,7 @@ js_printf(JSPrinter *jp, const char *format, ...) cc = strlen(bp); if (jp->sprinter.put(bp, (size_t)cc) < 0) cc = -1; - jp->sprinter.context->free_(bp); + js_free(bp); va_end(ap); return cc; @@ -1379,7 +1378,7 @@ GetOff(SprintStack *ss, unsigned i) if (off < 0) off = 0; ss->offsets[i] = off; - ss->sprinter.context->free_(bytes); + js_free(bytes); return off; } @@ -4290,7 +4289,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) jsbytecode **argbytecodes = (jsbytecode **) cx->malloc_((size_t)(argc + 1) * sizeof *argbytecodes); if (!argbytecodes) { - cx->free_(argv); + js_free(argv); return NULL; } @@ -4338,8 +4337,8 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) } ss->sprinter.put(rval); - cx->free_(argv); - cx->free_(argbytecodes); + js_free(argv); + js_free(argbytecodes); break; } @@ -4806,7 +4805,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) if (!rval) return NULL; todo = ss->sprinter.put(rval); - cx->free_((void *)rval); + js_free((void *)rval); break; } #endif /* JS_HAS_GENERATOR_EXPRS */ @@ -4928,7 +4927,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) cx->malloc_((size_t)j * sizeof *table); if (tmp) { MergeSort(table, size_t(j), tmp, CompareTableEntries); - Foreground::free_(tmp); + js_free(tmp); ok = true; } else { ok = false; @@ -4937,7 +4936,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) if (ok) ok = DecompileSwitch(ss, table, (unsigned)j, pc, len, off, false); - cx->free_(table); + js_free(table); if (!ok) return NULL; todo = -2; @@ -4980,7 +4979,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) ok = DecompileSwitch(ss, table, (unsigned)npairs, pc, len, off, JS_FALSE); - cx->free_(table); + js_free(table); if (!ok) return NULL; todo = -2; @@ -5052,7 +5051,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) ok = DecompileSwitch(ss, table, (unsigned)ncases, pc, len, off, JS_TRUE); - cx->free_(table); + js_free(table); if (!ok) return NULL; todo = -2; @@ -5371,7 +5370,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb) (*rval == '\0' || (ss->sprinter.put(" ", 1) >= 0 && ss->sprinter.put(rval))); - cx->free_((char *)rval); + js_free((char *)rval); if (!ok) return NULL; ss->sprinter.put("?>", 2); @@ -5797,7 +5796,7 @@ class PCStack PCStack::~PCStack() { - cx->free_(stack); + js_free(stack); } bool @@ -6034,7 +6033,7 @@ ExpressionDecompiler::decompilePC(jsbytecode *pc) ExpressionDecompiler::~ExpressionDecompiler() { - cx->delete_(localNames); + js_delete(localNames); } bool @@ -6213,7 +6212,7 @@ js::DecompileValueGenerator(JSContext *cx, int spindex, HandleValue v, if (result) { if (strcmp(result, "(intermediate value)")) return result; - cx->free_(result); + js_free(result); } } if (!fallback) { @@ -6305,11 +6304,11 @@ DecompileExpression(JSContext *cx, JSScript *script, JSFunction *fun, ~Guard() { if (printer) js_DestroyPrinter(printer); - Foreground::free_(pcstack); + js_free(pcstack); } } g; - g.pcstack = (jsbytecode **)OffTheBooks::malloc_(StackDepth(script) * sizeof *g.pcstack); + g.pcstack = (jsbytecode **)js_malloc(StackDepth(script) * sizeof *g.pcstack); if (!g.pcstack) return NULL; diff --git a/js/src/jsprf.cpp b/js/src/jsprf.cpp index 284f0380a80e..334f27f7432d 100644 --- a/js/src/jsprf.cpp +++ b/js/src/jsprf.cpp @@ -374,7 +374,7 @@ static int cvt_ws(SprintfState *ss, const jschar *ws, int width, int prec, if (!s) return -1; /* JSStuffFunc error indicator. */ result = cvt_s(ss, s, width, prec, flags); - UnwantedForeground::free_(s); + js_free(s); } else { result = cvt_s(ss, NULL, width, prec, flags); } @@ -592,7 +592,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv, if( *rv < 0 ){ if( nas != nasArray ) - UnwantedForeground::free_( nas ); + js_free( nas ); return NULL; } @@ -629,7 +629,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv, default: if( nas != nasArray ) - UnwantedForeground::free_( nas ); + js_free( nas ); *rv = -1; return NULL; } @@ -718,7 +718,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap) if( nas[i-1].type == TYPE_UNKNOWN ){ if( nas && ( nas != nasArray ) ) - UnwantedForeground::free_( nas ); + js_free( nas ); return -1; } @@ -999,7 +999,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap) rv = (*ss->stuff)(ss, "\0", 1); if( nas && ( nas != nasArray ) ){ - UnwantedForeground::free_( nas ); + js_free( nas ); } return rv; @@ -1060,9 +1060,9 @@ static int GrowStuff(SprintfState *ss, const char *sp, uint32_t len) /* Grow the buffer */ newlen = ss->maxlen + ((len > 32) ? len : 32); if (ss->base) { - newbase = (char*) OffTheBooks::realloc_(ss->base, newlen); + newbase = (char*) js_realloc(ss->base, newlen); } else { - newbase = (char*) OffTheBooks::malloc_(newlen); + newbase = (char*) js_malloc(newlen); } if (!newbase) { /* Ran out of memory */ @@ -1101,7 +1101,7 @@ JS_PUBLIC_API(char *) JS_smprintf(const char *fmt, ...) */ JS_PUBLIC_API(void) JS_smprintf_free(char *mem) { - Foreground::free_(mem); + js_free(mem); } JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap) @@ -1116,7 +1116,7 @@ JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap) rv = dosprintf(&ss, fmt, ap); if (rv < 0) { if (ss.base) { - Foreground::free_(ss.base); + js_free(ss.base); } return 0; } @@ -1215,7 +1215,7 @@ JS_PUBLIC_API(char *) JS_vsprintf_append(char *last, const char *fmt, va_list ap rv = dosprintf(&ss, fmt, ap); if (rv < 0) { if (ss.base) { - Foreground::free_(ss.base); + js_free(ss.base); } return 0; } diff --git a/js/src/jspropertytree.cpp b/js/src/jspropertytree.cpp index 2538ffddd375..74daccef9944 100644 --- a/js/src/jspropertytree.cpp +++ b/js/src/jspropertytree.cpp @@ -46,9 +46,9 @@ PropertyTree::newShape(JSContext *cx) static KidsHash * HashChildren(Shape *kid1, Shape *kid2) { - KidsHash *hash = OffTheBooks::new_(); + KidsHash *hash = js_new(); if (!hash || !hash->init(2)) { - Foreground::delete_(hash); + js_delete(hash); return NULL; } @@ -125,7 +125,7 @@ Shape::removeChild(Shape *child) Shape *otherChild = r.front(); JS_ASSERT((r.popFront(), r.empty())); /* No more elements! */ kidp->setShape(otherChild); - js::UnwantedForeground::delete_(hash); + js_delete(hash); } } diff --git a/js/src/jsreflect.cpp b/js/src/jsreflect.cpp index 47e068c6a425..9885dfca8285 100644 --- a/js/src/jsreflect.cpp +++ b/js/src/jsreflect.cpp @@ -3285,7 +3285,7 @@ reflect_parse(JSContext *cx, uint32_t argc, jsval *vp) return JS_FALSE; char *filename = NULL; - AutoReleaseNullablePtr filenamep(cx, filename); + AutoReleaseNullablePtr filenamep(filename); uint32_t lineno = 1; bool loc = true; diff --git a/js/src/jsscope.cpp b/js/src/jsscope.cpp index fffc10c740c3..39fd888724d2 100644 --- a/js/src/jsscope.cpp +++ b/js/src/jsscope.cpp @@ -128,7 +128,7 @@ Shape::hashify(JSContext *cx) return false; if (!table->init(rt, self)) { - rt->free_(table); + js_free(table); return false; } @@ -255,7 +255,7 @@ ShapeTable::change(int log2Delta, JSContext *cx) } /* Finally, free the old entries storage. */ - cx->free_(oldTable); + js_free(oldTable); return true; } diff --git a/js/src/jsscope.h b/js/src/jsscope.h index aa1da15c7c04..b8c884176cd0 100644 --- a/js/src/jsscope.h +++ b/js/src/jsscope.h @@ -130,7 +130,7 @@ struct ShapeTable { } ~ShapeTable() { - js::UnwantedForeground::free_(entries); + js_free(entries); } /* By definition, hashShift = HASH_BITS - log2(capacity). */ diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 2b8596ac1533..6475f09e2540 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -777,8 +777,8 @@ JSScript::initScriptCounts(JSContext *cx) if (!map) { map = cx->new_(); if (!map || !map->init()) { - cx->free_(cursor); - cx->delete_(map); + js_free(cursor); + js_delete(map); return false; } compartment()->scriptCountsMap = map; @@ -802,8 +802,8 @@ JSScript::initScriptCounts(JSContext *cx) } if (!map->putNew(this, scriptCounts)) { - cx->free_(cursor); - cx->delete_(map); + js_free(cursor); + js_delete(map); return false; } hasScriptCounts = true; // safe to set this; we can't fail after this point @@ -1057,7 +1057,7 @@ void SourceDataCache::put(ScriptSource *ss, JSFixedString *str) { if (!map_) { - map_ = OffTheBooks::new_(); + map_ = js_new(); if (!map_) return; if (!map_->init()) { @@ -1072,7 +1072,7 @@ SourceDataCache::put(ScriptSource *ss, JSFixedString *str) void SourceDataCache::purge() { - Foreground::delete_(map_); + js_delete(map_); map_ = NULL; } @@ -1093,13 +1093,13 @@ ScriptSource::substring(JSContext *cx, uint32_t start, uint32_t stop) if (!DecompressString(data.compressed, compressedLength_, reinterpret_cast(decompressed), nbytes)) { JS_ReportOutOfMemory(cx); - cx->free_(decompressed); + js_free(decompressed); return NULL; } decompressed[length_] = 0; cached = js_NewString(cx, decompressed, length_); if (!cached) { - cx->free_(decompressed); + js_free(decompressed); return NULL; } cx->runtime->sourceDataCache.put(this, cached); @@ -1173,12 +1173,12 @@ void ScriptSource::destroy(JSRuntime *rt) { JS_ASSERT(ready()); - rt->free_(data.compressed); - rt->free_(sourceMap_); + js_free(data.compressed); + js_free(sourceMap_); #ifdef DEBUG ready_ = false; #endif - rt->free_(this); + js_free(this); } size_t @@ -1227,7 +1227,7 @@ ScriptSource::performXDR(XDRState *xdr) } if (!xdr->codeBytes(data.compressed, byteLen)) { if (mode == XDR_DECODE) { - xdr->cx()->free_(data.compressed); + js_free(data.compressed); data.compressed = NULL; } return false; @@ -1254,7 +1254,7 @@ ScriptSource::performXDR(XDRState *xdr) } if (!xdr->codeChars(sourceMap_, sourceMapLen)) { if (mode == XDR_DECODE) { - xdr->cx()->free_(sourceMap_); + js_free(sourceMap_); sourceMap_ = NULL; } return false; @@ -1277,7 +1277,7 @@ ScriptSource::setSourceMap(JSContext *cx, jschar *sourceMapURL, const char *file if (hasSourceMap()) { if (!JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, js_GetErrorMessage, NULL, JSMSG_ALREADY_HAS_SOURCEMAP, filename)) { - cx->free_(sourceMapURL); + js_free(sourceMapURL); return false; } } @@ -1314,7 +1314,7 @@ js::SaveScriptFilename(JSContext *cx, const char *filename) strcpy(entry->filename, filename); if (!rt->scriptFilenameTable.add(p, entry)) { - Foreground::free_(entry); + js_free(entry); JS_ReportOutOfMemory(cx); return NULL; } @@ -1345,7 +1345,7 @@ js::SweepScriptFilenames(JSRuntime *rt) if (entry->marked) { entry->marked = false; } else if (!rt->gcKeepAtoms) { - Foreground::free_(entry); + js_free(entry); e.removeFront(); } } @@ -1356,7 +1356,7 @@ js::FreeScriptFilenames(JSRuntime *rt) { ScriptFilenameTable &table = rt->scriptFilenameTable; for (ScriptFilenameTable::Enum e(table); !e.empty(); e.popFront()) - Foreground::free_(e.front()); + js_free(e.front()); table.clear(); } @@ -2126,7 +2126,7 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, options, src->staticLevel, src->scriptSource(), src->sourceStart, src->sourceEnd); if (!dst) { - Foreground::free_(data); + js_free(data); return NULL; } @@ -2256,16 +2256,16 @@ JSScript::ensureHasDebugScript(JSContext *cx) if (!map) { map = cx->new_(); if (!map || !map->init()) { - cx->free_(debug); - cx->delete_(map); + js_free(debug); + js_delete(map); return false; } compartment()->debugScriptMap = map; } if (!map->putNew(this, debug)) { - cx->free_(debug); - cx->delete_(map); + js_free(debug); + js_delete(map); return false; } hasDebugScript = true; // safe to set this; we can't fail after this point @@ -2307,7 +2307,7 @@ JSScript::tryNewStepMode(JSContext *cx, uint32_t newValue) recompileForStepMode(cx->runtime->defaultFreeOp()); if (!stepModeEnabled() && !debug->numSites) - cx->free_(releaseDebugScript()); + js_free(releaseDebugScript()); } return true; diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index 8fce241939ae..5e163d4b3528 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -192,7 +192,7 @@ str_escape(JSContext *cx, unsigned argc, Value *vp) JSString *retstr = js_NewString(cx, newchars, newlength); if (!retstr) { - cx->free_(newchars); + js_free(newchars); return false; } @@ -624,7 +624,7 @@ js_toLowerCase(JSContext *cx, JSString *str) news[n] = 0; str = js_NewString(cx, news, n); if (!str) { - cx->free_(news); + js_free(news); return NULL; } return str; @@ -691,7 +691,7 @@ js_toUpperCase(JSContext *cx, JSString *str) news[n] = 0; str = js_NewString(cx, news, n); if (!str) { - cx->free_(news); + js_free(news); return NULL; } return str; @@ -3192,7 +3192,7 @@ js::str_fromCharCode(JSContext *cx, unsigned argc, Value *vp) for (unsigned i = 0; i < args.length(); i++) { uint16_t code; if (!ToUint16(cx, args[i], &code)) { - cx->free_(chars); + js_free(chars); return JS_FALSE; } chars[i] = (jschar)code; @@ -3200,7 +3200,7 @@ js::str_fromCharCode(JSContext *cx, unsigned argc, Value *vp) chars[args.length()] = 0; JSString *str = js_NewString(cx, chars, args.length()); if (!str) { - cx->free_(chars); + js_free(chars); return JS_FALSE; } @@ -3343,7 +3343,7 @@ js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n) news[n] = 0; JSFixedString *str = js_NewString(cx, news, n); if (!str) - cx->free_(news); + js_free(news); return str; } @@ -3358,7 +3358,7 @@ js_NewStringCopyN(JSContext *cx, const char *s, size_t n) return NULL; JSFixedString *str = js_NewString(cx, chars, n); if (!str) - cx->free_(chars); + js_free(chars); return str; } @@ -3376,7 +3376,7 @@ js_NewStringCopyZ(JSContext *cx, const jschar *s) js_memcpy(news, s, m); JSFixedString *str = js_NewString(cx, news, n); if (!str) - cx->free_(news); + js_free(news); return str; } @@ -3654,13 +3654,13 @@ DeflateString(JSContext *cx, const jschar *chars, size_t nchars) nbytes = GetDeflatedStringLength(cx, chars, nchars); if (nbytes == (size_t) -1) return NULL; - bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : OffTheBooks::malloc_(nbytes + 1)); + bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : js_malloc(nbytes + 1)); if (!bytes) return NULL; JS_ALWAYS_TRUE(DeflateStringToBuffer(cx, chars, nchars, bytes, &nbytes)); } else { nbytes = nchars; - bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : OffTheBooks::malloc_(nbytes + 1)); + bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : js_malloc(nbytes + 1)); if (!bytes) return NULL; for (i = 0; i < nbytes; i++) diff --git a/js/src/jstypedarray.cpp b/js/src/jstypedarray.cpp index 6a8e7e86da16..afc531430991 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -211,7 +211,7 @@ AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes, uint8_t *conten { uint32_t size = nbytes + sizeof(ObjectElements); ObjectElements *newheader = - static_cast(maybecx ? maybecx->calloc_(size) : OffTheBooks::calloc_(size)); + static_cast(maybecx ? maybecx->calloc_(size) : js_calloc(size)); if (!newheader) { if (maybecx) js_ReportOutOfMemory(maybecx); @@ -2181,7 +2181,7 @@ class TypedArrayTemplate break; } - UnwantedForeground::free_(srcbuf); + js_free(srcbuf); return true; } diff --git a/js/src/jsutil.cpp b/js/src/jsutil.cpp index 3489e48d8ae9..669ec04d745c 100644 --- a/js/src/jsutil.cpp +++ b/js/src/jsutil.cpp @@ -33,13 +33,13 @@ using namespace js; static void * zlib_alloc(void *cx, uInt items, uInt size) { - return OffTheBooks::malloc_(items * size); + return js_malloc(items * size); } static void zlib_free(void *cx, void *addr) { - Foreground::free_(addr); + js_free(addr); } bool diff --git a/js/src/jsweakmap.cpp b/js/src/jsweakmap.cpp index c9dad7668fd5..7d2be1f8a9ac 100644 --- a/js/src/jsweakmap.cpp +++ b/js/src/jsweakmap.cpp @@ -242,7 +242,7 @@ WeakMap_set_impl(JSContext *cx, CallArgs args) if (!map) { map = cx->new_(cx, thisObj.get()); if (!map->init()) { - cx->delete_(map); + js_delete(map); JS_ReportOutOfMemory(cx); return false; } diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index 32c0010c0bef..412574b635aa 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -378,14 +378,14 @@ ConvertQNameToString(JSContext *cx, JSObject *obj) *chars = '@'; const jschar *strChars = str->getChars(cx); if (!strChars) { - cx->free_(chars); + js_free(chars); return NULL; } js_strncpy(chars + 1, strChars, length); chars[++length] = 0; str = js_NewString(cx, chars, length); if (!str) { - cx->free_(chars); + js_free(chars); return NULL; } } @@ -862,7 +862,7 @@ ReallocateVector(HeapPtr *vector, size_t count) #endif size_t size = count * sizeof(HeapPtr); - return (HeapPtr *) OffTheBooks::realloc_(vector, size); + return (HeapPtr *) js_realloc(vector, size); } /* NB: called with null cx from the GC, via xml_trace => JSXMLArray::trim. */ @@ -874,9 +874,9 @@ JSXMLArray::setCapacity(JSContext *cx, uint32_t newCapacity) /* We could let realloc(p, 0) free this, but purify gets confused. */ if (vector) { if (cx) - cx->free_(vector); + js_free(vector); else - Foreground::free_(vector); + js_free(vector); } vector = NULL; } else { @@ -1062,7 +1062,7 @@ XMLArrayTruncate(JSContext *cx, JSXMLArray *array, uint32_t length) if (length == 0) { if (array->vector) - cx->free_(array->vector); + js_free(array->vector); vector = NULL; } else { vector = ReallocateVector(array->vector, length); @@ -1733,7 +1733,7 @@ ParseXMLSource(JSContext *cx, HandleString src) offset += dstlen; srcp = src->getChars(cx); if (!srcp) { - cx->free_(chars); + js_free(chars); return NULL; } js_strncpy(chars + offset, srcp, srclen); @@ -1765,7 +1765,7 @@ ParseXMLSource(JSContext *cx, HandleString src) if (parser.init()) { JSObject *scopeChain = GetCurrentScopeChain(cx); if (!scopeChain) { - cx->free_(chars); + js_free(chars); return NULL; } @@ -1779,7 +1779,7 @@ ParseXMLSource(JSContext *cx, HandleString src) } } - cx->free_(chars); + js_free(chars); return xml; #undef constrlen @@ -2360,7 +2360,7 @@ GeneratePrefix(JSContext *cx, JSLinearString *uri, JSXMLArray *decls) } else { prefix = js_NewString(cx, bp, newlength); if (!prefix) - cx->free_(bp); + js_free(bp); } return prefix; } @@ -5102,7 +5102,7 @@ xml_enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op, Value *state if (!statep->isInt32(0)) { cursor = (JSXMLArrayCursor *) statep->toPrivate(); if (cursor) - cx->delete_(cursor); + js_delete(cursor); } statep->setNull(); break; diff --git a/js/src/methodjit/Compiler.cpp b/js/src/methodjit/Compiler.cpp index 3ac7b5faa6c5..10b2c9c0a65d 100644 --- a/js/src/methodjit/Compiler.cpp +++ b/js/src/methodjit/Compiler.cpp @@ -384,7 +384,7 @@ mjit::Compiler::pushActiveFrame(JSScript *script, uint32_t argc) if (cx->runtime->profilingScripts && !script->hasScriptCounts) script->initScriptCounts(cx); - ActiveFrame *newa = OffTheBooks::new_(cx); + ActiveFrame *newa = js_new(cx); if (!newa) { js_ReportOutOfMemory(cx); return Compile_Error; @@ -435,7 +435,7 @@ mjit::Compiler::pushActiveFrame(JSScript *script, uint32_t argc) return Compile_Error; } - newa->jumpMap = (Label *)OffTheBooks::malloc_(sizeof(Label) * script->length); + newa->jumpMap = (Label *)js_malloc(sizeof(Label) * script->length); if (!newa->jumpMap) { js_ReportOutOfMemory(cx); return Compile_Error; @@ -525,7 +525,7 @@ mjit::Compiler::performCompilation() if (outerScript->hasScriptCounts || Probes::wantNativeAddressInfo(cx)) { size_t length = ssa.frameLength(ssa.numFrames() - 1); - pcLengths = (PCLengthEntry *) OffTheBooks::calloc_(sizeof(pcLengths[0]) * length); + pcLengths = (PCLengthEntry *) js_calloc(sizeof(pcLengths[0]) * length); if (!pcLengths) return Compile_Error; } @@ -568,20 +568,20 @@ mjit::Compiler::ActiveFrame::ActiveFrame(JSContext *cx) mjit::Compiler::ActiveFrame::~ActiveFrame() { - js::Foreground::free_(jumpMap); + js_free(jumpMap); if (varTypes) - js::Foreground::free_(varTypes); + js_free(varTypes); } mjit::Compiler::~Compiler() { if (outer) - cx->delete_(outer); + js_delete(outer); for (unsigned i = 0; i < inlineFrames.length(); i++) - cx->delete_(inlineFrames[i]); + js_delete(inlineFrames[i]); while (loop) { LoopState *nloop = loop->outer; - cx->delete_(loop); + js_delete(loop); loop = nloop; } } @@ -611,8 +611,7 @@ mjit::Compiler::prepareInferenceTypes(JSScript *script, ActiveFrame *a) * only if a variable has the same value on all incoming edges. */ - a->varTypes = (VarType *) - OffTheBooks::calloc_(TotalSlots(script) * sizeof(VarType)); + a->varTypes = (VarType *)js_calloc(TotalSlots(script) * sizeof(VarType)); if (!a->varTypes) { js_ReportOutOfMemory(cx); return Compile_Error; @@ -857,7 +856,7 @@ MakeJITScript(JSContext *cx, JSScript *script) size_t dataSize = sizeof(JITScript) + (chunks.length() * sizeof(ChunkDescriptor)) + (edges.length() * sizeof(CrossChunkEdge)); - uint8_t *cursor = (uint8_t *) OffTheBooks::calloc_(dataSize); + uint8_t *cursor = (uint8_t *) js_calloc(dataSize); if (!cursor) return NULL; @@ -1355,7 +1354,7 @@ mjit::Compiler::finishThisUp() #endif 0; - uint8_t *cursor = (uint8_t *)OffTheBooks::calloc_(dataSize); + uint8_t *cursor = (uint8_t *)js_calloc(dataSize); if (!cursor) { execPool->release(); js_ReportOutOfMemory(cx); @@ -1808,7 +1807,7 @@ mjit::Compiler::finishThisUp() if (!Probes::registerMJITCode(cx, chunk, a, (JSActiveFrame**) inlineFrames.begin())) { execPool->release(); - cx->free_(chunk); + js_free(chunk); js_ReportOutOfMemory(cx); return Compile_Error; } @@ -1826,14 +1825,14 @@ mjit::Compiler::finishThisUp() JSOp op = JSOp(script->code[edge.source]); if (op == JSOP_TABLESWITCH) { if (edge.jumpTableEntries) - cx->free_(edge.jumpTableEntries); + js_free(edge.jumpTableEntries); CrossChunkEdge::JumpTableEntryVector *jumpTableEntries = NULL; bool failed = false; for (unsigned j = 0; j < chunkJumps.length(); j++) { ChunkJumpTableEdge nedge = chunkJumps[j]; if (nedge.edge.source == edge.source && nedge.edge.target == edge.target) { if (!jumpTableEntries) { - jumpTableEntries = OffTheBooks::new_(); + jumpTableEntries = js_new(); if (!jumpTableEntries) failed = true; } @@ -1844,7 +1843,7 @@ mjit::Compiler::finishThisUp() } if (failed) { execPool->release(); - cx->free_(chunk); + js_free(chunk); js_ReportOutOfMemory(cx); return Compile_Error; } @@ -4618,7 +4617,7 @@ mjit::Compiler::inlineScriptedFunction(uint32_t argc, bool callingNew) frame.popn(argc + 2); if (entrySnapshot) - cx->array_delete(entrySnapshot); + js_free(entrySnapshot); if (exitState) frame.discardForJoin(exitState, analysis->getCode(PC).stackDepth - (argc + 2)); @@ -6895,7 +6894,7 @@ mjit::Compiler::startLoop(jsbytecode *head, Jump entry, jsbytecode *entryTarget) loop->clearLoopRegisters(); } - LoopState *nloop = OffTheBooks::new_(cx, &ssa, this, &frame); + LoopState *nloop = js_new(cx, &ssa, this, &frame); if (!nloop || !nloop->init(head, entry, entryTarget)) { js_ReportOutOfMemory(cx); return false; @@ -7032,7 +7031,7 @@ mjit::Compiler::finishLoop(jsbytecode *head) loop->flushLoop(stubcc); LoopState *nloop = loop->outer; - cx->delete_(loop); + js_delete(loop); loop = nloop; frame.setLoop(loop); diff --git a/js/src/methodjit/FrameState.cpp b/js/src/methodjit/FrameState.cpp index 3a86257b322f..ed34a614ccc9 100644 --- a/js/src/methodjit/FrameState.cpp +++ b/js/src/methodjit/FrameState.cpp @@ -31,10 +31,10 @@ FrameState::~FrameState() ActiveFrame *parent = a->parent; if (a->script->hasAnalysis()) a->script->analysis()->clearAllocations(); - cx->free_(a); + js_free(a); a = parent; } - cx->free_(entries); + js_free(entries); } void @@ -63,7 +63,7 @@ FrameState::pushActiveFrame(JSScript *script, uint32_t argc) size_t totalBytes = sizeof(FrameEntry) * nentries + // entries[] sizeof(FrameEntry *) * nentries + // tracker.entries sizeof(StackEntryExtra) * nentries; // extraArray - uint8_t *cursor = (uint8_t *)OffTheBooks::calloc_(totalBytes); + uint8_t *cursor = (uint8_t *)js_calloc(totalBytes); if (!cursor) return false; @@ -89,7 +89,7 @@ FrameState::pushActiveFrame(JSScript *script, uint32_t argc) /* We should have already checked that argc == nargs */ JS_ASSERT_IF(a, argc == script->function()->nargs); - ActiveFrame *newa = OffTheBooks::new_(); + ActiveFrame *newa = js_new(); if (!newa) return false; @@ -147,7 +147,7 @@ FrameState::popActiveFrame() } ActiveFrame *parent = a->parent; - cx->delete_(a); + js_delete(a); a = parent; } @@ -474,7 +474,7 @@ FrameEntry * FrameState::snapshotState() { /* Everything can be recovered from a copy of the frame entries. */ - FrameEntry *snapshot = cx->array_new(nentries); + FrameEntry *snapshot = (FrameEntry *)js_malloc(nentries * sizeof(FrameEntry)); if (!snapshot) return NULL; PodCopy(snapshot, entries, nentries); @@ -2858,7 +2858,7 @@ FrameState::getTemporaryCopies(Uses uses) FrameEntry *nfe = tracker[i]; if (!deadEntry(nfe, uses.nuses) && nfe->isCopy() && nfe->copyOf() == fe) { if (!res) - res = OffTheBooks::new_< Vector >(cx); + res = js_new< Vector >(cx); res->append(TemporaryCopy(addressOf(nfe), addressOf(fe))); } } diff --git a/js/src/methodjit/ImmutableSync.cpp b/js/src/methodjit/ImmutableSync.cpp index 2bc9250859ab..1eacccfab722 100644 --- a/js/src/methodjit/ImmutableSync.cpp +++ b/js/src/methodjit/ImmutableSync.cpp @@ -23,7 +23,7 @@ ImmutableSync::ImmutableSync() ImmutableSync::~ImmutableSync() { if (cx) - cx->free_(entries); + js_free(entries); } bool @@ -32,7 +32,7 @@ ImmutableSync::init(JSContext *cx, const FrameState &frame, uint32_t nentries) this->cx = cx; this->frame = &frame; - entries = (SyncEntry *)OffTheBooks::calloc_(sizeof(SyncEntry) * nentries); + entries = (SyncEntry *)js_calloc(sizeof(SyncEntry) * nentries); return !!entries; } diff --git a/js/src/methodjit/LoopState.cpp b/js/src/methodjit/LoopState.cpp index 728800a8bb39..04e6b70dc1c2 100644 --- a/js/src/methodjit/LoopState.cpp +++ b/js/src/methodjit/LoopState.cpp @@ -1438,7 +1438,7 @@ LoopState::restoreInvariants(jsbytecode *pc, Assembler &masm, } if (temporaryCopies) - cx->delete_(temporaryCopies); + js_delete(temporaryCopies); } /* Loop analysis methods. */ diff --git a/js/src/methodjit/MethodJIT.cpp b/js/src/methodjit/MethodJIT.cpp index 64664f9e000a..2adafcfa71bb 100644 --- a/js/src/methodjit/MethodJIT.cpp +++ b/js/src/methodjit/MethodJIT.cpp @@ -1260,7 +1260,7 @@ JITChunk::~JITChunk() rootedRegExps()[i]->decRef(); if (pcLengths) - Foreground::free_(pcLengths); + js_free(pcLengths); } void diff --git a/js/src/methodjit/PolyIC.cpp b/js/src/methodjit/PolyIC.cpp index ec88862ac1d9..11c8050d7708 100644 --- a/js/src/methodjit/PolyIC.cpp +++ b/js/src/methodjit/PolyIC.cpp @@ -2377,7 +2377,7 @@ GetElementIC::attachGetProp(VMFrame &f, HandleObject obj, HandleValue v, HandleP JaegerSpew(JSpew_PICs, "generated %s stub at %p for atom %p (\"%s\") shape %p (%s: %d)\n", js_CodeName[JSOp(*f.pc())], cs.executableAddress(), (void*)name, chars, (void*)holder->lastProperty(), cx->fp()->script()->filename, CurrentLine(cx)); - cx->free_(chars); + js_free(chars); #endif // Update the inline guards, if needed. diff --git a/js/src/methodjit/PolyIC.h b/js/src/methodjit/PolyIC.h index fa010ab36ea7..18d4cc2dcaa0 100644 --- a/js/src/methodjit/PolyIC.h +++ b/js/src/methodjit/PolyIC.h @@ -129,11 +129,11 @@ class BasePolyIC : public BaseIC { if (isOnePool()) { JSC::ExecutablePool *oldPool = u.execPool; JS_ASSERT(!isTagged(oldPool)); - ExecPoolVector *execPools = OffTheBooks::new_(SystemAllocPolicy()); + ExecPoolVector *execPools = js_new(SystemAllocPolicy()); if (!execPools) return false; if (!execPools->append(oldPool) || !execPools->append(pool)) { - Foreground::delete_(execPools); + js_delete(execPools); return false; } u.taggedExecPools = tag(execPools); @@ -154,7 +154,7 @@ class BasePolyIC : public BaseIC { ExecPoolVector *execPools = multiplePools(); for (size_t i = 0; i < execPools->length(); i++) (*execPools)[i]->release(); - Foreground::delete_(execPools); + js_delete(execPools); u.execPool = NULL; } JS_ASSERT(areZeroPools()); diff --git a/js/src/perf/pm_linux.cpp b/js/src/perf/pm_linux.cpp index 0a422f595016..fce4b78d6d09 100644 --- a/js/src/perf/pm_linux.cpp +++ b/js/src/perf/pm_linux.cpp @@ -234,7 +234,7 @@ namespace JS { #define initCtr(flag) ((eventsMeasured & flag) ? 0 : -1) PerfMeasurement::PerfMeasurement(PerfMeasurement::EventMask toMeasure) - : impl(OffTheBooks::new_()), + : impl(js_new()), eventsMeasured(impl ? static_cast(impl)->init(toMeasure) : EventMask(0)), cpu_cycles(initCtr(CPU_CYCLES)), @@ -255,7 +255,7 @@ PerfMeasurement::PerfMeasurement(PerfMeasurement::EventMask toMeasure) PerfMeasurement::~PerfMeasurement() { - js::Foreground::delete_(static_cast(impl)); + js_delete(static_cast(impl)); } void diff --git a/js/src/shell/jsheaptools.cpp b/js/src/shell/jsheaptools.cpp index 6a3a53a638da..cd1438f5776f 100644 --- a/js/src/shell/jsheaptools.cpp +++ b/js/src/shell/jsheaptools.cpp @@ -491,7 +491,7 @@ ReferenceFinder::addReferrer(jsval referrer_, Path *path) char *pathName = path->computeName(context); if (!pathName) return false; - AutoReleasePtr releasePathName(context, pathName); + AutoReleasePtr releasePathName(pathName); /* Find the property of the results object named |pathName|. */ JS::RootedValue valRoot(context); diff --git a/js/src/shell/jsoptparse.cpp b/js/src/shell/jsoptparse.cpp index b49d0a525b7a..1a54690de8c8 100644 --- a/js/src/shell/jsoptparse.cpp +++ b/js/src/shell/jsoptparse.cpp @@ -442,9 +442,9 @@ OptionParser::getMultiStringOption(const char *longflag) const OptionParser::~OptionParser() { for (Option **it = options.begin(), **end = options.end(); it != end; ++it) - Foreground::delete_