@Inline private boolean acquireRecyclableBlockAddressOrder() { if (recyclableExhausted) { if (VM.VERIFY_ASSERTIONS && Options.verbose.getValue() >= 9) { Log.writeln("[no recyclable available]"); } return false; } int markState = 0; boolean usable = false; while (!usable) { Address next = recyclableBlock.plus(BYTES_IN_BLOCK); if (recyclableBlock.isZero() || ImmixSpace.isRecycleAllocChunkAligned(next)) { recyclableBlock = space.acquireReusableBlocks(); if (recyclableBlock.isZero()) { recyclableExhausted = true; if (VM.VERIFY_ASSERTIONS && Options.verbose.getValue() >= 9) { Log.writeln("[recyclable exhausted]"); } line = LINES_IN_BLOCK; return false; } } else { recyclableBlock = next; } markState = Block.getBlockMarkState(recyclableBlock); usable = (markState > 0 && markState <= ImmixSpace.getReusuableMarkStateThreshold(copy)); if (copy && Block.isDefragSource(recyclableBlock)) usable = false; } if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!Block.isUnused(recyclableBlock)); Block.setBlockAsReused(recyclableBlock); lineUseCount += (LINES_IN_BLOCK - markState); return true; // found something good }
private boolean acquireRecyclableLines(int bytes, int align, int offset) { while (line < LINES_IN_BLOCK || acquireRecyclableBlock()) { line = space.getNextAvailableLine(markTable, line); if (line < LINES_IN_BLOCK) { int endLine = space.getNextUnavailableLine(markTable, line); cursor = recyclableBlock.plus(Extent.fromIntSignExtend(line << LOG_BYTES_IN_LINE)); limit = recyclableBlock.plus(Extent.fromIntSignExtend(endLine << LOG_BYTES_IN_LINE)); if (SANITY_CHECK_LINE_MARKS) { Address tmp = cursor; while (tmp.LT(limit)) { if (tmp.loadByte() != (byte) 0) { Log.write("cursor: "); Log.writeln(cursor); Log.write(" limit: "); Log.writeln(limit); Log.write("current: "); Log.write(tmp); Log.write(" value: "); Log.write(tmp.loadByte()); Log.write(" line: "); Log.write(line); Log.write("endline: "); Log.write(endLine); Log.write(" chunk: "); Log.write(Chunk.align(cursor)); Log.write(" hw: "); Log.write(Chunk.getHighWater(Chunk.align(cursor))); Log.writeln(" values: "); Address tmp2 = cursor; while (tmp2.LT(limit)) { Log.write(tmp2.loadByte()); Log.write(" "); } Log.writeln(); } VM.assertions._assert(tmp.loadByte() == (byte) 0); tmp = tmp.plus(1); } } if (VM.VERIFY_ASSERTIONS && bytes <= BYTES_IN_LINE) { Address start = alignAllocationNoFill(cursor, align, offset); Address end = start.plus(bytes); VM.assertions._assert(end.LE(limit)); } VM.memory.zero(cursor, limit.diff(cursor).toWord().toExtent()); if (VM.VERIFY_ASSERTIONS && Options.verbose.getValue() >= 9) { Log.write("Z["); Log.write(cursor); Log.write("->"); Log.write(limit); Log.writeln("]"); } line = endLine; if (VM.VERIFY_ASSERTIONS && copy) VM.assertions._assert(!Block.isDefragSource(cursor)); return true; } } return false; }
/** * External allocation slow path (called by superclass when slow path is actually taken. This is * necessary (rather than a direct call from the fast path) because of the possibility of a thread * switch and corresponding re-association of bump pointers to kernel threads. * * @param bytes The number of bytes allocated * @param align The requested alignment * @param offset The offset from the alignment * @return The address of the first byte of the allocated region or zero on failure */ protected final Address allocSlowOnce(int bytes, int align, int offset) { Address ptr = space.getSpace(hot, copy, lineUseCount); if (ptr.isZero()) { lineUseCount = 0; return ptr; // failed allocation --- we will need to GC } /* we have been given a clean block */ if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(Block.isAligned(ptr)); lineUseCount = LINES_IN_BLOCK; zeroBlock(ptr); if (requestForLarge) { largeCursor = ptr; largeLimit = ptr.plus(BYTES_IN_BLOCK); } else { cursor = ptr; limit = ptr.plus(BYTES_IN_BLOCK); } return alloc(bytes, align, offset); }