is fantom generated bytecode as performant as java equivalent bytecode?
Date : March 29 2020, 07:55 AM
I hope this helps you . from the many jvm languages appearing nowdays, there's one that seems to be particularly appealing , I did some quicksort performance testing. Int[100.000] array quicksort
Java ~ 11ms
Java using long and ArrayList<Long> ~ 66ms
Fantom ~ 97 ms
Int[1.000.000] array quicksort
Java ~ 91ms
Java using long and ArrayList<long> ~ 815ms
Fantom ~ 1100ms.
class TestQuickSort
{
public static Void swap(Int[] a, Int i, Int j) {
temp := a[i];
a[i] = a[j];
a[j] = temp;
}
public static Void quicksortA(Int[] a, Int L, Int R) {
m := a[(L + R) / 2];
i := L;
j := R;
while (i <= j) {
while (a[i] < m)
i++;
while (a[j] > m)
j--;
if (i <= j) {
swap(a, i, j);
i++;
j--;
}
}
if (L < j)
quicksortA(a, L, j);
if (R > i)
quicksortA(a, i, R);
}
public static Void quicksort(Int[] a) {
quicksortA(a, 0, a.size - 1);
}
static Void main(Str[] args) {
// Sample data
a := Int[,]
for(i := 0; i<1000000; i++)
{
a.add(i*3/2+1)
if(i%3==0) {a[i]=-a[i]}
}
t1 := Duration.now
quicksort(a);
t2 := Duration.now
echo((t2-t1).toMillis)
}
}
import java.util.ArrayList;
public class QuicksortJava {
public static void swap(ArrayList<Long> a, long i, long j) {
long temp = a.get((int)i);
a.set((int)i, a.get((int)j));
a.set((int)j, temp);
}
public static void quicksort(ArrayList<Long> a, long L, long R) {
long m = a.get((int)(L + R) / 2);
long i = L;
long j = R;
while (i <= j) {
while (a.get((int)i) < m)
i++;
while (a.get((int)j) > m)
j--;
if (i <= j) {
swap(a, i, j);
i++;
j--;
}
}
if (L < j)
quicksort(a, L, j);
if (R > i)
quicksort(a, i, R);
}
public static void quicksort(ArrayList<Long> a) {
quicksort(a, 0, a.size() - 1);
}
public static void main(String[] args) {
// Sample data
long size = 100000;
ArrayList<Long> a = new ArrayList<Long>((int)size);
for (long i = 0; i < size; i++) {
a.add(i * 3 / 2 + 1);
if (i % 3 == 0)
a.set((int)i, -a.get((int)i));
}
long t1 = System.currentTimeMillis();
quicksort(a);
long t2 = System.currentTimeMillis();
System.out.println(t2 - t1);
}
}
|
Is there a bytecode back-end (like LLVM) that has a tool to translate the assembled bytecode into machine code?
Date : March 29 2020, 07:55 AM
this one helps. LLVM already contains a bunch of back-ends for various popular architectures, including x86. So in theory if you want to create a new language you can just write an LLVM front-end for that language and you're done - you got a compiler for numerous architectures. In practice just writing a front-end might not be enough (e.g. if you need some runtime libraries or memory management), but it should definitely suffice for some languages. In fact, that's one of the principle idea behind systems like gcc and LLVM - that you can just add a front-end and get architecture support for free (or alternatively, just add a back-end and allow numerous languages to be compiled into it for free).
|
Hibernate - Difference between bytecode instrumentation and bytecode enhancement?
Tag : java , By : Steven Weber
Date : March 29 2020, 07:55 AM
Does that help The answer is the way byte code enhancement is done. Let's see what happen in both cases Bytecode instrumentation: Adding bytecode to a Java class during “run time.” It's not really during run time, but more during “load” time of the Java class. Further you can read this post in detail.
|
Tag : java , By : Arun Thomas
Date : March 29 2020, 07:55 AM
I hope this helps . There is example code to insert your line at the beggining of the function public class YourClassVisitor extends ClassVisitor {
public YourClassVisitor(ClassVisitor cv) {
super(Opcodes.ASM5, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("targetName")) {
return new YourMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
private static class YourMethodVisitor extends MethodVisitor {
public YourMethodVisitor(MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}
// This method will be called before almost all instructions
@Override
public void visitCode() {
// Default implementation is empty. So we haven't to call super method
// Puts 'this' on top of the stack. If your method is static just delete it
visitVarInsn(Opcodes.ALOAD, 0);
// Takes instance of class "the/full/name/of/your/Class" from top of the stack and put value of field interceptors
// "Ljava/util/List;" is just internal name of java.util.List
// If your field is static just replace GETFIELD with GETSTATIC
visitFieldInsn(Opcodes.GETFIELD, "the/full/name/of/your/Class", "interceptors", "Ljava/util/List;");
// Before we call add method of list we have to put target value on top of the stack
// New object creation starts with creating not initialized instance of it
visitTypeInsn(Opcodes.NEW, "com/shehabic/sherlock/interceptors");
// Than we just copy it
visitInsn(Opcodes.DUP);
visitTypeInsn(Opcodes.NEW, "example/path/to/class/SherlockOkHttpInterceptor");
visitInsn(Opcodes.DUP);
// We have to call classes constructor
// Internal name of constructor - <init>
// ()V - signature of method. () - method doesn't have parameters. V - method returns void
visitMethodInsn(Opcodes.INVOKESPECIAL, "example/path/to/class/SherlockOkHttpInterceptor", "<init>", "()V", false);
// So on top of the stack we have initialized instance of example/path/to/class/SherlockOkHttpInterceptor
// Now we can call constructor of com/shehabic/sherlock/interceptors
visitMethodInsn(Opcodes.INVOKESPECIAL, "com/shehabic/sherlock/interceptors", "<init>", "(Lexample/path/to/class/SherlockOkHttpInterceptor;)V", false);
// So on top of the stack we have initialized instance of com/shehabic/sherlock/interceptors
// Now we can put it into list
visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
}
}
}
byte[] cache = null;
try (FileInputStream in = new FileInputStream("C:\\Users\\JustAGod\\Projects\\gloomymods\\BuildTools\\BytecodeTools\\out\\production\\classes\\gloomyfolken\\Kek.class")) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassReader reader = new ClassReader(in);
reader.accept(new YourClassVisitor(writer), ClassReader.EXPAND_FRAMES);
cache = writer.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
try(FileOutputStream out = new FileOutputStream("C:\\Users\\JustAGod\\Projects\\gloomymods\\BuildTools\\BytecodeTools\\out\\production\\classes\\gloomyfolken\\Kek.class")) {
out.write(cache);
} catch (IOException e) {
e.printStackTrace();
}
|
Can someone explain the bytecode modification performed to prevent this bytecode from being directly decompiled?
Tag : java , By : Ted Leung
Date : March 29 2020, 07:55 AM
|