Bug 772722 - Remove superfluous usage of Atomics in SpiderMonkey; r=luke

None of the current usages of ATOMIC_INC/DEC are useful now that we do not allow
multi-threaded runtimes. This also removes a pre-mature optimization that
happened to be using the atomics. I measured it as saving strictly < 3us on old
hardware.
This commit is contained in:
Terrence Cole 2012-07-11 14:32:00 -07:00
Родитель 00703ab27b
Коммит 5d06b81262
9 изменённых файлов: 13 добавлений и 71 удалений

Просмотреть файл

@ -464,7 +464,7 @@ static unsigned finalizeCount = 0;
static void
finalize_counter_finalize(JSFreeOp *fop, JSObject *obj)
{
JS_ATOMIC_INCREMENT(&finalizeCount);
++finalizeCount;
}
static JSClass FinalizeCounterClass = {

Просмотреть файл

@ -4564,14 +4564,14 @@ JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id_, JSAccessMode mode,
JS_PUBLIC_API(void)
JS_HoldPrincipals(JSPrincipals *principals)
{
JS_ATOMIC_INCREMENT(&principals->refcount);
++principals->refcount;
}
JS_PUBLIC_API(void)
JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals)
{
int rc = JS_ATOMIC_DECREMENT(&principals->refcount);
if (rc == 0)
JS_AbortIfWrongThread(rt);
if (--principals->refcount == 0)
rt->destroyPrincipals(principals);
}

Просмотреть файл

@ -125,11 +125,7 @@ JSRuntime::sizeOfExplicitNonHeap()
void
JSRuntime::triggerOperationCallback()
{
/*
* Use JS_ATOMIC_SET in the hope that it ensures the write will become
* immediately visible to other processors polling the flag.
*/
JS_ATOMIC_SET(&interrupt, 1);
interrupt = 1;
}
void
@ -438,8 +434,9 @@ js_ReportOutOfMemory(JSContext *cx)
}
if (onError) {
AutoAtomicIncrement incr(&cx->runtime->inOOMReport);
++cx->runtime->inOOMReport;
onError(cx, msg, &report);
--cx->runtime->inOOMReport;
}
}
@ -911,7 +908,7 @@ js_InvokeOperationCallback(JSContext *cx)
* thread is racing us here we will accumulate another callback request
* which will be serviced at the next opportunity.
*/
JS_ATOMIC_SET(&rt->interrupt, 0);
rt->interrupt = 0;
if (rt->gcIsNeeded)
GCSlice(rt, GC_NORMAL, rt->gcTriggerReason);

Просмотреть файл

@ -758,7 +758,7 @@ struct JSRuntime : js::RuntimeFriendFields
* and for each JSObject::remove method call that frees a slot in the given
* object. See js_NativeGet and js_NativeSet in jsobj.cpp.
*/
int32_t propertyRemovals;
uint32_t propertyRemovals;
/* Number localization, used by jsnum.c */
const char *thousandsSeparator;

Просмотреть файл

@ -10,49 +10,17 @@
#ifdef JS_THREADSAFE
# include "pratom.h"
# include "prlock.h"
# include "prcvar.h"
# include "prthread.h"
# include "prinit.h"
# define JS_ATOMIC_INCREMENT(p) PR_ATOMIC_INCREMENT((PRInt32 *)(p))
# define JS_ATOMIC_DECREMENT(p) PR_ATOMIC_DECREMENT((PRInt32 *)(p))
# define JS_ATOMIC_ADD(p,v) PR_ATOMIC_ADD((PRInt32 *)(p), (PRInt32)(v))
# define JS_ATOMIC_SET(p,v) PR_ATOMIC_SET((PRInt32 *)(p), (PRInt32)(v))
#else /* JS_THREADSAFE */
typedef struct PRThread PRThread;
typedef struct PRCondVar PRCondVar;
typedef struct PRLock PRLock;
# define JS_ATOMIC_INCREMENT(p) (++*(p))
# define JS_ATOMIC_DECREMENT(p) (--*(p))
# define JS_ATOMIC_ADD(p,v) (*(p) += (v))
# define JS_ATOMIC_SET(p,v) (*(p) = (v))
#endif /* JS_THREADSAFE */
namespace js {
class AutoAtomicIncrement
{
int32_t *p;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
public:
AutoAtomicIncrement(int32_t *p JS_GUARD_OBJECT_NOTIFIER_PARAM)
: p(p) {
JS_GUARD_OBJECT_NOTIFIER_INIT;
JS_ATOMIC_INCREMENT(p);
}
~AutoAtomicIncrement() {
JS_ATOMIC_DECREMENT(p);
}
};
} /* namespace js */
#endif /* jslock_h___ */

