Bug 1291292 - Use an enum class for the chunk location values r=terrence

This commit is contained in:
Jon Coppeard 2016-08-11 17:14:56 +01:00
parent 7708926ca5
commit 4d37e5f20d
2 changed files with 14 additions and 18 deletions

View File

@ -69,19 +69,15 @@ static const uint32_t BLACK = 0;
static const uint32_t GRAY = 1;
/*
* The "location" field in the Chunk trailer is a bit vector indicting various
* roles of the chunk.
*
* The value 0 for the "location" field is invalid, at least one bit must be
* set.
*
* Some bits preclude others, for example, any "nursery" bit precludes any
* "tenured" or "middle generation" bit.
* The "location" field in the Chunk trailer is a enum indicating various roles
* of the chunk.
*/
const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery
const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation
const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery;
enum class ChunkLocation : uint32_t
{
Invalid = 0,
Nursery = 1,
TenuredHeap = 2
};
#ifdef JS_DEBUG
/* When downcasting, ensure we are actually the right type. */
@ -339,9 +335,9 @@ IsInsideNursery(const js::gc::Cell* cell)
uintptr_t addr = uintptr_t(cell);
addr &= ~js::gc::ChunkMask;
addr |= js::gc::ChunkLocationOffset;
uint32_t location = *reinterpret_cast<uint32_t*>(addr);
MOZ_ASSERT(location != 0);
return location & ChunkLocationAnyNursery;
auto location = *reinterpret_cast<ChunkLocation*>(addr);
MOZ_ASSERT(location == ChunkLocation::Nursery || location == ChunkLocation::TenuredHeap);
return location == ChunkLocation::Nursery;
}
} /* namespace gc */

View File

@ -756,17 +756,17 @@ struct ChunkTrailer
{
/* Construct a Nursery ChunkTrailer. */
ChunkTrailer(JSRuntime* rt, StoreBuffer* sb)
: location(gc::ChunkLocationBitNursery), storeBuffer(sb), runtime(rt)
: location(ChunkLocation::Nursery), storeBuffer(sb), runtime(rt)
{}
/* Construct a Tenured heap ChunkTrailer. */
explicit ChunkTrailer(JSRuntime* rt)
: location(gc::ChunkLocationBitTenuredHeap), storeBuffer(nullptr), runtime(rt)
: location(ChunkLocation::TenuredHeap), storeBuffer(nullptr), runtime(rt)
{}
public:
/* The index the chunk in the nursery, or LocationTenuredHeap. */
uint32_t location;
ChunkLocation location;
uint32_t padding;
/* The store buffer for writes to things in this chunk or nullptr. */