2

Possible Duplicate:
Technique or utility to minimize Java “warm-up” time?

I know JVM takes a while to "warm up" depending on the code size. My question is: Is there a way the programmer can help with it to speed-up the "warm up" process by specifying somehow the possible sections of the code to look into ?

Community
  • 1
  • 1
  • 3
    [same question](http://stackoverflow.com/questions/1481853/technique-or-utility-to-minimize-java-warm-up-time) – Subhrajyoti Majumder Apr 29 '12 at 16:37
  • Please check my suggestion http://stackoverflow.com/questions/1481853/technique-or-utility-to-minimize-java-warm-up-time/10383192#10383192 - possible it will works for you too. – Andriy Plokhotnyuk Apr 30 '12 at 11:48

3 Answers3

2

You can indirectly by the calling the code lots of times. The default -xx:CompileThreshold= is 10000. So you can call the critical code lots of times e.g. 12,000 times.

You can reduce the compilation threshold, but you still have the same problem, its just that the loop can be say 1000 instead of 10000.

One reason you want to warmup the code is to optimise it, but if you shorten the number of iterations, some of the optimisations may not be performed and you can get sub-optimal call (But not always)

Then again if you warm up the code is a way which is not representative it can optimise it in a sub-optimal way and the JVM may decide to re-optimise it later.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Why not change the option to a lower number? – assylias Apr 29 '12 at 16:44
  • 2
    Peter, I'd be really careful about giving this advice. The number of cases where I think it's a good idea to adjust CompileThreshold is very small. There are also interactions - e.g. if the code cache fills then the user may miss out on having important methods compiled (e.g. think about how a Spring app might behave). We should do some experiments. – kittylyst Apr 29 '12 at 21:08
  • @kittylyst If it wasn't clear from my answer, I don't think adjusting the compile threshold is ever helpful, at best it might not make it worse. I don't have much experience with optimising JVMs with huge code bases, and I have never come across a problem where your *critical* code (which is what I suggest warming up) is too large to fully optmise. If this is a problem I would suggest reducing the side of your code base, or I suspect making sure its your critical code which is optimised is probably a good thing. – Peter Lawrey Apr 30 '12 at 07:09
  • Another option for inline tuning: -XX:MaxInlineSize=, where n - is max length of method (in bytecodes) which allowed to be inlined. But, as noted by Peter above, it is better to have such kind of options untouched, but instead to have the critical path of code carefully factored to small methods. – Andriy Plokhotnyuk Apr 30 '12 at 12:15
0

You may want to consider an ahead-of-time compiler, e.g. gcj, which allows you to compile a set of classes to native code when you build your app, and only run runtime-loaded classes in a virtual machine. The performance after compiling is finished isn't as good (especially if you spend a lot of time in code loaded at runtime) but for programs with short run times the benefit of precompiling more than offsets this.

Jules
  • 14,841
  • 9
  • 83
  • 130
0

There is a real good article on developerWorks about micro performance measuring in Java. It also covers the topic of "warm-up" and other related things. The author has implemented a quite good framework for micro benchmarking in Java. This framework also deals with the warm-up phase of the JVM and tries to speed it up and to finish it before the actual tests start. The source code of the framework is also available, so you can have a look at how this is implemented.

sakthisundar
  • 3,278
  • 3
  • 16
  • 29
Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80