Class DynamicMethod
java.lang.Object
org.jruby.internal.runtime.methods.DynamicMethod
- Direct Known Subclasses:
AbstractIRMethod
,AliasMethod
,DefaultMethod
,DelegatingDynamicMethod
,HandleMethod
,Helpers.MethodMissingWrapper
,JavaMethod
,MethodMethod
,NativeInvoker
,NullMethod
,PartialDelegatingMethod
,ProcMethod
,RefinedMarker
,RefinedWrapper
,RubyStruct.Accessor
,RubyStruct.Mutator
,UndefinedMethod
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static @interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
How many times has this method been aliased.protected RubyModule
The module or class that originally defined this method.protected byte
Flags for builtin, notimpl, etcprotected Object
An arbitrarily-typed "method handle" for use by compilers and call sitesprotected RubyModule
The Ruby module or class from which this method should `super`.protected final String
The simple, base name this method was defined under.protected RubyModule
The "protected class" used for calculating protected access.protected long
The serial number for this method object, to globally identify it -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DynamicMethod
(String name) A no-arg constructor used only by the UndefinedMethod subclass and CompiledMethod handles.protected
DynamicMethod
(RubyModule implementationClass, Visibility visibility) Deprecated.protected
DynamicMethod
(RubyModule implementationClass, Visibility visibility, String name) Base constructor for dynamic method handles with names.protected
DynamicMethod
(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) Deprecated.protected
DynamicMethod
(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig, String name) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustAliasCount
(int delta) protected static RubyModule
Calculate, based on given RubyModule, which class in its hierarchy should be used to determine protected access.call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name) call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name, Block block) call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0) call
(ThreadContext context, IRubyObject self, RubyModule clazz, 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, String name, IRubyObject[] args, Block block) The minimum 'call' method required for a dynamic method handle.call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, Block block) call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1) call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) call
(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) boolean
callRespondTo
(ThreadContext context, IRubyObject self, String respondToMethodName, RubyModule klazz, RubySymbol name) abstract DynamicMethod
dup()
Duplicate this method, returning DynamicMethod referencing the same code and with the same attributes.int
getArity()
Deprecated.Deprecated.Get the original owner of this method/Get the "handle" associated with this DynamicMethod.Retrieve the class or module on which this method is implemented, used for 'super' logic among others.Additional metadata about this method.getName()
Get the base name this method was defined as.protected RubyModule
Retrieve the pre-calculated "protected class" used for access checks.Get the "real" method contained within this method.long
Get the global serial number for this method objectRetrieve the signature of this method.Get the visibility of this method.protected void
init
(RubyModule implementationClass, Visibility visibility) protected void
init
(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) Deprecated.boolean
Whether this method is a builtin method, i.e.boolean
isCallableFrom
(IRubyObject caller, CallType callType) Determine whether this method is callable from the given object using the given call type.boolean
isImplementedBy
(RubyModule other) boolean
isNative()
Returns true if this method is backed by native (i.e.boolean
Whether this method is "not implemented".final boolean
isNull()
Whether this method is the "null" method, used to stop method name resolution loops.boolean
final boolean
Whether this method is the "undefined" method, used to represent a missing or undef'ed method.void
setCallConfig
(CallConfiguration callConfig) Deprecated.void
setDefinedClass
(RubyModule definedClass) Set the defining class for this method, as when restructuring hierarchy for prepend.void
Set the "handle" associated with this DynamicMethod.void
setImplementationClass
(RubyModule implClass) Set the class on which this method is implemented, used for 'super' logic, among others.void
setIsBuiltin
(boolean isBuiltin) Force this method to be treated as a core built-in method if true, or as a normal non-core method otherwise.void
setNotImplemented
(boolean setNotImplemented) Set whether this method is "not implemented".void
Indicates the method will behave like a ruby2 keywords accepting method.void
setVisibility
(Visibility visibility) Set the visibility of this method.
-
Field Details
-
implementationClass
The Ruby module or class from which this method should `super`. Referred to as the `owner` in C Ruby. -
protectedClass
The "protected class" used for calculating protected access. -
definedClass
The module or class that originally defined this method. Referred to as the `defined_class` in C Ruby. -
serialNumber
protected long serialNumberThe serial number for this method object, to globally identify it -
flags
protected byte flagsFlags for builtin, notimpl, etc -
name
The simple, base name this method was defined under. May be null. -
handle
An arbitrarily-typed "method handle" for use by compilers and call sites -
aliasCount
protected int aliasCountHow many times has this method been aliased.
-
-
Constructor Details
-
DynamicMethod
Base constructor for dynamic method handles with names.- Parameters:
implementationClass
- The class to which this method will be immediately boundvisibility
- The visibility assigned to this methodname
- The simple name of this method
-
DynamicMethod
A no-arg constructor used only by the UndefinedMethod subclass and CompiledMethod handles. instanceof assertions make sure this is so.- Parameters:
name
- the name of the method
-
DynamicMethod
@Deprecated protected DynamicMethod(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) Deprecated. -
DynamicMethod
@Deprecated protected DynamicMethod(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig, String name) Deprecated. -
DynamicMethod
Deprecated.- Parameters:
implementationClass
- of the methodvisibility
- of the method
-
-
Method Details
-
init
-
getSerialNumber
public long getSerialNumber()Get the global serial number for this method object- Returns:
- This method object's serial number
-
isBuiltin
public boolean isBuiltin()Whether this method is a builtin method, i.e. a method built-in to JRuby and loaded during its core boot process.- Returns:
- true if this is a core built-in method, false otherwise
-
setIsBuiltin
public void setIsBuiltin(boolean isBuiltin) Force this method to be treated as a core built-in method if true, or as a normal non-core method otherwise.- Parameters:
isBuiltin
- true if this is a core built-in method, false otherwise
-
call
public abstract IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) The minimum 'call' method required for a dynamic method handle. Subclasses must implement 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 threadself
- The 'self' or 'receiver' object to use for this callclazz
- The Ruby class against which this method is bindingname
- The incoming name used to invoke this methodargs
- The argument list to this invocationblock
- The block passed to this invocation- Returns:
- The result of the call
-
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, 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 threadself
- The 'self' or 'receiver' object to use for this callclazz
- The Ruby class against which this method is bindingname
- The incoming name used to invoke this methodargs
- The first argument to this invocation- Returns:
- The result of the call
-
call
-
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, Block block) -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0) -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, Block block) -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1) -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) -
callRespondTo
public boolean callRespondTo(ThreadContext context, IRubyObject self, String respondToMethodName, RubyModule klazz, RubySymbol name) -
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
Determine whether this method is callable from the given object using the given call type.- Parameters:
caller
- The calling objectcallType
- The type of call- Returns:
- true if the call would not violate visibility; false otherwise
-
calculateProtectedClass
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
Retrieve the pre-calculated "protected class" used for access checks.- Returns:
- The "protected class" for access checks.
-
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
-
isImplementedBy
-
setImplementationClass
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
-
getDefinedClass
Get the original owner of this method/- Returns:
- the module method was defined in
-
setDefinedClass
Set the defining class for this method, as when restructuring hierarchy for prepend.- Parameters:
definedClass
- that method was defined in
-
getVisibility
Get the visibility of this method.- Returns:
- The visibility of this method
-
setVisibility
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
-
isNull
public final boolean isNull()Whether this method is the "null" method, used to stop method name resolution loops. Only returns true for NullMethod instances, of which there should be only one (a singleton).- Returns:
- true if this method is the undefined method; false otherwise
-
getArity
Deprecated.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.
-
getSignature
Retrieve the signature of this method.- Returns:
- the signature
-
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, PartialDelegatingMethod, ...).- Returns:
- The "real" method associated with this one
-
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
-
getName
Get the base name this method was defined as.- Returns:
- the base name for the method
-
getHandle
Get the "handle" associated with this DynamicMethod.- Returns:
- the handle
-
setHandle
Set the "handle" associated with this DynamicMethod.- Parameters:
handle
- the handle
-
isNotImplemented
public boolean isNotImplemented()Whether this method is "not implemented". This is primarily to support Ruby 1.9's behavior of respond_to? yielding false if the feature in question is unsupported (but still having the method defined).- Returns:
- is this a method which is marked as not implemented
-
getMethodData
Additional metadata about this method.- Returns:
- method data (defined in sub classes)
-
getInstanceVariableNames
-
setNotImplemented
public void setNotImplemented(boolean setNotImplemented) Set whether this method is "not implemented".- Parameters:
setNotImplemented
- is this not implement or not
-
isRefined
public boolean isRefined() -
init
@Deprecated protected void init(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) Deprecated. -
getCallConfig
Deprecated. -
setCallConfig
Deprecated. -
adjustAliasCount
public void adjustAliasCount(int delta) -
getAliasCount
public int getAliasCount() -
setRuby2Keywords
public void setRuby2Keywords()Indicates the method will behave like a ruby2 keywords accepting method. This must be a Ruby implementation to work. See Module#ruby2_keywords for information on the semantics of a method which is marked this way.
-
DynamicMethod(RubyModule, Visibility, String)