Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Fundamentals of the Java virtual machine memory management principles     - Binary tree traversal recursive and non-recursive (cyclic) traversal achieve (Programming)

- MongoDB replication instance (Database)

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

- Windows Remote Desktop Management CentOS 6.4 (Linux)

- Linux Getting Started tutorial: XWindow what (Linux)

- Laravel 4.2 Laravel5 comprehensive upgrade Raiders (Server)

- Ubuntu How to install screen recording tool Simple Screen Recorder 0.3.1 (Linux)

- Teach you to diagnose problems with strace (Linux)

- C ++ pointer of the (error-prone model) (Programming)

- Parameters of the extra port MySQL 5.6 (Database)

- Oracle 11g on Linux system boot from the startup settings (Database)

- build Android environment on Ubuntu 12.04 (Server)

- CentOS 6.5 installation using a data recovery software extundelete (Linux)

- RMAN backup file is much larger than the size of the database Cause Analysis (Database)

- Configuring Eclipse Note Templates (Linux)

- CentOS 6.6 installation certification system based on the ftp service (Server)

- CentOS7 Minimal minimize installation and then install the GNOME graphical interface (Linux)

- How to manage the time and date at systemd Linux systems (Linux)

- Oracle Database ORA-01555 snapshot too old (Database)

- Linux fixes fatal error: x264.h: No such file or directo (Linux)

  Fundamentals of the Java virtual machine memory management principles
  Add Date : 2018-11-21      
  Jdk: Java programming language, Java virtual machine, Java API class libraries.

Jdk is used to support Java application development environment minimal.

Jre: Java API class libraries in Java SE API subset, Java virtual machine.

Jre supports standard Java environment running.

Program Counter Register: less memory space, can be seen as byte code executed by the current thread line number indicator. Only a Java Virtual Machine Specification no area of ​​provision OutOfMemoryError.

VM Stack: life cycle and the same thread, which describes the Java memory model implemented method: Each method executed simultaneously creates a stack frame for storing local variable table, operand stack, dynamic linking, exporting methods and other information.

Two kinds of exception: StackOverflowError, OutOfMemoryError

Native Method Stack: similar VM Stack, combined direct and Sun HotSpot!

Heap: when the biggest piece of memory, virtual machine start-up, the sole purpose is to store the object instance.

Method Area: class information storage has been loaded in the virtual machine, constants, static variables, even if the compiler compiled code and other data. Java Virtual Machine specification referred to as a logical part of the heap, but an alias called Non-Heap (non-heap), or permanent generations.

Part of the method area: Runtime Constant Pool

Direcrt Memory: not part of the data area of ​​the virtual machine is running, nor is it a virtual machine specification defines the memory area.


To create an object - Keyword new

Memory partitioning: a pointer collision (regular heap memory, allocating memory by moving the pointer), the free list (irregular heap memory allocated memory by updating the list of memory).

TLAB (Thread Local Allocation Buffer): thread-local buffer allocated for the created thread will be allocated a separate space, to avoid conflicts of memory allocation, memory allocation enhance efficiency.

Memory layout object: the object header (Header), instance data (Instance Data) and its padding (Padding).

Access positioning objects: Java program by reference the stack (reference) data to manipulate specific objects on the heap.

Information: handle and direct pointer (Sun HotSpot).

OutOfMemoryError exception combat

Tools: Eclipse Memory Analyzer

Memory Leak Memory Leak, Memory Overflow Memory Overflow


Determining whether the object of death - heap memory

1, reference counting algorithm: add a reference to the object counter, place whenever there is a reference to it, the counter is incremented; when referring to the failure, the counter is decremented by one; any time counter reaches zero object is no longer being used.

2, reachability analysis algorithm: The "GC Roots" objects as a starting point down the search, when an object has no references to GC Roots chain attached to prove this object is not available.


To be or not to be!

1, using the algorithm determine whether the object is to use;

2, if no longer being used, the tag and filter;

Brush Option Is it necessary to perform finalize () method, without the need to perform the following:

l did not cover objects finalize () method;

l finalize () method has been called by the virtual machine;

3, if it is necessary to perform, put the object placed in the F-Queue queue;

