Package one.nio.compiler

Source Code of one.nio.compiler.CompilerTest

package one.nio.compiler;

import one.nio.gen.BytecodeGenerator;

public class CompilerTest {

    public static void main(String[] args) throws Exception {
        String code =
                "package one.nio.compiler;\n" +
                "public class GeneratedRunnable implements Runnable {\n" +
                "    public void run() {\n" +
                "        System.out.println(\"Hello \" + getClass().getClassLoader());\n" +
                "    }\n" +
                "}\n";

        long startMemory = Runtime.getRuntime().freeMemory();
        long startTime = System.currentTimeMillis();

        byte[] classData = new Javac(CompilerTest.class.getClassLoader()).compile(code);

        long compilationTime = System.currentTimeMillis();

        Runnable runnable = new BytecodeGenerator().instantiate(classData, Runnable.class);

        long loadingTime = System.currentTimeMillis();
        long endMemory = Runtime.getRuntime().freeMemory();

        runnable.run();

        System.out.println("Compilation time = " + (compilationTime - startTime) +
                ", loading time = " + (loadingTime - compilationTime) +
                ", memory = " + (startMemory - endMemory) / 1024 + " KB");
    }
}
TOP

Related Classes of one.nio.compiler.CompilerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.