Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Fundamentals of the Java virtual machine memory management principles     - Linux directory structure (Linux)

- Unix system security configuration (Linux)

- Install the Solaris 10 operating system environment over the network to sparc (Linux)

- CentOS7 install JDK (Linux)

- Windows7 system using Vagrant to build Linux virtualized development environment (Linux)

- Use GNU / Linux broadcasting of television programs (Linux)

- MySQL 5.6 database code changes (Database)

- Advanced network security tips Linux backdoor Technology and Practice (Linux)

- Oracle 11g + RAC + RHEL6.5 + udev + ASM + PSU installation summary (Database)

- How to install Linux Go Language (Linux)

- State and Linux nf_conntrack TCP disconnect time (Programming)

- Linux non-root user uses less than 1024 ports (Linux)

- Quagga use authentication on strengthening BGP session security (Linux)

- How to Install Suricata IDS on a Linux system (Server)

- Memcached and Redis (Linux)

- Access clipboard content across multiple vim instances in a terminal (Linux)

- Linux open handle limit adjustment (Linux)

- How to modify the SQL Server auto-increment value and the corresponding solution (Database)

- CKEditor + SWFUpload achieve a more powerful editor (Linux)

- Detailed Linux platform chip programming process (Programming)

  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
- You must ask yourself four questions before deploying Docker (Server)
- Shell Programming points to note about the function (Programming)
- KVM installation under CentOS 5.5 (Linux)
- Git you do not know about some of the things (Linux)
- Linux Mint 17.2 64 bit installation Docker and management software seagull (Linux)
- W and uptime command (Linux)
- Vim Common Command Summary (Linux)
- How to recover deleted files in Linux systems (Linux)
- Some problems and countermeasures Linux system calls exist (Linux)
- Python Basics: Search Path (Programming)
- Linux network cut package is not fully defragment (Linux)
- Linux virtual machine settings network, hostname ssh access (Linux)
- To configure Samba to share files with Windows under CentOS (Linux)
- Linux Command-line MySQL summary (Database)
- Ubuntu 15.10 installation and deployment Swift development environment (Linux)
- 10 Best Swift Tutorial examples (Programming)
- RHEL5 stalled due to power service error system can not start (Linux)
- Parts of the partition is not recognized after Debian mount mobile hard disk (Linux)
- Oracle table space is too large processing time (Database)
- 4 lvcreate example commonly used commands (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.