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

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.
    • 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
    • aliasCount

      protected int aliasCount
      How many times has this method been aliased.
  • Constructor Details

    • DynamicMethod

      protected DynamicMethod(RubyModule implementationClass, Visibility visibility, String name)
      Base constructor for dynamic method handles with names.
      Parameters:
      implementationClass - The class to which this method will be immediately bound
      visibility - The visibility assigned to this method
      name - The simple name of this method
    • DynamicMethod

      protected DynamicMethod(String name)
      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 protected DynamicMethod(RubyModule implementationClass, Visibility visibility)
      Parameters:
      implementationClass - of the method
      visibility - of the method
  • 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()
      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 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)
    • 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

      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
    • 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/
      Returns:
      the module method was defined in
    • setDefinedClass

      public void setDefinedClass(RubyModule definedClass)
      Set the defining class for this method, as when restructuring hierarchy for prepend.
      Parameters:
      definedClass - that method was defined in
    • 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).
      Returns:
      is this a method which is marked as not implemented
    • getMethodData

      public MethodData getMethodData()
      Additional metadata about this method.
      Returns:
      method data (defined in sub classes)
    • getInstanceVariableNames

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

      @Deprecated public void setCallConfig(CallConfiguration callConfig)
      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.