Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java Virtual Machine Basics     - Linux environment MySQL master-slave synchronization (Database)

- How to install and configure in Ubuntu 14.10 'Weather Information Indicator' (Linux)

- Spark local development environment to build (Server)

- Use source packages compiled and installed GCC5.1 in Mac OS X 10.10.3 (Linux)

- Node.js simple interface server (Server)

- Ubuntu 15.04 / 14.04 install Ubuntu After Install 2.6 (Linux)

- RedHat Linux 9.0 under P4VP-MX motherboard graphics resolution of problems (Linux)

- Install Debian Linux with R on the Android system (Linux)

- PXE + Kickstart automatically install CentOS 6.5 (Linux)

- jdbc Oracle database connection string writing pluggable (Database)

- C ++ 11 feature: decltype keywords (Programming)

- CentOS 6.6 running level (Linux)

- Five strokes to find out the IP address you want to know (Linux)

- Linux Systems Getting Started Learning: Configuration PCI passthrough on a virtual machine (Linux)

- Quickly locate the mistakes by gdb location (Programming)

- MySQL management partition table (Database)

- CentOS install SVN server configuration and automatically synchronized to the Web directory (Server)

- Android Activity launchMode (Programming)

- Kali Linux virtualbox rc = Error 1908 workaround (Linux)

- Linux Desktop allows exceptionally different launch applications (Linux)

 
         
  Java Virtual Machine Basics
     
  Add Date : 2018-11-21      
         
         
         
  EDITORIAL

Before boss let do some outsourcing interview, my question is very simple:

Tell us about the work more interesting problem solved.
HashMap use need to pay attention to the point.
The first major problem is to look at the other gold project experience, the second question is whether a test to know some details, such as HashMap is not thread-safe, use HashMap cache to do so may lead to memory leaks, etc., feel problems can also be designed to: D ~ but saw other colleagues on the subject of the tears collapse:

Design Patterns XXX
Garbage collection XXX
Rub, how I do not feel this problem. . .

It feels like a virtual machine operating system, compiler: the very tall. But Java programs run on top of the problems encountered have to go to troubleshooting, performance optimization not have to go, or basic knowledge required!

Memory Management

Java Virtual Machine in the implementation process will it manages memory is divided into a number of different data regions

Functions of each part as follows:

Regional function
The program counter can be seen as the current thread of execution bytecode line number
VM stack for local variables, stack operation etc.
Native method stack is similar to the virtual machine stack, but is to serve the local method
Heap storage objects
Method area to store such information, constant, static variables, JIT compiled code, etc.
When the runtime constant pool compiled a variety of literal and symbolic use
External memory via direct memory allocation NIO
In memory management is a relatively large piece of content GC (garbage collection), is the so-called garbage collection will reclaim the memory garbage out. Then the first question: What is spam?

Reference counting algorithm: The reference number 0 objects.
Root search algorithm: find references from GC Roots along the object.
Here are mentioned in references after JDK 1.2 Java has been the concept of reference were expanded, then the second question: What type of reference?

Strong reference: Object o = new Object () that are strong references.
Weak Quote: Also useful but not essential, to be recovered before the OOM.
Soft Quote: weaker reference to be recovered in the next GC time.
Phantom reference: the weakest, the only action is to be notified when the object is recovered.
There is only strong reference to the impact on the lifetime of an object. It evolved in the course of the development of many of the virtual machine garbage collection algorithm, such as:

Mark - sweep algorithm
Replication algorithm
Mark - Collation Algorithm
Generational collection algorithm
In the actual device is used in the recovery of these types of combination algorithms, such as seen from VisualVM Memory is such

On the whole a generational collection algorithm, and S0, S1 can be seen as two parts labeled - Collation Algorithm. Then the third question: Common CMS garbage collector implementation process like?

Initial Tags: GC Roots objects directly associated with.
Concurrent mark: Root Tracing.
Relabeled: repair because the program run lead mark fluctuates.
Concurrent Clear

Can be seen only in the initial marking and re-marking the only time required Stop The World, and other user threads are executed together, do not think this is perfect, parallel execution process will consume some CPU resources.

Code execution

The Java source threw JVM certainly can not be executed, you need to use javac compiled into class files for the job, then the first question: What is the structure of the class file?

