From 9e0ade728743e9361f985080d27772daed8d71b7 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Fri, 24 Jul 2009 00:01:37 -0400 Subject: [PATCH] Backed out changeset b3d459d23452 --- js/src/Makefile.in | 2 - js/src/jsapi.cpp | 12 +---- js/src/jsarray.cpp | 2 +- js/src/jscntxt.h | 19 ------- js/src/jsgc.cpp | 16 +----- js/src/jsgc.h | 24 --------- js/src/jsiter.cpp | 2 +- js/src/jsobj.cpp | 2 +- js/src/jspubtd.h | 1 + js/src/jsregexp.cpp | 4 +- js/src/jsscope.cpp | 2 +- js/src/jsscript.cpp | 2 +- js/src/jstask.cpp | 126 -------------------------------------------- js/src/jstask.h | 84 ----------------------------- 14 files changed, 11 insertions(+), 287 deletions(-) delete mode 100644 js/src/jstask.cpp delete mode 100644 js/src/jstask.h diff --git a/js/src/Makefile.in b/js/src/Makefile.in index 605400d414e..6117113e066 100644 --- a/js/src/Makefile.in +++ b/js/src/Makefile.in @@ -148,7 +148,6 @@ CPPSRCS = \ jsscope.cpp \ jsscript.cpp \ jsstr.cpp \ - jstask.cpp \ jsutil.cpp \ jsxdrapi.cpp \ jsxml.cpp \ @@ -205,7 +204,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 c684f075b8f..85653753467 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 5d9d4f49b0a..2d121e3ddc4 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 63f1a692d11..2a6c2cc6817 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 @@ -688,24 +687,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 dff601929d2..40ee8971bfc 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]; @@ -3649,12 +3648,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. * @@ -3841,13 +3834,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 cc37e8505b5..42e22bdab23 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 919ab16a9e8..f941a6e3bd7 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 6645f09d93a..982873f9588 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 90c4f40fe11..6c28b136a79 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 b80666cbcfa..91a41e49da7 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 876bed4d357..c343533dde3 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 0edf5070724..03e88f8d791 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -1647,7 +1647,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 417e8152389..00000000000 --- 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 6888214051a..00000000000 --- 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___ */