mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +00:00
snapshot
This commit is contained in:
parent
d5ce307a2a
commit
09f6a34510
38
src/heap.cpp
38
src/heap.cpp
@ -41,7 +41,6 @@ class Segment {
|
|||||||
Iterator(Map* map, unsigned start, unsigned end):
|
Iterator(Map* map, unsigned start, unsigned end):
|
||||||
map(map)
|
map(map)
|
||||||
{
|
{
|
||||||
assert(map->segment->context, map);
|
|
||||||
assert(map->segment->context, map->bitsPerRecord == 1);
|
assert(map->segment->context, map->bitsPerRecord == 1);
|
||||||
assert(map->segment->context, map->segment);
|
assert(map->segment->context, map->segment);
|
||||||
assert(map->segment->context, start <= map->segment->position());
|
assert(map->segment->context, start <= map->segment->position());
|
||||||
@ -55,8 +54,6 @@ class Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hasMore() {
|
bool hasMore() {
|
||||||
assert(map->segment->context, map);
|
|
||||||
|
|
||||||
unsigned word = wordOf(index);
|
unsigned word = wordOf(index);
|
||||||
unsigned bit = bitOf(index);
|
unsigned bit = bitOf(index);
|
||||||
unsigned wordLimit = wordOf(limit);
|
unsigned wordLimit = wordOf(limit);
|
||||||
@ -115,7 +112,6 @@ class Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void replaceWith(Map* m) {
|
void replaceWith(Map* m) {
|
||||||
assert(segment->context, m);
|
|
||||||
assert(segment->context, bitsPerRecord == m->bitsPerRecord);
|
assert(segment->context, bitsPerRecord == m->bitsPerRecord);
|
||||||
assert(segment->context, scale == m->scale);
|
assert(segment->context, scale == m->scale);
|
||||||
|
|
||||||
@ -154,7 +150,6 @@ class Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned indexOf(void* p) {
|
unsigned indexOf(void* p) {
|
||||||
assert(segment->context, segment);
|
|
||||||
assert(segment->context, segment->almostContains(p));
|
assert(segment->context, segment->almostContains(p));
|
||||||
assert(segment->context, segment->capacity());
|
assert(segment->context, segment->capacity());
|
||||||
return indexOf(segment->indexOf(p));
|
return indexOf(segment->indexOf(p));
|
||||||
@ -178,13 +173,13 @@ class Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clearBit(unsigned i) {
|
void clearBit(unsigned i) {
|
||||||
assert(segment->context, wordOf(i) * BytesPerWord < size());
|
assert(segment->context, wordOf(i) < size());
|
||||||
|
|
||||||
data()[wordOf(i)] &= ~(static_cast<uintptr_t>(1) << bitOf(i));
|
data()[wordOf(i)] &= ~(static_cast<uintptr_t>(1) << bitOf(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBit(unsigned i) {
|
void setBit(unsigned i) {
|
||||||
assert(segment->context, wordOf(i) * BytesPerWord < size());
|
assert(segment->context, wordOf(i) < size());
|
||||||
|
|
||||||
data()[wordOf(i)] |= static_cast<uintptr_t>(1) << bitOf(i);
|
data()[wordOf(i)] |= static_cast<uintptr_t>(1) << bitOf(i);
|
||||||
}
|
}
|
||||||
@ -288,16 +283,23 @@ class Segment {
|
|||||||
return reinterpret_cast<uintptr_t*>(this) + CHAIN_HEADER_SIZE;
|
return reinterpret_cast<uintptr_t*>(this) + CHAIN_HEADER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned footprint(unsigned capacity, Map* map) {
|
static unsigned footprint(unsigned capacity, Chain* previous,
|
||||||
|
Map* map)
|
||||||
|
{
|
||||||
unsigned n = CHAIN_HEADER_SIZE + capacity;
|
unsigned n = CHAIN_HEADER_SIZE + capacity;
|
||||||
if (map) {
|
if (map) {
|
||||||
n += map->footprint(capacity);
|
unsigned segmentCapacity = capacity;
|
||||||
|
if (previous) {
|
||||||
|
segmentCapacity += previous->offset + previous->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
n += map->footprint(segmentCapacity);
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned footprint() {
|
unsigned footprint() {
|
||||||
return footprint(capacity, segment->map);
|
return footprint(capacity, previous, segment->map);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -319,7 +321,7 @@ class Segment {
|
|||||||
if (capacity) {
|
if (capacity) {
|
||||||
front = rear = new
|
front = rear = new
|
||||||
(system(context)->allocate
|
(system(context)->allocate
|
||||||
(Chain::footprint(capacity, map) * BytesPerWord))
|
(Chain::footprint(capacity, 0, map) * BytesPerWord))
|
||||||
Chain(this, 0, capacity, 0);
|
Chain(this, 0, capacity, 0);
|
||||||
|
|
||||||
if (map) {
|
if (map) {
|
||||||
@ -441,8 +443,7 @@ class Segment {
|
|||||||
abort(context);
|
abort(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* allocate(unsigned sizeInBytes) {
|
void* allocate(unsigned size) {
|
||||||
unsigned size = divide(sizeInBytes, BytesPerWord);
|
|
||||||
assert(context, size);
|
assert(context, size);
|
||||||
assert(context, rear->position + size <= rear->capacity);
|
assert(context, rear->position + size <= rear->capacity);
|
||||||
void* p = reinterpret_cast<void**>(rear->data()) + rear->position;
|
void* p = reinterpret_cast<void**>(rear->data()) + rear->position;
|
||||||
@ -459,6 +460,9 @@ class Segment {
|
|||||||
|
|
||||||
void ensure(unsigned minimum) {
|
void ensure(unsigned minimum) {
|
||||||
if (remaining() < minimum) {
|
if (remaining() < minimum) {
|
||||||
|
assert(context, rear->position);
|
||||||
|
assert(context, rear->next == 0);
|
||||||
|
|
||||||
if (Verbose) {
|
if (Verbose) {
|
||||||
fprintf(stderr, "grow\n");
|
fprintf(stderr, "grow\n");
|
||||||
}
|
}
|
||||||
@ -469,7 +473,7 @@ class Segment {
|
|||||||
unsigned newCapacity = desired;
|
unsigned newCapacity = desired;
|
||||||
while (p == 0) {
|
while (p == 0) {
|
||||||
p = system(context)->tryAllocate
|
p = system(context)->tryAllocate
|
||||||
(Chain::footprint(newCapacity, map) * BytesPerWord);
|
(Chain::footprint(newCapacity, rear, map) * BytesPerWord);
|
||||||
|
|
||||||
if (p == 0) {
|
if (p == 0) {
|
||||||
if (newCapacity > minimum) {
|
if (newCapacity > minimum) {
|
||||||
@ -484,10 +488,10 @@ class Segment {
|
|||||||
(this, rear->offset + rear->position, newCapacity, rear);
|
(this, rear->offset + rear->position, newCapacity, rear);
|
||||||
|
|
||||||
if (map) {
|
if (map) {
|
||||||
map->update(c->data() + c->capacity, newCapacity);
|
map->update(c->data() + c->capacity, c->offset + c->capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
rear->previous = c;
|
rear->next = c;
|
||||||
rear = c;
|
rear = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -609,7 +613,7 @@ fresh(Context* c, object o)
|
|||||||
{
|
{
|
||||||
return c->nextGen1.contains(o)
|
return c->nextGen1.contains(o)
|
||||||
or c->nextGen2.contains(o)
|
or c->nextGen2.contains(o)
|
||||||
or (c->gen2.contains(o) and c->gen2.indexOf(o) > c->gen2Base);
|
or (c->gen2.contains(o) and c->gen2.indexOf(o) >= c->gen2Base);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
|
Loading…
Reference in New Issue
Block a user