Java thousands ask _07JVM architecture (019) _ Run a constant pool is what

Source: Internet
Author: User

Click to enter _ more _java thousand ask

1. What is the run-time constant pool?

Run a constant pool (runtime Constant pool), which is part of the method area. In addition to information such as the version, field, method, interface, and so on, the class file contains a constant pool (Constant pool Table) that holds the various literal and symbolic references generated during the compilation period, which are stored in the constant pool after the class is loaded.

Learn about Java memory Management look here: How the JVM manages memory

The running constant is relative to represented, and it has an important characteristic: dynamic. Of course, dynamic constants with the same value are different from the constants we normally say, but they are all stored in the same memory area within the pool.

The Java language does not require constants to be generated at compile time, and new constants may be generated during run time, and these constants are placed in the running constant pool. The constants described here are: the basic type wrapper class (The wrapper class does not manage floating-point types, shaping only manages 128 to 127) and a string (you can also force a string into a constant pool by using the String.intern () method).

Learn about the basic type wrapper look here: What is the basic type wrapper
Example:

 Public classTestconst { Public StaticString const_a ="the const B";//compile-time into a constant pool     PublicString Const_b; PublicInteger const_b_i; PublicInteger Const_b_ii; PublicFloat Const_b_f; Public Static void Main(string[] args) {Testconst Testconst =NewTestconst (); Testconst.const_b ="the const B";//run-time into a constant poolTestconst.const_b_i = A;//run-time into a constant poolTestconst.const_b_ii = -;//More than 127, so the constant pool is not placedTestconst.const_b_f =2.0F//floating-point wrapper is not placed in a constant poolString Const_c ="the const B";//run-time into a constant poolInteger const_c_i = A;//run-time into a constant poolInteger Const_c_ii = -;//More than 127, so the constant pool is not placedFloat Const_c_f =2.0F//floating-point wrapper is not placed in a constant poolSystem. out. println (Const_a = = Const_c); System. out. println (Const_a = = Testconst.const_b); System. out. println (Testconst.const_b = = Const_c); System. out. println (Testconst.const_b_i = = const_c_i); System. out. println (Testconst.const_b_ii = = Const_c_ii); System. out. println (Testconst.const_b_f = = Const_c_f); }}

Operation Result:

True
True
True
True
False
False

Java virtual machines have strict specifications for each part of a class file, and each byte is used to store which data must conform to the specification so that it is loaded and executed by the virtual machine. However, for running a constant pool, the Java Virtual Machine specification does not require any details, and the virtual machines implemented by different providers can implement this memory area as they want.

Because the run-time-constant pool is part of the method area, it is limited by the memory of the method area and throws a Outofmemoryerror:permgen space exception when the constant pool is no longer able to apply to memory.

After Java 8, the method area is removed, replaced by the local meta-space, and the run-time-constant pool is placed in the local meta-space, which throws a outofmemoryerror:metaspace error if the area memory overflows.

Java thousands ask _07JVM architecture (019) _ Run a constant pool is what

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.