• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access the String litral pool?  RSS feed

 
Sudhanshu Gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
is there any way we can access the global String literal pool?
say print the litrals in the pool at any given time or calculate the memory usage by the pool?

please help.


thanks & regards

Sudhanshu Gupta
 
Vijitha Kumara
Bartender
Posts: 4001
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudhanshu Gupta wrote:is there any way we can access the global String literal pool?
say print the litrals in the pool at any given time or calculate the memory usage by the pool?

You can access the SCP through intern() method of the String class, that is if you need to find a reference from a SCP for a given String or need to add a String to the SCP. SCP is for JVM's internal usage, so not sure whether it's possible to access the values in the SCP etc..
 
Sudhanshu Gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Vijitha Kumara
thank you very much.
I knew about the intern() method.
I was just wondering if there is anyway to access the pool.

I read somewhere that Console.readPassword() method returns a char array
of security reasons to prevent a hacker to read the password from the string pool.
This made me think does java allows access to the pool?

 
Vijitha Kumara
Bartender
Posts: 4001
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudhanshu Gupta wrote:I read somewhere that Console.readPassword() method returns a char array
of security reasons to prevent a hacker to read the password from the string pool.

To minimize the lifetime of sensitive data in memory it is adviced to manually make the char array empty. It's described in the Console API. But it has nothing to do with the String pool though.
 
Sudhanshu Gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Vijitha
Thanks. I got your point.
however i really think lifetime of a string data in the memory is certainly related to the SCP.
The lifetime of a string constant is longer than other objects as it is preserved in the SCP
by the JVM. Thus
To minimize the lifetime of sensitive data in memory it is adviced to manually make the char array empty.


so that it becomes available for GC.

About accessing the contents of a part of memory (including the SCP) should be a matter of some hardware interaction techniques.
so we dont need to discuss it here.

I just wanted to clarify if java provides any way to access the contents of the SCP. And that has already been clarified
thanks to you.
Thank you again Vijitha for your inputs.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!