Commit 4d1d78a4 authored by Eric Bruneton's avatar Eric Bruneton

Address the merge request review comments.

parent fd883951
Pipeline #545 canceled with stage
......@@ -36,8 +36,9 @@ import org.objectweb.asm.Opcodes;
*
* @author Eric Bruneton
*/
public class ASMGenerator implements Generator {
public class ASMGenerator extends Generator {
@Override
public String getVersion() {
for (int i = 6; i >= 4; --i) {
try {
......@@ -48,9 +49,10 @@ public class ASMGenerator implements Generator {
} catch (NoSuchFieldException e) {
}
}
return "";
return null;
}
@Override
public byte[] generateClass() {
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
......
......@@ -41,15 +41,10 @@ import org.aspectj.apache.bcel.generic.Type;
*
* @author Eric Bruneton
*/
public class AspectJBCELGenerator implements Generator {
public class AspectJBCELGenerator extends Generator {
private static final Type PRINT_STREAM_TYPE = Type.getType("Ljava/io/PrintStream;");
@Override
public String getVersion() {
return null;
}
@Override
public byte[] generateClass() {
ClassGen classGen =
......
......@@ -42,15 +42,10 @@ import org.apache.bcel.generic.Type;
*
* @author Eric Bruneton
*/
public class BCELGenerator implements Generator {
public class BCELGenerator extends Generator {
private static final Type PRINT_STREAM_TYPE = Type.getType("Ljava/io/PrintStream;");
@Override
public String getVersion() {
return null;
}
@Override
public byte[] generateClass() {
ClassGen classGen =
......
......@@ -41,14 +41,9 @@ import org.cojen.classfile.TypeDesc;
*
* @author Eric Bruneton
*/
public class CojenGenerator implements Generator {
public class CojenGenerator extends Generator {
static TypeDesc printStream = TypeDesc.forClass("java.io.PrintStream");
@Override
public String getVersion() {
return null;
}
private static final TypeDesc PRINT_STREAM = TypeDesc.forClass("java.io.PrintStream");
@Override
public byte[] generateClass() {
......@@ -61,9 +56,9 @@ public class CojenGenerator implements Generator {
TypeDesc[] params = new TypeDesc[] {TypeDesc.STRING.toArrayType()};
MethodInfo methodInfo = classFile.addMethod(Modifiers.PUBLIC_STATIC, "main", null, params);
CodeBuilder codeBuilder = new CodeBuilder(methodInfo);
codeBuilder.loadStaticField("java.lang.System", "out", printStream);
codeBuilder.loadStaticField("java.lang.System", "out", PRINT_STREAM);
codeBuilder.loadConstant("Hello world!");
codeBuilder.invokeVirtual(printStream, "println", null, new TypeDesc[] {TypeDesc.STRING});
codeBuilder.invokeVirtual(PRINT_STREAM, "println", null, new TypeDesc[] {TypeDesc.STRING});
codeBuilder.returnVoid();
try {
......
......@@ -38,12 +38,7 @@ import com.claritysys.jvm.classfile.JVM;
*
* @author Eric Bruneton
*/
public class CsgBytecodeGenerator implements Generator {
@Override
public String getVersion() {
return null;
}
public class CsgBytecodeGenerator extends Generator {
@Override
public byte[] generateClass() {
......
......@@ -32,15 +32,17 @@ package org.objectweb.asm.benchmarks;
*
* @author Eric Bruneton
*/
public interface Generator {
public abstract class Generator {
/** @return the version of this generator. */
String getVersion();
/** @return the version of this generator, or an empty string if there is no version. */
public String getVersion() {
return "";
}
/**
* Generates a "Hello World!" class.
*
* @return the JVMS ClassFile structure of the generated class.
*/
byte[] generateClass();
public abstract byte[] generateClass();
}
......@@ -187,8 +187,7 @@ public class GeneratorBenchmark {
// is needed to make sure that the classes it references (i.e. the ASM library classes) will
// be loaded by this class loader too.
if (name.equals(ASM_GENERATOR)) {
InputStream inputStream = getResourceAsStream(name.replace('.', '/') + ".class");
try {
try (InputStream inputStream = getResourceAsStream(name.replace('.', '/') + ".class")) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] data = new byte[inputStream.available()];
int bytesRead;
......@@ -204,12 +203,6 @@ public class GeneratorBenchmark {
return c;
} catch (Exception e) {
throw new ClassNotFoundException(name, e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
// Nothing to do.
}
}
}
// Look for the specified class *first* in asmDirectory, *then* using the parent class loader.
......
......@@ -39,21 +39,14 @@ import gnu.bytecode.Type;
*
* @author Eric Bruneton
*/
public class GnuByteCodeGenerator implements Generator {
public class GnuByteCodeGenerator extends Generator {
private static final Method OBJECT_CONSTRUCTOR = Type.pointer_type.getDeclaredMethod("<init>", 0);
private static final Field OUT_FIELD = ClassType.make("java.lang.System").getField("out");
private static final Method PRINTLN_METHOD =
ClassType.make("java.io.PrintStream")
.getDeclaredMethod("println", new Type[] {Type.string_type});
@Override
public String getVersion() {
return null;
}
@Override
public byte[] generateClass() {
ClassType classType = new ClassType("HelloWorld");
......
......@@ -51,12 +51,7 @@ import org.gjt.jclasslib.structures.constants.ConstantStringInfo;
*
* @author Eric Bruneton
*/
public class JClassLibGenerator implements Generator {
@Override
public String getVersion() {
return null;
}
public class JClassLibGenerator extends Generator {
@Override
public byte[] generateClass() {
......
......@@ -40,19 +40,12 @@ import net.sf.jiapi.reflect.Signature;
*
* @author Eric Bruneton
*/
public class JiapiGenerator implements Generator {
public class JiapiGenerator extends Generator {
private static final Signature EMPTY_SIGNATURE = new Signature("()V");
private static final Signature MAIN_SIGNATURE = new Signature("([Ljava/lang/String;)V");
private static final Signature PRINTLN_SIGNATURE = new Signature("(Ljava/lang/String;)V");
@Override
public String getVersion() {
return null;
}
@Override
public byte[] generateClass() {
try {
......
......@@ -35,12 +35,7 @@ import org.mozilla.classfile.ClassFileWriter;
*
* @author Eric Bruneton
*/
public class MozillaClassFileGenerator implements Generator {
@Override
public String getVersion() {
return null;
}
public class MozillaClassFileGenerator extends Generator {
@Override
public byte[] generateClass() {
......
......@@ -132,6 +132,8 @@ project(':benchmarks:read-write') {
project(':benchmarks:write') {
description = "Write benchmark for ${rootProject.description}"
apply plugin: 'me.champeau.gradle.jmh'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
['4', '5', '6'].each { version ->
configurations.create("asm${version}")
dependencies.add("asm${version}", "org.ow2.asm:asm:${version}.0@jar")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment