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