Class StringPool


  • public class StringPool
    extends Object
    Interning pool that materializes java/lang/String heap objects in char-array or compact byte-array layout.
    • Constructor Detail

      • StringPool

        public StringPool​(AtomicInteger nextId)
        Creates an empty pool.
        Parameters:
        nextId - shared heap id counter used for created objects
    • Method Detail

      • setUseCompactStrings

        public void setUseCompactStrings​(boolean compact)
        Selects the layout used for newly created string objects.
        Parameters:
        compact - true for the Java 9+ byte-array layout, false for char-array
      • isUsingCompactStrings

        public boolean isUsingCompactStrings()
        Returns:
        whether new strings use the compact byte-array layout
      • intern

        public ObjectInstance intern​(String value)
        Returns the pooled string object for a value, creating it on first use.
        Parameters:
        value - the string to intern
        Returns:
        the canonical heap object for the value
      • isInterned

        public boolean isInterned​(String value)
        Checks whether a value already has a pooled object.
        Parameters:
        value - the string to test
        Returns:
        true if the value is in the pool
      • size

        public int size()
        Returns:
        the number of interned strings
      • clear

        public void clear()
        Removes all pooled strings.