Package org.jruby.ast.executable

Examples of org.jruby.ast.executable.ScriptAndCode


                    Helpers.postLoad(context);
                }
            }
        };

        return new ScriptAndCode(bytecode, script);

    }
View Full Code Here


     * @param scriptNode The root node of the script to be executed
     * bytecode before execution
     * @return The result of executing the script
     */
    public IRubyObject runNormally(Node scriptNode) {
        ScriptAndCode scriptAndCode = null;
        boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
        if (compile || config.isShowBytecode()) {
            // IR JIT does not handle all scripts yet, so let those that fail run in interpreter instead
            // FIXME: restore error once JIT should handle everything
            try {
                scriptAndCode = tryCompile(scriptNode, new JRubyClassLoader(getJRubyClassLoader()));
                if (scriptAndCode != null && Options.JIT_LOGGING.load()) {
                    LOG.info("done compiling target script: " + scriptNode.getPosition().getFile());
                }
            } catch (Exception e) {
                if (Options.JIT_LOGGING.load()) {
                    LOG.error("failed to compile target script '" + scriptNode.getPosition().getFile() + "'");
                    if (Options.JIT_LOGGING_VERBOSE.load()) {
                        e.printStackTrace();
                    }
                }
            }
        }

        if (scriptAndCode != null) {
            if (config.isShowBytecode()) {
                TraceClassVisitor tracer = new TraceClassVisitor(new PrintWriter(System.err));
                ClassReader reader = new ClassReader(scriptAndCode.bytecode());
                reader.accept(tracer, 0);
                return getNil();
            }

            return runScript(scriptAndCode.script());
        } else {
            // FIXME: temporarily allowing JIT to fail for $0 and fall back on interpreter
//            failForcedCompile(scriptNode);
           
            return runInterpreter(scriptNode);
View Full Code Here

    public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
        InputStream readStream = in;
       
        try {
            Script script = null;
            ScriptAndCode scriptAndCode = null;
            String className = null;

            try {
                // read full contents of file, hash it, and try to load that class first
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int num;
                while ((num = in.read(buffer)) > -1) {
                    baos.write(buffer, 0, num);
                }
                buffer = baos.toByteArray();
                String hash = JITCompiler.getHashForBytes(buffer);
                className = JITCompiler.RUBY_JIT_PREFIX + ".FILE_" + hash;

                // FIXME: duplicated from ClassCache
                Class contents;
                try {
                    contents = jrubyClassLoader.loadClass(className);
                    if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
                        LOG.info("found jitted code for " + filename + " at class: " + className);
                    }
                    script = (Script)contents.newInstance();
                    readStream = new ByteArrayInputStream(buffer);
                } catch (ClassNotFoundException cnfe) {
                    if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
                        LOG.info("no jitted code in classloader for file " + filename + " at class: " + className);
                    }
                } catch (InstantiationException ie) {
                    if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
                        LOG.info("jitted code could not be instantiated for file " + filename + " at class: " + className);
                    }
                } catch (IllegalAccessException iae) {
                    if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
                        LOG.info("jitted code could not be instantiated for file " + filename + " at class: " + className);
                    }
                }
            } catch (IOException ioe) {
                // TODO: log something?
            }

            // script was not found in cache above, so proceed to compile
            Node scriptNode = parseFile(readStream, filename, null);
            if (script == null) {
                scriptAndCode = tryCompile(scriptNode, new JRubyClassLoader(jrubyClassLoader));
                if (scriptAndCode != null) script = scriptAndCode.script();
            }

            if (script == null) {
                failForcedCompile(scriptNode);
View Full Code Here

TOP

Related Classes of org.jruby.ast.executable.ScriptAndCode

Copyright © 2018 www.massapicom. 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.