Small white Ask a few questions about the Java Virtual machine memory allocation policy

Source: Internet
Author: User
Tags stub

Recently looking at Zhou Zhiming's "in-depth understanding of Java Virtual Machine", there are a few questions do not understand, I hope you help me to answer.
Let's talk about the environment I'm experimenting with:

Operating system: Mac OS X 10.11.6 EI Capitanjava Environment: Java version "1.8.0_92" Java (TM) SE Runtime Environment (build 1.8.0_92-b14) Java Ho Tspot (TM) 64-bit Server VM (build 25.92-b14, Mixed mode)

1. I found that in the younger generation, even if I was just an empty class, without any memory allocation work, the Eden Zone memory would still be part of the footprint, as in the following example:

public class Blankedclasssize {public static void main (string[] args) {//TODO auto-generated method stub}}

Virtual Machine parameter settings:

-verbose:gc-xx:+useserialgc-xx:+printgcdetails-xmx20m-xms20m-xmn10m

The virtual machine GC situation is as follows:

Heapdef New Generation Total  9216K, used1164k[0x00000007bf000000, 0x00000007bfa00000, 0x00000007bfa00000) Eden Space 8192K,  14% used [0x00000007bf000000, 0x00000007bf1231d0, 0x00000007bf800000) from Space 1024K,   0% used [0x00000007bf800000, 0x00000007bf800000, 0x00000007bf900000)   to Space 1024K,   0% used [0x00000007bf900000, 0x00000007bf900000, 0x00000007bfa00000) tenured generation   Total 6144K, used 0K [0x00000007bfa00000, 0x00000007c0000000, 0x00000007c0000000) The space 6144K,   0% used [ 0x00000007bfa00000, 0x00000007bfa00000, 0x00000007bfa00200, 0x00000007c0000000) metaspace       used 2666K, capacity 4486K, committed 4864K, reserved 1056768Kclass space    used 289K, capacity 386K, committed 512K, reserved 1048576K

Question 1: What is the memory here?

2. When a GC is performed by the young generation, since the young generation GC collects memory using a replication algorithm, why is the Eden region not 0 after a minor GC is normally performed? What is taking up the memory? Examples are as follows:

public class MINORGC {    private static final int_1mb = 1024*1024;        public static void Main (string[] args) {        //TODO auto-generated method Stub        TESTEDENGC ();    }    public static void Testedengc () {        byte[] allocation1,allocation2,allocation3,allocation4,allocation5, Allocation6;        ALLOCATION1=NEWBYTE[_1MB];        ALLOCATION2=NEWBYTE[_1MB];        ALLOCATION3=NEWBYTE[_1MB];        ALLOCATION4=NEWBYTE[_1MB];        ALLOCATION5=NEWBYTE[_1MB];        ALLOCATION6=NEWBYTE[_1MB];}    }

Virtual Machine parameter settings:

-verbose:gc-xx:tenuringthreshold=1-xms20m-xmx20m-xmn10m-xx:survivorration=3-xx:+printgcdetails-xx:+useserialgc

Virtual Machine GC Condition:

[GC (Allocation Failure) defnew: , 0.0032985 secs] 6029k->5450k (18432K), 0.0033216 secs] [times:user=0.00 sys=0.00, real=0.00 secs]heapdef New Generation total 8192K, used 2440K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf60000 0) Eden Space 6144K, 17% used [0x00000007bec00000, 0x00000007bed0f748, 0x00000007bf200000) from space 2048K, 66% used [0x0 0000007bf400000, 0x00000007bf5529b0, 0x00000007bf600000) to space 2048K, 0% used [0x00000007bf200000, 0x00000007bf20000 0, 0x00000007bf400000) tenured generation total 10240K, used 4096K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0 000000) The space 10240K, 40% used [0x00000007bf600000, 0x00000007bfa00040, 0x00000007bfa00200, 0x00000007c0000000) Metaspace used 2666K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 289K, capacity 386K, com Mitted 512K, reserved 1048576K 

Question 2: According to 6026k->1354k (8192K), after the GC, allocation1 into the survivor1,allocation2~4 into the old age area, when there is still 1354K memory in Eden is occupied, what is occupied? According to 6029k->5450k (18432K), when the GC is known, the Java heap memory is reduced by 579K, and whose memory is reduced (obviously new objects can be reached without being recycled)?

3. When allocating memory to new objects, because the young generation of space is not enough, a minor GC will occur, the young generation of still surviving objects copied to the old age area, to make room for new objects, according to my experiment, if the old age area memory is not enough to copy the younger generation of objects past but enough to store new objects, (There will be a guarantee failure at this point) and the new object will be placed directly into the old age, as in the following example:

public class MINORGC {private static  final int_1mb = 1024*1024;  public static void Main (string[] args) {//TODO auto-generated Method Stub testallocation ();    } public static void Testallocation () {byte[] allocation1,allocation2,allocation3,allocation4;    Allocation1 = NEWBYTE[2*_1MB];    Allocation2 = NEWBYTE[2*_1MB];    Allocation3 = NEWBYTE[2*_1MB];  Allocation4 = NEWBYTE[4*_1MB]; }}

The virtual machine parameters are set as follows:

-verbose:gc-xms16m-xmx16m-xmn10m-xx:+printgcdetails  -xx:survivorratio=8  -xx:+ Heapdumponoutofmemoryerror-xx:maxtenuringthreshold=15-xx:+useserialgc

The GC situation is as follows:

[GC (Allocation Failure) [defnew(Promotion failed): 7144k->7474k (9216K), 0.0028055 secs][tenured:4096k->4096k (6144K), 0.0015627 secs] 7144k->6473k (15360K), [metaspace:2660k->2660k (1056768K)], 0.0044048 secs] [times:user=0.00 sys =0.00, real=0.00 secs]heapdef New Generation total 9216K, used 6555K[0x00000007bf000000, 0x00000007bfa00000, 0x00000007bfa00000) Eden Space 8192K, 80% used [0x00000007bf000000, 0x00000007bf666ed0, 0x00000007bf800000) from space 1024K, 0% used [0x00000007bf900000, 0x00000007bf900000, 0x00000007bfa00000) to space 1024K, 0% used [0x00000007bf800000, 0x00000007bf800000, 0x00000007bf900000)tenured generation total 6144K, used 4096K[0x00000007bfa00000, 0x00000007c0000000, 0x00000007c0000000) The space 6144K, 66% used [0x00000007bfa00000, 0x00000007bfe00020, 0x00000007bfe00200, 0x00000007c0000000) Metaspace used 2666K, capacity 4486K, committed 4864K, re Served 1056768Kclass space used 289K, capacity 386K, committed 512K, reserved 1048576K

According to the above output, it can be seen that the GC process, the young generation of 7144k->;7144k (9216K), and did not transfer the young generation of objects away, while the old age 4096k->4096k (6144K), tenured generation Total 6144K, used 4096K, indicates that Allocation4 was transferred directly to the old age.

3: Is this the case that the virtual opportunity automatically sets the large object threshold?? Put new objects directly into old age?

The above three questions let me this virtual machine small Bai think not its solution, also hope everybody help me to explain, here thanked.

Small white Ask a few questions about the Java Virtual machine memory allocation policy

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.