Skip to content

Commit f02bb4f

Browse files
committed
don't change java.parameters option, but set defaults in .jinit instead (closes #341)
1 parent f05bb59 commit f02bb4f

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

R/jfirst.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646
for (x in .delayed.variables) assign(x, NULL, .env)
4747
assign(".jniInitialized", FALSE, .env)
4848

49-
# default JVM initialization parameters
50-
if (is.null(getOption("java.parameters")))
51-
options("java.parameters"="-Xmx512m")
52-
5349
## S4 classes update - all classes are created earlier in classes.R, but jobjRef's prototype is only valid after the dylib is loaded
5450
setClass("jobjRef", representation(jobj="externalptr", jclass="character"), prototype=list(jobj=.jzeroRef, jclass="java/lang/Object"), where=.env)
5551
}

R/jinit.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.Call(RJava_needs_init)
1111

1212
## initialization
13-
.jinit <- function(classpath=NULL, parameters=getOption("java.parameters"), ..., silent=FALSE, force.init=FALSE) {
13+
.jinit <- function(classpath=NULL, parameters=getOption("java.parameters", NA), ..., silent=FALSE, force.init=FALSE) {
1414
running.classpath <- character()
1515
if (!.need.init()) {
1616
running.classpath <- .jclassPath()
@@ -23,6 +23,21 @@
2323
}
2424
}
2525

26+
# default JVM initialization parameters
27+
# Up until 1.0-12 jfirst (=onLoad) set java.parameters to -Xmx512m to increase the heap
28+
# size, so parameters was always -Xmx512m unless the user set java.parameters or parameters.
29+
# We now leave the java.parameters alone and only set the default heap size if
30+
# java.parameters is not set -- with mostly the same effect.
31+
# (NB: JVMs have changed the default from 256Mb to 25% of available memory in some cases,
32+
# thus the default is becoming less important nowadays.)
33+
# We also increase the default heap size since machines using R are unlikely
34+
# to be starved for RAM. Note that the meaning of NULL has changed to "none"
35+
# since 1.0-13.
36+
if (any(is.na(parameters)))
37+
parameters <- "-Xmx1g"
38+
if (is.null(parameters))
39+
parameters <- character()
40+
2641
## determine path separator
2742
path.sep <- .Platform$path.sep
2843

man/jinit.Rd

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
\code{.jvmState() returns the state of the current JVM.}
1212
}
1313
\usage{
14-
.jinit(classpath = NULL, parameters = getOption("java.parameters"), ...,
15-
silent = FALSE, force.init = FALSE)
14+
.jinit(classpath = NULL, parameters = getOption("java.parameters", NA), ...,
15+
silent = FALSE, force.init = FALSE)
1616
.jvmState()
1717
}
1818
\arguments{
@@ -25,7 +25,10 @@ silent = FALSE, force.init = FALSE)
2525
the virtual machine. They are implementation dependent and apply
2626
to JDK version 1.2 or higher only. Please note that each parameter
2727
must be in a separate element of the array, you cannot use a
28-
space-separated string with multiple parameters.}
28+
space-separated string with multiple parameters. The value of
29+
\code{NA} means "use rJava default" which is \code{"-Xmx1g"}
30+
currently. \code{NULL} is equivalent to \code{character()}.
31+
}
2932
\item{...}{Other optional Java initialization parameters (implementation-dependent).}
3033
\item{silent}{If set to \code{TRUE} no warnings are issued.}
3134
\item{force.init}{If set to \code{TRUE} JVM is re-initialized even if
@@ -89,15 +92,17 @@ silent = FALSE, force.init = FALSE)
8992
rare and problematic in either case. Behavior of rJava functions other
9093
than \code{.jinit} and \code{.jvmState} is undefined unless
9194
\code{.jvmState()$initialized} is \code{TRUE}.
95+
96+
NOTE: \code{.jinit()} can be called implicitly by other functions such
97+
as \code{\link{.jpackage}} or \code{\link{J}}.
9298
}
9399
\seealso{
94100
\code{\link{.jpackage}}
95101
}
96102
\examples{
97103
\dontrun{
98-
## set heap size limit to 512MB (see java -X) and
99-
## use "myClasses.jar" as the class path
100-
.jinit(classpath="myClasses.jar", parameters="-Xmx512m")
104+
## set heap size limit to 512MB (see java -X)
105+
.jinit(parameters="-Xmx512m")
101106
.jvmState()
102107
}
103108
}

0 commit comments

Comments
 (0)