Просмотреть файл

@ -4616,7 +4616,7 @@ js_NativeSet(JSContext *cx, Handle<JSObject*> obj, Handle<JSObject*> receiver,
Rooted<Shape *> shapeRoot(cx, shape);
int32_t sample = cx->runtime->propertyRemovals;
uint32_t sample = cx->runtime->propertyRemovals;
if (!shapeRoot->set(cx, obj, receiver, strict, vp))
return false;

Просмотреть файл

@ -748,7 +748,7 @@ JSObject::putProperty(JSContext *cx, jsid id_,
if (hadSlot && !shape->hasSlot()) {
if (oldSlot < self->slotSpan())
self->freeSlot(cx, oldSlot);
JS_ATOMIC_INCREMENT(&cx->runtime->propertyRemovals);
++cx->runtime->propertyRemovals;
}
self->checkShapeConsistency();
@ -851,7 +851,7 @@ JSObject::removeProperty(JSContext *cx, jsid id_)
/* If shape has a slot, free its slot number. */
if (shape->hasSlot()) {
self->freeSlot(cx, shape->slot());
JS_ATOMIC_INCREMENT(&cx->runtime->propertyRemovals);
++cx->runtime->propertyRemovals;
}
/*
@ -928,7 +928,7 @@ JSObject::clear(JSContext *cx)
JS_ALWAYS_TRUE(setLastProperty(cx, shape));
JS_ATOMIC_INCREMENT(&cx->runtime->propertyRemovals);
++cx->runtime->propertyRemovals;
checkShapeConsistency();
}

Просмотреть файл

@ -346,15 +346,9 @@ def PRMJ_Now():
*/
// We parameterize the delay count just so that shell builds can
// set it to 0 in order to get high-resolution benchmarking.
// 10 seems to be the number of calls to load with a blank homepage.
int CALIBRATION_DELAY_COUNT = 10;
int64_t
PRMJ_Now(void)
{
static int nCalls = 0;
long double lowresTime, highresTimerValue;
FILETIME ft;
LARGE_INTEGER now;
@ -363,16 +357,6 @@ PRMJ_Now(void)
int64_t returnedTime;
long double cachedOffset = 0.0;
/* To avoid regressing startup time (where high resolution is likely
not needed), give the old behavior for the first few calls.
This does not appear to be needed on Vista as the timeBegin/timeEndPeriod
calls seem to immediately take effect. */
int thiscall = JS_ATOMIC_INCREMENT(&nCalls);
if (thiscall <= CALIBRATION_DELAY_COUNT) {
LowResTime(&ft);
return (FILETIME2INT64(ft)-win2un)/10L;
}
/* For non threadsafe platforms, NowInit is not necessary */
#ifdef JS_THREADSAFE
PR_CallOnce(&calibrationOnce, NowInit);

Просмотреть файл

@ -4853,13 +4853,6 @@ main(int argc, char **argv, char **envp)
if (op.getBoolOption('U'))
JS_SetCStringsAreUTF8();
#ifdef XP_WIN
// Set the timer calibration delay count to 0 so we get high
// resolution right away, which we need for precise benchmarking.
extern int CALIBRATION_DELAY_COUNT;
CALIBRATION_DELAY_COUNT = 0;
#endif
/* Use the same parameters as the browser in xpcjsruntime.cpp. */
rt = JS_NewRuntime(32L * 1024L * 1024L);
if (!rt)