Hi,
Am Montag, den 04.03.2019, 20:42 +0300 schrieb Lev Serebryakov:
> On Mon, Mar 4, 2019 at 8:35 PM 'Neil C Smith' via Java Native Access
> <
jna-...@googlegroups.com> wrote:
>
> > > I'm using `DoubleBuffer.allocate()` here to prepare buffers, as
> > > per JNA documentation [3].
> >
> > DoubleBuffer.allocate() is array backed and not off-heap. That
> > might be the issue?
> Yep. I'm idiot. Sorry for noise on list.
Neils thought sounds right. JNA can handle the non-direct buffer case
for pure Java -> C transitions, if the buffer is only used for the
duration of the call itself. This comes with a speed penalty though, as
the backing array is accessed and in most cases this be a copy.
However, there is another problem: The buffer
jna.JNAAllocated.BenchState.i becomes eligible for garbadge collection
directly after line line 54, before the
FFTW3Library.INSTANCE.fftw_execute(state.p) call, as it is not accessed
from java code anymore. The fftw_plan is not enough to strongly
reference the input array, as the GC can't "look" into it.
Adding a reachability fence should protect you from that:
Reference.reachabilityFence(state.i);
HTH
Matthias