finish allocate
This commit is contained in:
parent
5e0af863b3
commit
449ef9f503
4 changed files with 40 additions and 2 deletions
|
@ -61,11 +61,26 @@ public final class BuilderArena implements Arena {
|
|||
return new AllocateResult(this.segments.get(len - 1), result);
|
||||
}
|
||||
|
||||
// allocate_owned_memory
|
||||
|
||||
int size = Math.max(amount, this.nextSize);
|
||||
SegmentBuilder newSegment = new SegmentBuilder(
|
||||
ByteBuffer.allocate(amount * Constants.BYTES_PER_WORD),
|
||||
ByteBuffer.allocate(size * Constants.BYTES_PER_WORD),
|
||||
this);
|
||||
|
||||
switch (this.allocationStrategy) {
|
||||
case GROW_HEURISTICALLY:
|
||||
this.nextSize += size;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
newSegment.buffer.mark();
|
||||
newSegment.buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
newSegment.id = len;
|
||||
this.segments.add(newSegment);
|
||||
|
||||
return new AllocateResult(newSegment, newSegment.allocate(amount));
|
||||
|
|
9
runtime/src/main/java/org/capnproto/FarPointer.java
Normal file
9
runtime/src/main/java/org/capnproto/FarPointer.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package org.capnproto;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
final class FarPointer {
|
||||
public static void set(ByteBuffer buffer, int offset, int segmentId) {
|
||||
buffer.putInt(8 * offset + 4, segmentId);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ public final class SegmentBuilder extends SegmentReader {
|
|||
public static final int FAILED_ALLOCATION = -1;
|
||||
|
||||
public int pos = 0; // in words
|
||||
public int id = 0;
|
||||
|
||||
public SegmentBuilder(ByteBuffer buf, Arena arena) {
|
||||
super(buf, arena);
|
||||
|
|
|
@ -36,7 +36,20 @@ final class WireHelpers {
|
|||
int amountPlusRef = amount + Constants.POINTER_SIZE_IN_WORDS;
|
||||
BuilderArena.AllocateResult allocation = segment.getArena().allocate(amountPlusRef);
|
||||
|
||||
throw new Error("unimplemented");
|
||||
//# Set up the original pointer to be a far pointer to
|
||||
//# the new segment.
|
||||
WirePointer.setKindAndTarget(segment.buffer, refOffset, WirePointer.FAR, allocation.offset);
|
||||
FarPointer.set(segment.buffer, refOffset, allocation.segment.id);
|
||||
|
||||
//# Initialize the landing pad to indicate that the
|
||||
//# data immediately follows the pad.
|
||||
int resultRefOffset = allocation.offset;
|
||||
int ptr1 = allocation.offset + Constants.POINTER_SIZE_IN_WORDS;
|
||||
|
||||
WirePointer.setKindAndTarget(allocation.segment.buffer, resultRefOffset, kind,
|
||||
ptr1);
|
||||
|
||||
return new AllocateResult(ptr1, resultRefOffset, allocation.segment);
|
||||
} else {
|
||||
WirePointer.setKindAndTarget(segment.buffer, refOffset, kind, ptr);
|
||||
return new AllocateResult(ptr, refOffset, segment);
|
||||
|
|
Loading…
Reference in a new issue