4, automatically create a virtual machine from the low-priority Finalizer thread to execute it, that is, from the virtual machine to trigger the execution;

5, GC in the queue object second mark, that is, to re-establish a reference to an object, you can remove the recycling collection;

Note: Any finalize an object () method will only be called once the system!


Method zone recovery

Two main parts: the constant waste and useless classes

Control parameters

-Xnoclassgc: Turn off the virtual machine class garbage collection function;

-verbose: class: monitor how many classes are loaded;

-XX: TraceClassLoading, -XX: TraceClassUnLoading: print class is loaded and unloaded process information;

Note: The extensive use of reflection, dynamic proxies, CGLib ByteCode framework and other dynamically generated JSP and OSGI such scenes frequently custom ClassLoader needs to have a virtual machine class uninstall feature to ensure permanent generations will not overflow!


Garbage collection algorithm

1, mark - sweep algorithm: prone to memory fragmentation

2, the copy algorithm: two heap is divided into different areas: the new generation (Young) is mainly used to store newborn object old's (Old) main storage applications long life cycle memory objects. Cenozoic (Young) has been divided into three areas: Eden, From Survivor, To Survivor.

By default, the new generation (Young) and the old age of (Old) is the ratio of 1: 2

Default, Edem: from: to = 8: 1: 1

3, Mark - Collation Algorithm

4, generational collection algorithm

HotSpot GC algorithm

Enumerate the root: check individual; (Stop The World, must halt execution of all Java threads execute GC)

In OopMap assistance, HotSpot can quickly and accurately complete the enumeration.

Safety point: only safe point to begin GC pause

Security Zones: extended security points in the security zone can begin GC pause

Garbage collector: garbage collection implementation.

GC logs

GC common parameters

Memory allocation strategy

1, the object priority assignment in Eden: the new generation GC (Minor GC), the old age of GC (Major GC / Full GC)

2, large objects directly into the old year:

3, long-lived objects will enter the old year: for each object defined age (Age) counter. Object born in Eden and after the first Minor GC after still alive, and can be Survicor hold, it will be moved to Survivor space, and the age of the object is set to 1. Each object Survivor "survive" a Minor GC, the age is increased 1, when the age to a certain extent (default 15), was promoted to the old era.

4, Dynamic Object Age determination: The virtual machine is not always claim to a certain extent in order to target age old's promotion, if Survivor space of the same age greater than half the total size of all the objects in space Survivor, age greater than or equal to the age of the object can be direct access to the old era.

5, space allocation guarantees: continuous space old age is greater than the total size of the new generation of the object or the average size of the previous promotion will be Minor GC, otherwise it will be Full GC.

JDK1.5 in, getAllStackTraces () is used to obtain the virtual machine StackTraceElement objects for all threads.

HSDIS: JIT generated code disassembly.

JConsole: Java monitoring and management console based on JMX.

VisualVM: Combine Troubleshooting Tools
- PostgreSQL with the C Completing the storage process instances (Database)
- Linux environment variable configuration and save places (Linux)
- Normal start Lazarus 1.0.8 under Ubuntu (Linux)
- The difference between Objective-C language nil, Nil, NULL, NSNull (Programming)
- Linux log management make the system more secure (Linux)
- Linux installation Jetty deployment under RedHat5 8 (Linux)
- Chkconfig command Detailed service is added and shut down the system in two ways to start service under Linux (Linux)
- Linux ln command - create a file / directory link (Linux)
- How to install and use the malware detection tool LMD and ClamAV antivirus engine on Linux (Linux)
- Linux system security check method (Linux)
- How to fix fatal error: security / pam_modules.h: No such file or directory (Linux)
- How UTorrent download the ISO image from the command line (Linux)
- Android will save the picture to see the album and timely (Programming)
- How a lot of blocking malicious IP address in Linux (Linux)
- Ubuntu ADSL dial-up Internet access (Linux)
- shell script: the number of characters in the text to print no more than 6 words (Programming)
- How to restart after a crash Cinnamon (Linux)
- Hive handle count distinct inclination to produce data processing (Database)
- Linux cron job (Linux)
- To disable the function by pressing Ctrl-Alt-Del to restart the system in RHEL / CentOS 5/6 (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.