I tried to look at Java's String#intern()
method, but it's public native String intern();
In general, how is interning implemented? In String's case?
String Pool is a storage area in Java heap. String allocation, like all object allocation, proves to be a costly affair in both the cases of time and memory. The JVM performs some steps while initializing string literals to increase performance and decrease memory overhead.
String concatenation is implemented through the StringBuilder (or StringBuffer ) class and its append method. String conversions are implemented through the method toString , defined by Object and inherited by all classes in Java.
In Java, a string is a sequence of characters. For example, "hello" is a string containing a sequence of characters 'h' , 'e' , 'l' , 'l' , and 'o' . We use double quotes to represent a string in Java.
For Sun Java, start with JVM_InternString
, on line ~3639 of jvm.cpp
. Technically, the actual String method is in java/lang/String.c
, but it immediately calls JVM_InternString
. You can continue to StringTable::intern
in symbolTable.cpp
.
In a more abstract sense, the purpose of interning is to map equivalent strings to a single canonical one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With