MaxHeapSize in Java - java

I run command in window machine
java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize
and got below value for MaxHeapSize
2118123520
which is 2020MB however, when I call Runtime.getRuntime().maxMemory() , it gives me 259522560 only i.e. 247MB .
Can anyone please suggest why I'm getting this mismatch ?

As per your last comment
I'm using eclipse IDE and didn't change any setting . do you know how to change maximum heap size in eclipse IDE ?
Set the VM arguments found under Run configuration.
VM arguments are typically values that change the behaviour of the Java Virtual Machine (JVM). For example, the -Xmx256M argument allows the Java heap to grow to 256MB.
For more info have a look at Eclipse launching program and VM arguments

Can anyone please suggest why I'm getting this mismatch ?
The Runtime.getRuntime().maxMemory() call is returning the maximum heap size for the current JVM. This is determined by either the -Xmx command line option (e.g. for the java command) or a platform specific default.
The command you are running is giving the maximum allowed value for the -Xmx commandline option on your platform.
Clearly these are different things. Furthermore, the numbers are usually different.

Related

JVM heap memory

Do we need to mandatory specify JVM heap memory arguments in bat file while calling .jar file?
For example:
start /b "" "jre7\bin\javaw.exe" -Xmx1G -jar XYZ.jar
I have the scenario that in some machine when I explicitly specify the arguments(as above) then Java fatal exception is generated!
enter image description here
Error Message:
"Java virtual machine Launcher:
Error: Could not create Java virtual machine.
Error: A fatal exception has occurred. Program will exit."
But when I remove the arguments then no error is reported.
Please anyone let me know. Thank you.
Xmx is an optional argument that specifies the maximum heap size that can be used by Java. It is not required.
If you specify too large a number, you may get a fatal exception. If you don't specify an option, java chooses the max heap size. You can find the default value of this on linux by running 'java -XX:+PrintFlagsFinal -version | grep MaxHeapSize'
You need to update the windows environment variables _JAVA_OPTIONS and set Xmx1024M there. Once done you can start your JVM just fine.

-XX:MaxPermSize=128m: command not found when setting MaxPermSize on linux server

Getting this kind of error on linux server in my project when i run my spring-hibernate project
i read the
Increase permgen space
someone replied to execute
-XX:MaxPermSize=128m
to increase of MaxPermSize but when i execute this command in in my
project under directory of classes i got an error
[root#server classes]# -XX:MaxPermSize=128m
-bash: -XX:MaxPermSize=128m: command not found
Initial SessionFactory creation failed.java.lang.OutOfMemoryError: PermGen space
How can I set MaxPermSize only for one particular project as I am working on live server some projects are live on that server so please suggest me right solution so that I can set MaxPermSize on live server
You misunderstood the answer on the original question.
When you run a Java program, you use a command like:
java [JVM arguments] ClassName [program arguments]
The --XX:MaxPermSize=128m part goes in the "JVM arguments" part - it is a directive to the JVM to allocate 128m of memory to the PermGen.
So you are supposed to edit the java command in your script and not put that argument on a separate line.
You should also consider upgrading to Java 8, in which Permgen no longer exists.
-XX:MaxPermSize=128m is a JVM argument, not a bash command.

Difficulty setting Solr JVM memory settings on Ubuntu with Bitnami AMI

I am using the Apache Solr powered by BitNami EC2 AMI. Solr is running, but I'd like to change the startup configuration to increase the amount of memory allocated to JVM.
I have tried modifying the startup script at at /opt/bitnami/apache-solr/scripts/ctl.sh by modifying the following line:
SOLR="$JAVABIN -Dsolr.solr.home=$SOLR_HOME
-Djetty.logs=$INSTALL_PATH/logs/ -Djetty.home=$INSTALL_PATH/ -jar $INSTALL_PATH/start.jar $INSTALL_PATH/etc/jetty.xml"
I've tried different permutations for the memory flags and none of them work (some of them cause the Solr server to fail to start at all, while others allow it to start but have no effect on the JVM memory allocated). This is what I've tried adding to the line:
-Xmx 1000 -Xms 8000
-Xms1000m -Xmx8000m
-Xms1000 -Xmx8000
-Xms 1000m -Xmx 8000m
What is the correct way of going about this?
It turns out that the arguments needed to be at the start of the line. The following works:
SOLR="$JAVABIN -Xmx7168m -Xms1024m -Dsolr.solr.home=$SOLR_HOME
-Djetty.logs=$INSTALL_PATH/logs/ -Djetty.home=$INSTALL_PATH/ -jar $INSTALL_PATH/start.jar $INSTALL_PATH/etc/jetty.xml"

Java Hotspot command line parameter to increase the maximum size of Java method

Is there a command line parameter to increase the maximum size of Java method (from 8000 bytecodes) that Hotspot will compile?
You might have to download the sources and build with debug flags for this (I'm not sure).
java -XX:+UnlockDiagnosticVMOptions -XX:-DontCompileHugeMethods
More information can be found here.
If you download the sources I think most of the (hundreds) flags can be found..
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/src/share/vm/runtime/globals.cpp

Problems with java heap space, how to increas the heap size?

I'm running a ".bat" file which points to asant:
C:\Sun\SDK\bin\asant Startbds
asant again points to a xml file i've got, build.xml:
<target name="Startbds" description="Start bds">
This has been fine for now, but now i have added more data, which leads to an out of memory error:
java.lang.outOfMemoryError: Java heap space
So i've tried to increase the heap space by various methods i've found while searching around for a solution:
cmd: set ANT_OPTS=-Xms512m -Xmx512m (did not work, same error message)
Editing the asant.bat where i edited the line "-set ANT_OPTS" from
.
set ANT_OPTS="-Dos.name=Windows_NT" -Djava.library.path=%AS_INSTALL%\lib;%AS_ICU_LIB%;%AS_NSS%" "-Dcom.sun.aas.installRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceName=server" "-Dcom.sun.aas.configRoot=%AS_CONFIG%" "-Dcom.sun.aas.processLauncher=SE" "-Dderby.root=%AS_DERBY_INSTALL%"
TO
set ANT_OPTS="-Xms512m -Xmx512m" "-Dos.name=Windows_NT" -Djava.library.path=%AS_INSTALL%\lib;%AS_ICU_LIB%;%AS_NSS%" "-Dcom.sun.aas.installRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceName=server" "-Dcom.sun.aas.configRoot=%AS_CONFIG%" "-Dcom.sun.aas.processLauncher=SE" "-Dderby.root=%AS_DERBY_INSTALL%"
but this gave me the error message:
"Invalid initial heap size: -Xms512m -Xmx512m
Could not create the Java virtual machine."
Anyone got an idea of how i should increase the heapsize?
And maybe also give a pointer to where i can find a tool to watch the heapsize.
Thanks in advance.
By using "-Xms512m -Xmx512m" you gave a single argument. -Xms expects the minimum heap size to be specified by the rest of the argument. So you defined the minimum heap size to be "512m -Xmx512m", which is not a valid value.
You will want to provide those switches as two arguments:
set ANT_OPTS=-Xms512m -Xmx512m "-Dos.name=Windows_NT" ...
I think that if you're in windows, you don't need the double quotes in your set.
Here is an example I saw somewhere:
set ANT_OPTS=-Xms512m -Xmx512m (Windows)
export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)
setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
As for monitoring heap usage, if you are using the most recent JDK on Windows, you should have Sun's VisualVM.
In eclipse -> window -> preferences -> Tomcat -> JVM Setting -> Append to JVM Parameters:
-XX:MaxPermSize=512m
-Xms512m
-Xmx512m

Categories

Resources