Class DynamicMethod
java.lang.Object
org.jruby.internal.runtime.methods.DynamicMethod
- Direct Known Subclasses:
AbstractIRMethod,AliasMethod,DefaultMethod,DelegatingDynamicMethod,HandleMethod,Helpers.MethodMissingMethod,Java.ProcToInterface,JavaMethod,JavaPackage.BlankSlateWrapper.MethodValue,MethodMethod,NativeInvoker,NullMethod,PartialDelegatingMethod,Pointer.NilToPointerMethod,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 classstatic @interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprotected RubyModuleThe module or class that originally defined this method.protected byteFlags for builtin, notimpl, etcprotected ObjectAn arbitrarily-typed "method handle" for use by compilers and call sitesprotected RubyModuleThe Ruby module or class from which this method should `super`.protected final StringThe simple, base name this method was defined under.private static final intprotected RubyModuleThe "protected class" used for calculating protected access.private static final intprotected longThe serial number for this method object, to globally identify itprivate byteThe visibility of this method. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDynamicMethod(String name) A no-arg constructor used only by the UndefinedMethod subclass and CompiledMethod handles.protectedDynamicMethod(RubyModule implementationClass, Visibility visibility) Deprecated.protectedDynamicMethod(RubyModule implementationClass, Visibility visibility, String name) Base constructor for dynamic method handles with names.protectedDynamicMethod(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) Deprecated.protectedDynamicMethod(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig, String name) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprotected static RubyModuleCalculate, 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) Arity 0, no blockcall(ThreadContext context, IRubyObject self, RubyModule klazz, String name, Block block) Arity 0, with block; calls through IRubyObject[] pathcall(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0) Arity 1, no blockcall(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 IRubyObjectcall(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) Arity 1, with block; calls through IRubyObject[] pathcall(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1) Arity 2, no blockcall(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) Arity 2, with block; calls through IRubyObject[] pathcall(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) Arity 3, no blockcall(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) Arity 3, with block; calls through IRubyObject[] pathbooleancallRespondTo(ThreadContext context, IRubyObject self, String respondToMethodName, RubyModule klazz, RubySymbol name) Will call respond_to?/respond_to_missing? on object and nameabstract DynamicMethoddup()Duplicate this method, returning DynamicMethod referencing the same code and with the same attributes.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 RubyModuleRetrieve the pre-calculated "protected class" used for access checks.Get the "real" method contained within this method.longGet the global serial number for this method objectRetrieve the signature of this method.Get the visibility of this method.protected voidinit(RubyModule implementationClass, Visibility visibility) protected voidinit(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) Deprecated.booleanbooleanisCallableFrom(IRubyObject caller, CallType callType) Determine whether this method is callable from the given object using the given call type.booleanisImplementedBy(RubyModule other) booleanisNative()Returns true if this method is backed by native (i.e.booleanWhether this method is "not implemented".final booleanisNull()Whether this method is the "null" method, used to stop method name resolution loops.booleanfinal booleanWhether this method is the "undefined" method, used to represent a missing or undef'ed method.private booleanprotectedAccessOk(IRubyObject caller) Determine whether the given object can safely invoke protected methods on the class this method is bound to.voidsetCallConfig(CallConfiguration callConfig) Deprecated.voidsetDefinedClass(RubyModule definedClass) Set the defining class for this method, as when restructuring hierarchy for prepend.voidSet the "handle" associated with this DynamicMethod.voidsetImplementationClass(RubyModule implClass) Set the class on which this method is implemented, used for 'super' logic, among others.voidsetIsBuiltin(boolean isBuiltin) voidsetNotImplemented(boolean setNotImplemented) Set whether this method is "not implemented".voidsetVisibility(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. -
visibility
private byte visibilityThe visibility of this method. This is the ordinal of the Visibility enum value. -
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 -
BUILTIN_FLAG
private static final int BUILTIN_FLAG- See Also:
-
NOTIMPL_FLAG
private static final int NOTIMPL_FLAG- See Also:
-
REFINED_FLAG
private static final int REFINED_FLAG- See Also:
-
-
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. -
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.
-
-
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() -
setIsBuiltin
public void setIsBuiltin(boolean isBuiltin) -
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
Arity 0, no block -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, Block block) Arity 0, with block; calls through IRubyObject[] path -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0) Arity 1, no block -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, Block block) Arity 1, with block; calls through IRubyObject[] path -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1) Arity 2, no block -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, 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, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) Arity 3, no block -
call
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) Arity 3, with block; calls through IRubyObject[] path -
callRespondTo
public boolean callRespondTo(ThreadContext context, IRubyObject self, String respondToMethodName, RubyModule klazz, RubySymbol name) Will call respond_to?/respond_to_missing? on object and 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
-
protectedAccessOk
Determine whether the given object can safely invoke protected methods on the class this method is bound to.- Parameters:
caller- The calling object- Returns:
- true if the calling object can call protected methods; 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/ -
setDefinedClass
Set the defining class for this method, as when restructuring hierarchy for prepend. -
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). -
getMethodData
Additional metadata about this method. -
getInstanceVariableNames
-
setNotImplemented
public void setNotImplemented(boolean setNotImplemented) Set whether this method is "not implemented". -
isRefined
public boolean isRefined() -
init
@Deprecated protected void init(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) Deprecated. -
getCallConfig
Deprecated. -
setCallConfig
Deprecated.
-
DynamicMethod(RubyModule, Visibility, String)