[Rcpp-devel] RInside Using JNI

Kota, Ravindra B ravindra_kota at freddiemac.com
Tue Aug 15 10:45:52 CEST 2017


Hi,

We have financial models written in C++, exposed to Java applications using the JNI. Lately, we have started writing these models in R, and trying to integrate them in C++ using RInside. Standalone integration with C++/RInside/R works fine. We get seg faults when integrated with JNI.

Questions.


1.       Are there any limitations integrating RInside inside the JVM?

2.       Do we have any best practices for this.?

3.       Do we have tools available to debug this better?

We have narrowed  down to the source of the seg fault. Both 'e' and 'rho' are invalid references.

/* Return value of "e" evaluated in "rho". */

/* some places, e.g. deparse2buff, call this with a promise and rho = NULL */
SEXP eval(SEXP e, SEXP rho)
{
    SEXP op, tmp;
    static int evalcount = 0;

    R_Visible = TRUE;

    /* this is needed even for self-evaluating objects or something like
       'while (TRUE) NULL' will not be interruptable */
    if (++evalcount > 1000) { /* was 100 before 2.8.0 */
        R_CheckUserInterrupt();
#ifndef IMMEDIATE_FINALIZERS
        /* finalizers are run here since this should only be called at
           points where running arbitrary code should be safe */
        R_RunPendingFinalizers();
#endif
        evalcount = 0 ;
    }

    /* handle self-evaluating objects with minimal overhead */
    switch (TYPEOF(e)) {
    case NILSXP:
    case LISTSXP:
    case LGLSXP:
    case INTSXP:
    case REALSXP:
    case STRSXP:
    case CPLXSXP:
    case RAWSXP:
    case S4SXP:
    case SPECIALSXP:
    case BUILTINSXP:
    case ENVSXP:
    case CLOSXP:
    case VECSXP:
    case EXTPTRSXP:
    case WEAKREFSXP:
    case EXPRSXP:


#0  0x00002b1a1cd9866f in bcEval (body=0x0, rho=0x0, useCache=FALSE) at eval.c:5873
#1  0x00002b1a1cd8bc11 in Rf_eval (e=0x2b1a15190b38, rho=0x2b1a21180a28) at eval.c:624
#2  0x00002b1a1cd8b944 in forcePromise (e=0x2b1a21180a60) at eval.c:520
#3  0x00002b1a1cd950b7 in FORCE_PROMISE (value=0x2b1a21180a60, symbol=0x2b1a151751a8, rho=0x2b1a21180b40, keepmiss=FALSE)
    at eval.c:4714
#4  0x00002b1a1cd95285 in getvar (symbol=0x2b1a151751a8, rho=0x2b1a21180b40, dd=FALSE, keepmiss=FALSE, vcache=0x2b1a14c57f50,
    sidx=3) at eval.c:4756
#5  0x00002b1a1cd9ac1e in bcEval (body=0x2b1a151764f0, rho=0x2b1a21180b40, useCache=TRUE) at eval.c:6189
#6  0x00002b1a1cd8bc11 in Rf_eval (e=0x2b1a151764f0, rho=0x2b1a21180b40) at eval.c:624
#7  0x00002b1a1cd8e2e2 in R_execClosure (call=0x2b1a151910e8, newrho=0x2b1a21180b40, sysparent=0x2b1a21180a28, rho=0x2b1a21180a28,
    arglist=0x2b1a21180a98, op=0x2b1a15176608) at eval.c:1614
#8  0x00002b1a1cd8e000 in Rf_applyClosure (call=0x2b1a151910e8, op=0x2b1a15176608, arglist=0x2b1a21180a98, rho=0x2b1a21180a28,
    suppliedvars=0x2b1a14957188) at eval.c:1549
#9  0x00002b1a1cd9d2d1 in bcEval (body=0x2b1a1518eaf0, rho=0x2b1a21180a28, useCache=TRUE) at eval.c:6400
#10 0x00002b1a1cd8bc11 in Rf_eval (e=0x2b1a1518eaf0, rho=0x2b1a21180a28) at eval.c:624
#11 0x00002b1a1cd8e2e2 in R_execClosure (call=0x2b1a179b4100, newrho=0x2b1a21180a28, sysparent=0x2b1a211812c8, rho=0x2b1a211812c8,
    arglist=0x2b1a211816f0, op=0x2b1a1518ebd0) at eval.c:1614
#12 0x00002b1a1cd8e000 in Rf_applyClosure (call=0x2b1a179b4100, op=0x2b1a1518ebd0, arglist=0x2b1a211816f0, rho=0x2b1a211812c8,
    suppliedvars=0x2b1a14957188) at eval.c:1549
#13 0x00002b1a1cd9d2d1 in bcEval (body=0x2b1a179b3fb0, rho=0x2b1a211812c8, useCache=TRUE) at eval.c:6400
#14 0x00002b1a1cd8bc11 in Rf_eval (e=0x2b1a179b3fb0, rho=0x2b1a211812c8) at eval.c:624
#15 0x00002b1a1cd8b944 in forcePromise (e=0x2b1a211814f8) at eval.c:520
#16 0x00002b1a1cd950b7 in FORCE_PROMISE (value=0x2b1a211814f8, symbol=0x2b1a149af960, rho=0x2b1a21181610, keepmiss=FALSE)
    at eval.c:4714


Help is greatly appreciated. You can reach me at 571-340-1578 for any kind of questions.

Regards
Ravindra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170815/87cb98bb/attachment.html>


More information about the Rcpp-devel mailing list