forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce quarkus-classloader-commons and related benchmarks infrastr…
…ucture
- Loading branch information
Showing
11 changed files
with
281 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>quarkus-bootstrap-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>benchmarks</artifactId> | ||
<name>Quarkus - Bootstrap - JMH Benchmarks</name> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-bootstrap-bom</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-bootstrap-bom-test</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-core</artifactId> | ||
<version>${jmh.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>${jmh.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-classloader-commons</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<finalName>benchmark</finalName> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.openjdk.jmh.Main</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>${jmh.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
65 changes: 65 additions & 0 deletions
65
...ap/benchmarks/src/main/java/io/quarkus/commons/benchmarks/BenchmarkClassnameSanitize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.quarkus.commons.benchmarks; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
import io.quarkus.commons.classloading.ClassloadHelper; | ||
|
||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@Warmup(iterations = 10, time = 200, timeUnit = TimeUnit.MILLISECONDS) | ||
@Measurement(iterations = 20, time = 100, timeUnit = TimeUnit.MILLISECONDS) | ||
@Fork(2) | ||
public class BenchmarkClassnameSanitize { | ||
|
||
@Param({ "true", "false" }) | ||
public boolean worseCase; | ||
|
||
private static final String TEST_CLASS_NAME_BAD = "/some/odd/package/and/ClassName/"; | ||
private static final String TEST_CLASS_NAME_GOOD = "some/odd/package/and/ClassName"; | ||
|
||
private String TESTINPUT; | ||
|
||
@Setup | ||
public void setup() { | ||
TESTINPUT = worseCase ? TEST_CLASS_NAME_BAD : TEST_CLASS_NAME_GOOD; | ||
} | ||
|
||
@Benchmark | ||
public String sanitizeNameOptimised() { | ||
return ClassloadHelper.sanitizeName(TESTINPUT); | ||
} | ||
|
||
@Benchmark | ||
public String sanitizeNameStandard() { | ||
return legacySanitize(TESTINPUT); | ||
} | ||
|
||
private String legacySanitize(String name) { | ||
if (name.startsWith("/")) { | ||
name = name.substring(1); | ||
} | ||
if (name.endsWith("/")) { | ||
name = name.substring(0, name.length() - 1); | ||
} | ||
return name; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
org.openjdk.jmh.Main.main(args); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
independent-projects/bootstrap/classloader-commons/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>quarkus-bootstrap-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>quarkus-classloader-commons</artifactId> | ||
<name>Quarkus - Bootstrap - Classloader common utilities</name> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-bootstrap-bom</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-bootstrap-bom-test</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
34 changes: 34 additions & 0 deletions
34
...ap/classloader-commons/src/main/java/io/quarkus/commons/classloading/ClassloadHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.commons.classloading; | ||
|
||
public final class ClassloadHelper { | ||
|
||
private ClassloadHelper() { | ||
//Not meant to be instantiated | ||
} | ||
|
||
/** | ||
* Sanitizes the string passed as argument, by removing any "/" | ||
* symbol at the end or at the beginning. | ||
* | ||
* @param name the string to be sanitized | ||
* @return a new String with the offending characters removed, or potentially the same String | ||
* if no modifications were required. | ||
*/ | ||
public static String sanitizeName(final String name) { | ||
final int length = name.length(); | ||
if (length == 0) { | ||
return name; | ||
} | ||
final int beginIndex = (name.charAt(0) == '/') ? 1 : 0; | ||
final int endIndex = (name.charAt(length - 1) == '/') ? length - 1 : length; | ||
if (beginIndex == 0 && endIndex == length) { | ||
return name; | ||
} else { | ||
if (beginIndex > endIndex) { | ||
return ""; | ||
} | ||
return name.substring(beginIndex, endIndex); | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...lassloader-commons/src/test/java/io/quarkus/commons/classloading/ClassloadHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.commons.classloading; | ||
|
||
import static io.quarkus.commons.classloading.ClassloadHelper.sanitizeName; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ClassloadHelperTest { | ||
|
||
@Test | ||
public void testSanitizeNameSpec() { | ||
Assertions.assertEquals("", sanitizeName("")); | ||
Assertions.assertEquals("", sanitizeName("/")); | ||
Assertions.assertEquals("", sanitizeName("//")); | ||
Assertions.assertEquals("a", sanitizeName("/a/")); | ||
Assertions.assertEquals("a", sanitizeName("/a")); | ||
Assertions.assertEquals("a", sanitizeName("a/")); | ||
Assertions.assertEquals("abcd", sanitizeName("/abcd/")); | ||
Assertions.assertEquals("ab/cd", sanitizeName("/ab/cd/")); | ||
Assertions.assertEquals("ab/cd/something/something", sanitizeName("/ab/cd/something/something")); | ||
//The following cases are left out intentionally as they would IMO | ||
//fall in the cathegory of illegal input, and not worth sanitising for: | ||
// "/abcd//" : multiple slashes at end[begin] | ||
// "/abcd//abds/" :multiple slashes in the middle | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters