1 2 Previous Next 18 Replies Latest reply: Jan 24, 2012 9:46 AM by jtahlborn Go to original post RSS
      • 15. Re: When String instances in Constant Pool will be GC'ed?
        796440
        EJP wrote:
        So clearly String.intern() does use the String constant pool.
        For literals that are already in it. That doesn't prove that the private String pool and the constant pool are the same,
        My code shows that literals, and the results of intern() go to the same place.
        It also doesn't prove that the constant pool is subject to GC, which is the topic of this thread. It isn't.
        The JVM spec citations I gave make it very clear that the constant pool can be subject to GC on a per-implementation basis.
        • 16. Re: When String instances in Constant Pool will be GC'ed?
          EJP
          So clearly String.intern() does use the String constant pool.
          For literals that are already in it. That doesn't prove that the private String pool and the constant pool are the same,
          My code shows that literals, and the results of intern() go to the same place. I agree. That still doesn't prove that the String pool and the Constant pool are the same thing. It proves that the String pool may defer to the CP for literals that are already in the CP. There is no wording anywhere that says they are the same thing, and there is wording that suggests they aren't.

          And what exactly is that private data structure in String? Is that really the constant pool? Please. It's simple. The CP is for string literals etc. The String data structure is for other interned strings. Long time since I saw the code but it's something like a WeakHashSet would be, and that's also why interned Strings can be GC'd. Except the literal ones. If you can construct a proof that a literal String can be GC'd I'd like to see it.
          The JVM spec citations I gave make it very clear that the constant pool can be subject to GC on a per-implementation basis.
          There is no such stament in what you quoted, at least I cannot find anything there at all about GC on several readings, but in any case 'can ... on a per-implementation basis' isn't the same thing as 'is'.

          What goes into the constant pool is string literals and other constants, e.g. large integers that don't fit into the bytecode instructions as immediate mode constants.
          • 17. Re: When String instances in Constant Pool will be GC'ed?
            796440
            EJP wrote:
            So clearly String.intern() does use the String constant pool.
            For literals that are already in it. That doesn't prove that the private String pool and the constant pool are the same,
            My code shows that literals, and the results of intern() go to the same place.
            I agree. That still doesn't prove that the String pool and the Constant pool are the same thing.
            Honestly, I don't think you're making any sense. Nothing in the spec suggests that there is a "string pool" that is separate from a "constant pool," and there's nothing in the String source code corresponding to any pool. I'm done debating it though.
            • 18. Re: When String instances in Constant Pool will be GC'ed?
              jtahlborn
              EJP wrote:
              And what exactly is that private data structure in String? Is that really the constant pool? Please. It's simple.
              What private data structure in String? in the source for jdk 1.6.0_27, String.intern() is a native method. in the openjdk 6 source code, that native impl calls JVM_InternString, which uses the StringTable. tracking that all through, i see that the constant pool interns all strings using this global StringTable. so i see now your assertion that they are technically different pools. they do, however contain references to the same String instances because every String in the constant pool is interned in the StringTable.
              1 2 Previous Next