2012-10-26 11:17:24 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2013-04-16 13:47:10 -07:00
|
|
|
* 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/. */
|
2012-10-26 11:17:24 -07:00
|
|
|
|
|
|
|
#ifndef js_heap_api_h___
|
|
|
|
#define js_heap_api_h___
|
|
|
|
|
2013-03-19 17:59:42 -07:00
|
|
|
#include "jspubtd.h"
|
|
|
|
|
2012-10-26 11:18:50 -07:00
|
|
|
/* These values are private to the JS engine. */
|
2012-10-26 11:17:24 -07:00
|
|
|
namespace js {
|
2012-10-26 11:18:50 -07:00
|
|
|
namespace gc {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Page size must be static to support our arena pointer optimizations, so we
|
|
|
|
* are forced to support each platform with non-4096 pages as a special case.
|
|
|
|
* Note: The freelist supports a maximum arena shift of 15.
|
|
|
|
* Note: Do not use JS_CPU_SPARC here, this header is used outside JS.
|
|
|
|
*/
|
|
|
|
#if (defined(SOLARIS) || defined(__FreeBSD__)) && \
|
|
|
|
(defined(__sparc) || defined(__sparcv9) || defined(__ia64))
|
|
|
|
const size_t PageShift = 13;
|
|
|
|
const size_t ArenaShift = PageShift;
|
2012-11-06 10:50:19 -08:00
|
|
|
#elif defined(__powerpc64__)
|
2012-10-26 11:18:50 -07:00
|
|
|
const size_t PageShift = 16;
|
|
|
|
const size_t ArenaShift = 12;
|
|
|
|
#else
|
|
|
|
const size_t PageShift = 12;
|
|
|
|
const size_t ArenaShift = PageShift;
|
|
|
|
#endif
|
|
|
|
const size_t PageSize = size_t(1) << PageShift;
|
|
|
|
const size_t ArenaSize = size_t(1) << ArenaShift;
|
|
|
|
const size_t ArenaMask = ArenaSize - 1;
|
|
|
|
|
|
|
|
const size_t ChunkShift = 20;
|
|
|
|
const size_t ChunkSize = size_t(1) << ChunkShift;
|
|
|
|
const size_t ChunkMask = ChunkSize - 1;
|
|
|
|
|
2012-11-28 17:03:54 -08:00
|
|
|
const size_t CellShift = 3;
|
|
|
|
const size_t CellSize = size_t(1) << CellShift;
|
|
|
|
const size_t CellMask = CellSize - 1;
|
|
|
|
|
|
|
|
/* These are magic constants derived from actual offsets in gc/Heap.h. */
|
2013-01-23 12:22:36 -08:00
|
|
|
const size_t ChunkMarkBitmapOffset = 1032368;
|
2012-11-28 17:03:54 -08:00
|
|
|
const size_t ChunkMarkBitmapBits = 129024;
|
2013-03-19 17:59:42 -07:00
|
|
|
const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*);
|
2012-11-28 17:03:54 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Live objects are marked black. How many other additional colors are available
|
|
|
|
* depends on the size of the GCThing. Objects marked gray are eligible for
|
|
|
|
* cycle collection.
|
|
|
|
*/
|
|
|
|
static const uint32_t BLACK = 0;
|
|
|
|
static const uint32_t GRAY = 1;
|
|
|
|
|
2012-10-26 11:18:50 -07:00
|
|
|
} /* namespace gc */
|
|
|
|
} /* namespace js */
|
|
|
|
|
2013-01-27 12:37:18 -08:00
|
|
|
namespace JS {
|
2013-03-16 20:36:37 -07:00
|
|
|
struct Zone;
|
2013-01-27 12:37:18 -08:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2012-10-26 11:18:50 -07:00
|
|
|
namespace JS {
|
|
|
|
namespace shadow {
|
|
|
|
|
|
|
|
struct ArenaHeader
|
|
|
|
{
|
2013-01-27 12:37:18 -08:00
|
|
|
js::Zone *zone;
|
2012-10-26 11:18:50 -07:00
|
|
|
};
|
|
|
|
|
2013-01-27 12:37:18 -08:00
|
|
|
struct Zone
|
2012-11-28 17:03:54 -08:00
|
|
|
{
|
|
|
|
bool needsBarrier_;
|
|
|
|
|
2013-01-27 12:37:18 -08:00
|
|
|
Zone() : needsBarrier_(false) {}
|
2012-11-28 17:03:54 -08:00
|
|
|
};
|
|
|
|
|
2012-10-26 11:18:50 -07:00
|
|
|
} /* namespace shadow */
|
2012-11-28 17:03:54 -08:00
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
namespace gc {
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE uintptr_t *
|
|
|
|
GetGCThingMarkBitmap(const void *thing)
|
|
|
|
{
|
|
|
|
uintptr_t addr = uintptr_t(thing);
|
|
|
|
addr &= ~js::gc::ChunkMask;
|
|
|
|
addr |= js::gc::ChunkMarkBitmapOffset;
|
|
|
|
return reinterpret_cast<uintptr_t *>(addr);
|
|
|
|
}
|
2012-10-26 11:18:50 -07:00
|
|
|
|
2013-03-19 17:59:42 -07:00
|
|
|
static JS_ALWAYS_INLINE JS::shadow::Runtime *
|
|
|
|
GetGCThingRuntime(const void *thing)
|
|
|
|
{
|
|
|
|
uintptr_t addr = uintptr_t(thing);
|
|
|
|
addr &= ~js::gc::ChunkMask;
|
|
|
|
addr |= js::gc::ChunkRuntimeOffset;
|
|
|
|
return *reinterpret_cast<JS::shadow::Runtime **>(addr);
|
|
|
|
}
|
|
|
|
|
2012-11-28 17:03:54 -08:00
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
GetGCThingMarkWordAndMask(const void *thing, uint32_t color,
|
|
|
|
uintptr_t **wordp, uintptr_t *maskp)
|
|
|
|
{
|
|
|
|
uintptr_t addr = uintptr_t(thing);
|
|
|
|
size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color;
|
|
|
|
JS_ASSERT(bit < js::gc::ChunkMarkBitmapBits);
|
|
|
|
uintptr_t *bitmap = GetGCThingMarkBitmap(thing);
|
|
|
|
*maskp = uintptr_t(1) << (bit % JS_BITS_PER_WORD);
|
|
|
|
*wordp = &bitmap[bit / JS_BITS_PER_WORD];
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JS::shadow::ArenaHeader *
|
2012-10-26 11:18:50 -07:00
|
|
|
GetGCThingArena(void *thing)
|
|
|
|
{
|
|
|
|
uintptr_t addr = uintptr_t(thing);
|
|
|
|
addr &= ~js::gc::ArenaMask;
|
2012-11-28 17:03:54 -08:00
|
|
|
return reinterpret_cast<JS::shadow::ArenaHeader *>(addr);
|
2012-10-26 11:18:50 -07:00
|
|
|
}
|
2012-10-26 11:17:24 -07:00
|
|
|
|
2012-11-28 17:03:54 -08:00
|
|
|
} /* namespace gc */
|
2013-03-16 20:36:37 -07:00
|
|
|
|
2012-11-28 17:03:54 -08:00
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2013-01-27 13:51:41 -08:00
|
|
|
static JS_ALWAYS_INLINE Zone *
|
|
|
|
GetGCThingZone(void *thing)
|
|
|
|
{
|
|
|
|
JS_ASSERT(thing);
|
|
|
|
return js::gc::GetGCThingArena(thing)->zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Zone *
|
|
|
|
GetObjectZone(JSObject *obj)
|
|
|
|
{
|
|
|
|
return GetGCThingZone(obj);
|
|
|
|
}
|
|
|
|
|
2012-11-28 17:03:54 -08:00
|
|
|
static JS_ALWAYS_INLINE bool
|
|
|
|
GCThingIsMarkedGray(void *thing)
|
|
|
|
{
|
|
|
|
uintptr_t *word, mask;
|
|
|
|
js::gc::GetGCThingMarkWordAndMask(thing, js::gc::GRAY, &word, &mask);
|
|
|
|
return *word & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE bool
|
2013-04-01 15:31:49 -07:00
|
|
|
IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind)
|
2012-11-28 17:03:54 -08:00
|
|
|
{
|
2013-03-19 17:59:42 -07:00
|
|
|
if (!rt->needsBarrier_)
|
|
|
|
return false;
|
2013-01-27 13:51:41 -08:00
|
|
|
js::Zone *zone = GetGCThingZone(thing);
|
2013-01-27 12:37:18 -08:00
|
|
|
return reinterpret_cast<shadow::Zone *>(zone)->needsBarrier_;
|
2012-11-28 17:03:54 -08:00
|
|
|
}
|
|
|
|
|
2012-10-26 11:18:50 -07:00
|
|
|
} /* namespace JS */
|
2012-10-26 11:17:24 -07:00
|
|
|
|
|
|
|
#endif /* js_heap_api_h___ */
|