Roedy said:
I was under the impression all string constants lived in the same pool
along with the interned strings. That would imply a shared constant
pool since day 1. Have I had this wrong since Java 1.0?
Yeah, probably the answer is not a good one. Blurring
the compiletime format of byte code with the runtime
representation of a string.
But I guess there is a difference between Hotspot
and Dalvik in compiletime, the Hotspot Bytecode has
different pools per class, and the Dalvik has a single
pool.
What this implies for the runtime, I don't know. I
even don't know whether the constants from the pools
go into memory via intern(). The constant pool can
also have floats etc.. And there are complications
such as:
"Class data sharing (CDS) is a feature introduced in J2SE 5.0 that is
intended to reduce the startup time for Java programming language
applications, in particular smaller applications, as well as reduce
footprint. When the JRE is installed on 32-bit platforms using the Sun
provided installer, the installer loads a set of classes from the system
jar file into a private internal representation, and dumps that
representation to a file, called a “shared archive”. If the Sun JRE
installer is not being used, this can be done manually, as explained
below. During subsequent JVM invocations, the shared archive is
memory-mapped in, saving the cost of loading those classes and allowing
much of the JVM's metadata for these classes to be shared among multiple
JVM processes. etc.."
http://openjdk.java.net/groups/hotspot/docs/RuntimeOverview.html#VM Class Loading|outline
Possibly the best idea is to say it is implementation
dependent what happens with the Strings in the constant
pool. You can try the following test code:
class A {
String t = "hello";
}
class B {
String t = "hello";
}
if (A.t == B.t) {
System.out.println("yes");
} else {
System.out.println("no");
}
The bottom line could be, that we are not in position to
say what the above program does alone from the Java
Language Specification, since it is JVM implementation
dependent. But I might be wrong.
Bye