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

public abstract class DynamicMethod extends 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 Details

    • implementationClass

      protected RubyModule implementationClass
      The Ruby module or class from which this method should `super`. Referred to as the `owner` in C Ruby.
    • protectedClass

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

      protected RubyModule definedClass
      The module or class that originally defined this method. Referred to as the `defined_class` in C Ruby.
    • visibility

      private byte visibility
      The visibility of this method. This is the ordinal of the Visibility enum value.
    • serialNumber

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

      protected byte flags
      Flags for builtin, notimpl, etc
    • name

      protected final String name
      The simple, base name this method was defined under. May be null.
    • handle

      protected Object 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

  • Method Details

    • init

      protected void init(RubyModule implementationClass, Visibility visibility)
    • 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 thread
      self - The 'self' or 'receiver' object to use for this call
      clazz - 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, 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
      clazz - The Ruby class against which this method is binding
      name - The incoming name used to invoke this method
      args - The first argument to this invocation
      Returns:
      The result of the call
    • call

      public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name)
      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

      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
    • protectedAccessOk

      private boolean protectedAccessOk(IRubyObject caller)
      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

      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
    • isImplementedBy

      public boolean isImplementedBy(RubyModule other)
    • 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
    • getDefinedClass

      public RubyModule getDefinedClass()
      Get the original owner of this method/
    • setDefinedClass

      public void setDefinedClass(RubyModule definedClass)
      Set the defining class for this method, as when restructuring hierarchy for prepend.
    • 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
    • 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 public Arity 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

      public Signature getSignature()
      Retrieve the signature of this method.
      Returns:
      the signature
    • 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, 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

      public String getName()
      Get the base name this method was defined as.
      Returns:
      the base name for the method
    • getHandle

      public Object getHandle()
      Get the "handle" associated with this DynamicMethod.
      Returns:
      the handle
    • setHandle

      public void setHandle(Object handle)
      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

      public MethodData getMethodData()
      Additional metadata about this method.
    • getInstanceVariableNames

      public Collection<String> 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 public CallConfiguration getCallConfig()
      Deprecated.
    • setCallConfig

      @Deprecated public void setCallConfig(CallConfiguration callConfig)
      Deprecated.