views:

551

answers:

4

I've just upgraded some old Java source which has been running on a Sun Java 1.4.2 VM to Sun Java (JRE) 6 VM. More or less the only thing I had to change was to add explicit datatypes for some abstract objects (Hashmap's, Vector's and so on). The code itself it quite memory intensive, using up to 1G of heap memory (using -Xmx1024m as a parameter to start the VM).

Since I read alot about better performance on newer Java VM's, this was one of the reasons I did this upgrade.

  1. Can anyone think of a reason why the performance is worse in my case now (just in general, of course, since you can't take a look at the code)?
  2. Has anyone some advice for a non Java guru what to look for if I wanted to optimize (speed wise) existing code? Any hints, recommended docs, tools?

Thanks.

+3  A: 

If your application nearly runs out of free space, garbage collection time may dominate computation time.

Enable gc debugging to look for this. Or, even better, simply start jconsole and attach it to your program.

mfx
+8  A: 

Not much information here. But here are a couple of things you might want to explore:

  • Start the VM with Xmx and Xms as the same value (in your case 1024M)

  • Ensure that the server jvm dll is being used to start the virtual machine.

  • Run a profiler to see what objects are hogging memory or what objects are not being garbage collected

  • Hook up your VM with the jconsole and trace through the objects

Nikhil Kashyap
The server hotspot VM isn't selected by default on Windows machines (even "server" class machines) so this is a good tip.
Fortyrunner
+3  A: 

Theoretically it could be that you application consumes more memory, because there were changes to the way Strings share their internal char[]. Less sharing is done after 1.4. Check my old blog at http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/5100 (new blog is here)

I would compare the Garbage Collector logs to see whether memory usage is really the problem.

If that doesn't help, us a profiler such as Yourkit to find the differences.

kohlerm
A: 

Definitely use a profiler on the app (YourKit is great)...it's easy to waste a lot of time guessing at the problem when most of the time you'll be able to narrow it down really quickly in the profiler.

Ken Liu