Java code, under bright debug JVM result!

6ef0058b05a6c0b211e8dbdea1fca081e27.jpg

As shown below. The next thing would be to do something.

# Build debugging environment

## 1. Download the software CLion

Jetbrains is a very fast hardware company, we IDEA Java which used the function is very powerful, which the company also provides an IDE for the C / C ++, called Clion , we need to download the IDE to debug JVM source.

# 2. Import Source

After installing Clion, let's first be introduced into the code recorded at the following simple steps.

选择 New CMake Project from Sources

Open Directory we downloaded OpenJDK13, my directory is /opt/java/openjdk/jdk13.

Then a bomb box Click Next on the line, waiting for completion of the import source (a few minutes, a cup of tea).

3. Start configure #

After conducting complete source code, we need to configure the program to start, here are some configuration needs to be reassigned, there are the following two points.

  • Executable amended as after we compile the javaprogram.

  • Build needs deleted.

# 4. lay breakpoint

We thread.cppcode Threads::create_vmto lay a breakpoint method.

# 5. Start Debug

Click the Debug button to start debugging our JVM code. We can see that we hit a breakpoint in force, as shown below.

Congratulations, we successfully commissioned JVM code. However, this exception found the following information to solve it.

# 6. found that the abnormal

Press F9 to let the program continue to run, we found a line of word Console red box below.

This is the exception information GDB, we can solve this problem by adding a configuration in our user directory. Create a ~/.gdbinitfile, add the following configuration.

handle SIGSEGV nostop noprint pass
handle SIGBUS nostop noprint pass
handle SIGFPE nostop noprint pass
handle SIGPIPE nostop noprint pass
handle SIGILL nostop noprint pass
复制代码

This exception would not have run the information.

# Debug your code

As already transferred through our compilation of JVM source code, some students may want to know that you want to debug the code must write their own how does it work? We have seen above Debug source code to the JVM, and our own code can be compiled JDK compiled by us, and then perform parameter to specify where in the program. Here's an example.

# 1. Write Test Code

We write a simple Hello JVM program code is as follows.

public class Test {

    public static void main(String[] args) {
        System.out.println("hello jvm");
    }
}
复制代码

# 2.javac compilation

We compiled by JDK the javac Test.java command to compile.

liebrother@liebrother:/opt/java/openjdk/jdk13/build/linux-x86_64-server-release/jdk/bin$ ./javac Test.java
复制代码

# 3. Configure start parameters

Then Clion launch configuration to specify where our class Test.

The result is that our program is running.

These are our talk today debugger to write our own on the JVM level.

# to sum up

To summarize build this JVM environment. In fact, the process did not build it twists and turns, official documents written in very clear (although are in English), to simplify some steps, but also screenshots retained, on the one hand give yourself the opportunity to review, on the one hand but also want to have this building environmental friends a shortcut . This environment is defined as the following: give yourself the opportunity to understand the JVM, some knowledge is not clear, I do not understand the principles when it came to, you can take a look at the source code, uncover the source of logic .

Java compiled some aspects of the architecture, the interview data (micro-services, clustering, distributed, middleware, etc.), there is little need to be concerned about the public partner number [Java's] work, receive no routine self


Guess you like

Origin juejin.im/post/5e493696e51d45270d53060d