Memory implements ProgramTraceListenerAware { public void extend(int address, int size) { if (size <= 0) return; final int newSize = address + size; int toAllocate = newSize - internalSize(); if (toAllocate > 0) { addChunks((int) ceil((double) toAllocate / CHUNK_SIZE)); } toAllocate = newSize - softSize; if (toAllocate > 0) { toAllocate = (int) ceil((double) toAllocate / WORD_SIZE) * WORD_SIZE; softSize += toAllocate; if (traceListener != null) traceListener.onMemoryExtend(toAllocate); } }  @Override void setTraceListener(ProgramTraceListener traceListener); byte[] read(int address, int size); void write(int address, byte[] data, int dataSize, boolean limited); void extendAndWrite(int address, int allocSize, byte[] data); void extend(int address, int size); DataWord readWord(int address); byte readByte(int address); @Override String toString(); int size(); int internalSize(); List<byte[]> getChunks();  }
@Test public void testExtend() { checkMemoryExtend(0); checkMemoryExtend(1); checkMemoryExtend(WORD_SIZE); checkMemoryExtend(WORD_SIZE * 2); checkMemoryExtend(CHUNK_SIZE - 1); checkMemoryExtend(CHUNK_SIZE); checkMemoryExtend(CHUNK_SIZE + 1); checkMemoryExtend(2000); }