org.jruby.internal.runtime.methods
Class DynamicMethod

java.lang.Object
  extended by org.jruby.internal.runtime.methods.DynamicMethod
Direct Known Subclasses:
AliasMethod, CompiledMethod.LazyCompiledMethod, DefaultMethod, FullFunctionCallbackMethod, InterpretedMethod, JavaMethod, JittedMethod, MethodMethod, ProcMethod, SimpleCallbackMethod, UndefinedMethod, WrapperMethod

public abstract class DynamicMethod
extends java.lang.Object

DynamicMethod represents a method handle in JRuby, to provide both entry points into AST and bytecode interpreters, but also to provide handles to JIT-compiled and hand-implemented Java methods. All methods invokable from Ruby code are referenced by method handles, either directly or through delegation or callback mechanisms.


Field Summary
protected  CallConfiguration callConfig
          The "call configuration" to use for pre/post call logic.
protected  RubyModule implementationClass
          The Ruby module or class in which this method is immediately defined.
protected  RubyModule protectedClass
          The "protected class" used for calculating protected access.
protected  long serialNumber
          The serial number for this method object, to globally identify it
protected  Visibility visibility
          The visibility of this method.
 
Constructor Summary
protected DynamicMethod()
          A no-arg constructor used only by the UndefinedMethod subclass and CompiledMethod handles.
protected DynamicMethod(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig)
          Base constructor for dynamic method handles.
 
Method Summary
protected static RubyModule calculateProtectedClass(RubyModule cls)
          Calculate, based on given RubyModule, which class in its hierarchy should be used to determine protected access.
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name)
          Arity 0, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, Block block)
          Arity 0, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0)
          Arity 1, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, java.lang.String name, IRubyObject[] args)
          A default implementation of n-arity, non-block 'call' method, which simply calls the n-arity, block-receiving version with the arg list and Block.NULL_BLOCK.
abstract  IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, java.lang.String name, IRubyObject[] args, Block block)
          The minimum 'call' method required for a dynamic method handle.
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, Block block)
          Arity 1, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1)
          Arity 2, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, Block block)
          Arity 2, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2)
          Arity 3, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
          Arity 3, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3)
          Arity 4, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block)
          Arity 4, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4)
          Arity 5, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, Block block)
          Arity 5, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5)
          Arity 6, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, Block block)
          Arity 6, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6)
          Arity 7, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6, Block block)
          Arity 7, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6, IRubyObject arg7)
          Arity 8, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6, IRubyObject arg7, Block block)
          Arity 8, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6, IRubyObject arg7, IRubyObject arg8)
          Arity 9, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6, IRubyObject arg7, IRubyObject arg8, Block block)
          Arity 9, with block; calls through IRubyObject[] path
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6, IRubyObject arg7, IRubyObject arg8, IRubyObject arg9)
          Arity 10, no block
 IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, IRubyObject arg5, IRubyObject arg6, IRubyObject arg7, IRubyObject arg8, IRubyObject arg9, Block block)
          Arity 10, with block; calls through IRubyObject[] path
abstract  DynamicMethod dup()
          Duplicate this method, returning DynamicMethod referencing the same code and with the same attributes.
 Arity getArity()
          Retrieve the arity of this method, used for reporting arity to Ruby code.
 CallConfiguration getCallConfig()
          Get the CallConfiguration used for pre/post logic for this method handle.
 RubyModule getImplementationClass()
          Retrieve the class or module on which this method is implemented, used for 'super' logic among others.
protected  RubyModule getProtectedClass()
          Retrieve the pre-calculated "protected class" used for access checks.
 DynamicMethod getRealMethod()
          Get the "real" method contained within this method.
 long getSerialNumber()
          Get the global serial number for this method object
 Visibility getVisibility()
          Get the visibility of this method.
protected  IRubyObject handleRedo(Ruby runtime)
           
