зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1573879
- Refactor ZoneAllocator to remove the dependency on JSRuntime r=sfink
Differential Revision: https://phabricator.services.mozilla.com/D41988 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e4ab7a03ad
Коммит
19abd935f9
|
@ -3480,11 +3480,14 @@ bool GCRuntime::maybeMallocTriggerZoneGC(Zone* zone, const HeapSize& heap,
|
|||
JS::GCReason reason) {
|
||||
if (!CurrentThreadCanAccessRuntime(rt)) {
|
||||
// Zones in use by a helper thread can't be collected.
|
||||
MOZ_ASSERT(zone->usedByHelperThread() || zone->isAtomsZone());
|
||||
MOZ_ASSERT(zone->usedByHelperThread() || zone->isAtomsZone() ||
|
||||
JS::RuntimeHeapIsBusy());
|
||||
return false;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!JS::RuntimeHeapIsCollecting());
|
||||
if (rt->heapState() != JS::HeapState::Idle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t usedBytes = heap.gcBytes();
|
||||
size_t thresholdBytes = threshold.gcTriggerBytes();
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
#ifndef gc_ZoneAllocator_h
|
||||
#define gc_ZoneAllocator_h
|
||||
|
||||
#include "gc/Cell.h"
|
||||
#include "gc/Scheduling.h"
|
||||
#include "vm/Runtime.h" // For JSRuntime::gc.
|
||||
#include "vm/MallocProvider.h"
|
||||
|
||||
namespace JS {
|
||||
class Zone;
|
||||
|
@ -20,6 +21,12 @@ class Zone;
|
|||
|
||||
namespace js {
|
||||
|
||||
class ZoneAllocator;
|
||||
|
||||
#ifdef DEBUG
|
||||
bool CurrentThreadIsGCSweeping();
|
||||
#endif
|
||||
|
||||
namespace gc {
|
||||
void MaybeMallocTriggerZoneGC(JSRuntime* rt, ZoneAllocator* zoneAlloc,
|
||||
const HeapSize& heap,
|
||||
|
@ -146,10 +153,9 @@ class ZoneAllocator : public JS::shadow::Zone,
|
|||
void maybeTriggerZoneGC(const js::gc::HeapSize& heap,
|
||||
const js::gc::ZoneThreshold& threshold,
|
||||
JS::GCReason reason) {
|
||||
JSRuntime* rt = runtimeFromAnyThread();
|
||||
if (heap.gcBytes() >= threshold.gcTriggerBytes() &&
|
||||
rt->heapState() == JS::HeapState::Idle) {
|
||||
gc::MaybeMallocTriggerZoneGC(rt, this, heap, threshold, reason);
|
||||
if (heap.gcBytes() >= threshold.gcTriggerBytes()) {
|
||||
gc::MaybeMallocTriggerZoneGC(runtimeFromAnyThread(), this, heap,
|
||||
threshold, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -319,39 +325,6 @@ inline void RemoveCellMemory(gc::Cell* cell, size_t nbytes, MemoryUse use,
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize an object's reserved slot with a private value pointing to
|
||||
// malloc-allocated memory and associate the memory with the object.
|
||||
//
|
||||
// This call should be matched with a call to JSFreeOp::free_/delete_ in the
|
||||
// object's finalizer to free the memory and update the memory accounting.
|
||||
|
||||
inline void InitReservedSlot(NativeObject* obj, uint32_t slot, void* ptr,
|
||||
size_t nbytes, MemoryUse use) {
|
||||
AddCellMemory(obj, nbytes, use);
|
||||
obj->initReservedSlot(slot, PrivateValue(ptr));
|
||||
}
|
||||
template <typename T>
|
||||
inline void InitReservedSlot(NativeObject* obj, uint32_t slot, T* ptr,
|
||||
MemoryUse use) {
|
||||
InitReservedSlot(obj, slot, ptr, sizeof(T), use);
|
||||
}
|
||||
|
||||
// Initialize an object's private slot with a pointer to malloc-allocated memory
|
||||
// and associate the memory with the object.
|
||||
//
|
||||
// This call should be matched with a call to JSFreeOp::free_/delete_ in the
|
||||
// object's finalizer to free the memory and update the memory accounting.
|
||||
|
||||
inline void InitObjectPrivate(NativeObject* obj, void* ptr, size_t nbytes,
|
||||
MemoryUse use) {
|
||||
AddCellMemory(obj, nbytes, use);
|
||||
obj->initPrivate(ptr);
|
||||
}
|
||||
template <typename T>
|
||||
inline void InitObjectPrivate(NativeObject* obj, T* ptr, MemoryUse use) {
|
||||
InitObjectPrivate(obj, ptr, sizeof(T), use);
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
||||
#endif // gc_ZoneAllocator_h
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "gc/Barrier.h"
|
||||
#include "gc/Heap.h"
|
||||
#include "gc/Marking.h"
|
||||
#include "gc/ZoneAllocator.h"
|
||||
#include "js/Value.h"
|
||||
#include "vm/JSObject.h"
|
||||
#include "vm/Shape.h"
|
||||
|
@ -1646,6 +1647,39 @@ extern bool CopyDataPropertiesNative(JSContext* cx, HandlePlainObject target,
|
|||
HandlePlainObject excludedItems,
|
||||
bool* optimized);
|
||||
|
||||
// Initialize an object's reserved slot with a private value pointing to
|
||||
// malloc-allocated memory and associate the memory with the object.
|
||||
//
|
||||
// This call should be matched with a call to JSFreeOp::free_/delete_ in the
|
||||
// object's finalizer to free the memory and update the memory accounting.
|
||||
|
||||
inline void InitReservedSlot(NativeObject* obj, uint32_t slot, void* ptr,
|
||||
size_t nbytes, MemoryUse use) {
|
||||
AddCellMemory(obj, nbytes, use);
|
||||
obj->initReservedSlot(slot, PrivateValue(ptr));
|
||||
}
|
||||
template <typename T>
|
||||
inline void InitReservedSlot(NativeObject* obj, uint32_t slot, T* ptr,
|
||||
MemoryUse use) {
|
||||
InitReservedSlot(obj, slot, ptr, sizeof(T), use);
|
||||
}
|
||||
|
||||
// Initialize an object's private slot with a pointer to malloc-allocated memory
|
||||
// and associate the memory with the object.
|
||||
//
|
||||
// This call should be matched with a call to JSFreeOp::free_/delete_ in the
|
||||
// object's finalizer to free the memory and update the memory accounting.
|
||||
|
||||
inline void InitObjectPrivate(NativeObject* obj, void* ptr, size_t nbytes,
|
||||
MemoryUse use) {
|
||||
AddCellMemory(obj, nbytes, use);
|
||||
obj->initPrivate(ptr);
|
||||
}
|
||||
template <typename T>
|
||||
inline void InitObjectPrivate(NativeObject* obj, T* ptr, MemoryUse use) {
|
||||
InitObjectPrivate(obj, ptr, sizeof(T), use);
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
||||
#endif /* vm_NativeObject_h */
|
||||
|
|
Загрузка…
Ссылка в новой задаче