JIT does method optimization (-XX:+PrintCompilation) after 10k invocations and you can configure it with -XX:CompileThreshold. I read the reason not to lower that threshold is the JIT optimization might be wrong or you optimize the infrequently used code. I have a few questions regarding this area:
Updated: #3. never should expect java faster than c++, just want to be closer.
is there a way to force optimization upfront to increase performance to be better than that of c++?
Nope. It's a fundamental limitation of the semantics enforced in the Java specification and the way that the JVM ecosystem works that it will be slower than a C++ implementation, assuming equivalent quality of implementation and code. Have a look at my existing answer on this subject for more details.