Skip to content

Commit

Permalink
Fix #23837: Set -XX:MaxRAMPercentage to >25% of system memory
Browse files Browse the repository at this point in the history
This does not currently work for WebStart, see
AdoptOpenJDK/IcedTea-Web#954 .

As noted in the ticket, all supported MS Windows and Apple macOS machines have
4G+ of RAM. Linux machines don't have a baseline, and some have 1G or less. Where
we detect that a machine has <8G of memory in the linux start scripts, we don't
add the JVM parameters.

As a reminder to everyone reading the changelog: just because we ''ask'' for the
ability to use 75% of the system memory doesn't mean we will ''use'' all of that
memory. The JVM ''will'' free up unused memory for the rest of the system.

We additionally set the minimum memory allocation to 256m; while this ''can'' be
lower, that is for minimal amounts of data loaded. A clean JOSM install will use
99mb, for example. But once we add a minimal amount of data and a background
layer, static memory usage goes up to 161mb.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19215 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Sep 9, 2024
1 parent 85b28a3 commit 86382f4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion native/josm-latest.jnlp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<all-permissions/>
</security>
<resources>
<java version="11+" vendor="Azul" java-vm-args="--add-modules=java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web --add-exports=java.base/sun.security.action=ALL-UNNAMED --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED --add-exports=jdk.deploy/com.sun.deploy.config=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED"/>
<java version="11+" vendor="Azul" java-vm-args="-XX:MaxRAMPercentage=75.0 -Xms256m --add-modules=java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web --add-exports=java.base/sun.security.action=ALL-UNNAMED --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED --add-exports=jdk.deploy/com.sun.deploy.config=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED"/>
<jar href="josm-latest.jar"/>
</resources>
<application-desc main-class="org.openstreetmap.josm.gui.MainApplication"/>
Expand Down
2 changes: 1 addition & 1 deletion native/josm.jnlp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<all-permissions/>
</security>
<resources>
<java version="11+" vendor="Azul" java-vm-args="--add-modules=java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web --add-exports=java.base/sun.security.action=ALL-UNNAMED --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED --add-exports=jdk.deploy/com.sun.deploy.config=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED"/>
<java version="11+" vendor="Azul" java-vm-args="-XX:MaxRAMPercentage=75.0 -Xms256m --add-modules=java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web --add-exports=java.base/sun.security.action=ALL-UNNAMED --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED --add-exports=jdk.deploy/com.sun.deploy.config=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED"/>
<jar href="josm-tested.jar"/>
<!-- This was removed from josm-latest.jnlp on 2024-06-17. Remove if nothing gets reported. -->
<property name="java.util.Arrays.useLegacyMergeSort" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion native/linux/latest/etc/default/josm-latest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Uncomment the JAVA_OPTS lines to enable their use by /usr/bin/josm-latest

# Increase usable memory
#JAVA_OPTS="-Xmx2048m ${JAVA_OPTS}"
#JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -Xms256m ${JAVA_OPTS}"

# Enable OpenGL pipeline (2D graphic accelerators)
#JAVA_OPTS="-Dsun.java2d.opengl=True ${JAVA_OPTS}"
Expand Down
6 changes: 6 additions & 0 deletions native/linux/latest/usr/bin/josm-latest
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ if [ -f "/etc/default/${JOSM_VERSION}" ]; then
. "/etc/default/${JOSM_VERSION}"
fi

# If there is more than 8G ram, we can use up to 75% of the memory while still leaving 2G for other things.
if [ "$(free --mega | grep '^Mem:' | awk '{print $2}')" -gt 8192 ]; then
# But don't set anything if JAVA_OPTS is already set.
JAVA_OPTS="${JAVA_OPTS:=-XX:MaxRAMPercentage=75.0 -Xms256m}"
fi

JAVA_OPTS="-Djosm.restart=true -Djosm.dir.name=JOSM-latest -Djava.net.useSystemProxies=true $JAVA_OPTS"

if [ -z "${JAVACMD}" ] && [ -n "${ALTERNATIVE_JDK}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion native/linux/tested/etc/default/josm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Uncomment the JAVA_OPTS lines to enable their use by /usr/bin/josm

# Increase usable memory
#JAVA_OPTS="-Xmx2048m ${JAVA_OPTS}"
#JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -Xms256m ${JAVA_OPTS}"

# Enable OpenGL pipeline (2D graphic accelerators)
#JAVA_OPTS="-Dsun.java2d.opengl=True ${JAVA_OPTS}"
Expand Down
6 changes: 6 additions & 0 deletions native/linux/tested/usr/bin/josm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ if [ -f "/etc/default/${JOSM_VERSION}" ]; then
. "/etc/default/${JOSM_VERSION}"
fi

# If there is more than 8G ram, we can use up to 75% of the memory while still leaving 2G for other things.
if [ "$(free --mega | grep '^Mem:' | awk '{print $2}')" -gt 8192 ]; then
# But don't set anything if JAVA_OPTS is already set.
JAVA_OPTS="${JAVA_OPTS:=-XX:MaxRAMPercentage=75.0 -Xms256m}"
fi

JAVA_OPTS="-Djosm.restart=true -Djava.net.useSystemProxies=true $JAVA_OPTS"

if [ -z "${JAVACMD}" ] && [ -n "${ALTERNATIVE_JDK}" ]; then
Expand Down
2 changes: 2 additions & 0 deletions native/macosx/macos-jpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function do_jpackage() {
"${JAVA_HOME}/bin/jpackage" $JPACKAGEOPTIONS -n "JOSM" --input dist --main-jar josm-custom.jar \
--main-class org.openstreetmap.josm.gui.MainApplication \
--icon ./native/macosx/JOSM.icns --type app-image --dest app \
--java-options "-XX:MaxRAMPercentage=75.0" \
--java-options "-Xms256m" \
--java-options "--add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web" \
--java-options "--add-exports=java.base/sun.security.action=ALL-UNNAMED" \
--java-options "--add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED" \
Expand Down
2 changes: 2 additions & 0 deletions native/windows/win-jpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ do
jpackage $JPACKAGEOPTIONS -n "JOSM" --input dist --main-jar josm-custom.jar \
--main-class org.openstreetmap.josm.gui.MainApplication \
--icon ./native/windows/logo.ico --type $type --dest app \
--java-options "-XX:MaxRAMPercentage=75.0" \
--java-options "-Xms256m" \
--java-options "--add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web" \
--java-options "--add-exports=java.base/sun.security.action=ALL-UNNAMED" \
--java-options "--add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED" \
Expand Down

0 comments on commit 86382f4

Please sign in to comment.