Skip to content

Commit

Permalink
8268622: Performance issues in javac Name class
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
Archie Cobbs authored and Vicente Romero committed Oct 2, 2023
1 parent ad81abd commit 5c8366e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,18 @@ record = fromString("record");
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,31 @@
public class StringNameTable extends Name.Table {

private final HashMap<String, Name> 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
Expand Down

1 comment on commit 5c8366e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.