JVM from scratch: Java key concepts and JVM (b)

Original Address: www.sudo.ren/article/81?...

Java architecture consists of the Java programming language, bytecode, Java API and the Java virtual machine-related technology components. 1.Java programming language; 3.JVM the byte code is loaded into the inside thereof, and then interpreted / compiled into a corresponding internet; 2. compiler front end (the javac) The Java source code is compiled into byte code file (* .class) machine instructions.

Java language: Java about 51 defined keywords.

Java inherits the syntax of C language structure, the adaptation of the C ++ object model. And give up a lot of Java syntax unsafe features of C and C ++. such as:

  • Waste pointer operations;
  • Automatic memory management;
  • Array bounds checking;
  • Checking type conversion;
  • Thread-safe mechanism;
  • Physical environment access restrictions.

Byte code:

Java source code is compiled results are not local machine instruction, but byte code, which is a good solution to the security of the program, cross-platform portability and other issues. We can deploy the compiled byte code to the other with a jre environment, the same can be normal operation, this is what we often say "once, run everywhere"

JavaAPI:

API is the application programming interfaces are predefined interfaces, the ability to provide application developers with a given software or hardware to access a set of routines, but without having to access the source code or understand the details of the inner workings. Which contains a collection of Java foundation class library, provides a standard way to access a host system resources.

Java Virtual Machine:

JVM is an abstract computer set defined by the specification. It is responsible for loading bytecode to the inside, interpreted / compiled into machine instructions corresponding to the internet. We are going to learn is to HotSpot VM, it is one of the high-performance virtual machines currently on the market. HotSpot detection function provided with the hot, can frequently be a method or whine body more effective cycles code block is marked as "hot", then embedded dual JIT (Just In Time Compiler) compiler bytecode directly compiled to native machine instructions. The compiler and interpreter HotSpot coexist, hot-dependent detection function determines by interpreting the running bytecode instructions, or compiled to run.

Compiler / interpreter to run in a virtual machine:

The virtual machine starts, the interpreter began to play a role, without waiting for the completion of the compiler to compile all again executed, this can save a lot of time to compile. The focus detection function, the compiler will valuable bytecode compiler native machine instructions in return for higher efficiency of program execution.

HotSpot embedded in two JIT compiler:

Physical hardware system automatically selects which compiler, developers can manually invoke the compiler display strategy. Open tiered strategy compiled by default, coordinated by the C1 and C2 compiler work together to complete the compilation.

  • Client Compiler (C1): the byte code optimization simple and reliable, faster compilation speed has been reached;
  • Server Compiler (C2): start some compiler optimization will take longer to get better compiler quality;

Fully explain / fully compiled

Developers can call manually using the HotSpot VM fully compiled, or fully explain.

  • Fully explain: Compiler stops all work, completely dependent on the bytecode interpreter gradually interpreted;
  • Fully compiled: In special cases the interpreter will still be unable to access the implementation of the compiler.

Java Technical characteristics:

  • Java language independence: JVM to run java language and applications written in other programming languages. Java language itself does not support other language features, but JVM support (and as long as the internal instruction set comprising jvm, symbols, and other auxiliary information is a valid byte code file, the JVM loads can be run)
  • Fork / Join multicore parallel: (hereinafter java5, java.util.concurrent package under) split task to a minimum, then each run separately calculated. (Eg: Hadoop Map / Reduce)
  • Java7 new features: switch (supports String, binary), try-with-resources automatically manages resources, generic inference operator, the new file system NIO2.0, Fork / Join
  • 32-bit machine up to 4GB of memory: Java heap memory allocation maximum (windows 1.5G, linux 2 ~ 3G)
  • JDK1.6 update14 Start: provides a pointer compression, by aligning operation like padding 64-bit 32-bit pointer compression, improved CPU cache utilization, will improve performance JVM 64. Between update14 ~ update22, by "-XX: + UseCompressedOops" display on the pointer compression, after update23, enabled by default.

OpenJDK/Oracle JDK:

  • OpenJDK:
    1.HotSpot with C ++, C and assembler to write a small amount of other content using Java (such as Base Class Library);
    2 is a Sun / Oracle JDK open source version (released in 2009 the first version);
    3. Compared with Oracle JDK7, a small amount of code other techniques instead.
  • Oracle JDK:
    1.HotSpot with C ++, C and assembler to write a small amount of other content using Java (such as Base Class Library);
    2. For personal development, not commercial.
  • OpenJDK market-based custom JVM:
    TaoBao JVM: strong business performance in one, but not universal, heavily dependent on CPU type: Intel CPU, compiler means using IntelC, CPP
    Complier, to promote the GC performance, crc32 instruction to achieve JVM intrinsic lower JNI (jav local interface) call overhead.

Guess you like

Origin juejin.im/post/5dce13795188254eb23dd562
JVM
JVM