# HG changeset patch # User Christian Wimmer # Date 1428736330 25200 # Node ID 2818f2862a0d036fdf3e54af5f21952d43047a7b # Parent 129a0981506333fc2da7fca9aeb28bd061556df9 Use increasingly big arrays to avoid wasting space when writing few bytes diff -r 129a09815063 -r 2818f2862a0d graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeWriter.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeWriter.java Fri Apr 10 21:53:38 2015 -0700 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeWriter.java Sat Apr 11 00:12:10 2015 -0700 @@ -37,12 +37,17 @@ */ public class UnsafeArrayTypeWriter implements TypeWriter { - private static final int CHUNK_SIZE = 4000; + private static final int MIN_CHUNK_LENGTH = 200; + private static final int MAX_CHUNK_LENGTH = 16000; static class Chunk { - protected final byte[] data = new byte[CHUNK_SIZE]; + protected final byte[] data; protected int size; protected Chunk next; + + protected Chunk(int arrayLength) { + data = new byte[arrayLength]; + } } private Chunk firstChunk; @@ -50,7 +55,7 @@ private int totalSize; public UnsafeArrayTypeWriter() { - firstChunk = new Chunk(); + firstChunk = new Chunk(MIN_CHUNK_LENGTH); writeChunk = firstChunk; } @@ -153,7 +158,7 @@ private long writeOffset(int writeBytes) { if (writeChunk.size + writeBytes >= writeChunk.data.length) { - Chunk newChunk = new Chunk(); + Chunk newChunk = new Chunk(Math.min(writeChunk.data.length * 2, MAX_CHUNK_LENGTH)); writeChunk.next = newChunk; writeChunk = newChunk; }