Friday, November 19, 2004

String.intern()

The current project I'm currently work on doesn't currently make use of String.intern() - which is probably not that surprising since part of the codebase dates back from 1998. Genady has a good overview of the inner workings of intern(). Assuming you agree to the license over at the Sun Community Source License Download, you can download the appropriate JDK source code and look at the VM implementation. I have to admit I found the source very interesting, especially how the C++ classes have changed from JDK 1.3.1 to 5.0. One thing that surprised me was that intern() is a native method, I'd expected intern() to be implemented in Java and use a HashMap or similar. It's a shame that Sun's JavaDocs don't identify which methods are native.

Sun's memory allocator article made me wonder if the Java VM uses a special malloc for multi-processor machines. The JDK 5.0 appears to perform memory allocations via a macro that wraps os:malloc. Does anyone have any information on this?

1 Comments:

At 2:08 pm, Anonymous Anonymous said...

I don't understand what 1998 has to do with it? String.intern has been around from Java 1.0a.

 

Post a Comment

<< Home