Commit ee903e17 authored by Mathieu Chartier's avatar Mathieu Chartier
Browse files

Fix broken card table asserts.

We had an off by one error due to getting the card for the heap
source limit. This is not a valid card when the heap is at
maximum size, but doesn't need to be since we do less than
comparison on it. Fixed another error where we didn't take into
account the biased begin in an assert.

Did a bit of refactoring by removing useless if statement.

Fixes 061-out-of-memory.

Bug: 8282011
Change-Id: I66e3026e7b98b738ecfbced101846ec9f184ab70
parent 27366b6a
......@@ -54,9 +54,12 @@ bool dvmCardTableStartup(size_t heapMaximumSize, size_t growthLimit)
void *allocBase;
u1 *biasedBase;
GcHeap *gcHeap = gDvm.gcHeap;
int offset;
void *heapBase = dvmHeapSourceGetBase();
assert(gcHeap != NULL);
assert(heapBase != NULL);
/* All zeros is the correct initial value; all clean. */
assert(GC_CARD_CLEAN == 0);
/* Set up the card table */
length = heapMaximumSize / GC_CARD_SIZE;
......@@ -69,17 +72,11 @@ bool dvmCardTableStartup(size_t heapMaximumSize, size_t growthLimit)
gcHeap->cardTableBase = (u1*)allocBase;
gcHeap->cardTableLength = growthLimit / GC_CARD_SIZE;
gcHeap->cardTableMaxLength = length;
gcHeap->cardTableOffset = 0;
/* All zeros is the correct initial value; all clean. */
assert(GC_CARD_CLEAN == 0);
biasedBase = (u1 *)((uintptr_t)allocBase -
((uintptr_t)heapBase >> GC_CARD_SHIFT));
if (((uintptr_t)biasedBase & 0xff) != GC_CARD_DIRTY) {
int offset = GC_CARD_DIRTY - ((uintptr_t)biasedBase & 0xff);
gcHeap->cardTableOffset = offset + (offset < 0 ? 0x100 : 0);
biasedBase += gcHeap->cardTableOffset;
}
((uintptr_t)heapBase >> GC_CARD_SHIFT));
offset = GC_CARD_DIRTY - ((uintptr_t)biasedBase & 0xff);
gcHeap->cardTableOffset = offset + (offset < 0 ? 0x100 : 0);
biasedBase += gcHeap->cardTableOffset;
assert(((uintptr_t)biasedBase & 0xff) == GC_CARD_DIRTY);
gDvm.biasedCardTableBase = biasedBase;
......@@ -164,7 +161,7 @@ bool dvmIsValidCard(const u1 *cardAddr)
}
/*
* Returns the address of the relevent byte in the card table, given
* Returns the address of the relevant byte in the card table, given
* an address on the heap.
*/
u1 *dvmCardFromAddr(const void *addr)
......
......@@ -558,8 +558,9 @@ static void scanGrayObjects(GcMarkContext *ctx)
const u1 *base, *limit, *ptr, *dirty;
base = &h->cardTableBase[0];
limit = dvmCardFromAddr((u1 *)dvmHeapSourceGetLimit());
assert(limit <= &h->cardTableBase[h->cardTableLength]);
// The limit is the card one after the last accessible card.
limit = dvmCardFromAddr((u1 *)dvmHeapSourceGetLimit() - GC_CARD_SIZE) + 1;
assert(limit <= &base[h->cardTableOffset + h->cardTableLength]);
ptr = base;
for (;;) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment