From 3e02c0a7c39ea208c973b591cb97902533ad4e5f Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Tue, 18 Aug 2015 09:47:28 +0900 Subject: [PATCH] java/Prequest: keep a pointer to the buffer this prevents garbage collector from freeing the buffer --- ompi/mpi/java/java/Comm.java | 10 +++++----- ompi/mpi/java/java/Prequest.java | 14 +++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ompi/mpi/java/java/Comm.java b/ompi/mpi/java/java/Comm.java index c8693153f2a..2b796985ef1 100644 --- a/ompi/mpi/java/java/Comm.java +++ b/ompi/mpi/java/java/Comm.java @@ -769,7 +769,7 @@ public final Prequest sendInit(Buffer buf, int count, { MPI.check(); assertDirectBuffer(buf); - return new Prequest(sendInit(handle, buf, count, type.handle, dest, tag)); + return new Prequest(sendInit(handle, buf, count, type.handle, dest, tag), buf); } private native long sendInit( @@ -794,7 +794,7 @@ public final Prequest bSendInit(Buffer buf, int count, { MPI.check(); assertDirectBuffer(buf); - return new Prequest(bSendInit(handle, buf, count, type.handle, dest, tag)); + return new Prequest(bSendInit(handle, buf, count, type.handle, dest, tag), buf); } private native long bSendInit( @@ -819,7 +819,7 @@ public final Prequest sSendInit(Buffer buf, int count, { MPI.check(); assertDirectBuffer(buf); - return new Prequest(sSendInit(handle, buf, count, type.handle, dest, tag)); + return new Prequest(sSendInit(handle, buf, count, type.handle, dest, tag), buf); } private native long sSendInit( @@ -844,7 +844,7 @@ public final Prequest rSendInit(Buffer buf, int count, { MPI.check(); assertDirectBuffer(buf); - return new Prequest(rSendInit(handle, buf, count, type.handle, dest, tag)); + return new Prequest(rSendInit(handle, buf, count, type.handle, dest, tag), buf); } private native long rSendInit( @@ -869,7 +869,7 @@ public final Prequest recvInit(Buffer buf, int count, { MPI.check(); assertDirectBuffer(buf); - return new Prequest(recvInit(handle, buf, count, type.handle, source, tag)); + return new Prequest(recvInit(handle, buf, count, type.handle, source, tag), buf); } private native long recvInit( diff --git a/ompi/mpi/java/java/Prequest.java b/ompi/mpi/java/java/Prequest.java index 94b36978392..1ea96ba930a 100644 --- a/ompi/mpi/java/java/Prequest.java +++ b/ompi/mpi/java/java/Prequest.java @@ -11,6 +11,8 @@ * All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -47,18 +49,28 @@ package mpi; +import java.nio.Buffer; + /** * Persistent request object. */ public final class Prequest extends Request { + /** + * Buffer used internally by the persistent request + * maintain a pointer to the buffer to ensure it + * cannot be free'd by the garbage collector + */ + private Buffer buffer; + /** * Constructor used by {@code sendInit}, etc. * @param handle Handle for the Prequest object */ - protected Prequest(long handle) + protected Prequest(long handle, Buffer buffer) { super(handle); + this.buffer = buffer; } /**