changeset 394:545012959ccb

Referencing two @States with the same base name should not fail to compile.
author shade
date Wed, 12 Feb 2014 16:15:57 +0400
parents 01f878b94d95
children 11325bebcc6c
files jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/SameBasenameStateTest.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java
diffstat 2 files changed, 58 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/SameBasenameStateTest.java	Wed Feb 12 16:15:57 2014 +0400
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2005, 2013, 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.it.compile;
+
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+
+public class SameBasenameStateTest {
+
+    public static class Enclosure1 {
+        @State(Scope.Thread)
+        public static class S {
+
+        }
+    }
+
+    public static class Enclosure2 {
+        @State(Scope.Thread)
+        public static class S {
+
+        }
+    }
+
+    @GenerateMicroBenchmark
+    public void work(Enclosure1.S s1, Enclosure2.S s2) {
+        // this method was intentionally left blank
+    }
+
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Wed Feb 12 16:03:06 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Wed Feb 12 16:15:57 2014 +0400
@@ -68,6 +68,7 @@
     private final HashMap<String, String> collapsedTypes = new HashMap<String, String>();
     private int collapsedIndex = 0;
 
+    private final Set<String> claimedJmhTypes = new HashSet<String>();
     private final HashMap<String, String> jmhTypes = new HashMap<String, String>();
     private final Multimap<String, String> auxNames = new HashMultimap<String, String>();
     private final Map<String, String> auxAccessors = new HashMap<String, String>();
@@ -83,7 +84,11 @@
     private String getJMHtype(String type) {
         String jmhType = jmhTypes.get(type);
         if (jmhType == null) {
-            jmhType = getBaseType(type) + "_jmh";
+            int v = 1;
+            do {
+                jmhType = getBaseType(type) + "_" + v + "_jmh";
+                v++;
+            } while (!claimedJmhTypes.add(jmhType));
             jmhTypes.put(type, jmhType);
         }
         return jmhType;