Skip to content

Commit

Permalink
7903478: JMH: Use different padding names for B1 and B3 classes to av…
Browse files Browse the repository at this point in the history
…oid "hiding fields with same name" warnings

Reviewed-by: shade
  • Loading branch information
vlsi authored and shipilev committed May 31, 2023
1 parent c8ab22b commit 46c97c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private void generateClass(GeneratorDestination destination, ClassInfo classInfo
writer.println();

// generate padding
Paddings.padding(writer);
Paddings.padding(writer, "p");

writer.println(ident(1) + "int startRndMask;");
writer.println(ident(1) + "BenchmarkParams benchmarkParams;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,37 @@
package org.openjdk.jmh.generators.core;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;

public class Paddings {

private static final List<String> PADDING_CACHE;
private static final Map<String, String> PADDING_CACHE =
Collections.synchronizedMap(new HashMap<>());

static {
PADDING_CACHE = new ArrayList<>();
private static String generate(String prefix) {
if (prefix.isEmpty()) {
throw new IllegalArgumentException("prefix must not be empty");
}
StringJoiner sj = new StringJoiner("");
for (int p = 0; p < 16; p++) {
StringBuilder sb = new StringBuilder();
sb.append(" ");
sb.append(String.format("byte p%03d", p * 16 + 0));
for (int q = 1; q < 16; q++) {
sb.append(String.format(", p%03d", p * 16 + q));
sj.add(" byte ");
for (int q = 0; q < 16; q++) {
if (q != 0) {
sj.add(", ");
}
sj.add(prefix);
sj.add(String.format("%03d", p * 16 + q));
}
sb.append(";");
PADDING_CACHE.add(sb.toString());
sj.add(";");
sj.add(System.lineSeparator());
}
return sj.toString();
}

public static void padding(List<String> lines) {
lines.addAll(PADDING_CACHE);
}

public static void padding(PrintWriter writer) {
for (String s : PADDING_CACHE) {
writer.println(s);
}
public static void padding(PrintWriter writer, String prefix) {
writer.print(PADDING_CACHE.computeIfAbsent(prefix, Paddings::generate));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ public void writeStateOverrides(BenchmarkGeneratorSession sess, GeneratorDestina
pw.println("import " + so.userType + ";");

pw.println("public class " + so.type + "_B1 extends " + so.userType + " {");
Paddings.padding(pw);
Paddings.padding(pw, "b1_");
pw.println("}");

pw.close();
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public void writeStateOverrides(BenchmarkGeneratorSession sess, GeneratorDestina

pw.println("package " + so.packageName + ";");
pw.println("public class " + so.type + "_B3 extends " + so.type + "_B2 {");
Paddings.padding(pw);
Paddings.padding(pw, "b3_");
pw.println("}");
pw.println("");

Expand Down

0 comments on commit 46c97c2

Please sign in to comment.