changeset 1271:a427fb8dccc1

7901490: @Benchmark with name "jmh" clashes with generated class name
author shade
date Fri, 28 Aug 2015 19:08:56 +0300
parents ba8884f1ddea
children 7b3f64d2cd9c
files jmh-core-ct/src/test/java/org/openjdk/jmh/ct/other/JmhNameTest.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/Identifiers.java
diffstat 3 files changed, 53 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/other/JmhNameTest.java	Fri Aug 28 19:08:56 2015 +0300
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.ct.other;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.ct.CompileTest;
+
+public class JmhNameTest {
+
+    @Benchmark
+    public void jmh() {
+        // Intentionally left blank
+    }
+
+    @Benchmark
+    public void jmhNameTest() {
+        // Intentionally left blank
+    }
+
+    @Test
+    public void compileTest() {
+        CompileTest.assertOK(this.getClass());
+    }
+
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Fri Aug 28 18:28:29 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Fri Aug 28 19:08:56 2015 +0300
@@ -24,31 +24,12 @@
  */
 package org.openjdk.jmh.generators.core;
 
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.CompilerControl;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Group;
-import org.openjdk.jmh.annotations.GroupThreads;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OperationsPerInvocation;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Threads;
-import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.annotations.*;
 import org.openjdk.jmh.infra.BenchmarkParams;
 import org.openjdk.jmh.infra.Blackhole;
 import org.openjdk.jmh.infra.IterationParams;
 import org.openjdk.jmh.infra.ThreadParams;
-import org.openjdk.jmh.results.AverageTimeResult;
-import org.openjdk.jmh.results.BenchmarkTaskResult;
-import org.openjdk.jmh.results.RawResults;
-import org.openjdk.jmh.results.Result;
-import org.openjdk.jmh.results.ResultRole;
-import org.openjdk.jmh.results.SampleTimeResult;
-import org.openjdk.jmh.results.SingleShotResult;
-import org.openjdk.jmh.results.ThroughputResult;
+import org.openjdk.jmh.results.*;
 import org.openjdk.jmh.runner.BenchmarkList;
 import org.openjdk.jmh.runner.BenchmarkListEntry;
 import org.openjdk.jmh.runner.Defaults;
@@ -64,14 +45,7 @@
 import java.io.Reader;
 import java.lang.annotation.IncompleteAnnotationException;
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -524,7 +498,7 @@
         for (MethodGroup group : result.values()) {
             String sourcePackage = clazz.getPackageName();
             String generatedPackageName = sourcePackage + ".generated";
-            String generatedClassName = BenchmarkGeneratorUtils.getGeneratedName(clazz) + "_" + group.getName();
+            String generatedClassName = BenchmarkGeneratorUtils.getGeneratedName(clazz) + "_" + group.getName() + "_jmhTest";
 
             BenchmarkInfo info = new BenchmarkInfo(clazz.getQualifiedName(), generatedPackageName, generatedClassName, group);
             validateBenchmarkInfo(info);
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/Identifiers.java	Fri Aug 28 18:28:29 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/Identifiers.java	Fri Aug 28 19:08:56 2015 +0300
@@ -45,7 +45,7 @@
         if (jmhType == null) {
             int v = 0;
             do {
-                jmhType = id + (v == 0 ? "" : "_" + v) + "_jmh";
+                jmhType = id + (v == 0 ? "" : "_" + v) + "_jmhType";
                 v++;
             } while (!claimedJmhTypes.add(jmhType));
             jmhTypes.put(id, jmhType);