JVM Notes 3-java memory area run constant pool

Source: Internet
Author: User

1. The run-time-constant pool is part of the method area in the thread sharing area.

2. Running a constant pool is used for various arguments generated by the compilation period, symbolic references, which are stored in the run-time pool that will be used to access the method area after the class is loaded.

Look at the code below,

 Public class Test {    publicstaticvoid  main (string[] args) {        = "abc";        = "abc";         New String ("abc");         = = s2)        ; = = s3);}    }

It is obvious that S1 = = S2 is true, and S1 = = S3 is False.

Because the reference to the base data type and the abstract data class is placed in the local variable table of the stack frame. So the S1 S2 is placed in the local variable table of the stack frame. and the "ABC" object is placed in the run-time constant pool.

And this constant pool has a clock data structure called stringtable, its data type can be understood as hashset. And the hashset is disordered and not repeatable. So put the defined "ABC" into it for the first time.

The second definition found in the constant pool has "ABC", then no longer create "ABC", at this time S1 and S2 are referring to the same "ABC". so S1 = = S2 is true.

The S3 is then put into the Java heap by a new instance, and S3 refers to the "ABC" in the heap. so S1 = = S3 is False.

What will happen if we change the S3? As shown in the following code:

 Public class Test {    publicstaticvoid  main (string[] args) {        = "abc";        = "abc";         New String ("abc");         = = s2)        ; = = S3)        ; = = S3.intern ());}    }

It is obvious that System.out.println (S1 = = S3.intern ()) is true. Because S3.intern () takes the "ABC" in the heap and puts it into the constant pool, there is already "ABC" in the constant pool, so directly the

"ABC" is quoted to S3, so System.out.println (S1 = = S3.intern ()); True, this forms the run-time constant.

Note The OutOfMemory memory overflow exception is thrown when the constant pool is full.

Here, by the way, is called direct memory.

Direct memory: Not part of the data area when the virtual runtime is running. Of course, this is not the memory area defined in the virtual machine specification. It is an external area of memory.

NiO is often used to external memory. It also throws a OutOfMemory memory overflow exception when the external memory is full. This is also the area to consider when throwing this exception.

JVM Notes 3-java memory area run constant pool

Related Article

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.