-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Hi,
Thank you in advance for your time. I recently have had issues with rJava hanging when calling .jinit, very similar to what was linked here NixOS/nixpkgs#171597 and #272. I pulled down the repository, rebuilt with debugging and started looking at RJAVA_JVM_STACK_WORKAROUND. For context, the baseline hang looks like the below with debugging enabled
> require(rJava)
Loading required package: rJava
> .jinit()
JSW workaround: (level 4)
RinitJVM(non-threaded): cannot disable guard pages
RLIMIT_STACK (rlimsize) 8388608
R_CStackStart 0x7ffd6199b000
R_CStackLimit 7969177
maxBound 0x7ffd6119b000
oldBound 0x7ffd6119afff
{must now be killed}
and noticed that forcing RJAVA_JVM_STACK_WORKAROUND=2 works, at the expense of reducing the stack, as noted in the warning. I started debugging by adding print statements within RinitJVM_with_padding
diff --git a/src/init.c b/src/init.c
index 6805d71..5e6b23e 100644
--- a/src/init.c
+++ b/src/init.c
@@ -576,6 +576,10 @@ static SEXP RinitJVM_with_padding(SEXP par, intptr_t padding, char *last) {
/* reduce the risk that dummy will be optimized out */
dummy[0] = (char) (uintptr_t) &dummy;
padding -= (last - dummy) * R_CStackDir;
+ //_dbg(rjprintf(" LA: padding %d\n", padding));
+ //_dbg(rjprintf(" LA: last %d\n", last));
+ //_dbg(rjprintf(" LA: dummy %d\n", dummy));
+
if (padding <= 0)
return RinitJVM_real(par, 0);
else
With just padding being printed, the code stays in an infinite loop
LA: padding 2097041
LA: padding 2097042
LA: padding 2097043
LA: padding 2097044
LA: padding 2097045
...
However when I print last or dummy the loop breaks.
...
LA: padding 307
LA: last 1425866431
LA: dummy 1425866367
LA: padding 243
LA: last 1425866367
LA: dummy 1425866303
LA: padding 179
LA: last 1425866303
LA: dummy 1425866239
LA: padding 115
LA: last 1425866239
LA: dummy 1425866175
LA: padding 51
LA: last 1425866175
LA: dummy 1425866111
LA: padding -13
LA: last 1425866111
LA: dummy 1425866047
RinitJVM(non-threaded): initJVM returned 0
JSW workaround (ctd): (level 3)
newBound 0x7ffe549d8fff
new R_CStackLimit 7957504
RcallMethod (env=27389f8):
This suggests the compiler is optimizing away these variables. I can either set the environment variable to 2, or maybe add some hack to my local install to try and help the compiler not remove the variable. Do you have any suggestions? On an older compiler I am not seeing these issues. For context here is my Makevars and gcc/g++ versions
cat ~/.R/Makevars
CC = /bin/gcc
CXX = /bin/g++
CFLAGS = -O2 -march=native
CXXFLAGS = -O2 -march=native
/bin/gcc --version
gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++ --version
g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
R --version
R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
Thank you again for your time
Luke Anderson