Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
BEGIN LICENSE BLOCK ***** Version: EPL 1.0/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Eclipse Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.eclipse.org/legal/epl-v10.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyright (C) 2004-2008 Thomas E Enebo <enebo@acm.org> Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the EPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the EPL, the GPL or the LGPL. END LICENSE BLOCK ***
 
 
 package org.jruby.internal.runtime.methods;
 
 import org.jruby.Ruby;
This is the mixed-mode method type. It will call out to JIT compiler to see if the compiler wants to JIT or not. If the JIT compiler does JIT this it will return the new method to be executed here instead of executing the interpreted version of this method. The next invocation of the method will end up causing the runtime to load and execute the newly JIT'd method.
 
 public class DefaultMethod extends DynamicMethod implements MethodArgsPositionAwareCacheableMethod {
 
     private static class DynamicMethodBox {
         public DynamicMethod actualMethod;
         public int callCount = 0;
     }
 
     private DynamicMethodBox box = new DynamicMethodBox();
     private final StaticScope staticScope;
     private final Node body;
     private final ArgsNode argsNode;
     private final ISourcePosition position;
     private final InterpretedMethod interpretedMethod;
     private MethodData methodData;
 
     public DefaultMethod(RubyModule implementationClassStaticScope staticScopeNode body,
             String nameArgsNode argsNodeVisibility visibilityISourcePosition position) {
         super(implementationClassvisibility.name);
         this. = DynamicMethodFactory.newInterpretedMethod(
                 implementationClass.getRuntime(), implementationClassstaticScope,
                 bodynameargsNodevisibilityposition);
         this.. = this.;
         this.. = ;
         this. = argsNode;
         this. = body;
         this. = staticScope;
         this. = position;
 
         assert argsNode != null;
     }
 
     public int getCallCount() {
         return .;
     }
 
     public int incrementCallCount() {
         return ++.;
     }
 
     public void setCallCount(int callCount) {
         this.. = callCount;
    }
    public Node getBodyNode() {
        return ;
    }
    public ArgsNode getArgsNode() {
        return ;
    }
    public StaticScope getStaticScope() {
        return ;
    }
    
    @Override
    public MethodData getMethodData() {
        if ( == null){
             = new MethodData(getFile(), InstanceVariableFinder.findVariables());
        }
        return ;
    }
        DynamicMethod method = .;
        if (method instanceof JittedMethod) {
            return method;
        }
        return this;
    }
    public void switchToJitted(Script jitCompiledScriptCallConfiguration jitCallConfig) {
        this.. = DynamicMethodFactory.newJittedMethod(
                getImplementationClass().getRuntime(), getImplementationClass(),
                jitCompiledScriptjitCallConfiggetVisibility(), .getArity(), ,
                this);
        this... = this.;
        this.. = -1;
    }
    private DynamicMethod tryJitReturnMethod(ThreadContext context) {
        String className;
        if (.isSingleton()) {
            MetaClass metaClass = (MetaClass);
            RubyClass realClass = metaClass.getRealClass();
            // if real class is Class
            if (realClass == context.runtime.getClassClass()) {
                // use the attached class's name
                className = ((RubyClass)metaClass.getAttached()).getName();
            } else {
                // use the real class name
                className = realClass.getName();
            }
        } else {
            // use the class name
            className = .getName();
        }
        context.runtime.getJITCompiler().tryJIT(thiscontextclassName);
        return .;
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject[] argsBlock block) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznameargsblock);
        }
        
        return ..call(contextselfclazznameargsblock);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject[] args) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznameargs);
        }
        return ..call(contextselfclazznameargs);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString name) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazzname);
        }
        return ..call(contextselfclazzname );
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameBlock block) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznameblock);
        }
        return ..call(contextselfclazznameblock);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject arg0) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznamearg0);
        }
        return ..call(contextselfclazzname , arg0);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject arg0Block block) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznamearg0block);
        }
        return ..call(contextselfclazznamearg0block);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject arg0IRubyObject arg1) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznamearg0arg1);
        }
        return ..call(contextselfclazzname , arg0arg1);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject arg0IRubyObject arg1Block block) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznamearg0arg1block);
        }
        return ..call(contextselfclazznamearg0arg1block);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject arg0IRubyObject arg1IRubyObject arg2) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznamearg0arg1arg2);
        }
        return ..call(contextselfclazzname , arg0arg1arg2);
    }
    @Override
    public IRubyObject call(ThreadContext contextIRubyObject selfRubyModule clazzString nameIRubyObject arg0IRubyObject arg1IRubyObject arg2Block block) {
        if (. >= 0) {
            return tryJitReturnMethod(context).call(contextselfclazznamearg0arg1arg2block);
        }
        return ..call(contextselfclazznamearg0arg1arg2block);
    }
    public ISourcePosition getPosition() {
        return ;
    }
    public String getFile() {
        return .getFile();
    }
    public int getLine() {
        return .getLine();
    }
    @Override
    public Arity getArity() {
        return .getArity();
    }
    public DynamicMethod dup() {
        newMethod.setIsBuiltin(this.);
        newMethod.box = this.;
        return newMethod;
    }
    @Override
    public void setVisibility(Visibility visibility) {
        // We promote our box to being its own box since we're changing
        // visibilities, and need it to be reflected on this method object
        // independent of any other sharing the box.
        DynamicMethodBox newBox = new DynamicMethodBox();
        newBox.actualMethod = ..dup();
        newBox.callCount = .;
         = newBox;
        super.setVisibility(visibility);
    }
New to GrepCode? Check out our FAQ X