Constant pool
Access Flag
Class index, the parent index and index interfaces
Field Table
Method Table
Property sheet
Virtual machine specification does not specify at what time you want to load the class, but sets out in the face of new, reflection, the parent class, Main needs initialization is complete.

Performed by ClassLoader class load in a virtual machine, this place needs to understand:

Two classes are the same, except for the name of the outer class ClassLoader also need to determine whether or not the same.
Parents delegate model is not a hard constraint.
After the completion of the class loader can begin, and things related to the operation and threads are placed in the stack frame, its structure is as follows:

Property role / meaning
Local variables Local variable table method parameters and methods defined inside
Operand stack is used for instruction
Dynamic connection point to the runtime constant pool reference method stack frame belongs
Method returns the address of the top position of the method call this method
Additional information debugging information
Which method performs specific call is a headache, you need to be addressed:

Static assignment: the same name but different parameter types.
Dynamic assignment: The replication method inheritance.
Bytecode instructions are stack-based operations, such as 1 + 1 to complete such a calculation, the corresponding command as follows:

iconst_1 // constants 1 onto the stack
iconst_1
iadd // adding the two values of the stack and the stack, and then put the result back into the stack
istore_0 // top of the stack into the value of the local variable table 0 Solt
Interpreted benefits are downloaded fast start, but OK also very clear: to run slow. JIT it is used to solve this problem, the method can be called multiple times, the body of the loop is executed many times compiled to native code.

Optimization is a very interesting topic, I remember participating in a game when the code into gcc -O3 compiled after the printf () did not export. . In the JIT more common optimization methods are:

Description means
Common subexpression elimination If an expression has been calculated, and then the latter does not need to repeat the calculation
Array bounds checking is not necessary to eliminate once without missing check
Copy the code within the method of linking to the calling process
Escape analysis to determine whether the object may be referenced outside the method
Program execution will be related to memory operations, defined in Java eight operations to complete:

Operation Meaning
lock the variable identified as a thread exclusive state
unlock release variables
read the variable read from main memory into the working memory
load variable value to be read into the working memory copy
use the working memory of the variable is passed to the execution engine
Assign the value passed to the engine returns a copy of the working memory
store the working memory of the variable is passed to main memory
write the variable obtained from the working memory write variables corresponding to the main memory
Here it is necessary to talk about the volatile role in the use of time to be able to understand the following two:

Guaranteed variable for all threads are visible.
Prohibit instruction rearrangement optimization.
If all the operations in Java programmers need to control it, there will be a lot of duplicate code, and write very tired, so we can advance two parallel operating principles to determine whether there is a conflict:

Program sequence rules: a single-threaded programs written in accordance with the order.
Tube Blocking rule: unlock must precede the lock.
volatile variable rules: first occurrence of a write operation to the read operation.
Thread Start Rule: Thread.start () prior to thread any other method.
Thread Termination rules: thread in all operations prior to the termination of this thread detection.
Thread interrupts rules: interrupt () prior to the break detection.
End of rule objects: the object is initialized prior to the completion of its finalize () method.
Transfer rules: If A precedes B, B precedes C, then A precedes C.
Thread the underlying implementation is quite troublesome, but should at least know how the state of Thread conversion
     
         
         
         
  More:      
 
- Linux System Getting Started Tutorial: Using the Linux common commands (Linux)
- Linux server Php injection prevention (Linux)
- Efficient Linux Shell - Shell special characters Summary (Linux)
- Linux use logs to troubleshoot (Linux)
- The need to avoid a gap of InnoDB lock (Database)
- A step by step teach have to install multi-node cluster configuration Hadoop (Server)
- MySQL query optimization: profile function (Database)
- Ubuntu 14.04 / 14.10 how to install Mate 1.10.0 (Linux)
- 10 example of the detection memory usage free Linux commands (Linux)
- Additional SQL Server 5123 database reported error (Database)
- Red Hat Linux mount U disk (Linux)
- Redis performance test (Database)
- Getting the Linux shell flow control statements (Programming)
- Linux dmidecode command detail (Linux)
- Linux file and directory management - ls, cp, mv (Linux)
- PSUADE installation under Linux (Linux)
- Linux system security infrastructure Highlights (Linux)
- Install the latest ATI / Nvidia graphics driver on Ubuntu (Linux)
- The several technical presentation Raid under Linux (Linux)
- Ubuntu firewall installation and configuration (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.