Merge backout.

This commit is contained in:
Robert Sayre 2009-07-24 00:02:02 -04:00
commit 6968ea2205
14 changed files with 11 additions and 287 deletions

View File

@ -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 \

View File

@ -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) {

View File

@ -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;
}

View File

@ -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. */

View File

@ -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

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);

View File

@ -1639,7 +1639,7 @@ js_DestroyScript(JSContext *cx, JSScript *script)
}
}
cx->runtime->asynchronousFree(script);
JS_free(cx, script);
}
void

View File

@ -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 <gal@mozilla.com>
*
* 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

View File

@ -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 <gal@mozilla.com>
*
* 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___ */