diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java index ac358ac9521..229c710f7df 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java @@ -428,17 +428,18 @@ public class Names { } protected Name.Table createTable(Options options) { - boolean useStringTable = options.isSet("useStringTable"); - if (useStringTable) - return newStringNameTable(); boolean useUnsharedTable = options.isSet("useUnsharedTable"); if (useUnsharedTable) return newUnsharedNameTable(); - return newSharedNameTable(); + boolean useSharedTable = options.isSet("useSharedTable"); + if (useSharedTable) + return newSharedNameTable(); + boolean internStringTable = options.isSet("internStringTable"); + return newStringNameTable(internStringTable); } - public StringNameTable newStringNameTable() { - return StringNameTable.create(this); + public StringNameTable newStringNameTable(boolean intern) { + return StringNameTable.create(this, intern); } public SharedNameTable newSharedNameTable() { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/StringNameTable.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/StringNameTable.java index 811814ed851..b8106a43b7c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/StringNameTable.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/StringNameTable.java @@ -38,29 +38,31 @@ import java.util.HashMap; public class StringNameTable extends Name.Table { private final HashMap nameMap; + private final boolean intern; // Factory - public static StringNameTable create(Names names) { - return new StringNameTable(names); + public static StringNameTable create(Names names, boolean intern) { + return new StringNameTable(names, intern); } // Constructors - public StringNameTable(Names names) { - this(names, 0x8000); + public StringNameTable(Names names, boolean intern) { + this(names, 0x8000, intern); } - public StringNameTable(Names names, int initialCapacity) { + public StringNameTable(Names names, int initialCapacity, boolean intern) { super(names); this.nameMap = new HashMap<>(initialCapacity); + this.intern = intern; } // Name.Table @Override public Name fromString(String string) { - return this.nameMap.computeIfAbsent(string, s -> new NameImpl(this, s)); + return this.nameMap.computeIfAbsent(string, s -> new NameImpl(this, intern ? s.intern() : s)); } @Override