protected  IRubyObject handleReturn(ThreadContext context, JumpException.ReturnJump rj)
           
protected  void init(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig)
           
 boolean isCallableFrom(IRubyObject caller, CallType callType)
          Determine whether this method is callable from the given object using the given call type.
 boolean isNative()
          Returns true if this method is backed by native (i.e.
 boolean isUndefined()
          Whether this method is the "undefined" method, used to represent a missing or undef'ed method.
 void setCallConfig(CallConfiguration callConfig)
          Set the CallConfiguration used for pre/post logic for this method handle.
 void setImplementationClass(RubyModule implClass)
          Set the class on which this method is implemented, used for 'super' logic, among others.
 void setVisibility(Visibility visibility)
          Set the visibility of this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

implementationClass

protected RubyModule implementationClass
The Ruby module or class in which this method is immediately defined.


protectedClass

protected RubyModule protectedClass
The "protected class" used for calculating protected access.


visibility

protected Visibility visibility
The visibility of this method.


callConfig

protected CallConfiguration callConfig
The "call configuration" to use for pre/post call logic.


serialNumber

protected long serialNumber
The serial number for this method object, to globally identify it

Constructor Detail

DynamicMethod

protected DynamicMethod(RubyModule implementationClass,
                        Visibility visibility,
                        CallConfiguration callConfig)
Base constructor for dynamic method handles.

Parameters:
implementationClass - The class to which this method will be immediately bound
visibility - The visibility assigned to this method
callConfig - The CallConfiguration to use for this method's pre/post invocation logic.

DynamicMethod

protected DynamicMethod()
A no-arg constructor used only by the UndefinedMethod subclass and CompiledMethod handles. instanceof assertions make sure this is so.

Method Detail

init

protected void init(RubyModule implementationClass,
                    Visibility visibility,
                    CallConfiguration callConfig)

getSerialNumber

public long getSerialNumber()
Get the global serial number for this method object

Returns:
This method object's serial number

call

public abstract IRubyObject call(ThreadContext context,
                                 IRubyObject self,
                                 RubyModule clazz,
                                 java.lang.String name,
                                 IRubyObject[] args,
                                 Block block)
The minimum 'call' method required for a dynamic method handle. Subclasses must impleemnt this method, but may implement the other signatures to provide faster, non-boxing call paths. Typically subclasses will implement this method to check variable arity calls, then performing a specific-arity invocation to the appropriate method or performing variable-arity logic in-line.

Parameters:
context - The thread context for the currently executing thread
self - The 'self' or 'receiver' object to use for this call
klazz - The Ruby class against which this method is binding
name - The incoming name used to invoke this method
args - The argument list to this invocation
block - The block passed to this invocation
Returns:
The result of the call

call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule clazz,
                        java.lang.String name,
                        IRubyObject[] args)
A default implementation of n-arity, non-block 'call' method, which simply calls the n-arity, block-receiving version with the arg list and Block.NULL_BLOCK.

Parameters:
context - The thread context for the currently executing thread
self - The 'self' or 'receiver' object to use for this call
klazz - The Ruby class against which this method is binding
name - The incoming name used to invoke this method
arg1 - The first argument to this invocation
arg2 - The second argument to this invocation
Returns:
The result of the call

call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name)
Arity 0, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        Block block)
Arity 0, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0)
Arity 1, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        Block block)
Arity 1, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1)
Arity 2, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        Block block)
Arity 2, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2)
Arity 3, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        Block block)
Arity 3, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3)
Arity 4, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        Block block)
Arity 4, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4)
Arity 5, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        Block block)
Arity 5, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5)
Arity 6, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        Block block)
Arity 6, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6)
Arity 7, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6,
                        Block block)
Arity 7, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6,
                        IRubyObject arg7)
Arity 8, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6,
                        IRubyObject arg7,
                        Block block)
Arity 8, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6,
                        IRubyObject arg7,
                        IRubyObject arg8)
