Now, the way that we can find out what kind of compilation is happening when the Java virtual machine
is running, our code is by providing a flag to the Java virtual machine, which is Dash X, X Kolon
plus print compilation.
This is the first of the virtual machine flags that we're seeing of this course.
And most of the flags do follow this format.
Dash X X means this is an advanced option.
Then there's a column, then we have a plus or a minus, which indicates if we want the option to be
switched on or off and then the option name, we'll see quite a few of these flags as we proceed through
the course.
And the one thing I suppose I should point out is that the flags are case sensitive so that X X must
be in capitals and they normally use what I think is called sentence case.
Each word has a capital letter.
So capital letter P for print capital letters for compilation.
So let's run this code again with this flag Switched-On.
I'll do it, I think, from the console, first of all, so we're going to do Java, then we put our
flag in, so that's dash X X Kolon plus print compilation.
Then we want the class that we're running, which was main and any runtime arguments.
We want to produce 10 of the prime numbers.
Now, we'll look at this output in just a moment.
But in case you want to run this through the idea, just do the same thing here so you can see where
to put the flags.
We want to do run and run configurations again.
And this time under arguments, you can see there's a separate box for PVM argument.
So that's where we put in our dash X X Kolon plus four compilation.
And let's just run it here.
So here's our console output and we've got some output there and there is quite a bit of output here,
so I'm going to try and talk through it.
And what we're seeing then is every bit of compiling that is going on within the virtual machine as
our application runs.
This is split into columns.
The first column here is the number of milliseconds since the virtual machine started.
Next is the order in which the method or code block was compiled.
Now, don't worry that these numbers don't appear in order.
It just means that some parts took longer to compile than others.
This could be due to multi threading issues or the complexity or length of the code being compiled.
For example, we now have a few different columns, most of which are blank, but we do have one that
has an engine and one that has an S.
In the end here means native method and S means it's a synchronized method.
You might see other things in here.
An explanation, Mark, would mean there, some exception handling going on and a percentage simple
would mean that the code has been natively compiled and is now running in a special part of memory called
the code cache.
A percentage simple in here means that the method is now running in the most optimal way possible.
The next column has a number from zero to four, and I'm going to look like this number in a moment
or two.
And then we have the line of code that has actually been compiled now producing just 10 prime numbers.
Actually, there's not that much going on here, in fact, or the compilation is being done on core
Java IP methods.
There's none of our own code appearing here.
So I'd like to run this again with a much larger set of numbers to calculate.
Doing that should give us some more interesting results and then we'll be able to understand more about
what's going on here.
So what I think we'll do actually is change our code to not print out the numbers at the end.
I'm going to come right out the print line.
And then we'll run it again, but this time we'll ask for 5000 prime numbers to be produced rather than
10, and I think I'll do this from the console window.
So I'm going to record my previous command.
I still want the print compilation flag.
And this time we're going to calculate 5000 prime numbers.
So we'll let that one.
It has finished.
And I think the results here now then are a bit more interesting within the column that contains our
method names.
We've got references to get next time above and is prime.
These are methods that exist in our code and we have that percentage symbol appearing here too.
So in fact, is prime has been placed in the code cache.
So let's talk now about this.
A number here, the number between zero and four.
Well, this tells us what kind of compiling has taken place.
A zero would mean no compilation.
The code has just been interpreted and the numbers, one to four mean that a progressively deeper level
of compilation has happened.
So, in fact, at this point, our is prime method was compiled at the highest possible level of compilation
at level four and was placed in the code cache down here.
We can see get next prime above was also compiled to level four, although it wasn't placed in the code
cache.