fix style violations

This commit is contained in:
lax1dude 2024-11-02 21:02:25 -07:00
parent df6fc752b6
commit a5836dff25
5 changed files with 60 additions and 43 deletions

View File

@ -100,7 +100,7 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost {
private List<WasmGCCustomGeneratorFactory> customGeneratorFactories = new ArrayList<>(); private List<WasmGCCustomGeneratorFactory> customGeneratorFactories = new ArrayList<>();
private EntryPointTransformation entryPointTransformation = new EntryPointTransformation(); private EntryPointTransformation entryPointTransformation = new EntryPointTransformation();
private List<WasmGCClassConsumer> classConsumers = new ArrayList<>(); private List<WasmGCClassConsumer> classConsumers = new ArrayList<>();
private boolean enableDirectMallocSupport = false; private boolean enableDirectMallocSupport;
private int directMallocMinHeapSize = 0x10000; private int directMallocMinHeapSize = 0x10000;
private int directMallocMaxHeapSize = 0x10000000; private int directMallocMaxHeapSize = 0x10000000;
@ -308,7 +308,8 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost {
var heapSegment = new WasmMemorySegment(); var heapSegment = new WasmMemorySegment();
if (!module.getSegments().isEmpty()) { if (!module.getSegments().isEmpty()) {
var lastSegment = module.getSegments().get(module.getSegments().size() - 1); var lastSegment = module.getSegments().get(module.getSegments().size() - 1);
heapSegment.setOffset(WasmRuntime.align(lastSegment.getOffset() + lastSegment.getLength(), WasmHeap.PAGE_SIZE)); heapSegment.setOffset(WasmRuntime.align(lastSegment.getOffset()
+ lastSegment.getLength(), WasmHeap.PAGE_SIZE));
} }
heapSegment.setLength(directMallocMinHeapSize); heapSegment.setLength(directMallocMinHeapSize);
module.getSegments().add(heapSegment); module.getSegments().add(heapSegment);
@ -422,7 +423,8 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost {
if (enableDirectMallocSupport) { if (enableDirectMallocSupport) {
var minPages = (memorySize - 1) / WasmHeap.PAGE_SIZE + 1; var minPages = (memorySize - 1) / WasmHeap.PAGE_SIZE + 1;
var maxPages = (memorySize - directMallocMinHeapSize + directMallocMaxHeapSize - 1) / WasmHeap.PAGE_SIZE + 1; var maxPages = (memorySize - directMallocMinHeapSize + directMallocMaxHeapSize - 1)
/ WasmHeap.PAGE_SIZE + 1;
module.setMinMemorySize(minPages); module.setMinMemorySize(minPages);
module.setMaxMemorySize(maxPages); module.setMaxMemorySize(maxPages);
} else { } else {

View File

@ -41,13 +41,14 @@ public class LaxMallocIntrinsic implements WasmGCIntrinsic {
// if addrHeap is passed a constant i32, add the heap offset at compile time // if addrHeap is passed a constant i32, add the heap offset at compile time
final int memOffset = ((WasmInt32Constant) value).getValue(); final int memOffset = ((WasmInt32Constant) value).getValue();
WasmInt32Constant ret = new WasmInt32Constant(0); WasmInt32Constant ret = new WasmInt32Constant(0);
addressList.add((heapLoc) -> { addressList.add(heapLoc -> {
ret.setValue(heapLoc + memOffset); ret.setValue(heapLoc + memOffset);
}); });
return ret; return ret;
} else { } else {
WasmInt32Constant heapLocConst = new WasmInt32Constant(0); WasmInt32Constant heapLocConst = new WasmInt32Constant(0);
WasmExpression calcOffset = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD, heapLocConst, value); WasmExpression calcOffset = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD,
heapLocConst, value);
addressList.add(heapLocConst::setValue); addressList.add(heapLocConst::setValue);
return calcOffset; return calcOffset;
} }

View File

@ -44,19 +44,32 @@ public final class LaxMalloc {
private static final int MIN_ALLOC_SIZE = 8; private static final int MIN_ALLOC_SIZE = 8;
private static final int ADDR_HEAP_OUTER_LIMIT = 0; // Address where we store the WebAssembly.Memory limit (32 bit int) // Address where we store the WebAssembly.Memory limit (32 bit int)
private static final int ADDR_HEAP_INNER_LIMIT = 4; // Address where we store the current heap limit (32 bit int) private static final int ADDR_HEAP_OUTER_LIMIT = 0;
private static final int ADDR_HEAP_BUCKETS_FREE_MASK = 8; // Address where we store the bitmask of free chunk lists (64 bit int)
private static final int ADDR_HEAP_BUCKETS_START = 16; // Address to the list of 64 pointers to the beginnings of the 64 buckets
private static final int ADDR_HEAP_DATA_START = 272; // Beginning of the first chunk of the heap
private static native Address addrHeap(int offset); // Intrinsic function to get an address in the heap segment // Address where we store the current heap limit (32 bit int)
private static final int ADDR_HEAP_INNER_LIMIT = 4;
private static native int growHeapOuter(int bytes); // Intrinsic function to grow the heap segment // Address where we store the bitmask of free chunk lists (64 bit int)
private static final int ADDR_HEAP_BUCKETS_FREE_MASK = 8;
private static native Address getHeapMinAddr(); // Intrinsic function to get the minimum direct malloc heap segment ending address // Address to the list of 64 pointers to the beginnings of the 64 buckets
private static final int ADDR_HEAP_BUCKETS_START = 16;
private static native Address getHeapMaxAddr(); // Intrinsic function to get the maximum direct malloc heap segment ending address // Beginning of the first chunk of the heap
private static final int ADDR_HEAP_DATA_START = 272;
// Intrinsic function to get an address in the heap segment
private static native Address addrHeap(int offset);
// Intrinsic function to grow the heap segment
private static native int growHeapOuter(int bytes);
// Intrinsic function to get the minimum direct malloc heap segment ending address
private static native Address getHeapMinAddr();
// Intrinsic function to get the maximum direct malloc heap segment ending address
private static native Address getHeapMaxAddr();
@Import(name = "teavm_notifyHeapResized") @Import(name = "teavm_notifyHeapResized")
private static native void notifyHeapResized(); private static native void notifyHeapResized();
@ -110,11 +123,11 @@ public final class LaxMalloc {
long bucketMask = addrHeap(ADDR_HEAP_BUCKETS_FREE_MASK).getLong(); long bucketMask = addrHeap(ADDR_HEAP_BUCKETS_FREE_MASK).getLong();
// mask away the buckets that we know are too small for this allocation // mask away the buckets that we know are too small for this allocation
bucketMask = (bucketMask & (0xFFFFFFFFFFFFFFFFL << bucket)); bucketMask = bucketMask & (0xFFFFFFFFFFFFFFFFL << bucket);
// there are no more buckets with free chunks // there are no more buckets with free chunks
// need to sbrk // need to sbrk
if(bucketMask == 0l) { if (bucketMask == 0L) {
int sizePlusInts = sizeBytes + 8; // size + 2 ints int sizePlusInts = sizeBytes + 8; // size + 2 ints
Address newChunk = growHeap(sizePlusInts); // sbrk Address newChunk = growHeap(sizePlusInts); // sbrk
@ -155,9 +168,9 @@ public final class LaxMalloc {
} }
// extend mask to the next bucket // extend mask to the next bucket
bucketMask = (bucketMask & (0xFFFFFFFFFFFFFFFFL << (bucket + 1))); bucketMask &= 0xFFFFFFFFFFFFFFFFL << (bucket + 1);
if(bucketMask != 0l) { if (bucketMask != 0L) {
// there is a bucket with a larger chunk // there is a bucket with a larger chunk
int availableLargerBucket = Long.numberOfTrailingZeros(bucketMask); int availableLargerBucket = Long.numberOfTrailingZeros(bucketMask);
Address largerBucketStartAddr = addrHeap(ADDR_HEAP_BUCKETS_START).add(availableLargerBucket << SIZEOF_PTR_SH); Address largerBucketStartAddr = addrHeap(ADDR_HEAP_BUCKETS_START).add(availableLargerBucket << SIZEOF_PTR_SH);
@ -220,7 +233,8 @@ public final class LaxMalloc {
return ret; return ret;
} }
}while((addrIterator = readChunkNextFreeAddr(addrIterator)).getInt() != chunkPtr.getInt()); addrIterator = readChunkNextFreeAddr(addrIterator);
} while (addrIterator.getInt() != chunkPtr.getInt());
} }
// no other options, time to sbrk // no other options, time to sbrk

View File

@ -119,7 +119,7 @@ public class TeaVMTool {
private Set<File> generatedFiles = new HashSet<>(); private Set<File> generatedFiles = new HashSet<>();
private int minHeapSize = 4 * (1 << 20); private int minHeapSize = 4 * (1 << 20);
private int maxHeapSize = 128 * (1 << 20); private int maxHeapSize = 128 * (1 << 20);
private boolean directMallocSupport = false; private boolean directMallocSupport;
private ReferenceCache referenceCache; private ReferenceCache referenceCache;
private boolean heapDump; private boolean heapDump;
private boolean shortFileNames; private boolean shortFileNames;