/** * @param obj Instance of the BinaryObjectImpl to offheap marshalling. * @param marsh Binary marshaller. * @return Instance of BinaryObjectOffheapImpl. */ private BinaryObjectOffheapImpl marshalOffHeap(BinaryObjectImpl obj, BinaryMarshaller marsh) { long ptr = copyOffheap(obj); return new BinaryObjectOffheapImpl(binaryContext(marsh), ptr, 0, obj.array().length); }
/** {@inheritDoc} */ @Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception { byte[] arr = marsh.marshal(obj); long ptr = GridUnsafe.allocateMemory(arr.length); ptrs.add(ptr); GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr, arr.length); return new BinaryObjectOffheapImpl(ctx, ptr, 0, arr.length); } }
/** * Convert binary object to it's final state. * * @param obj Object. * @param offheap Offheap flag. * @return Result. */ private BinaryObjectExImpl convert(BinaryObjectExImpl obj, boolean offheap) { if (offheap) { byte[] arr = obj.array(); long ptr = GridUnsafe.allocateMemory(arr.length); ptrs.add(ptr); GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length); obj = new BinaryObjectOffheapImpl(obj.context(), ptr, 0, obj.array().length); } return obj; }
/** * Convert binary object to it's final state. * * @param obj Object. * @param offheap Offheap flag. * @return Result. */ private BinaryObjectExImpl convert(BinaryObject obj, boolean offheap) { BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj; if (offheap) { byte[] arr = obj0.array(); long ptr = GridUnsafe.allocateMemory(arr.length); ptrs.add(ptr); GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length); obj0 = new BinaryObjectOffheapImpl(obj0.context(), ptr, 0, obj0.array().length); } return obj0; }
/** * Perform post-write hash code update if necessary. * * @param clsName Class name. Always null if class is registered. */ public void postWriteHashCode(@Nullable String clsName) { int typeId = clsName == null ? this.typeId : ctx.typeId(clsName); BinaryIdentityResolver identity = ctx.identity(typeId); if (out.hasArray()) { // Heap. byte[] data = out.array(); BinaryObjectImpl obj = new BinaryObjectImpl(ctx, data, start); BinaryPrimitives.writeInt(data, start + GridBinaryMarshaller.HASH_CODE_POS, identity.hashCode(obj)); } else { // Offheap. long ptr = out.rawOffheapPointer(); assert ptr != 0; BinaryObjectOffheapImpl obj = new BinaryObjectOffheapImpl(ctx, ptr, start, out.capacity()); BinaryPrimitives.writeInt(ptr, start + GridBinaryMarshaller.HASH_CODE_POS, identity.hashCode(obj)); } }
/** {@inheritDoc} */ @Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception { byte[] arr = marsh.marshal(obj); long ptr = GridUnsafe.allocateMemory(arr.length); ptrs.add(ptr); GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr, arr.length); return new BinaryObjectOffheapImpl(binaryContext(marsh), ptr, 0, arr.length); } }
/** * @return Value. */ public static BinaryObject doReadBinaryObject(BinaryInputStream in, BinaryContext ctx, boolean detach) { if (in.offheapPointer() > 0) { int len = in.readInt(); int pos = in.position(); in.position(in.position() + len); int start = in.readInt(); return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len); } else { byte[] arr = doReadByteArray(in); int start = in.readInt(); BinaryObjectImpl binO = new BinaryObjectImpl(ctx, arr, start); if (detach) { binO.detachAllowed(true); return binO.detach(); } return binO; } }
ptr = copyOffheap(obj); BinaryObjectOffheapImpl offheapObj = new BinaryObjectOffheapImpl(ctx, ptr, 0, BinaryObjectOffheapImpl offheapObj1 = new BinaryObjectOffheapImpl(ctx, ptr1, 0, BinaryObjectOffheapImpl offheapObj2 = new BinaryObjectOffheapImpl(ctx, ptr2, 0,
po = new BinaryObjectImpl(ctx, in.array(), start); else po = new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start, in.remaining() + in.position());
/** * Perform post-write hash code update if necessary. * * @param clsName Class name. Always null if class is registered. */ public void postWriteHashCode(@Nullable String clsName) { int typeId = clsName == null ? this.typeId : ctx.typeId(clsName); BinaryIdentityResolver identity = ctx.identity(typeId); if (out.hasArray()) { // Heap. byte[] data = out.array(); BinaryObjectImpl obj = new BinaryObjectImpl(ctx, data, start); BinaryPrimitives.writeInt(data, start + GridBinaryMarshaller.HASH_CODE_POS, identity.hashCode(obj)); } else { // Offheap. long ptr = out.rawOffheapPointer(); assert ptr != 0; BinaryObjectOffheapImpl obj = new BinaryObjectOffheapImpl(ctx, ptr, start, out.capacity()); BinaryPrimitives.writeInt(ptr, start + GridBinaryMarshaller.HASH_CODE_POS, identity.hashCode(obj)); } }
/** * @return Value. */ public static BinaryObject doReadBinaryObject(BinaryInputStream in, BinaryContext ctx, boolean detach) { if (in.offheapPointer() > 0) { int len = in.readInt(); int pos = in.position(); in.position(in.position() + len); int start = in.readInt(); return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len); } else { byte[] arr = doReadByteArray(in); int start = in.readInt(); BinaryObjectImpl binO = new BinaryObjectImpl(ctx, arr, start); if (detach) { binO.detachAllowed(true); return binO.detach(); } return binO; } }
po = new BinaryObjectImpl(ctx, in.array(), start); else po = new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start, in.remaining() + in.position());