Feature/bael 4911 tiered compilation (#10958)

* BASE-4911: Tiered Compilation Initial Commit

* BASE-4911: Use Generics
This commit is contained in:
Daniel Strmecki 2021-07-11 15:18:10 +02:00 committed by GitHub
parent fe8ec4460c
commit 4f3f287923
6 changed files with 85 additions and 0 deletions

View File

@ -21,6 +21,16 @@
<artifactId>jmh-core</artifactId>
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>

View File

@ -0,0 +1,21 @@
package com.baeldung.tieredcompilation;
public class Article {
private String name;
private String author;
public Article(String name, String author) {
this.name = name;
this.author = author;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.tieredcompilation;
public interface Formatter {
<T> String format(T object) throws Exception;
}

View File

@ -0,0 +1,15 @@
package com.baeldung.tieredcompilation;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.json.JsonMapper;
public class JsonFormatter implements Formatter {
private static final JsonMapper mapper = new JsonMapper();
@Override
public <T> String format(T object) throws JsonProcessingException {
return mapper.writeValueAsString(object);
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.tieredcompilation;
public class TieredCompilation {
public static void main(String[] args) throws Exception {
for (int i = 0; i < 1_000_000; i++) {
Formatter formatter;
if (i < 500_000) {
formatter = new JsonFormatter();
} else {
formatter = new XmlFormatter();
}
formatter.format(new Article("Tiered Compilation in JVM", "Baeldung"));
}
}
}

View File

@ -0,0 +1,15 @@
package com.baeldung.tieredcompilation;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class XmlFormatter implements Formatter {
private static final XmlMapper mapper = new XmlMapper();
@Override
public <T> String format(T object) throws JsonProcessingException {
return mapper.writeValueAsString(object);
}
}