How can I see the machine code generated by v8?

I don’t know how to invoke the disassembler from C++ code, but there is a quick-and-dirty way to get a disassembly from the shell. First, compile v8 with disassembler support: scons [your v8 build options here] disassembler=on sample=shell Now you can invoke the shell with the “–print_code” option: ./shell –print_code hello.js Which should give you … Read more

How to emit and execute Java bytecode at runtime?

Here is a working “hello world” made with ObjectWeb ASM (a library which I recommend): package hello; import java.lang.reflect.Method; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; public class HelloWorldASM implements Opcodes { public static byte[] compile(String name) { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, “hello/HelloWorld”, null, “java/lang/Object”, null); cw.visitSource(“HelloWorld.java”, … Read more

Is it possible to programmatically compile java source code in memory only?

To start, look at the JavaCompiler API. Basically: Create the Java class in a string. Put the string into class that extends SimpleJavaFileObject. Compile using a JavaCompiler instance. Finally, call the methods the new class. Here is an example that works with JDK6+: import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.util.Arrays; … Read more

‘CompanyName.Foo’ is a ‘namespace’ but is used like a ‘type’

how do I tag Eric Lippert? If you have something you want brought to my attention you can use the “contact” link on my blog. I’m still utterly confused why the C# compiler bothers to check for collisions between namespaces and types in contexts where it makes no sense for a namespace to exist. Indeed, … Read more

Is there away to generate Variables’ names dynamically in Java?

If you really want to do something like that, you can do it through bytecode generation using ASM or some other library. Here is code that will generate a class named “foo.bar.ClassWithFields” that contains fields “var0” to “var99”. Of course there is no way other than reflection to access those fields, because they don’t exist … Read more