Arity 9, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6,
                        IRubyObject arg7,
                        IRubyObject arg8,
                        Block block)
Arity 9, with block; calls through IRubyObject[] path


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6,
                        IRubyObject arg7,
                        IRubyObject arg8,
                        IRubyObject arg9)
Arity 10, no block


call

public IRubyObject call(ThreadContext context,
                        IRubyObject self,
                        RubyModule klazz,
                        java.lang.String name,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        IRubyObject arg3,
                        IRubyObject arg4,
                        IRubyObject arg5,
                        IRubyObject arg6,
                        IRubyObject arg7,
                        IRubyObject arg8,
                        IRubyObject arg9,
                        Block block)
Arity 10, with block; calls through IRubyObject[] path


dup

public abstract DynamicMethod dup()
Duplicate this method, returning DynamicMethod referencing the same code and with the same attributes. It is not required that this method produce a new object if the semantics of the DynamicMethod subtype do not require such.

Returns:
An identical DynamicMethod object to the target.

isCallableFrom

public boolean isCallableFrom(IRubyObject caller,
                              CallType callType)
Determine whether this method is callable from the given object using the given call type.

Parameters:
caller - The calling object
callType - The type of call
Returns:
true if the call would not violate visibility; false otherwise

calculateProtectedClass

protected static RubyModule calculateProtectedClass(RubyModule cls)
Calculate, based on given RubyModule, which class in its hierarchy should be used to determine protected access.

Parameters:
cls - The class from which to calculate
Returns:
The class to be used for protected access checking.

getProtectedClass

protected RubyModule getProtectedClass()
Retrieve the pre-calculated "protected class" used for access checks.

Returns:
The "protected class" for access checks.

getImplementationClass

public RubyModule getImplementationClass()
Retrieve the class or module on which this method is implemented, used for 'super' logic among others.

Returns:
The class on which this method is implemented

setImplementationClass

public void setImplementationClass(RubyModule implClass)
Set the class on which this method is implemented, used for 'super' logic, among others.

Parameters:
implClass - The class on which this method is implemented

getVisibility

public Visibility getVisibility()
Get the visibility of this method.

Returns:
The visibility of this method

setVisibility

public void setVisibility(Visibility visibility)
Set the visibility of this method.

Parameters:
visibility - The visibility of this method

isUndefined

public final boolean isUndefined()
Whether this method is the "undefined" method, used to represent a missing or undef'ed method. Only returns true for UndefinedMethod instances, of which there should be only one (a singleton).

Returns:
true if this method is the undefined method; false otherwise

getArity

public Arity getArity()
Retrieve the arity of this method, used for reporting arity to Ruby code. This arity may or may not reflect the actual specific or variable arities of the referenced method.

Returns:
The arity of the method, as reported to Ruby consumers.

getRealMethod

public DynamicMethod getRealMethod()
Get the "real" method contained within this method. This simply returns self except in cases where a method is wrapped to give it a new name or new implementation class (AliasMethod, WrapperMethod, ...).

Returns:
The "real" method associated with this one

getCallConfig

public CallConfiguration getCallConfig()
Get the CallConfiguration used for pre/post logic for this method handle.

Returns:
The CallConfiguration for this method handle

setCallConfig

public void setCallConfig(CallConfiguration callConfig)
Set the CallConfiguration used for pre/post logic for this method handle.

Parameters:
callConfig - The CallConfiguration for this method handle

isNative

public boolean isNative()
Returns true if this method is backed by native (i.e. Java) code.

Returns:
true If backed by Java code or JVM bytecode; false otherwise

handleRedo

protected IRubyObject handleRedo(Ruby runtime)
                          throws RaiseException
Throws:
RaiseException

handleReturn

protected IRubyObject handleReturn(ThreadContext context,
                                   JumpException.ReturnJump rj)


Copyright © 2002-2009 JRuby Team. All Rights Reserved.