Bug 1199215 - Implement JS::ubi::Node::size for JS::Symbol referents; r=sfink

This commit is contained in:
Nick Fitzgerald 2015-09-22 12:15:23 -07:00
parent dc80274310
commit 44fa198fb1
4 changed files with 51 additions and 1 deletions

View File

@ -1005,7 +1005,18 @@ class TracerConcreteWithCompartment : public TracerConcrete<Referent> {
// Define specializations for some commonly-used public JSAPI types.
// These can use the generic templates above.
template<> struct Concrete<JS::Symbol> : TracerConcrete<JS::Symbol> { };
template<>
struct Concrete<JS::Symbol> : TracerConcrete<JS::Symbol> {
Size size(mozilla::MallocSizeOf mallocSizeOf) const override;
protected:
explicit Concrete(JS::Symbol* ptr) : TracerConcrete(ptr) { }
public:
static void construct(void* storage, JS::Symbol* ptr) {
new (storage) Concrete(ptr);
}
};
template<> struct Concrete<JSScript> : TracerConcreteWithCompartment<JSScript> {
CoarseType coarseType() const final { return CoarseType::Script; }

View File

@ -0,0 +1,25 @@
// Check JS::ubi::Node::size results for symbols.
// We actually hard-code specific sizes into this test, even though they're
// implementation details, because in practice there are only two architecture
// variants to consider (32-bit and 64-bit), and if these sizes change, that's
// something SpiderMonkey hackers really want to know; they're supposed to be
// stable.
// Run this test only if we're using jemalloc. Other malloc implementations
// exhibit surprising behaviors. For example, 32-bit Fedora builds have
// non-deterministic allocation sizes.
var config = getBuildConfiguration();
if (!config['moz-memory'])
quit(0);
const SIZE_OF_SYMBOL = config['pointer-byte-size'] == 4 ? 16 : 24;
// Without a description.
assertEq(byteSize(Symbol()), SIZE_OF_SYMBOL);
// With a description.
assertEq(byteSize(Symbol("This is a relatively long description to be passed to "
+ "Symbol() but it doesn't matter because it just gets "
+ "interned as a JSAtom* anyways.")),
SIZE_OF_SYMBOL);

View File

@ -152,3 +152,13 @@ js::ToSymbolPrimitive(Value v)
MOZ_ASSERT(IsSymbolOrSymbolWrapper(v));
return v.isSymbol() ? v.toSymbol() : v.toObject().as<SymbolObject>().unbox();
}
JS::ubi::Node::Size
JS::ubi::Concrete<JS::Symbol>::size(mozilla::MallocSizeOf mallocSizeOf) const
{
// If we start allocating symbols in the nursery, we will need to update
// this method.
MOZ_ASSERT(get().isTenured());
return js::gc::Arena::thingSize(get().asTenured().getAllocKind());
}

View File

@ -67,6 +67,10 @@ class Symbol : public js::gc::TenuredCell
thing->asTenured().writeBarrierPre(thing);
}
size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
return mallocSizeOf(this);
}
#ifdef DEBUG
void dump(FILE* fp = stderr);
#endif