Hi,

I have a few questions related to the Java String pool, I wonder if I can get 
some clarification from the experts?


1.       Location of the String pool

Following are from some of the posts I read but with conflicting information:


·         http://java-performance.info/string-intern-in-java-6-7-8/

“In those good old days [before java 7] all interned strings were stored in the 
PermGen – the fixed size part of heap mainly used for storing loaded classes 
and string pool.”  … ”in Java 7 – the string pool was relocated to the heap. 
... All strings are now located in the heap, as most of other ordinary objects”

Above statement suggests that both the interned strings and the string pool are 
in the PermGen prior to java 7 but being relocated to the heap in 7.


·         
https://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html

“Objects are created on the heap and Strings are no exception. So, Strings that 
are part of the "String Literal Pool" still live on the heap, but they have 
references to them from the String Literal Pool.”

This post suggests that string literals are created on the heap as other 
objects but did not tie that to any java version.


·         
http://www.javamadesoeasy.com/2015/05/string-pool-string-literal-pool-string.html

“From java 7 String pool is a storage area in java heap memory, where all the 
other objects are created. Prior to Java 7 String pool was created in permgen 
space of heap.”

So prior to java 7 the string pool was in the PermGen; beginning with 7 it’s in 
the heap. Same as the 1st post.

My questions are:

1.       Where is the string pool located prior and after java 7

2.       Are the string literals & interned strings objects created in the 
PermGen prior to java 7 then being created on the heap after?



2.       Can string literals be garbage collected?



The post 
@https://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html 
says “Unlike most objects, String literals always have a reference to them from 
the String Literal Pool. That means that they always have a reference to them 
and are, therefore, not eligible for garbage collection.” But this one 
@http://java-performance.info/string-intern-in-java-6-7-8/ says “Yes, all 
strings in the JVM string pool are eligible for garbage collection if there are 
no references to them from your program roots.” Are they both true under 
certain conditions?




Appreciate your help,
Jun

Jun Zhuang
Sr. Performance QA Engineer | 
Hobsons<https://www.hobsons.com/?utm_source=outlook&utm_medium=email&utm_campaign=banner_02.12.16_general>
T: +1 513 746 2288 | jun.zhu...@hobsons.com<mailto:jun.zhu...@hobsons.com>
50 E-Business Way, Suite 300 | Cincinnati, OH 45241 | USA



Upgraded by Hobsons - Subscribe Today
_______________________________________________
hotspot-gc-use mailing list
hotspot-gc-use@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/hotspot-gc-use

Reply via email to