Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
7902929: JMH generators fail for benchmark in unnamed package
Reviewed-by: shade
  • Loading branch information
Jason Zaugg authored and shipilev committed May 12, 2021
1 parent 0aeda8d commit 768f38e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
39 changes: 39 additions & 0 deletions jmh-core-ct/src/test/java/UnnamedPackageTest.java
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2021, 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.
*/

import org.junit.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.ct.CompileTest;

public class UnnamedPackageTest {
@Benchmark
public void test() {
}

@Test
public void compileTest() {
CompileTest.assertFail(getClass(), "Benchmark class should have package other than default.");
}
}
Expand Up @@ -79,11 +79,24 @@ public void visit(int version, int access, String name, String signature, String
this.superName = superName;
this.idName = name;
this.access = access;
qualifiedName = name.replace("/", ".");
packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf("."));
origQualifiedName = qualifiedName;
qualifiedName = qualifiedName.replace('$', '.');
this.name = qualifiedName.substring(qualifiedName.lastIndexOf(".") + 1);
this.qualifiedName = name.replace("/", ".");

int dotIndex = qualifiedName.lastIndexOf(".");
if (dotIndex != -1) {
packageName = qualifiedName.substring(0, dotIndex);
} else {
packageName = "";
}

this.origQualifiedName = qualifiedName;
this.qualifiedName = qualifiedName.replace('$', '.');

dotIndex = qualifiedName.lastIndexOf(".");
if (dotIndex != -1) {
this.name = qualifiedName.substring(dotIndex + 1);
} else {
this.name = qualifiedName;
}
}

@Override
Expand Down
Expand Up @@ -46,9 +46,9 @@ public RFClassInfo(Class<?> klass) {
@Override
public String getPackageName() {
if (klass.getDeclaringClass() != null) {
return klass.getDeclaringClass().getPackage().getName();
return nameOf(klass.getDeclaringClass().getPackage());
} else {
return klass.getPackage().getName();
return nameOf(klass.getPackage());
}
}

Expand Down Expand Up @@ -171,4 +171,8 @@ public Collection<String> getEnumConstants() {
public String toString() {
return getQualifiedName();
}

private String nameOf(Package pack) {
return pack == null ? "" : pack.getName();
}
}

0 comments on commit 768f38e

Please sign in to comment.