]> rtime.felk.cvut.cz Git - orte/eurobot.git/commit
JORTE: switch to direct ByteBuffer
authorMartin Vajnar <martin.vajnar@gmail.com>
Sun, 14 Jul 2013 18:08:07 +0000 (20:08 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Mon, 23 Sep 2013 09:06:25 +0000 (11:06 +0200)
commit5e3acad2883da79c29458d5965d3dad8cbf629f7
tree1dcfe94469b5914e6be54ccd7b56925222870206
parent3fe7c3a77544c835bdc9060984b79a6ef3e155b3
JORTE: switch to direct ByteBuffer

This commit significantly changes the way new issues are sent and received
both on the Java side and on the C side.

In the past there was one Java instance of HeapByteBuffer in the
MessageData class. ByteBuffer is used to perform serialization and
deserialization of received and sent issues in Java. It is compatible with
the CORBA standard that is used in the main ORTE library.

The HeapByteBuffer has one significant drawback. It allocates memory
on the heap managed by Java VM's garbage collector and when accessing
the backing array from C it has to copy the entire array to new space
in memory outside the VM. Added to that the backing array wasn't accessed
as an array object from the C code, but rather every byte from the Java
buffer was copied to a C byte array or vice versa (publisher x subscriber
part). This adds a lot of overhead (calling JNI functions to obtain new
values).

Instead the DirectByteBuffer is now used which allocates memory directly
(outside of Java VM) through malloc() and stores the pointer in such a way,
that it is easily accesible from C code using GetDirectBufferAddress,
that returns (void *). The Java part behaves much the same as normal
(Heap) ByteBuffer. The allocated byte array could be used like any other
C array and the VM ensures that the memory region allocated by direct
ByteBuffer is contiguous. This is very useful, because normal Java arrays
are not guaranteed to be contiguous which makes them difficult to handle,
because JNI functions must be called that make copies of them in a
contiguous space and that adds another overhead.

As a bonus the C code for both publisher and subscriber Java wrappers
is much shorter and simpler than it used to be.
orte/include/jorte/jorte_typedefs_defines.h
orte/include/jorte/org_ocera_orte_Publication.h
orte/include/jorte/org_ocera_orte_Subscription.h
orte/java/src/org/ocera/orte/Publication.java
orte/java/src/org/ocera/orte/Subscription.java
orte/java/src/org/ocera/orte/types/MessageData.java
orte/libjorte/JORTEPublicationCreate.c
orte/libjorte/JORTEPublicationDestroy.c
orte/libjorte/JORTEPublicationSend.c
orte/libjorte/JORTESubscriptionCreate.c
orte/libjorte/JORTESubscriptionDestroy.c