use of java.nio.ByteBuffer in project jvm-tools by aragozin.
the class ByteBufferPageManager method accurePage.
@Override
public ByteBuffer accurePage() throws NoMorePagesException {
if (freePages.isEmpty()) {
refill();
}
if (freePages.isEmpty()) {
throw new NoMorePagesException();
}
Iterator<BW> it = freePages.iterator();
ByteBuffer bb = it.next().pageBuffer;
it.remove();
return bb;
}
use of java.nio.ByteBuffer in project jvm-tools by aragozin.
the class PagedVirtualMemory method ensureBuffer.
private ByteBuffer ensureBuffer(long index) {
if (index > SANITY_LIMIT) {
throw new IllegalArgumentException("Offset beyond sanity: " + index);
}
int n = (int) (index >> pageBits);
if (n >= bufferMap.length) {
int nsize = Math.max(n + 1, (3 * bufferMap.length) / 4);
bufferMap = Arrays.copyOf(bufferMap, nsize);
hitCounts = Arrays.copyOf(hitCounts, nsize);
pageMap = Arrays.copyOf(pageMap, nsize);
}
ByteBuffer b = bufferMap[n];
if (b == null) {
pageFault(n);
b = bufferMap[n];
if (b == null) {
throw new IllegalArgumentException("Failed to load page #" + n);
}
}
return b;
}
use of java.nio.ByteBuffer in project disunity by ata4.
the class SerializedFileReader method readObjects.
private void readObjects(DataReader in) throws IOException {
long ofsMin = Long.MAX_VALUE;
long ofsMax = Long.MIN_VALUE;
SerializedFileHeader header = serialized.header();
SerializedFileMetadata metadata = serialized.metadata();
Map<Long, ObjectInfo> objectInfoMap = metadata.objectInfoTable().infoMap();
Map<Integer, TypeRoot<Type>> typeTreeMap = metadata.typeTree().typeMap();
List<SerializedObjectData> objectData = serialized.objectData();
for (Map.Entry<Long, ObjectInfo> infoEntry : objectInfoMap.entrySet()) {
ObjectInfo info = infoEntry.getValue();
long id = infoEntry.getKey();
long ofs = header.dataOffset() + info.offset();
ofsMin = Math.min(ofsMin, ofs);
ofsMax = Math.max(ofsMax, ofs + info.length());
SerializedObjectData object = new SerializedObjectData(id);
object.info(info);
// create and read object data buffer
ByteBuffer buf = ByteBufferUtils.allocate((int) info.length());
in.position(ofs);
in.readBuffer(buf);
object.buffer(buf);
// get type tree if possible
TypeRoot typeRoot = typeTreeMap.get(info.typeID());
if (typeRoot != null) {
object.typeTree(typeRoot.nodes());
}
objectData.add(object);
}
DataBlock objectDataBlock = serialized.objectDataBlock();
objectDataBlock.offset(ofsMin);
objectDataBlock.endOffset(ofsMax);
L.log(Level.FINER, "objectDataBlock: {0}", objectDataBlock);
}
use of java.nio.ByteBuffer in project disunity by ata4.
the class SerializedFileWriter method writeObjects.
private void writeObjects(DataWriter out) throws IOException {
long ofsMin = Long.MAX_VALUE;
long ofsMax = Long.MIN_VALUE;
for (SerializedObjectData data : serialized.objectData()) {
ByteBuffer bb = data.buffer();
bb.rewind();
out.align(8);
ofsMin = Math.min(ofsMin, out.position());
ofsMax = Math.max(ofsMax, out.position() + bb.remaining());
ObjectInfo info = data.info();
info.offset(out.position() - serialized.header().dataOffset());
info.length(bb.remaining());
out.writeBuffer(bb);
}
DataBlock objectDataBlock = serialized.objectDataBlock();
objectDataBlock.offset(ofsMin);
objectDataBlock.endOffset(ofsMax);
L.log(Level.FINER, "objectDataBlock: {0}", objectDataBlock);
}
use of java.nio.ByteBuffer in project bazel by bazelbuild.
the class CentralDirectoryTest method testParse.
/**
* Test of parse method, of class CentralDirectory.
*/
@Test
public void testParse() {
// First fill it with some entries
ByteBuffer inputBuffer = ByteBuffer.allocate(10000).order(ByteOrder.LITTLE_ENDIAN);
String comment = null;
byte[] extra = null;
String filename = "pkg/0.txt";
DirectoryEntry entry = DirectoryEntry.view(inputBuffer, filename, extra, comment);
int expSize = entry.getSize();
comment = "";
extra = new byte[] {};
for (int i = 1; i < 20; i++) {
filename = "pkg/" + i + ".txt";
entry = DirectoryEntry.view(inputBuffer, filename, extra, comment);
expSize += entry.getSize();
extra = new byte[extra.length + 1];
comment = comment + "," + i;
}
// Parse the entries.
CentralDirectory cdir = CentralDirectory.viewOf(inputBuffer).at(0).parse();
assertEquals("Count", 20, cdir.getCount());
assertEquals("Position after parse", expSize, cdir.buffer.position());
assertEquals("Limit after parse", 10000, cdir.buffer.limit());
cdir.buffer.flip();
assertEquals("Position after finish", 0, cdir.buffer.position());
assertEquals("Limit after finish", expSize, cdir.buffer.limit());
}
Aggregations