Chapter 1 Java code execution process, Chapter 1 java

Source: Internet
Author: User

Chapter 1 Java code execution process, Chapter 1 java

Note: This article mainly references distributed Java applications: basics and practices

 

1. Java code execution process

  • Step 1: *. java --> *. class (compilation period)
  • Step 2: load the content from the *. class file to the memory (class loading) (runtime)
  • Step 3: Execute the code (runtime)

 

2. code compilation

The javac command compiles the source code file into a *. class file.

Next we will introduce:

  • Javac compiles *. java into *. class files
  • Class file format and its storage content

 

3. class loading

It mainly refers to loading *. class files to JVM and forming a Class object mechanism. Then, Class objects can be instantiated and called.

Features:

  • The class loading mechanism can dynamically load external classes at runtime.

Next we will introduce:

  • Class loading process
  • Parent-parent Delegation for class loading
  • Class Loader hierarchy and source code

 

4. Run the code

Two execution methods:

  • Explain and execute (the bytecode is interpreted and executed at runtime)
    • Slow speed and low efficiency
    • However, it saves more memory than the compiled machine code.
  • Compile to machine code for execution (compile the bytecode into machine code and execute it. This compilation process occurs at runtime, called JIT compilation). The following two modes are available:
    • Client (C1): only a small amount of optimization with high performance overhead and low memory usage. It is suitable for desktop programs. The main optimizations include:
      • Method inline
      • De-Virtualization
      • Redundancy Elimination
    • Server (C2): optimizes a lot and occupies a large amount of memory, which is suitable for server programs. Will collect a large amount of runtime information.
      • Escape analysis: determines whether the variable in the method will be read externally based on the running status. If not, the variable will be escaped. Based on this, C2 will do the following during compilation:
        • Scalar replacement
        • Stack allocation
        • Synchronous Removal
    • 32 is the default machine C1, you can add-client or-server at startup to specify, 64-bit machine if CPU> 2 and physical memory> 2G is the default C2, otherwise C1
  • Mechanism for Sun JDK to execute code: Compile the code that is frequently executed during the execution process, and continue to explain and execute the code that is not frequently executed.

Next we will introduce:

  • Sun JDK Code Execution Process
  • Optimization of C1 and C2 execution
  • Measure of the usage of compilation execution and interpretation execution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.