How can I know the targets of JVM configuration?
I know how to set JVM for my server, which can be done by command
'java -Xmx3550m -Xms3550m -Xmn2g -Xss128k'.
But what's command can to see what it is like? Any guidance?
You can use VisualVm/Jconsole to connect to your running jvm. This will give you all the information you need.
If you're running linux you can use something like ps -efx | grep java
You can use VisualVM to display information about the JVM.
If you want to see the command line arguments you can use jps -lvm to list all your java processes.
The maximum size is a little suspect. It appear you are trying to pick the maximum size for a 32-bit JVM on a 64-bit OS (which can be about 3.5 GB on some OSes) Personally I would just use a 64-bit JVM and use 4 GB as this uses 32-bit references so there is very little disadvantage in doing so.
Related
we're running a Java application for rendering ans displaying quite a number of images. To make this smooth, we's like to assign a fair amount of heap space, and would like to check if there's a 64 bit version available on the computer. We'd like to run the application on many different computers, so manually checking the available memory and the Runtime version by trial and error is quite a hassle.
Does anyone know of a method to determine the availably memory that can be reserved for heap space, and to determine the available JREs; so we could somehow pass these parameters on to the JRE when executing the jar?
I'm aware that this would require some sort of batch file, like discussed in this thread:
Setting Launch Parameters In Java Class
Has anyone come across a running example for a Windows environment? My knowledge about Windows Batch-files is limited at best.
Regards, Marius
to check if java is 64-bit:
java -version 2>&1|find /i "64-Bit" && echo YEP!||echo NOPE!
To get free memory :
wmic os get freephysicalmemory
or:
systeminfo | find "Physical Memory"
EDIT
Universal and fast way to get free memory:
mshta "javascript:close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(GetObject('winmgmts:').ExecQuery('Select * from Win32_PerfFormattedData_PerfOS_Memory').ItemIndex(0).AvailableBytes));"|more
assign result to variable:
for /f "usebackq" %%a in (`mshta ^"javascript^:close^(new ActiveXObject^(^'Scripting.FileSystemObject^'^).GetStandardStream^(1^).Write^(GetObject^(^'winmgmts:^'^).ExecQuery^(^'Select * from Win32_PerfFormattedData_PerfOS_Memory^'^).ItemIndex^(0^).AvailableBytes^)^);^"^|more`) do set free_mem=%%a
I have a windows pc with 64 bit OS (windows 7 Enterprise) and 8 GB of RAM. I want to run a heavy java program on eclipse and I would like to allocate as much of the PC resources only to eclipse/JVM to boost the performance.
By the way, in two different runs of the same program, it took 33 mintues in one and 15 hours in the other. That's a very big difference which I do not know what configuration change (if any) caused this deterioration in the performance.
Could you please help me to Configure it properly?
In eclipse.ini (in the main folder of eclipse) there is a bunch of parameters that should help you to configure the amount of memory. At the end of the file should be sth like this:
-vmargs
-Xms1024m
-Xmx2048m (max heap)
-Xss1m (stack)
You can add as many parameters as you need. All of them must be after the line
-vmargs
You can find more JVM parameters here
also you can allocate memory for Java with this way:
Type Java inside the Search Control Panel box.
Click the Java icon that pops up.
Click view
Make sure to get the x64 version if you have a 64-bit OS.
Change Runtime Parameters, put '-Xmx1024m' for exemple
Change it depending on how much RAM you have, it is recommend you use 256/512/768/1024/1536/2048.
For 32-bit Operating Systems 768M is recommended.
If you have 64-bit, or that doesn't work, continue to try the following:1024m, 1536m, 2084m
hope that help.
I need a way to be able to trigger full GC from a linux console script on ubuntu.
I know this is extremely bad practice but without going into too much detail this keeps my server running, This is only meant for 1 or 2 days while I fix the actual problem, so I don't have to wake up in the night and perform manual GC through jconsole or jvisualvm.
Alternatively I have to make a mouse script that clicks the button every 3-4 hours or so which is even worse.
Please help.
If you can have your application start a JMX server (which I believe is implied from your use of jconsole/jvisualvm), then you can invoke the Memory MBean's gc operation via command-line utilities.
Firstly you'll need some kind of command-line JMX client. I've used this one in the past for simple command-line invocations and it worked fine. (Edit: In fact I used it just now to test out the following command, and it invoked GC successfully on a local Tomcat process)
Then you'll need to work out the command to trigger garbage collection. I think this should work (you'll of course need to change hosts/ports/credentials as appropriate):
java -jar cmdline-jmxclient-X.X.jar - localhost:8081 java.lang:type=Memory gc
Finally, you can schedule invocation of this command via cron or equivalent.
Voila!
If you have oracle jvm 1.7, you can use jcmd to list the jvm PIDs, and then jcmd <pid> GC.run to GC.
jcmd <pid> help will show you what other commands are available.
jcmd <pid> GC.run
Example:
jcmd 20350 GC.run
It's not bad practice, it is impossible - even for the java application being executed by the JVM. There is a gc() call available but even it is only a hint to the JVM to run garbage collection. From the console, there is normally no way to influence the JVM while it is running.
Some has asked this question for the Windows platform, see question How to request JVM garbage collection (not from code) when run from Windows command-line
You might check out the JVM arguments for stack/heap sizes (both min and max). There are lots of tweaks you can do in that area but they are mostly specific to the JVM you are using.
JVM performance tuning for large applications
There are two following options in Java HotSpot VM Options:
-XX:OnError="<cmd args>;<cmd args>" Run user-defined commands on fatal error. (Introduced in 1.4.2 update 9.)
-XX:OnOutOfMemoryError="<cmd args>;
<cmd args>" Run user-defined commands when an OutOfMemoryError is first thrown. (Introduced in 1.4.2 update 12, 6)
As far as I can see there are no such options in IBM JVM.
Is it correct?
I need to call some shell script in case if heap dump was generated.
What is the simplest way to do it?
The IBM J9 JDK offers the said ability via the -Xdump flag; this is the preferred way of registering dump agents.
A typical way of configuring the JVM to produce heap dumps on OOME is to catch all Out Of Memory Errors thrown by the application or by the JVM, and to prepare the dump for "walking" (with a heap inspector).
-Xdump:system+heap+java:events=systhrow+user,filter=java/lang/OutOfMemoryError,request=exclusive+prepwalk+compact
Ref:Eclipse Memory Analyzer Guide
The JAVA_DUMP_OPTS environment variable can also be used. More information on this is available in the IBM JDK diagnostics guide.
EDIT
For the purpose of running a command on a OOME, the tool option needs to be specified in the -Xdump option.
-Xdump is your friend and is very powerful.
For your OOM case, something like:
"-Xdump:tool:events=throw,filter=*OutOfMemoryError,exec=cmd_to_run
I would expect IBM's JVM to support the same flags, as it is an instrumented version of the Sun JVM if I remember correctly. Is it possible you compare command line options between major versions of Java? (I.e. Sun 1.6 versus IBM 1.4.2?)
If you do not find a solution for the flags, you could take advantage of the fact that the IBM JVM updates the file /tmp/dump-locations by appending the full path of the dumpfile. A cron job can run your script when that file is touched since its last run.
How do I set Java's min and max heap size through environment variables?
I know that the heap sizes can be set when launching java, but I would like to have this adjusted through environment variables on my server.
You can't do it using environment variables directly. You need to use the set of "non standard" options that are passed to the java command. Run: java -X for details. The options you're looking for are -Xmx and -Xms (this is "initial" heap size, so probably what you're looking for.)
Some products like Ant or Tomcat might come with a batch script that looks for the JAVA_OPTS environment variable, but it's not part of the Java runtime. If you are using one of those products, you may be able to set the variable like:
set JAVA_OPTS="-Xms128m -Xmx256m"
You can also take this approach with your own command line like:
set JAVA_OPTS="-Xms128m -Xmx256m"
java ${JAVA_OPTS} MyClass
If you want any java process, not just ant or Tomcat, to pick up options like -Xmx use the environment variable _JAVA_OPTIONS.
In bash: export _JAVA_OPTIONS="-Xmx1g"
You can use JAVA_TOOL_OPTIONS.
Example:
export JAVA_TOOL_OPTIONS=-Xmx512m
It has been mentioned in some comments, and in another answer.
The OP's question is quite old, but as it is the first google result for the question, I thought i would add the answer here for clarity's sake.
Actually, there is a way to set global defaults for Sun's JVM via environment variables.
See How to set a java system property so that it is effective whenever I start JVM without adding it to the command line arguments.
You can't do it using environment variables. It's done via "non standard" options. Run: java -X for details. The options you're looking for are -Xmx and -Xms (this is "initial" heap size, so probably what you're looking for.)
I think your only option is to wrap java in a script that substitutes the environment variables into the command line
A couple of notes:
Apache ant doesn't know anything about JAVA_OPTS, while Tomcat's startup scripts do. For Apache ant, use ANT_OPTS to affect the environment for the JVM that runs /ant/, but not for the things that ant might launch.
The maximum heap size you can set depends entirely on the environment: for most 32-bit systems, the maximum amount of heap space you can request, regardless of available memory, is in the 2GiB range. The largest heap on a 64-bit system is "really big". Also, you are practically limited by physical memory as well, since the heap is managed by the JVM and you don't want a lot of swapping going on to the disk.
For server environments, you typically want to set -Xms and -Xmx to the same value: this will fix the size of the heap at a certain size and the garbage collector has less work to do because the heap will never have to be re-sized.