JVM of Java Basics

Source: Internet
Author: User

A JVM is a virtual machine that runs Java bytecode, including a set of bytecode instructions, a set of registers, a stack, a garbage collection, a heap, and a storage method domain.
Run:
Java source file---compiler---bytecode file
Byte code file-->jvm--> machine code
, when a program runs from the beginning, the virtual machine begins to instantiate, and multiple instances of the virtual machine are present when several programs start. When the program exits or shuts down, the virtual machine instance dies and data cannot be shared between multiple virtual machine instances.
1.8JDK uses the JRockit two elite of Sun's hotspot and Bea company to form the JVM

1. Class instantiation order, such as parent class static data, constructors, fields, subclass static data, constructors, fields, their order of execution
A: First static, the father after the son.
Static First: parent static > Child static
Precedence: Parent > Subclass Static Code blocks > non-static code blocks > Constructors
The instantiation process of a class:
1, static code block in the parent class, static for the current class
2, sequential execution of normal code blocks of the parent class
3, the constructor of the parent class
4, subclass generic code block
5, the constructor of the subclass (current class), executed sequentially.
6, the execution of the subclass method,

JVM memory allocation: Virtual machine stack (with a stack frame inside), heap, method area, program counter, local method stack
Method stack: Generated when thread is created, stack frame is produced when method executes
Local method stack: servicing the native method
Method Area: Is the area where each thread shares data, including the class information that is loaded by the virtual machine, the constant with the final decoration, the string object, and the static variable (Chang) of the statics modifier.
Heap: All new operations in Java code
Non-heap: JVM's own area, method area, JVM internal processing, class method, construction method, etc.
Program counter: A small amount of memory space that represents the line number indicator of the byte code executed by the current thread, recording the line number executed. Program counters are thread-private.
Virtual machine stack: The memory model used to describe the Java method, each method executes at the same time creates a stack frame, the stack frame is stored in the method of the local variables, the operation of the data, the method of the entry return value and other information. A reference to a basic data type and object (a pointer to an object in the box heap memory).

JVM garbage collection mechanism:
Generational garbage collection mechanism: Different object life cycles are different. The different life cycle objects are placed on different generations, and the most suitable garbage collection methods are used for recycling in different generations.
The JVM is divided into three generations: the young generation, the old generation and the enduring generation,
Young generation: Store all newly generated objects;
Older generation: In the younger generation, the object that the N garbage collection still survives will be put into the old age, and ancient capital is the object of some long life cycle;
Persistent generation: Used to store static files, such as Java classes, methods, and so on.
The new generation of garbage collectors is named "minor GC", and the GC for Laosheng generation is named "full GC or Major GC". The full GC is enforced with System.GC ().
There are two ways to determine whether an object needs to be recycled:
1. Reference counting
When an object has a reference count of 0 o'clock, garbage collection is possible.
2. Object reference Traversal
If an object cannot arrive from one (at least one) of these root objects, it is garbage collected. During the object traversal phase, the GC must remember which objects can be reached in order to delete the Unreachable object, which is known as the markup (marking) object.
Conditions for triggering GC (garbage Collector):
1) The GC runs in the lowest priority thread, typically when the application is idle and no application threads are invoked at run time.
2) When the Java heap is low on memory, the GC is called.

What is a complete GC process (from YGC to FGC) in the JVM, focusing on how the object is promoted to the old age, etc.
A: The object priority in the Cenozoic region allocation, if there is not enough space, Minor GC;
Large objects (which require a large amount of contiguous memory space) go directly into the old age, and long-lived objects enter the old age state. If the object is still alive after the birth of the new generation and after the first MGC, the age of +1, if the age exceeds a certain limit (15), is promoted to the old age state.

You know what kinds of garbage collectors, their pros and cons, focus on the following cms,g1:
Serial collector: Pauses all application threads to work, single thread.
Parallel collector: The default garbage collector. Pause all applications, multithreading.
G1 Collector: For large heap areas. Heap memory is separated, and concurrent recycles.
CMS Collector: Multi-threaded scan, mark the instance that needs to be recycled, clear.

Tell me about your understanding of environmental variables Classpath? If a class is not under Classpath, why does it throw a classnotfoundexception exception, and if it does not change the class path, how can the class be loaded correctly?
Classpath is an environment variable for the Javac compiler. Its role is related to import, the package keyword. The package location is set CLASSPATH when the compiler faces the import packag this statement, it first looks up the directory specified by Classpath and examines the existence of the subdirectory java/util, Then find the compiled file (. class file) that matches the name. If you do not find it will be an error!
Dynamic Load Package

Say strong references, soft references, weak references, virtual references, and relationships between them and the GC:
Strong references: References such as new objects,
As long as the strong references are still there, they will never be recycled
Soft references: References but non-required objects, memory overflow exceptions, before recycling
Weak references: Objects that are not required can survive until the next garbage collection occurs.
Virtual reference: Has no effect on the time to live and is notified when garbage is collected.

JVM of Java Basics

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.