mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
Bug 1412912 - Split out JSObject alloc kind helper functions into ObjectKind-inl.h r=sfink
This commit is contained in:
parent
eee897b0f9
commit
b889aa465d
24
js/src/builtin/TypedObject-inl.h
Normal file
24
js/src/builtin/TypedObject-inl.h
Normal file
@ -0,0 +1,24 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef builtin_TypedObject_inl_h
|
||||
#define builtin_TypedObject_inl_h
|
||||
|
||||
#include "builtin/TypedObject.h"
|
||||
|
||||
#include "gc/ObjectKind-inl.h"
|
||||
|
||||
/* static */
|
||||
js::gc::AllocKind
|
||||
js::InlineTypedObject::allocKindForTypeDescriptor(TypeDescr* descr)
|
||||
{
|
||||
size_t nbytes = descr->size();
|
||||
MOZ_ASSERT(nbytes <= MaximumSize);
|
||||
|
||||
return gc::GetGCObjectKindForBytes(nbytes + sizeof(TypedObject));
|
||||
}
|
||||
|
||||
#endif // builtin_TypedObject_inl_h
|
@ -4,7 +4,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "builtin/TypedObject.h"
|
||||
#include "builtin/TypedObject-inl.h"
|
||||
|
||||
#include "mozilla/Casting.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
|
@ -707,12 +707,7 @@ class InlineTypedObject : public TypedObject
|
||||
public:
|
||||
static const size_t MaximumSize = JSObject::MAX_BYTE_SIZE - sizeof(TypedObject);
|
||||
|
||||
static gc::AllocKind allocKindForTypeDescriptor(TypeDescr* descr) {
|
||||
size_t nbytes = descr->size();
|
||||
MOZ_ASSERT(nbytes <= MaximumSize);
|
||||
|
||||
return gc::GetGCObjectKindForBytes(nbytes + sizeof(TypedObject));
|
||||
}
|
||||
static inline gc::AllocKind allocKindForTypeDescriptor(TypeDescr* descr);
|
||||
|
||||
uint8_t* inlineTypedMem(const JS::AutoRequireNoGC&) const {
|
||||
return inlineTypedMem();
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "wasm/AsmJS.h"
|
||||
|
||||
#include "jsatominlines.h"
|
||||
#include "jsobjinlines.h"
|
||||
#include "jsscriptinlines.h"
|
||||
|
||||
#include "frontend/ParseNode-inl.h"
|
||||
|
@ -191,6 +191,84 @@ FOR_EACH_ALLOCKIND(EXPAND_ELEMENT)
|
||||
static const size_t MAX_BACKGROUND_FINALIZE_KINDS =
|
||||
size_t(AllocKind::LIMIT) - size_t(AllocKind::OBJECT_LIMIT) / 2;
|
||||
|
||||
static inline bool
|
||||
IsNurseryAllocable(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
true, /* AllocKind::FUNCTION */
|
||||
true, /* AllocKind::FUNCTION_EXTENDED */
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT2 */
|
||||
true, /* AllocKind::OBJECT2_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT4 */
|
||||
true, /* AllocKind::OBJECT4_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT8 */
|
||||
true, /* AllocKind::OBJECT8_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT12 */
|
||||
true, /* AllocKind::OBJECT12_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT16 */
|
||||
true, /* AllocKind::OBJECT16_BACKGROUND */
|
||||
false, /* AllocKind::SCRIPT */
|
||||
false, /* AllocKind::LAZY_SCRIPT */
|
||||
false, /* AllocKind::SHAPE */
|
||||
false, /* AllocKind::ACCESSOR_SHAPE */
|
||||
false, /* AllocKind::BASE_SHAPE */
|
||||
false, /* AllocKind::OBJECT_GROUP */
|
||||
false, /* AllocKind::FAT_INLINE_STRING */
|
||||
false, /* AllocKind::STRING */
|
||||
false, /* AllocKind::EXTERNAL_STRING */
|
||||
false, /* AllocKind::FAT_INLINE_ATOM */
|
||||
false, /* AllocKind::ATOM */
|
||||
false, /* AllocKind::SYMBOL */
|
||||
false, /* AllocKind::JITCODE */
|
||||
false, /* AllocKind::SCOPE */
|
||||
false, /* AllocKind::REGEXP_SHARED */
|
||||
};
|
||||
JS_STATIC_ASSERT(JS_ARRAY_LENGTH(map) == size_t(AllocKind::LIMIT));
|
||||
return map[size_t(kind)];
|
||||
}
|
||||
|
||||
static inline bool
|
||||
IsBackgroundFinalized(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
true, /* AllocKind::FUNCTION */
|
||||
true, /* AllocKind::FUNCTION_EXTENDED */
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT2 */
|
||||
true, /* AllocKind::OBJECT2_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT4 */
|
||||
true, /* AllocKind::OBJECT4_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT8 */
|
||||
true, /* AllocKind::OBJECT8_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT12 */
|
||||
true, /* AllocKind::OBJECT12_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT16 */
|
||||
true, /* AllocKind::OBJECT16_BACKGROUND */
|
||||
false, /* AllocKind::SCRIPT */
|
||||
true, /* AllocKind::LAZY_SCRIPT */
|
||||
true, /* AllocKind::SHAPE */
|
||||
true, /* AllocKind::ACCESSOR_SHAPE */
|
||||
true, /* AllocKind::BASE_SHAPE */
|
||||
true, /* AllocKind::OBJECT_GROUP */
|
||||
true, /* AllocKind::FAT_INLINE_STRING */
|
||||
true, /* AllocKind::STRING */
|
||||
true, /* AllocKind::EXTERNAL_STRING */
|
||||
true, /* AllocKind::FAT_INLINE_ATOM */
|
||||
true, /* AllocKind::ATOM */
|
||||
true, /* AllocKind::SYMBOL */
|
||||
false, /* AllocKind::JITCODE */
|
||||
true, /* AllocKind::SCOPE */
|
||||
true, /* AllocKind::REGEXP_SHARED */
|
||||
};
|
||||
JS_STATIC_ASSERT(JS_ARRAY_LENGTH(map) == size_t(AllocKind::LIMIT));
|
||||
return map[size_t(kind)];
|
||||
}
|
||||
|
||||
} /* namespace gc */
|
||||
} /* namespace js */
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "jscntxt.h"
|
||||
|
||||
#include "gc/ArenaList.h"
|
||||
#include "gc/GCInternals.h"
|
||||
#include "gc/GCTrace.h"
|
||||
#include "gc/Nursery.h"
|
||||
@ -19,6 +18,7 @@
|
||||
|
||||
#include "jsobjinlines.h"
|
||||
|
||||
#include "gc/ArenaList-inl.h"
|
||||
#include "gc/Heap-inl.h"
|
||||
|
||||
using namespace js;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "js/RootingAPI.h"
|
||||
|
||||
namespace js {
|
||||
|
||||
struct Class;
|
||||
|
||||
// Allocate a new GC thing. After a successful allocation the caller must
|
||||
|
@ -34,7 +34,6 @@
|
||||
|
||||
#include "jscompartmentinlines.h"
|
||||
#include "jsgcinlines.h"
|
||||
#include "jsobjinlines.h"
|
||||
|
||||
#include "gc/Nursery-inl.h"
|
||||
#include "vm/NativeObject-inl.h"
|
||||
|
174
js/src/gc/ObjectKind-inl.h
Normal file
174
js/src/gc/ObjectKind-inl.h
Normal file
@ -0,0 +1,174 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* GC-internal helper functions for getting the AllocKind used to allocate a
|
||||
* JSObject and related information.
|
||||
*/
|
||||
|
||||
#ifndef gc_ObjectKind_inl_h
|
||||
#define gc_ObjectKind_inl_h
|
||||
|
||||
#include "vm/NativeObject.h"
|
||||
|
||||
namespace js {
|
||||
namespace gc {
|
||||
|
||||
static inline bool
|
||||
CanBeFinalizedInBackground(AllocKind kind, const Class* clasp)
|
||||
{
|
||||
MOZ_ASSERT(IsObjectAllocKind(kind));
|
||||
/* If the class has no finalizer or a finalizer that is safe to call on
|
||||
* a different thread, we change the alloc kind. For example,
|
||||
* AllocKind::OBJECT0 calls the finalizer on the active thread,
|
||||
* AllocKind::OBJECT0_BACKGROUND calls the finalizer on the gcHelperThread.
|
||||
* IsBackgroundFinalized is called to prevent recursively incrementing
|
||||
* the alloc kind; kind may already be a background finalize kind.
|
||||
*/
|
||||
return (!IsBackgroundFinalized(kind) &&
|
||||
(!clasp->hasFinalize() || (clasp->flags & JSCLASS_BACKGROUND_FINALIZE)));
|
||||
}
|
||||
|
||||
static inline AllocKind
|
||||
GetBackgroundAllocKind(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(!IsBackgroundFinalized(kind));
|
||||
MOZ_ASSERT(IsObjectAllocKind(kind));
|
||||
return AllocKind(size_t(kind) + 1);
|
||||
}
|
||||
|
||||
/* Capacity for slotsToThingKind */
|
||||
const size_t SLOTS_TO_THING_KIND_LIMIT = 17;
|
||||
|
||||
extern const AllocKind slotsToThingKind[];
|
||||
|
||||
/* Get the best kind to use when making an object with the given slot count. */
|
||||
static inline AllocKind
|
||||
GetGCObjectKind(size_t numSlots)
|
||||
{
|
||||
if (numSlots >= SLOTS_TO_THING_KIND_LIMIT)
|
||||
return AllocKind::OBJECT16;
|
||||
return slotsToThingKind[numSlots];
|
||||
}
|
||||
|
||||
static inline AllocKind
|
||||
GetGCObjectKind(const Class* clasp)
|
||||
{
|
||||
if (clasp == FunctionClassPtr)
|
||||
return AllocKind::FUNCTION;
|
||||
|
||||
MOZ_ASSERT(!clasp->isProxy(), "Proxies should use GetProxyGCObjectKind");
|
||||
|
||||
uint32_t nslots = JSCLASS_RESERVED_SLOTS(clasp);
|
||||
if (clasp->flags & JSCLASS_HAS_PRIVATE)
|
||||
nslots++;
|
||||
return GetGCObjectKind(nslots);
|
||||
}
|
||||
|
||||
/* As for GetGCObjectKind, but for dense array allocation. */
|
||||
static inline AllocKind
|
||||
GetGCArrayKind(size_t numElements)
|
||||
{
|
||||
/*
|
||||
* Dense arrays can use their fixed slots to hold their elements array
|
||||
* (less two Values worth of ObjectElements header), but if more than the
|
||||
* maximum number of fixed slots is needed then the fixed slots will be
|
||||
* unused.
|
||||
*/
|
||||
JS_STATIC_ASSERT(ObjectElements::VALUES_PER_HEADER == 2);
|
||||
if (numElements > NativeObject::MAX_DENSE_ELEMENTS_COUNT ||
|
||||
numElements + ObjectElements::VALUES_PER_HEADER >= SLOTS_TO_THING_KIND_LIMIT)
|
||||
{
|
||||
return AllocKind::OBJECT2;
|
||||
}
|
||||
return slotsToThingKind[numElements + ObjectElements::VALUES_PER_HEADER];
|
||||
}
|
||||
|
||||
static inline AllocKind
|
||||
GetGCObjectFixedSlotsKind(size_t numFixedSlots)
|
||||
{
|
||||
MOZ_ASSERT(numFixedSlots < SLOTS_TO_THING_KIND_LIMIT);
|
||||
return slotsToThingKind[numFixedSlots];
|
||||
}
|
||||
|
||||
// Get the best kind to use when allocating an object that needs a specific
|
||||
// number of bytes.
|
||||
static inline AllocKind
|
||||
GetGCObjectKindForBytes(size_t nbytes)
|
||||
{
|
||||
MOZ_ASSERT(nbytes <= JSObject::MAX_BYTE_SIZE);
|
||||
|
||||
if (nbytes <= sizeof(NativeObject))
|
||||
return AllocKind::OBJECT0;
|
||||
nbytes -= sizeof(NativeObject);
|
||||
|
||||
size_t dataSlots = AlignBytes(nbytes, sizeof(Value)) / sizeof(Value);
|
||||
MOZ_ASSERT(nbytes <= dataSlots * sizeof(Value));
|
||||
return GetGCObjectKind(dataSlots);
|
||||
}
|
||||
|
||||
/* Get the number of fixed slots and initial capacity associated with a kind. */
|
||||
static inline size_t
|
||||
GetGCKindSlots(AllocKind thingKind)
|
||||
{
|
||||
/* Using a switch in hopes that thingKind will usually be a compile-time constant. */
|
||||
switch (thingKind) {
|
||||
case AllocKind::FUNCTION:
|
||||
case AllocKind::OBJECT0:
|
||||
case AllocKind::OBJECT0_BACKGROUND:
|
||||
return 0;
|
||||
case AllocKind::FUNCTION_EXTENDED:
|
||||
case AllocKind::OBJECT2:
|
||||
case AllocKind::OBJECT2_BACKGROUND:
|
||||
return 2;
|
||||
case AllocKind::OBJECT4:
|
||||
case AllocKind::OBJECT4_BACKGROUND:
|
||||
return 4;
|
||||
case AllocKind::OBJECT8:
|
||||
case AllocKind::OBJECT8_BACKGROUND:
|
||||
return 8;
|
||||
case AllocKind::OBJECT12:
|
||||
case AllocKind::OBJECT12_BACKGROUND:
|
||||
return 12;
|
||||
case AllocKind::OBJECT16:
|
||||
case AllocKind::OBJECT16_BACKGROUND:
|
||||
return 16;
|
||||
default:
|
||||
MOZ_CRASH("Bad object alloc kind");
|
||||
}
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
GetGCKindSlots(AllocKind thingKind, const Class* clasp)
|
||||
{
|
||||
size_t nslots = GetGCKindSlots(thingKind);
|
||||
|
||||
/* An object's private data uses the space taken by its last fixed slot. */
|
||||
if (clasp->flags & JSCLASS_HAS_PRIVATE) {
|
||||
MOZ_ASSERT(nslots > 0);
|
||||
nslots--;
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions have a larger alloc kind than AllocKind::OBJECT to reserve
|
||||
* space for the extra fields in JSFunction, but have no fixed slots.
|
||||
*/
|
||||
if (clasp == FunctionClassPtr)
|
||||
nslots = 0;
|
||||
|
||||
return nslots;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
GetGCKindBytes(AllocKind thingKind)
|
||||
{
|
||||
return sizeof(JSObject_Slots0) + GetGCKindSlots(thingKind) * sizeof(Value);
|
||||
}
|
||||
|
||||
} // namespace gc
|
||||
} // namespace js
|
||||
|
||||
#endif // gc_ObjectKind_inl_h
|
@ -29,6 +29,7 @@
|
||||
#include "jsboolinlines.h"
|
||||
#include "jsobjinlines.h"
|
||||
#include "jsscriptinlines.h"
|
||||
#include "vm/UnboxedObject-inl.h"
|
||||
|
||||
using namespace js;
|
||||
using namespace js::jit;
|
||||
|
215
js/src/jsgc.h
215
js/src/jsgc.h
@ -84,221 +84,6 @@ template <typename T> struct ParticipatesInCC {};
|
||||
JS_FOR_EACH_TRACEKIND(EXPAND_PARTICIPATES_IN_CC)
|
||||
#undef EXPAND_PARTICIPATES_IN_CC
|
||||
|
||||
static inline bool
|
||||
IsNurseryAllocable(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
true, /* AllocKind::FUNCTION */
|
||||
true, /* AllocKind::FUNCTION_EXTENDED */
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT2 */
|
||||
true, /* AllocKind::OBJECT2_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT4 */
|
||||
true, /* AllocKind::OBJECT4_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT8 */
|
||||
true, /* AllocKind::OBJECT8_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT12 */
|
||||
true, /* AllocKind::OBJECT12_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT16 */
|
||||
true, /* AllocKind::OBJECT16_BACKGROUND */
|
||||
false, /* AllocKind::SCRIPT */
|
||||
false, /* AllocKind::LAZY_SCRIPT */
|
||||
false, /* AllocKind::SHAPE */
|
||||
false, /* AllocKind::ACCESSOR_SHAPE */
|
||||
false, /* AllocKind::BASE_SHAPE */
|
||||
false, /* AllocKind::OBJECT_GROUP */
|
||||
false, /* AllocKind::FAT_INLINE_STRING */
|
||||
false, /* AllocKind::STRING */
|
||||
false, /* AllocKind::EXTERNAL_STRING */
|
||||
false, /* AllocKind::FAT_INLINE_ATOM */
|
||||
false, /* AllocKind::ATOM */
|
||||
false, /* AllocKind::SYMBOL */
|
||||
false, /* AllocKind::JITCODE */
|
||||
false, /* AllocKind::SCOPE */
|
||||
false, /* AllocKind::REGEXP_SHARED */
|
||||
};
|
||||
JS_STATIC_ASSERT(JS_ARRAY_LENGTH(map) == size_t(AllocKind::LIMIT));
|
||||
return map[size_t(kind)];
|
||||
}
|
||||
|
||||
static inline bool
|
||||
IsBackgroundFinalized(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
true, /* AllocKind::FUNCTION */
|
||||
true, /* AllocKind::FUNCTION_EXTENDED */
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT2 */
|
||||
true, /* AllocKind::OBJECT2_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT4 */
|
||||
true, /* AllocKind::OBJECT4_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT8 */
|
||||
true, /* AllocKind::OBJECT8_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT12 */
|
||||
true, /* AllocKind::OBJECT12_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT16 */
|
||||
true, /* AllocKind::OBJECT16_BACKGROUND */
|
||||
false, /* AllocKind::SCRIPT */
|
||||
true, /* AllocKind::LAZY_SCRIPT */
|
||||
true, /* AllocKind::SHAPE */
|
||||
true, /* AllocKind::ACCESSOR_SHAPE */
|
||||
true, /* AllocKind::BASE_SHAPE */
|
||||
true, /* AllocKind::OBJECT_GROUP */
|
||||
true, /* AllocKind::FAT_INLINE_STRING */
|
||||
true, /* AllocKind::STRING */
|
||||
true, /* AllocKind::EXTERNAL_STRING */
|
||||
true, /* AllocKind::FAT_INLINE_ATOM */
|
||||
true, /* AllocKind::ATOM */
|
||||
true, /* AllocKind::SYMBOL */
|
||||
false, /* AllocKind::JITCODE */
|
||||
true, /* AllocKind::SCOPE */
|
||||
true, /* AllocKind::REGEXP_SHARED */
|
||||
};
|
||||
JS_STATIC_ASSERT(JS_ARRAY_LENGTH(map) == size_t(AllocKind::LIMIT));
|
||||
return map[size_t(kind)];
|
||||
}
|
||||
|
||||
static inline bool
|
||||
CanBeFinalizedInBackground(AllocKind kind, const Class* clasp)
|
||||
{
|
||||
MOZ_ASSERT(IsObjectAllocKind(kind));
|
||||
/* If the class has no finalizer or a finalizer that is safe to call on
|
||||
* a different thread, we change the alloc kind. For example,
|
||||
* AllocKind::OBJECT0 calls the finalizer on the active thread,
|
||||
* AllocKind::OBJECT0_BACKGROUND calls the finalizer on the gcHelperThread.
|
||||
* IsBackgroundFinalized is called to prevent recursively incrementing
|
||||
* the alloc kind; kind may already be a background finalize kind.
|
||||
*/
|
||||
return (!IsBackgroundFinalized(kind) &&
|
||||
(!clasp->hasFinalize() || (clasp->flags & JSCLASS_BACKGROUND_FINALIZE)));
|
||||
}
|
||||
|
||||
/* Capacity for slotsToThingKind */
|
||||
const size_t SLOTS_TO_THING_KIND_LIMIT = 17;
|
||||
|
||||
extern const AllocKind slotsToThingKind[];
|
||||
|
||||
/* Get the best kind to use when making an object with the given slot count. */
|
||||
static inline AllocKind
|
||||
GetGCObjectKind(size_t numSlots)
|
||||
{
|
||||
if (numSlots >= SLOTS_TO_THING_KIND_LIMIT)
|
||||
return AllocKind::OBJECT16;
|
||||
return slotsToThingKind[numSlots];
|
||||
}
|
||||
|
||||
/* As for GetGCObjectKind, but for dense array allocation. */
|
||||
static inline AllocKind
|
||||
GetGCArrayKind(size_t numElements)
|
||||
{
|
||||
/*
|
||||
* Dense arrays can use their fixed slots to hold their elements array
|
||||
* (less two Values worth of ObjectElements header), but if more than the
|
||||
* maximum number of fixed slots is needed then the fixed slots will be
|
||||
* unused.
|
||||
*/
|
||||
JS_STATIC_ASSERT(ObjectElements::VALUES_PER_HEADER == 2);
|
||||
if (numElements > NativeObject::MAX_DENSE_ELEMENTS_COUNT ||
|
||||
numElements + ObjectElements::VALUES_PER_HEADER >= SLOTS_TO_THING_KIND_LIMIT)
|
||||
{
|
||||
return AllocKind::OBJECT2;
|
||||
}
|
||||
return slotsToThingKind[numElements + ObjectElements::VALUES_PER_HEADER];
|
||||
}
|
||||
|
||||
static inline AllocKind
|
||||
GetGCObjectFixedSlotsKind(size_t numFixedSlots)
|
||||
{
|
||||
MOZ_ASSERT(numFixedSlots < SLOTS_TO_THING_KIND_LIMIT);
|
||||
return slotsToThingKind[numFixedSlots];
|
||||
}
|
||||
|
||||
// Get the best kind to use when allocating an object that needs a specific
|
||||
// number of bytes.
|
||||
static inline AllocKind
|
||||
GetGCObjectKindForBytes(size_t nbytes)
|
||||
{
|
||||
MOZ_ASSERT(nbytes <= JSObject::MAX_BYTE_SIZE);
|
||||
|
||||
if (nbytes <= sizeof(NativeObject))
|
||||
return AllocKind::OBJECT0;
|
||||
nbytes -= sizeof(NativeObject);
|
||||
|
||||
size_t dataSlots = AlignBytes(nbytes, sizeof(Value)) / sizeof(Value);
|
||||
MOZ_ASSERT(nbytes <= dataSlots * sizeof(Value));
|
||||
return GetGCObjectKind(dataSlots);
|
||||
}
|
||||
|
||||
static inline AllocKind
|
||||
GetBackgroundAllocKind(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(!IsBackgroundFinalized(kind));
|
||||
MOZ_ASSERT(IsObjectAllocKind(kind));
|
||||
return AllocKind(size_t(kind) + 1);
|
||||
}
|
||||
|
||||
/* Get the number of fixed slots and initial capacity associated with a kind. */
|
||||
static inline size_t
|
||||
GetGCKindSlots(AllocKind thingKind)
|
||||
{
|
||||
/* Using a switch in hopes that thingKind will usually be a compile-time constant. */
|
||||
switch (thingKind) {
|
||||
case AllocKind::FUNCTION:
|
||||
case AllocKind::OBJECT0:
|
||||
case AllocKind::OBJECT0_BACKGROUND:
|
||||
return 0;
|
||||
case AllocKind::FUNCTION_EXTENDED:
|
||||
case AllocKind::OBJECT2:
|
||||
case AllocKind::OBJECT2_BACKGROUND:
|
||||
return 2;
|
||||
case AllocKind::OBJECT4:
|
||||
case AllocKind::OBJECT4_BACKGROUND:
|
||||
return 4;
|
||||
case AllocKind::OBJECT8:
|
||||
case AllocKind::OBJECT8_BACKGROUND:
|
||||
return 8;
|
||||
case AllocKind::OBJECT12:
|
||||
case AllocKind::OBJECT12_BACKGROUND:
|
||||
return 12;
|
||||
case AllocKind::OBJECT16:
|
||||
case AllocKind::OBJECT16_BACKGROUND:
|
||||
return 16;
|
||||
default:
|
||||
MOZ_CRASH("Bad object alloc kind");
|
||||
}
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
GetGCKindSlots(AllocKind thingKind, const Class* clasp)
|
||||
{
|
||||
size_t nslots = GetGCKindSlots(thingKind);
|
||||
|
||||
/* An object's private data uses the space taken by its last fixed slot. */
|
||||
if (clasp->flags & JSCLASS_HAS_PRIVATE) {
|
||||
MOZ_ASSERT(nslots > 0);
|
||||
nslots--;
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions have a larger alloc kind than AllocKind::OBJECT to reserve
|
||||
* space for the extra fields in JSFunction, but have no fixed slots.
|
||||
*/
|
||||
if (clasp == FunctionClassPtr)
|
||||
nslots = 0;
|
||||
|
||||
return nslots;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
GetGCKindBytes(AllocKind thingKind)
|
||||
{
|
||||
return sizeof(JSObject_Slots0) + GetGCKindSlots(thingKind) * sizeof(Value);
|
||||
}
|
||||
|
||||
/* The number of GC cycles an empty chunk can survive before been released. */
|
||||
const size_t MAX_EMPTY_CHUNK_AGE = 4;
|
||||
|
||||
|
@ -29,20 +29,6 @@ MakeAccessibleAfterMovingGC(JSObject* obj) {
|
||||
obj->as<NativeObject>().updateShapeAfterMovingGC();
|
||||
}
|
||||
|
||||
static inline AllocKind
|
||||
GetGCObjectKind(const Class* clasp)
|
||||
{
|
||||
if (clasp == FunctionClassPtr)
|
||||
return AllocKind::FUNCTION;
|
||||
|
||||
MOZ_ASSERT(!clasp->isProxy(), "Proxies should use GetProxyGCObjectKind");
|
||||
|
||||
uint32_t nslots = JSCLASS_RESERVED_SLOTS(clasp);
|
||||
if (clasp->flags & JSCLASS_HAS_PRIVATE)
|
||||
nslots++;
|
||||
return GetGCObjectKind(nslots);
|
||||
}
|
||||
|
||||
class ArenaIter
|
||||
{
|
||||
Arena* arena;
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "jscntxtinlines.h"
|
||||
#include "jscompartmentinlines.h"
|
||||
|
||||
#include "builtin/TypedObject-inl.h"
|
||||
#include "vm/ArrayObject-inl.h"
|
||||
#include "vm/BooleanObject-inl.h"
|
||||
#include "vm/Caches-inl.h"
|
||||
@ -66,6 +67,8 @@
|
||||
#include "vm/NumberObject-inl.h"
|
||||
#include "vm/Shape-inl.h"
|
||||
#include "vm/StringObject-inl.h"
|
||||
#include "vm/TypedArrayObject-inl.h"
|
||||
#include "vm/UnboxedObject-inl.h"
|
||||
|
||||
using namespace js;
|
||||
using namespace js::gc;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "jscompartmentinlines.h"
|
||||
#include "jsgcinlines.h"
|
||||
|
||||
#include "gc/ObjectKind-inl.h"
|
||||
#include "vm/ShapedObject-inl.h"
|
||||
#include "vm/TypeInference-inl.h"
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "gc/GCTrace.h"
|
||||
#include "vm/String.h"
|
||||
|
||||
#include "jsgcinlines.h"
|
||||
#include "jsobjinlines.h"
|
||||
|
||||
#include "vm/TypeInference-inl.h"
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "wasm/WasmInstance.h"
|
||||
|
||||
#include "jsatominlines.h"
|
||||
#include "jsobjinlines.h"
|
||||
#include "jsscriptinlines.h"
|
||||
|
||||
#include "vm/NativeObject-inl.h"
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "jscntxt.h"
|
||||
|
||||
#include "builtin/TypedObject.h"
|
||||
#include "gc/GCTrace.h"
|
||||
#include "proxy/Proxy.h"
|
||||
#include "vm/ProxyObject.h"
|
||||
#include "vm/TypedArrayObject.h"
|
||||
@ -19,6 +20,7 @@
|
||||
#include "jsobjinlines.h"
|
||||
|
||||
#include "gc/Heap-inl.h"
|
||||
#include "gc/ObjectKind-inl.h"
|
||||
|
||||
namespace js {
|
||||
|
||||
|
@ -20,9 +20,6 @@
|
||||
#include "vm/RegExpObject.h"
|
||||
#include "vm/Shape.h"
|
||||
#include "vm/TaggedProto.h"
|
||||
#include "vm/UnboxedObject.h"
|
||||
|
||||
#include "jsobjinlines.h"
|
||||
|
||||
#include "vm/UnboxedObject-inl.h"
|
||||
|
||||
|
@ -8,10 +8,15 @@
|
||||
|
||||
#include "jscompartment.h"
|
||||
|
||||
#include "gc/Allocator.h"
|
||||
#include "gc/GCTrace.h"
|
||||
#include "proxy/DeadObjectProxy.h"
|
||||
|
||||
#include "jsobjinlines.h"
|
||||
|
||||
#include "gc/ObjectKind-inl.h"
|
||||
#include "vm/TypeInference-inl.h"
|
||||
|
||||
using namespace js;
|
||||
|
||||
static gc::AllocKind
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "vm/StringBuffer.h"
|
||||
#include "wasm/WasmInstance.h"
|
||||
|
||||
#include "gc/ObjectKind-inl.h"
|
||||
#include "vm/Shape-inl.h"
|
||||
|
||||
using namespace js;
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
#include "vm/NativeObject.h"
|
||||
|
||||
#include "gc/ObjectKind-inl.h"
|
||||
|
||||
namespace js {
|
||||
|
||||
template<typename To, typename From>
|
||||
@ -608,6 +610,18 @@ class ElementSpecific
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* static */ gc::AllocKind
|
||||
js::TypedArrayObject::AllocKindForLazyBuffer(size_t nbytes)
|
||||
{
|
||||
MOZ_ASSERT(nbytes <= INLINE_BUFFER_LIMIT);
|
||||
if (nbytes == 0)
|
||||
nbytes += sizeof(uint8_t);
|
||||
size_t dataSlots = AlignBytes(nbytes, sizeof(Value)) / sizeof(Value);
|
||||
MOZ_ASSERT(nbytes <= dataSlots * sizeof(Value));
|
||||
return gc::GetGCObjectKind(FIXED_DATA_START + dataSlots);
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
||||
#endif // vm_TypedArrayObject_inl_h
|
||||
|
@ -115,16 +115,7 @@ class TypedArrayObject : public NativeObject
|
||||
static const uint32_t INLINE_BUFFER_LIMIT =
|
||||
(NativeObject::MAX_FIXED_SLOTS - FIXED_DATA_START) * sizeof(Value);
|
||||
|
||||
static gc::AllocKind
|
||||
AllocKindForLazyBuffer(size_t nbytes)
|
||||
{
|
||||
MOZ_ASSERT(nbytes <= INLINE_BUFFER_LIMIT);
|
||||
if (nbytes == 0)
|
||||
nbytes += sizeof(uint8_t);
|
||||
size_t dataSlots = AlignBytes(nbytes, sizeof(Value)) / sizeof(Value);
|
||||
MOZ_ASSERT(nbytes <= dataSlots * sizeof(Value));
|
||||
return gc::GetGCObjectKind(FIXED_DATA_START + dataSlots);
|
||||
}
|
||||
static inline gc::AllocKind AllocKindForLazyBuffer(size_t nbytes);
|
||||
|
||||
inline Scalar::Type type() const;
|
||||
inline size_t bytesPerElement() const;
|
||||
|
@ -168,6 +168,17 @@ UnboxedPlainObject::layout() const
|
||||
return group()->unboxedLayout();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// UnboxedLayout
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
gc::AllocKind
|
||||
js::UnboxedLayout::getAllocKind() const
|
||||
{
|
||||
MOZ_ASSERT(size());
|
||||
return gc::GetGCObjectKindForBytes(UnboxedPlainObject::offsetOfData() + size());
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
||||
#endif // vm_UnboxedObject_inl_h
|
||||
|
@ -317,13 +317,6 @@ bool
|
||||
TryConvertToUnboxedLayout(JSContext* cx, AutoEnterAnalysis& enter, Shape* templateShape,
|
||||
ObjectGroup* group, PreliminaryObjectArray* objects);
|
||||
|
||||
inline gc::AllocKind
|
||||
UnboxedLayout::getAllocKind() const
|
||||
{
|
||||
MOZ_ASSERT(size());
|
||||
return gc::GetGCObjectKindForBytes(UnboxedPlainObject::offsetOfData() + size());
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
||||
namespace JS {
|
||||
|
Loading…
Reference in New Issue
Block a user