• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

How to access the String litral pool?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic