mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1227535 - Add ZoneAllocPolicy and use it to attribute module memory usage to the zone r=terrence
This commit is contained in:
parent
041557604f
commit
8f16053c13
@ -219,6 +219,11 @@ IndirectBindingMap::Binding::Binding(ModuleEnvironmentObject* environment, Shape
|
||||
: environment(environment), shape(shape)
|
||||
{}
|
||||
|
||||
IndirectBindingMap::IndirectBindingMap(Zone* zone)
|
||||
: map_(ZoneAllocPolicy(zone))
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
IndirectBindingMap::init()
|
||||
{
|
||||
@ -583,7 +588,8 @@ ModuleObject::create(ExclusiveContext* cx, HandleObject enclosingStaticScope)
|
||||
|
||||
self->initReservedSlot(StaticScopeSlot, ObjectOrNullValue(enclosingStaticScope));
|
||||
|
||||
IndirectBindingMap* bindings = cx->new_<IndirectBindingMap>();
|
||||
Zone* zone = cx->zone();
|
||||
IndirectBindingMap* bindings = zone->new_<IndirectBindingMap>(zone);
|
||||
if (!bindings || !bindings->init()) {
|
||||
ReportOutOfMemory(cx);
|
||||
return nullptr;
|
||||
@ -591,9 +597,11 @@ ModuleObject::create(ExclusiveContext* cx, HandleObject enclosingStaticScope)
|
||||
|
||||
self->initReservedSlot(ImportBindingsSlot, PrivateValue(bindings));
|
||||
|
||||
FunctionDeclarationVector* funDecls = cx->new_<FunctionDeclarationVector>(cx);
|
||||
if (!funDecls)
|
||||
FunctionDeclarationVector* funDecls = zone->new_<FunctionDeclarationVector>(zone);
|
||||
if (!funDecls) {
|
||||
ReportOutOfMemory(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
self->initReservedSlot(FunctionDeclarationsSlot, PrivateValue(funDecls));
|
||||
return self;
|
||||
@ -826,7 +834,8 @@ ModuleObject::createNamespace(JSContext* cx, HandleModuleObject self, HandleArra
|
||||
if (!ns)
|
||||
return nullptr;
|
||||
|
||||
IndirectBindingMap* bindings = cx->new_<IndirectBindingMap>();
|
||||
Zone* zone = cx->zone();
|
||||
IndirectBindingMap* bindings = zone->new_<IndirectBindingMap>(zone);
|
||||
if (!bindings || !bindings->init()) {
|
||||
ReportOutOfMemory(cx);
|
||||
return nullptr;
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
|
||||
#include "gc/Zone.h"
|
||||
|
||||
#include "js/TraceableVector.h"
|
||||
|
||||
#include "vm/NativeObject.h"
|
||||
@ -84,6 +86,7 @@ typedef Handle<ExportEntryObject*> HandleExportEntryObject;
|
||||
class IndirectBindingMap
|
||||
{
|
||||
public:
|
||||
IndirectBindingMap(Zone* zone);
|
||||
bool init();
|
||||
|
||||
void trace(JSTracer* trc);
|
||||
@ -115,7 +118,7 @@ class IndirectBindingMap
|
||||
RelocatablePtrShape shape;
|
||||
};
|
||||
|
||||
typedef HashMap<jsid, Binding, JsidHasher, SystemAllocPolicy> Map;
|
||||
typedef HashMap<jsid, Binding, JsidHasher, ZoneAllocPolicy> Map;
|
||||
|
||||
Map map_;
|
||||
};
|
||||
@ -189,7 +192,7 @@ struct FunctionDeclaration
|
||||
RelocatablePtrFunction fun;
|
||||
};
|
||||
|
||||
using FunctionDeclarationVector = TraceableVector<FunctionDeclaration>;
|
||||
using FunctionDeclarationVector = TraceableVector<FunctionDeclaration, 0, ZoneAllocPolicy>;
|
||||
|
||||
class ModuleObject : public NativeObject
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ struct Zone : public JS::shadow::Zone,
|
||||
void onTooMuchMalloc();
|
||||
|
||||
void* onOutOfMemory(js::AllocFunction allocFunc, size_t nbytes, void* reallocPtr = nullptr) {
|
||||
if (!CurrentThreadCanAccessRuntime(runtime_))
|
||||
if (!js::CurrentThreadCanAccessRuntime(runtime_))
|
||||
return nullptr;
|
||||
return runtimeFromMainThread()->onOutOfMemory(allocFunc, nbytes, reallocPtr);
|
||||
}
|
||||
@ -576,6 +576,62 @@ class CompartmentsIterT
|
||||
|
||||
typedef CompartmentsIterT<ZonesIter> CompartmentsIter;
|
||||
|
||||
/*
|
||||
* Allocation policy that uses Zone::pod_malloc and friends, so that memory
|
||||
* pressure is accounted for on the zone. This is suitable for memory associated
|
||||
* with GC things allocated in the zone.
|
||||
*
|
||||
* Since it doesn't hold a JSContext (those may not live long enough), it can't
|
||||
* report out-of-memory conditions itself; the caller must check for OOM and
|
||||
* take the appropriate action.
|
||||
*
|
||||
* FIXME bug 647103 - replace these *AllocPolicy names.
|
||||
*/
|
||||
class ZoneAllocPolicy
|
||||
{
|
||||
Zone* const zone;
|
||||
|
||||
public:
|
||||
MOZ_IMPLICIT ZoneAllocPolicy(Zone* zone) : zone(zone) {}
|
||||
|
||||
template <typename T>
|
||||
T* maybe_pod_malloc(size_t numElems) {
|
||||
return zone->maybe_pod_malloc<T>(numElems);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* maybe_pod_calloc(size_t numElems) {
|
||||
return zone->maybe_pod_calloc<T>(numElems);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize) {
|
||||
return zone->maybe_pod_realloc<T>(p, oldSize, newSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* pod_malloc(size_t numElems) {
|
||||
return zone->pod_malloc<T>(numElems);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* pod_calloc(size_t numElems) {
|
||||
return zone->pod_calloc<T>(numElems);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* pod_realloc(T* p, size_t oldSize, size_t newSize) {
|
||||
return zone->pod_realloc<T>(p, oldSize, newSize);
|
||||
}
|
||||
|
||||
void free_(void* p) { js_free(p); }
|
||||
void reportAllocOverflow() const {}
|
||||
|
||||
bool checkSimulatedOOM() const {
|
||||
return !js::oom::ShouldFailWithOOM();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace js
|
||||
|
||||
#endif // gc_Zone_h
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "jsopcode.h"
|
||||
#include "jstypes.h"
|
||||
|
||||
#include "builtin/ModuleObject.h"
|
||||
#include "gc/Barrier.h"
|
||||
#include "gc/Rooting.h"
|
||||
#include "jit/IonCode.h"
|
||||
@ -47,6 +46,7 @@ class BreakpointSite;
|
||||
class BindingIter;
|
||||
class Debugger;
|
||||
class LazyScript;
|
||||
class ModuleObject;
|
||||
class NestedScopeObject;
|
||||
class RegExpObject;
|
||||
struct SourceCompressionTask;
|
||||
|
@ -21,9 +21,11 @@
|
||||
* - SystemAllocPolicy: No extra functionality over bare allocators.
|
||||
*
|
||||
* - TempAllocPolicy: Adds automatic error reporting to the provided
|
||||
* Context when allocations fail.
|
||||
* JSContext when allocations fail.
|
||||
*
|
||||
* - RuntimeAllocPolicy: forwards to the JSRuntime MallocProvider.
|
||||
* - RuntimeAllocPolicy: Forwards to the JSRuntime MallocProvider.
|
||||
*
|
||||
* - ZoneAllocPolicy: Forwards to the Zone MallocProvider.
|
||||
*
|
||||
* - MallocProvider. A mixin base class that handles automatically updating
|
||||
* the GC's state in response to allocations that are tied to a GC lifetime
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "jsobj.h"
|
||||
#include "jsweakmap.h"
|
||||
|
||||
#include "builtin/ModuleObject.h"
|
||||
#include "gc/Barrier.h"
|
||||
#include "vm/ArgumentsObject.h"
|
||||
#include "vm/ProxyObject.h"
|
||||
|
Loading…
Reference in New Issue
Block a user