microoptimizations

This commit is contained in:
lax1dude 2024-11-01 18:05:29 -07:00
parent cd8066757b
commit eb2cab3597

View File

@ -126,7 +126,7 @@ public final class LaxMalloc {
Address bucketStartAddr = Address.fromInt(ADDR_HEAP_BUCKETS_START).add(availableBucket << SIZEOF_PTR_SH); Address bucketStartAddr = Address.fromInt(ADDR_HEAP_BUCKETS_START).add(availableBucket << SIZEOF_PTR_SH);
Address chunkPtr = bucketStartAddr.getAddress(); Address chunkPtr = bucketStartAddr.getAddress();
int chunkSize = readChunkSize(chunkPtr); int chunkSize = readChunkSizeStatus(chunkPtr);
Address itrChunkStart = Address.fromInt(0); Address itrChunkStart = Address.fromInt(0);
// check if the first chunk in the bucket is large enough // check if the first chunk in the bucket is large enough
@ -150,7 +150,7 @@ public final class LaxMalloc {
int availableLargerBucket = numberOfTrailingZerosL(bucketMask); int availableLargerBucket = numberOfTrailingZerosL(bucketMask);
Address largerBucketStartAddr = Address.fromInt(ADDR_HEAP_BUCKETS_START).add(availableLargerBucket << SIZEOF_PTR_SH); Address largerBucketStartAddr = Address.fromInt(ADDR_HEAP_BUCKETS_START).add(availableLargerBucket << SIZEOF_PTR_SH);
Address largerChunkPtr = largerBucketStartAddr.getAddress(); Address largerChunkPtr = largerBucketStartAddr.getAddress();
int largerChunkSize = readChunkSize(largerChunkPtr); int largerChunkSize = readChunkSizeStatus(largerChunkPtr);
// this will remove the chunk from the free list // this will remove the chunk from the free list
allocateMemoryFromChunk(largerChunkPtr, largerChunkSize, sizeBytes); allocateMemoryFromChunk(largerChunkPtr, largerChunkSize, sizeBytes);
@ -190,7 +190,7 @@ public final class LaxMalloc {
// iterate the (only) bucket of possibly large enough chunks // iterate the (only) bucket of possibly large enough chunks
Address addrIterator = itrChunkStart; Address addrIterator = itrChunkStart;
do { do {
chunkSize = readChunkSize(addrIterator); chunkSize = readChunkSizeStatus(addrIterator);
// check if the chunk is large enough // check if the chunk is large enough
if(chunkSize - 8 >= sizeBytes) { // size - 2 ints if(chunkSize - 8 >= sizeBytes) { // size - 2 ints
@ -242,7 +242,7 @@ public final class LaxMalloc {
// iterate all free huge chunks // iterate all free huge chunks
Address addrIterator = chunkPtr; Address addrIterator = chunkPtr;
do { do {
int chunkSize = readChunkSize(addrIterator); int chunkSize = readChunkSizeStatus(addrIterator);
if(chunkSize - 8 >= sizeBytes) { // size - 2 ints if(chunkSize - 8 >= sizeBytes) { // size - 2 ints
// we've found a large enough chunk // we've found a large enough chunk
@ -501,6 +501,9 @@ public final class LaxMalloc {
@Import(name = "teavm_growHeap") @Import(name = "teavm_growHeap")
private static native boolean growHeapOuter(int bytes); private static native boolean growHeapOuter(int bytes);
/**
* Note that on a free chunk, this is the size, because the status bit is 0
*/
private static int readChunkSizeStatus(Address chunkAddr) { private static int readChunkSizeStatus(Address chunkAddr) {
return chunkAddr.getInt(); return chunkAddr.getInt();
} }