}
enter();
try {
// Calculate the number of blocks needed
final Word reqBlockCount = blockAlign(blockSize.toWord(), true).rshl(BLOCK_SIZE_SHIFT);
// Find a large enough series of blocks
final Word nr = findFreeBlocks(reqBlockCount);
if (nr.isMax()) {
Unsafe.debug("ret null.");
Unsafe.debug(blockSize.toInt());
// Unsafe.debug("allocated blocks");
// Unsafe.debug(allocatedBlocks);
// Unsafe.debug("total blocks"); Unsafe.debug(blockCount);
VmProcessor.current().getArchitecture().getStackReader().debugStackTrace();
// Unsafe.die("allocateBlock");
return null;
}
// Mark all blocks as in use
for (Word i = Word.zero(); i.LT(reqBlockCount); i = i.add(1)) {
setInUse(nr.add(i), true);
}
// Return the address of block "nr".
allocatedBlocks = allocatedBlocks.add(reqBlockCount);
nextBlockNr = nr.add(reqBlockCount);
return startPtr.add(nr.lsh(BLOCK_SIZE_SHIFT));
} finally {
exit();
}
}