Well, imagine this situation: the program window is open, there is a button in it. The program is still resting and waiting for a button.

At one point, juzver pushes a button, and the program will have to execute a method of a couple of thousand (/ million or something in it once).

And you can say to the JIT compiler: "Listen, while the program is resting, please compile that method, ok?". Those. roughly speaking to start compiling a particular method?

  • You first measure how long the first execution of the method will take and the second (when the jit has already worked), and then decide whether the game is worth the candle. - rfq
  • PS: in vain minusanuli, a normal question. - JEcho
  • If people have such questions, then either they are very beginning programmers who think that they will speed up their code with this, or those who simply made a mistake in the programming language at the very beginning. No need to do with Java pure C. It was not created for this. - KoVadim
  • one
    if he comes exactly to me, then I will say that I do not write in java. And there is no problem (I really do not write to java, well, except to indulge under the android). But usually with the customer specify the "desired characteristics." And there is always the opportunity to say "I can not / refuse." But if the software slows down terribly, then most likely the problem is not in java, but in who wrote the code. running jit precompilation will not help. Sometimes replacing some algorithms with more suitable ones gives a huge increase in speed. main idea: do not confuse the brakes of a particular language / environment and the brakes of a programmer. - KoVadim
  • one
    Well, about a couple of bytes, the question is clearly not in Java. but the fact that in order to do some kind of operation, different from the standard one (I’m exaggerating here), is used, which is used, which is used .... that is In fact, a paradox turns out: most likely, what you need to write is written (rarely there are unique tasks) and it seems to be expensive and problematic to write from scratch (development, testing, support, etc.), and ready to use will give this ... if I write diy I try to write "bicycles", at work, so nez, they will not appreciate it, you will get an extra ten tasks in jira and even a minus a couple of hours of your personal life, nerves and depression - JEcho

2 answers 2

Are you sure you are not trying to save on matches?

Solution option:

  1. Come up with something like an IDLE mode in the application, and run the necessary methods one by one, until they are compiled (You can only determine indirectly). It is impossible to determine if methods could be compiled - because this does not happen immediately, but after expiration of treshchold.
  2. Pokold with flags (More on SO again) and set up a small treshchold or forced compilation.

This approach has a lot of minuses and not a single plus, so use only if you really know that you need to compile the methods while the processor is idle.

  • Second link beaten - kandi
  • corrected the link - IronVbif
  • one
    > and run the necessary methods in it one by one, no need to try to deceive the compiler and jit. He will punish later. It may just start the calculation in the background right away, and when the user presses the button, then by that moment everything is possible and it will be calculated. - KoVadim
  • hmm ... a funny sentence, he has a dofig bitart method that slows down like a lazy man who drank a bottle of tormozuhi in hibernation and needs to be called a bunch of times until a jit jitched his compile ... hm ... and you have an interesting approach to optimization ) .. sorry for cynicism .. - JEcho
  • This is not my approach, I answered the question of how to program my background in the background. - IronVbif

In short: no.
Expanded: it seems to me that you do not quite understand the idea of ​​dynamic compilation, which is why it is dynamic ;-) In the sense that everything is not so simple. Your task is more like an auto-compile. In general, to be honest, I'm a little lazy to paint an ideology, there are many good articles, for example: Java theory and practice: Dynamic compilation and performance measurement

Shl: if you have a place for a million repetitions, it’s not yet a fact that this particular code should be compiled with JIT (in the sense of not unlikely, but not fak) JIT compiler is still a byte code.