I took compiler, operating system, computer architecture course in graduate school. But I want to see those concepts in a simple but real example (not too theoretical). HelloWorld is a good choice for simple example.
Not only the life cycle of this little program is interesting, but also knowing how JVM, OS and Architecture works can help us to become a better programmer.
In short, my question is: do I describe the steps correctly and completely?
In detail, I need your help with the following:
- Point out any part that I am wrong
- I'm sure I miss a lot of valuable points, so please add any point that makes sense in the life cycle.
What I want to know is how HelloWorld goes through each layer, and then come back from it. Assume this program runs on an Intel CPU with Ubuntu.
I will keep this post updated by combining good answers until one answer is finally accepted.
The following is THE HelloWorld program that everybody knows.
It is compiled to bytecode like the following.
The bytecode is not readable, but we can use javap -classpath . -c HelloWorld
to see mnemonics like the following.
Then it gets loaded, linked and initialized in JVM.
Since it has only one thread, let's assume it is the the left thread in the following JVM run-time data area.
JVM threads are user-level threads, so it will be mapped to kernel. In Ubuntu, it is one-to-one mapping like the following:
Now JVM makes the x86 instructions? (update)
What is operating system's role for this particular program?
What is next in Architecture?
Fetch instruction, decode, execute, memory access, write back in 5-steps MIPS.
References:
This could be an extremely difficult question. Unlike questions of how to use a certain API, this requires understanding of almost everything.