Skip to content

Commit 818435f

Browse files
author
Nathaniel Graham
committed
Error handling improvements
This commit improves and corrects error handling. In cases where existing objects are altered after a call to ompi_java_exceptionCheck, the results of the exception check method are checked. In the case of an exception, memory is cleaned up and the code returns to Java without altering existing objects. Signed-off-by: Nathaniel Graham <[email protected]>
1 parent 9c496f7 commit 818435f

File tree

6 files changed

+174
-66
lines changed

6 files changed

+174
-66
lines changed

ompi/mpi/java/c/mpi_Comm.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ JNIEXPORT jlongArray JNICALL Java_mpi_Comm_iDup(
205205
MPI_Comm newcomm;
206206
MPI_Request request;
207207
int rc = MPI_Comm_idup((MPI_Comm)comm, &newcomm, &request);
208-
ompi_java_exceptionCheck(env, rc);
208+
209+
if(ompi_java_exceptionCheck(env, rc))
210+
return NULL;
211+
209212
jlongArray jcr = (*env)->NewLongArray(env, 2);
210213
jlong *cr = (jlong*)(*env)->GetPrimitiveArrayCritical(env, jcr, NULL);
211214
cr[0] = (jlong)newcomm;
@@ -332,6 +335,7 @@ JNIEXPORT void JNICALL Java_mpi_Comm_recv(
332335
jobject buf, jboolean db, jint offset, jint count,
333336
jlong jType, jint bType, jint source, jint tag, jlongArray jStatus)
334337
{
338+
jboolean exception;
335339
MPI_Comm comm = (MPI_Comm)jComm;
336340
MPI_Datatype type = (MPI_Datatype)jType;
337341

@@ -341,10 +345,12 @@ JNIEXPORT void JNICALL Java_mpi_Comm_recv(
341345

342346
MPI_Status status;
343347
int rc = MPI_Recv(ptr, count, type, source, tag, comm, &status);
344-
ompi_java_exceptionCheck(env, rc);
348+
exception = ompi_java_exceptionCheck(env, rc);
345349

346350
ompi_java_releaseWritePtr(ptr,item,env,buf,db,offset,count,type,bType);
347-
ompi_java_status_set(env, jStatus, &status);
351+
352+
if(!exception)
353+
ompi_java_status_set(env, jStatus, &status);
348354
}
349355

350356
JNIEXPORT void JNICALL Java_mpi_Comm_sendRecv(
@@ -355,6 +361,7 @@ JNIEXPORT void JNICALL Java_mpi_Comm_sendRecv(
355361
jlong rjType, jint rBType, jint source, jint rTag,
356362
jlongArray jStatus)
357363
{
364+
jboolean exception;
358365
MPI_Comm comm = (MPI_Comm)jComm;
359366
MPI_Datatype sType = (MPI_Datatype)sjType;
360367
MPI_Datatype rType = (MPI_Datatype)rjType;
@@ -369,10 +376,12 @@ JNIEXPORT void JNICALL Java_mpi_Comm_sendRecv(
369376
int rc = MPI_Sendrecv(sPtr, sCount, sType, dest, sTag,
370377
rPtr, rCount, rType, source, rTag, comm, &status);
371378

372-
ompi_java_exceptionCheck(env, rc);
379+
exception = ompi_java_exceptionCheck(env, rc);
373380
ompi_java_releaseReadPtr(sPtr, sItem, sBuf, sdb);
374381
ompi_java_releaseWritePtr(rPtr,rItem,env,rBuf,rdb,rOff,rCount,rType,rBType);
375-
ompi_java_status_set(env, jStatus, &status);
382+
383+
if(!exception)
384+
ompi_java_status_set(env, jStatus, &status);
376385
}
377386

378387
JNIEXPORT void JNICALL Java_mpi_Comm_sendRecvReplace(
@@ -392,8 +401,9 @@ JNIEXPORT void JNICALL Java_mpi_Comm_sendRecvReplace(
392401
int rc = MPI_Sendrecv_replace(ptr, count, type, dest,
393402
sTag, source, rTag, comm, &status);
394403

395-
ompi_java_exceptionCheck(env, rc);
396-
ompi_java_status_set(env, jStatus, &status);
404+
if(!ompi_java_exceptionCheck(env, rc))
405+
ompi_java_status_set(env, jStatus, &status);
406+
397407
ompi_java_releaseWritePtr(ptr,item,env,buf,db,offset,count,type,bType);
398408
}
399409

@@ -662,8 +672,9 @@ JNIEXPORT void JNICALL Java_mpi_Comm_probe(
662672
{
663673
MPI_Status status;
664674
int rc = MPI_Probe(source, tag, (MPI_Comm)comm, &status);
665-
ompi_java_exceptionCheck(env, rc);
666-
ompi_java_status_set(env, jStatus, &status);
675+
676+
if(!ompi_java_exceptionCheck(env, rc))
677+
ompi_java_status_set(env, jStatus, &status);
667678
}
668679

669680
JNIEXPORT jint JNICALL Java_mpi_Comm_getTopology(

ompi/mpi/java/c/mpi_Datatype.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ JNIEXPORT void JNICALL Java_mpi_Datatype_getLbExtent(
9292
{
9393
MPI_Aint lb, extent;
9494
int rc = MPI_Type_get_extent((MPI_Datatype)type, &lb, &extent);
95-
ompi_java_exceptionCheck(env, rc);
95+
if(ompi_java_exceptionCheck(env, rc))
96+
return;
9697

9798
jint *lbExt = (*env)->GetIntArrayElements(env, jLbExt, NULL);
9899
lbExt[0] = (jint)lb;
@@ -105,7 +106,8 @@ JNIEXPORT void JNICALL Java_mpi_Datatype_getTrueLbExtent(
105106
{
106107
MPI_Aint lb, extent;
107108
int rc = MPI_Type_get_true_extent((MPI_Datatype)type, &lb, &extent);
108-
ompi_java_exceptionCheck(env, rc);
109+
if(ompi_java_exceptionCheck(env, rc))
110+
return;
109111

110112
jint *lbExt = (*env)->GetIntArrayElements(env, jLbExt, NULL);
111113
lbExt[0] = (jint)lb;

0 commit comments

Comments
 (0)