[Rcpp-devel] Integrating java, C++ and R

Royden Fernandes roydenstar at gmail.com
Thu Jan 3 11:34:34 CET 2013


Hi,

I am able to integrate C++ and R through RInside library. However when I
use a jni call as my UI is through java it crashes at C++ side. My files
are

JNICallingClass.C:

JNIEXPORT void JNICALL Java_CallR_run (JNIEnv* env, jobject callr){

        std::cout << "Inside JNICALL" << std::endl;

        testR();

        std::cout << "ENd of JNICALL" << std::endl;

}

-------------------------------------------------

CppCall2R.C

void testR(){

        Rcpp::NumericVector vec(1);

        cout << "RInside ready" << endl;

}

---------------------------------------------------

JavaClass.java

public class CallR{

        static{

                try {


                        System.loadLibrary("callr");


                } catch (UnsatisfiedLinkError e) {

                        System.err.println("Native code library failed to
load.\n" + e);

                        System.exit(1);

                }

        }

        public native void run();

        public static void main(String[] args){

                CallR callr = new CallR();

                //Runtime.getRuntime().exec("R");

                callr.run();

        }

}

----------------------------------------------------------------------------

If I just compile the c++ code and invoke it through a main c++ class I get
no error . But when I call the code from Java I get the following error:

#

# A fatal error has been detected by the Java Runtime Environment:

#

#  SIGSEGV (0xb) at pc=0x00007f9e6974ba8e, pid=5891, tid=140319087077120

#

# JRE version: 6.0_31-b05

# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.6-b01 mixed mode
linux-amd64 compressed oops)

# Problematic frame:

# C  [libR.so+0x11aa8e]  R_gc+0x9e

--------------------------------------------------------------------------------------------

The error log is :

Current thread (0x00007f9e90006800):  JavaThread "main" [_thread_in_native,
id=5892, stack(0x00007f9e95472000,0x00007f9e95573000)]


siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR),
si_addr=0x0000000000000018


Registers:

RAX=0x0000000000000001, RBX=0x0000000000000030, RCX=0x0000000000000000,
RDX=0x00007f9e900b7588

RSP=0x00007f9e95571580, RBP=0x0000000000000028, RSI=0x0000000000000000,
RDI=0x0000000000000004

R8 =0x00007f9e69af9990, R9 =0x000000000000004f, R10=0x00007f9e69af9850,
R11=0x00000036b327f430

R12=0x00007f9e900b7580, R13=0x0000000000000001, R14=0x0000000000000001,
R15=0x00007f9e69adfc00

RIP=0x00007f9e6974ba8e, EFLAGS=0x0000000000010206,
CSGSFS=0x0000000000000033, ERR=0x0000000000000004

  TRAPNO=0x000000000000000e


Top of Stack: (sp=0x00007f9e95571580)

0x00007f9e95571580:   0000000000000000 0000000000000001

0x00007f9e95571590:   000000000000000e 000000077b07d340

0x00007f9e955715a0:   00007f9e95571948 00007f9e6974c9ed

0x00007f9e955715b0:   000000077b07d340 00007f9e95571640

0x00007f9e955715c0:   0000000000000000 00000036b2e14915

0x00007f9e955715d0:   0000000000000001 00000036b32e495d

0x00007f9e955715e0:   00007f9e8c3f2430 000000077b07d340

0x00007f9e955715f0:   00007f9e95571640 0000000000000000

0x00007f9e95571600:   000000077b07d340 00007f9e95571948

0x00007f9e95571610:   00007f9e90006800 00007f9e8c1e9857

0x00007f9e95571620:   00007f9e95571898 00007f9e95571860

0x00007f9e95571630:   00007f9e95572700 000000077b07d340

0x00007f9e95571640:   00007f9e955718b0 00007f9e8c1e94cf

0x00007f9e95571650:   00007f9e6918ba98 0000000000000000

0x00007f9e95571660:   00007f9e6918b990 00007f9e900b5330

0x00007f9e95571670:   00007f9e900b5330 00007f9e900b5330

0x00007f9e95571680:   0000000000000000 0000000000000000

0x00007f9e95571690:   0000000000000000 00007f9e691a1ac0

0x00007f9e955716a0:   0000000000000000 0000000000000000

0x00007f9e955716b0:   0000000000000000 0000000000000000

0x00007f9e955716c0:   0000000000000000 00007f9e900b50f0

0x00007f9e955716d0:   0000000000000001 0000000000000008

0x00007f9e955716e0:   0000000000000000 0000000000000000

0x00007f9e955716f0:   0000003600000000 00007f9e900b5330

0x00007f9e95571700:   0000000000002000 00007f9e00000001

0x00007f9e95571710:   0000000000000000 0000000000000000

0x00007f9e95571720:   0000000000000000 00007f9e691a1f80

0x00007f9e95571730:   0000000000000000 0000000000000000

0x00007f9e95571740:   0000000000000000 0000000000000000

0x00007f9e95571750:   00007f9e6918bac0 0000000000000006

0x00007f9e95571760:   0000000000000000 0000000000001002

0x00007f9e95571770:   0000003600000002 0000000000000000


Instructions: (pc=0x00007f9e6974ba8e)

0x00007f9e6974ba6e:   40 04 01 85 ed 4d 89 60 08 49 89 0c 24 48 8d 0d

0x00007f9e6974ba7e:   6e dc 3a 00 4c 8d 14 01 49 8b 0a 74 4d 44 89 e8

0x00007f9e6974ba8e:   4c 8b 49 18 31 f6 c1 e0 05 89 c7 4c 89 d0 0f 1f

0x00007f9e6974ba9e:   40 00 41 83 00 01 48 89 4a 10 83 c6 01 48 89 51


Register to memory mapping:


RAX=0x0000000000000001 is an unknown value

RBX=0x0000000000000030 is an unknown value

RCX=0x0000000000000000 is an unknown value

RDX=0x00007f9e900b7588 is an unknown value

RSP=0x00007f9e95571580 is pointing into the stack for thread:
0x00007f9e90006800

RBP=0x0000000000000028 is an unknown value

RSI=0x0000000000000000 is an unknown value

RDI=0x0000000000000004 is an unknown value

R8 =0x00007f9e69af9990: <offset 0x4c8990> in /usr/lib64/R/lib/libR.so at
0x00007f9e69631000

R9 =0x000000000000004f is an unknown value

R10=0x00007f9e69af9850: <offset 0x4c8850> in /usr/lib64/R/lib/libR.so at
0x00007f9e69631000

R11=0x00000036b327f430: __libc_malloc+0 in /lib64/libc.so.6 at
0x00000036b3200000

R12=0x00007f9e900b7580 is an unknown value

R13=0x0000000000000001 is an unknown value

R14=0x0000000000000001 is an unknown value

R15=0x00007f9e69adfc00: <offset 0x4aec00> in /usr/lib64/R/lib/libR.so at
0x00007f9e69631000



Stack: [0x00007f9e95472000,0x00007f9e95573000],  sp=0x00007f9e95571580,
 free space=1021k

Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native
code)

C  [libR.so+0x11aa8e]  R_gc+0x9e


[error occurred during error reporting (printing native stack), id 0xb]


Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)

j  CallR.run()V+0

j  CallR.main([Ljava/lang/String;)V+9

v  ~StubRoutines::call_stub


Is there a solution for this?

Roy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130103/5c92261b/attachment-0001.html>


More information about the Rcpp-devel mailing list