Skip to content

Commit

Permalink
Backed out changeset ab1d29e9c95c (bug 1308039)
Browse files Browse the repository at this point in the history
UltraBlame original commit: d38210acd0dcbfc7cdca146c7d4eb44793611859
  • Loading branch information
marco-c committed Sep 30, 2019
1 parent a94bcea commit 9d0cc16
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 127 deletions.
12 changes: 0 additions & 12 deletions js/public/GCAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,18 +692,6 @@ PokeGC(JSContext* cx);
extern JS_FRIEND_API(void)
NotifyDidPaint(JSContext* cx);




typedef bool
(* GCInterruptCallback)(JSContext* cx);

extern JS_FRIEND_API(bool)
AddGCInterruptCallback(JSContext* cx, GCInterruptCallback callback);

extern JS_FRIEND_API(void)
RequestGCInterruptCallback(JSContext* cx);

}

#endif
35 changes: 4 additions & 31 deletions js/public/SliceBudget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#ifndef js_SliceBudget_h
#define js_SliceBudget_h

#include "mozilla/Atomics.h"

#include <stdint.h>

namespace js {
Expand Down Expand Up @@ -38,7 +36,7 @@ class JS_PUBLIC_API(SliceBudget)
static const int64_t unlimitedDeadline = INT64_MAX;
static const intptr_t unlimitedStartCounter = INTPTR_MAX;

bool checkOverBudget(JSContext* maybeCx);
bool checkOverBudget();

SliceBudget();

Expand All @@ -50,7 +48,7 @@ class JS_PUBLIC_API(SliceBudget)
WorkBudget workBudget;

int64_t deadline;
mozilla::Atomic<intptr_t, mozilla::Relaxed> counter;
intptr_t counter;

static const intptr_t CounterReset = 1000;

Expand All @@ -66,44 +64,19 @@ class JS_PUBLIC_API(SliceBudget)

explicit SliceBudget(WorkBudget work);


SliceBudget(const SliceBudget& other)
: timeBudget(other.timeBudget),
workBudget(other.workBudget),
deadline(other.deadline),
counter(other.counter)
{}


SliceBudget& operator=(const SliceBudget& other) {
timeBudget = other.timeBudget;
workBudget = other.workBudget;
deadline = other.deadline;
counter = intptr_t(other.counter);
return *this;
}

void makeUnlimited() {
deadline = unlimitedDeadline;
counter = unlimitedStartCounter;
}



void requestFullCheck() {
counter = 0;
}

void step(intptr_t amt = 1) {
counter -= amt;
}



bool isOverBudget(JSContext* maybeCx = nullptr) {
bool isOverBudget() {
if (counter > 0)
return false;
return checkOverBudget(maybeCx);
return checkOverBudget();
}

bool isWorkBudget() const { return deadline == 0; }
Expand Down
21 changes: 0 additions & 21 deletions js/src/gc/GCRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace js {

class AutoLockGC;
class AutoLockHelperThreadState;
class SliceBudget;
class VerifyPreTracer;

namespace gc {
Expand Down Expand Up @@ -865,19 +864,6 @@ class GCRuntime
#endif


bool addInterruptCallback(JS::GCInterruptCallback callback);
void requestInterruptCallback();

bool checkInterruptCallback(JSContext* cx) {
if (interruptCallbackRequested) {
invokeInterruptCallback(cx);
return true;
}
return false;
}
void invokeInterruptCallback(JSContext* cx);


void freeUnusedLifoBlocksAfterSweeping(LifoAlloc* lifo);
void freeAllLifoBlocksAfterSweeping(LifoAlloc* lifo);
void freeAllLifoBlocksAfterMinorGC(LifoAlloc* lifo);
Expand Down Expand Up @@ -1089,13 +1075,6 @@ class GCRuntime
mozilla::Atomic<uint32_t, mozilla::ReleaseAcquire> numArenasFreeCommitted;
VerifyPreTracer* verifyPreData;


using GCInterruptCallbackVector = js::Vector<JS::GCInterruptCallback, 2, js::SystemAllocPolicy>;
GCInterruptCallbackVector interruptCallbacks;

mozilla::Atomic<bool, mozilla::Relaxed> interruptCallbackRequested;
SliceBudget* currentBudget;

private:
bool chunkAllocationSinceLastGC;
int64_t lastGCTime;
Expand Down
14 changes: 5 additions & 9 deletions js/src/gc/Marking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,15 +1545,13 @@ GCMarker::drainMarkStack(SliceBudget& budget)
auto acc = mozilla::MakeScopeExit([&] {strictCompartmentChecking = false;});
#endif

JSContext* cx = runtime()->contextFromMainThread();

if (budget.isOverBudget(cx))
if (budget.isOverBudget())
return false;

for (;;) {
while (!stack.isEmpty()) {
processMarkStackTop(budget);
if (budget.isOverBudget(cx)) {
if (budget.isOverBudget()) {
saveValueRanges();
return false;
}
Expand Down Expand Up @@ -1628,8 +1626,6 @@ GCMarker::processMarkStackTop(SliceBudget& budget)
uintptr_t tag = addr & StackTagMask;
addr &= ~StackTagMask;

JSContext* cx = runtime()->contextFromMainThread();


switch (tag) {
case ValueArrayTag: {
Expand Down Expand Up @@ -1683,7 +1679,7 @@ GCMarker::processMarkStackTop(SliceBudget& budget)
MOZ_ASSERT(vp <= end);
while (vp != end) {
budget.step();
if (budget.isOverBudget(cx)) {
if (budget.isOverBudget()) {
pushValueArray(obj, vp, end);
return;
}
Expand Down Expand Up @@ -1713,7 +1709,7 @@ GCMarker::processMarkStackTop(SliceBudget& budget)
AssertZoneIsMarking(obj);

budget.step();
if (budget.isOverBudget(cx)) {
if (budget.isOverBudget()) {
repush(obj);
return;
}
Expand Down Expand Up @@ -2161,7 +2157,7 @@ GCMarker::markDelayedChildren(SliceBudget& budget)
markDelayedChildren(arena);

budget.step(150);
if (budget.isOverBudget(runtime()->contextFromMainThread()))
if (budget.isOverBudget())
return false;
} while (unmarkedArenaStackTop);
MOZ_ASSERT(!markLaterArenas);
Expand Down
58 changes: 4 additions & 54 deletions js/src/jsgc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
#include "mozilla/MacroForEach.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Move.h"
#include "mozilla/ScopeExit.h"

#include <ctype.h>
#include <string.h>
Expand Down Expand Up @@ -507,8 +506,6 @@ FinalizeTypedArenas(FreeOp* fop,
size_t thingSize = Arena::thingSize(thingKind);
size_t thingsPerArena = Arena::thingsPerArena(thingKind);

JSContext* cx = fop->onMainThread() ? fop->runtime()->contextFromMainThread() : nullptr;

while (Arena* arena = *src) {
*src = arena->next;
size_t nmarked = arena->finalize<T>(fop, thingKind, thingSize);
Expand All @@ -522,7 +519,7 @@ FinalizeTypedArenas(FreeOp* fop,
fop->runtime()->gc.releaseArena(arena, maybeLock.ref());

budget.step(thingsPerArena);
if (budget.isOverBudget(cx))
if (budget.isOverBudget())
return false;
}

Expand Down Expand Up @@ -811,8 +808,6 @@ GCRuntime::GCRuntime(JSRuntime* rt) :
nextCellUniqueId_(LargestTaggedNullCellPointer + 1),
numArenasFreeCommitted(0),
verifyPreData(nullptr),
interruptCallbackRequested(false),
currentBudget(nullptr),
chunkAllocationSinceLastGC(false),
lastGCTime(PRMJ_Now()),
mode(JSGC_MODE_INCREMENTAL),
Expand Down Expand Up @@ -2938,11 +2933,8 @@ SliceBudget::describe(char* buffer, size_t maxlen) const
}

bool
SliceBudget::checkOverBudget(JSContext* cx)
SliceBudget::checkOverBudget()
{
if (cx)
cx->gc.checkInterruptCallback(cx);

bool over = PRMJ_Now() >= deadline;
if (!over)
counter = CounterReset;
Expand Down Expand Up @@ -5489,7 +5481,7 @@ GCRuntime::compactPhase(JS::gcreason::Reason reason, SliceBudget& sliceBudget,
updatePointersToRelocatedCells(zone, lock);
zone->setGCState(Zone::Finished);
zonesToMaybeCompact.removeFront();
if (sliceBudget.isOverBudget(rt->contextFromMainThread()))
if (sliceBudget.isOverBudget())
break;
}

Expand Down Expand Up @@ -5895,7 +5887,7 @@ GCRuntime::incrementalCollectSlice(SliceBudget& budget, JS::gcreason::Reason rea


beginSweepPhase(destroyingRuntime, lock);
if (budget.isOverBudget(rt->contextFromMainThread()))
if (budget.isOverBudget())
break;


Expand Down Expand Up @@ -6302,11 +6294,6 @@ GCRuntime::collect(bool nonincrementalByAPI, SliceBudget budget, JS::gcreason::R
if (!checkIfGCAllowedInCurrentState(reason))
return;

currentBudget = &budget;
auto guard = mozilla::MakeScopeExit([&] {
currentBudget = nullptr;
});

AutoTraceLog logGC(TraceLoggerForMainThread(rt), TraceLogger_GC);
AutoStopVerifyingBarriers av(rt, IsShutdownGC(reason));
AutoEnqueuePendingParseTasksAfterGC aept(*this);
Expand Down Expand Up @@ -7681,40 +7668,3 @@ js::gc::Cell::dump() const
dump(stderr);
}
#endif

bool
JS::AddGCInterruptCallback(JSContext* cx, GCInterruptCallback callback)
{
return cx->runtime()->gc.addInterruptCallback(callback);
}

void
JS::RequestGCInterruptCallback(JSContext* cx)
{
cx->runtime()->gc.requestInterruptCallback();
}

bool
GCRuntime::addInterruptCallback(JS::GCInterruptCallback callback)
{
return interruptCallbacks.append(callback);
}

void
GCRuntime::requestInterruptCallback()
{
if (currentBudget) {
interruptCallbackRequested = true;
currentBudget->requestFullCheck();
}
}

void
GCRuntime::invokeInterruptCallback(JSContext* cx)
{
JS::AutoAssertOnGC aaogc(cx);
JS::AutoAssertOnBarrier nobarrier(cx);
for (JS::GCInterruptCallback callback : interruptCallbacks) {
(*callback)(cx);
}
}

0 comments on commit 9d0cc16

Please sign in to comment.