diff --git a/js/src/Makefile.in b/js/src/Makefile.in index d442b58b1100..38a2a00a6c15 100644 --- a/js/src/Makefile.in +++ b/js/src/Makefile.in @@ -144,7 +144,6 @@ CPPSRCS = \ jsscope.cpp \ jsscript.cpp \ jsstr.cpp \ - jstask.cpp \ jsutil.cpp \ jsxdrapi.cpp \ jsxml.cpp \ @@ -201,7 +200,6 @@ INSTALLED_HEADERS = \ jsscript.h \ jsstaticcheck.h \ jsstr.h \ - jstask.h \ jstracer.h \ jstypes.h \ jsutil.h \ diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index c684f075b8fd..856537534671 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -79,7 +79,6 @@ #include "jsscope.h" #include "jsscript.h" #include "jsstr.h" -#include "jstask.h" #include "jstracer.h" #include "jsdbgapi.h" #include "prmjtime.h" @@ -818,9 +817,6 @@ JS_NewRuntime(uint32 maxbytes) rt->debuggerLock = JS_NEW_LOCK(); if (!rt->debuggerLock) goto bad; - rt->deallocatorThread = new JSBackgroundThread(); - if (!rt->deallocatorThread || !rt->deallocatorThread->init()) - goto bad; #endif if (!js_InitPropertyTree(rt)) goto bad; @@ -890,10 +886,6 @@ JS_DestroyRuntime(JSRuntime *rt) JS_DESTROY_CONDVAR(rt->titleSharingDone); if (rt->debuggerLock) JS_DESTROY_LOCK(rt->debuggerLock); - if (rt->deallocatorThread) { - rt->deallocatorThread->cancel(); - delete rt->deallocatorThread; - } #endif js_FinishPropertyTree(rt); free(rt); @@ -1847,8 +1839,8 @@ JS_malloc(JSContext *cx, size_t nbytes) void *p; JS_ASSERT(nbytes != 0); - if (nbytes < sizeof(jsuword)) - nbytes = sizeof(jsuword); + if (nbytes == 0) + nbytes = 1; p = malloc(nbytes); if (!p) { diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 5d9d4f49b0a5..2d121e3ddc4b 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -1188,7 +1188,7 @@ static void array_finalize(JSContext *cx, JSObject *obj) { if (obj->dslots) - cx->runtime->asynchronousFree(obj->dslots - 1); + JS_free(cx, obj->dslots - 1); obj->dslots = NULL; } diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 0668897f90a3..a7c81a697c16 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -57,7 +57,6 @@ #include "jsregexp.h" #include "jsutil.h" #include "jsarray.h" -#include "jstask.h" JS_BEGIN_EXTERN_C @@ -687,24 +686,6 @@ struct JSRuntime { void setGCTriggerFactor(uint32 factor); void setGCLastBytes(size_t lastBytes); - -#ifdef JS_THREADSAFE - JSBackgroundThread *deallocatorThread; - JSFreePointerListTask *deallocatorTask; - - inline void asynchronousFree(void* p) { - if (p) { - if (deallocatorTask) - deallocatorTask->add(p); - else - free(p); - } - } -#else - inline void asynchronousFree(void* p) { - free(p); - } -#endif }; /* Common macros to access thread-local caches in JSThread or JSRuntime. */ diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 6af897192dd9..45fe5352a14c 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -76,7 +76,6 @@ #include "jsscript.h" #include "jsstaticcheck.h" #include "jsstr.h" -#include "jstask.h" #include "jstracer.h" #if JS_HAS_XML_SUPPORT @@ -3364,7 +3363,7 @@ js_FinalizeStringRT(JSRuntime *rt, JSString *str, intN type, JSContext *cx) JS_ASSERT(type < 0); rt->unitStrings[*chars] = NULL; } else if (type < 0) { - rt->asynchronousFree(chars); + free(chars); } else { JS_ASSERT((uintN) type < JS_ARRAY_LENGTH(str_finalizers)); finalizer = str_finalizers[type]; @@ -3645,12 +3644,6 @@ js_GC(JSContext *cx, JSGCInvocationKind gckind) rt->gcMarkingTracer = NULL; -#ifdef JS_THREADSAFE - JS_ASSERT(!rt->deallocatorTask); - if (rt->deallocatorThread && !rt->deallocatorThread->busy()) - rt->deallocatorTask = new JSFreePointerListTask(); -#endif - /* * Sweep phase. * @@ -3837,13 +3830,6 @@ js_GC(JSContext *cx, JSGCInvocationKind gckind) */ DestroyGCArenas(rt, emptyArenas); -#ifdef JS_THREADSAFE - if (rt->deallocatorTask) { - rt->deallocatorThread->schedule(rt->deallocatorTask); - rt->deallocatorTask = NULL; - } -#endif - if (rt->gcCallback) (void) rt->gcCallback(cx, JSGC_FINALIZE_END); #ifdef DEBUG_srcnotesize diff --git a/js/src/jsgc.h b/js/src/jsgc.h index cc37e8505b50..42e22bdab236 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -47,7 +47,6 @@ #include "jsdhash.h" #include "jsbit.h" #include "jsutil.h" -#include "jstask.h" JS_BEGIN_EXTERN_C @@ -354,29 +353,6 @@ js_AddAsGCBytes(JSContext *cx, size_t sz); extern void js_RemoveAsGCBytes(JSRuntime* rt, size_t sz); -#ifdef JS_THREADSAFE -class JSFreePointerListTask : public JSBackgroundTask { - void* head; - - public: - JSFreePointerListTask() : head(NULL) {} - - void add(void* ptr) { - *(void**)ptr = head; - head = ptr; - } - - void run() { - void *ptr = head; - while (ptr) { - void* next = *(void **)ptr; - free(ptr); - ptr = next; - } - } -}; -#endif - /* * Free the chars held by str when it is finalized by the GC. When type is * less then zero, it denotes an internal string. Otherwise it denotes the diff --git a/js/src/jsiter.cpp b/js/src/jsiter.cpp index 919ab16a9e87..f941a6e3bd7e 100644 --- a/js/src/jsiter.cpp +++ b/js/src/jsiter.cpp @@ -649,7 +649,7 @@ generator_finalize(JSContext *cx, JSObject *obj) */ JS_ASSERT(gen->state == JSGEN_NEWBORN || gen->state == JSGEN_CLOSED || gen->state == JSGEN_OPEN); - cx->runtime->asynchronousFree(gen); + JS_free(cx, gen); } } diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 8fdaafabef22..6b16b191d0e5 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -3066,7 +3066,7 @@ js_ShrinkSlots(JSContext *cx, JSObject *obj, size_t nslots) JS_ASSERT(nslots <= size_t(slots[-1])); if (nslots <= JS_INITIAL_NSLOTS) { - cx->runtime->asynchronousFree(slots - 1); + JS_free(cx, slots - 1); obj->dslots = NULL; } else { size_t nwords = SLOTS_TO_DYNAMIC_WORDS(nslots); diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h index 90c4f40fe119..6c28b136a792 100644 --- a/js/src/jspubtd.h +++ b/js/src/jspubtd.h @@ -145,6 +145,7 @@ typedef struct JSObject JSObject; typedef struct JSObjectMap JSObjectMap; typedef struct JSObjectOps JSObjectOps; typedef struct JSRuntime JSRuntime; +typedef struct JSRuntime JSTaskState; /* XXX deprecated name */ typedef struct JSScript JSScript; typedef struct JSStackFrame JSStackFrame; typedef struct JSString JSString; diff --git a/js/src/jsregexp.cpp b/js/src/jsregexp.cpp index b80666cbcfa9..91a41e49da76 100644 --- a/js/src/jsregexp.cpp +++ b/js/src/jsregexp.cpp @@ -3807,9 +3807,9 @@ js_DestroyRegExp(JSContext *cx, JSRegExp *re) JS_free(cx, re->classList[i].u.bits); re->classList[i].u.bits = NULL; } - cx->runtime->asynchronousFree(re->classList); + JS_free(cx, re->classList); } - cx->runtime->asynchronousFree(re); + JS_free(cx, re); } } diff --git a/js/src/jsscope.cpp b/js/src/jsscope.cpp index f14a5b2914f0..a9689fcfe02b 100644 --- a/js/src/jsscope.cpp +++ b/js/src/jsscope.cpp @@ -252,7 +252,7 @@ JSScope::destroy(JSContext *cx, JSScope *scope) js_FinishTitle(cx, &scope->title); #endif if (scope->table) - cx->runtime->asynchronousFree(scope->table); + JS_free(cx, scope->table); if (scope->emptyScope) scope->emptyScope->drop(cx, NULL); diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 463feea707a2..ff817993e96b 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -1639,7 +1639,7 @@ js_DestroyScript(JSContext *cx, JSScript *script) } } - cx->runtime->asynchronousFree(script); + JS_free(cx, script); } void diff --git a/js/src/jstask.cpp b/js/src/jstask.cpp deleted file mode 100644 index 417e81523892..000000000000 --- a/js/src/jstask.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: set ts=4 sw=4 et tw=99 ft=cpp: - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla SpiderMonkey JavaScript 1.9.1 code, released - * June 30, 2009. - * - * The Initial Developer of the Original Code is - * Andreas Gal - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "jstask.h" - -#ifdef JS_THREADSAFE -static void start(void* arg) { - ((JSBackgroundThread*)arg)->work(); -} - -JSBackgroundThread::JSBackgroundThread() - : thread(NULL), stack(NULL), lock(NULL), wakeup(NULL), shutdown(false) -{ -} - -JSBackgroundThread::~JSBackgroundThread() -{ - if (wakeup) - PR_DestroyCondVar(wakeup); - if (lock) - PR_DestroyLock(lock); - /* PR_DestroyThread is not necessary. */ -} - -bool -JSBackgroundThread::init() -{ - if (!(lock = PR_NewLock())) - return false; - if (!(wakeup = PR_NewCondVar(lock))) - return false; - thread = PR_CreateThread(PR_USER_THREAD, start, this, PR_PRIORITY_LOW, - PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); - return !!thread; -} - -void -JSBackgroundThread::cancel() -{ - PR_Lock(lock); - if (shutdown) { - PR_Unlock(lock); - return; - } - shutdown = true; - PR_NotifyCondVar(wakeup); - PR_Unlock(lock); - PR_JoinThread(thread); -} - -void -JSBackgroundThread::work() -{ - PR_Lock(lock); - do { - PR_WaitCondVar(wakeup, PR_INTERVAL_NO_TIMEOUT); - JSBackgroundTask* task; - while ((task = stack) != NULL) { - stack = task->next; - PR_Unlock(lock); - task->run(); - delete task; - PR_Lock(lock); - } - } while (!shutdown); - PR_Unlock(lock); -} - -bool -JSBackgroundThread::busy() -{ - return !!stack; // we tolerate some racing here -} - -void -JSBackgroundThread::schedule(JSBackgroundTask* task) -{ - PR_Lock(lock); - if (shutdown) { - PR_Unlock(lock); - task->run(); - delete task; - return; - } - task->next = stack; - stack = task; - PR_NotifyCondVar(wakeup); - PR_Unlock(lock); -} - -#endif diff --git a/js/src/jstask.h b/js/src/jstask.h deleted file mode 100644 index 6888214051ae..000000000000 --- a/js/src/jstask.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: set ts=4 sw=4 et tw=99 ft=cpp: - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released - * June 30, 2009. - * - * The Initial Developer of the Original Code is - * Andreas Gal - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef jstask_h___ -#define jstask_h___ - -class JSBackgroundTask { - friend class JSBackgroundThread; - JSBackgroundTask* next; -public: - virtual void run() = 0; -}; - -#ifdef JS_THREADSAFE - -#include "prthread.h" -#include "prlock.h" -#include "prcvar.h" - -class JSBackgroundThread { - PRThread* thread; - JSBackgroundTask* stack; - PRLock* lock; - PRCondVar* wakeup; - bool shutdown; - - public: - JSBackgroundThread(); - ~JSBackgroundThread(); - - bool init(); - void cancel(); - void work(); - bool busy(); - void schedule(JSBackgroundTask* task); -}; - -#else - -class JSBackgroundThread { -public: - void schedule(JSBackgroundTask* task) { - task->run(); - } -}; - -#endif - -#endif /* jstask_h___ */