Class StringPool
- java.lang.Object
-
- com.tonic.analysis.execution.heap.StringPool
-
public class StringPool extends Object
Interning pool that materializes java/lang/String heap objects in char-array or compact byte-array layout.
-
-
Constructor Summary
Constructors Constructor Description StringPool(AtomicInteger nextId)Creates an empty pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all pooled strings.ObjectInstanceintern(String value)Returns the pooled string object for a value, creating it on first use.booleanisInterned(String value)Checks whether a value already has a pooled object.booleanisUsingCompactStrings()voidsetUseCompactStrings(boolean compact)Selects the layout used for newly created string objects.intsize()
-
-
-
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.
-
-