The total number of words in this article: 986, reading needs 5min

In daily program development, I often encounter the situation that the code does not run, and then my colleagues joke with me: people and code, as long as one can run. So I thought, I’m running on two legs, so how does the code run? Out of curiosity, today I’m going to uncover the mysteries of the JVM and see how our code actually works.

So where do you start? I fell into thinking, thinking ing, 3 minutes later, I have an idea! Since Java is an object-oriented language, how does that person run? You may be saying, “Well, with your legs.” So since the leg is the actuator of running, how does the leg know when to run? That, of course, depends on nerve conduction, the signal arrives, transmits the information to run, the leg knows! So we know that the JVM is so smart is it also running through instructions like this?

Well, let’s assume that the JVM runs by instructions, just like we do. We need to verify that it does so. How do we verify that? I have to ask the JVM, so I decided to write a hello with the following code:

The result is a set of addresses

Why, the JVM actually knows what I want to do and can read my mind, which is much better than the real complex world.

It’s true that this is what I want, but how does it know what I want? Buddha said: as you sow, so shall you reap, kind of object must also get the object, but it is clear the machine is no more able to read our popular language, that is to say, do not have real intelligence, then we will need to parse we write their own code, code and see what is happening in the world, note: we will enter to the microscopic world, there is more interesting.

Javac Desktop\hello\ SRC \ hello.java, // Java ->class javap -c Desktop\hello\ SRC \heima\ hello.class // disassember. javac Desktop\hello\ SRC \heima\ hello.class

The door of the world opens:

I was surprised, what are these demons and ghosts ah, in addition to the letter recognition, the rest of the do not know, this is an ancient spell carved on the stone, waiting for us to reveal the secret, so I began to almighty Google, to crack this weird spell.

After a long time of Google, I have a clue. I won’t learn. What are I afraid of? As you can see, the commands that come up a lot are load and store. What does that mean? Let me draw a picture to help you understand:

puzzles

The first code0: aload_0// Load the local variable table information into the stack
     code 1: invokespecial// Invoke is a null parameter that calls the Object class
     code 4return / / returnNext comes the main method: code0 : new // Create an instance directive for the class
     code 3: dup/ / pressure stack
     code 4: invokespecial// Invoke means to call, where it means to call the initialized method
     code 7: astore_1// Load in the opposite direction
     code 8: getstatic// Print the stream method
     code 11: aload_1/ / same as above
     code 12: invokevirtual// Call the newline print method of the print stream
     code 15return
Copy the code

End in the small world to explore for so long, the brain and body are a little not to live, because I don’t really understand, also in the study, if there are any errors, please contain more, I just want to in my Angle of view to lead the people to meet the JVM, help Java programmers to understand and recognize the JVM, hope can exchange and study with more Java developers, I’m CocaCoder, a programmer who’s not very good at writing articles, and I’ll see you next time.