public class NativeMethod extends DynamicMethod
NativeMethod represents a method handle to a C extension function in JRuby,
to provide entry points into C code. Native methods setup and tear down scope and context
around a native method call and lock the GIL. Native methods restrict concurrency
in C extensions to avoid threading issues in C code.DynamicMethod.NativeCall| Modifier and Type | Field and Description |
|---|---|
protected Arity |
arity |
protected long |
function |
private Native |
nativeInstance |
builtin, callConfig, handle, implementationClass, name, nativeCall, nativeCalls, notImplemented, protectedClass, serialNumber, visibility| Constructor and Description |
|---|
NativeMethod(RubyModule clazz,
int arity,
long function) |
| Modifier and Type | Method and Description |
|---|---|
IRubyObject |
call(ThreadContext context,
IRubyObject recv,
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.
|
IRubyObject |
call(ThreadContext context,
IRubyObject recv,
RubyModule clazz,
java.lang.String name,
IRubyObject[] args,
Block block)
The minimum 'call' method required for a dynamic method handle.
|
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.
|
(package private) Native |
getNativeInstance() |
boolean |
isNative()
Returns true if this method is backed by native (i.e.
|
(package private) static void |
post(ThreadContext context)
Release the
GIL and pop the call frame and scope. |
(package private) static void |
pre(ThreadContext context,
IRubyObject self,
RubyModule klazz,
java.lang.String name)
Pushes the method frame for execution of the native function.
|
(package private) static void |
pre(ThreadContext context,
IRubyObject self,
RubyModule klazz,
java.lang.String name,
Block block)
|
calculateProtectedClass, call, call, call, call, call, call, call, call, getCallConfig, getHandle, getImplementationClass, getMethodData, getName, getNativeCall, getNativeCall, getProtectedClass, getRealMethod, getSerialNumber, getVisibility, handleBreak, handleRedo, handleReturn, init, isBuiltin, isCallableFrom, isNotImplemented, isUndefined, setCallConfig, setHandle, setImplementationClass, setIsBuiltin, setName, setNativeCall, setNativeCall, setNativeCall, setNotImplemented, setVisibilityprotected final Arity arity
protected final long function
private final Native nativeInstance
public NativeMethod(RubyModule clazz, int arity, long function)
public final DynamicMethod dup()
DynamicMethoddup in class DynamicMethodpublic final Arity getArity()
DynamicMethodgetArity in class DynamicMethodpublic final boolean isNative()
DynamicMethodisNative in class DynamicMethodstatic void pre(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name)
ManyVarsDynamicScope
since we don't know what we will need in the function execution. Lastly, this acquires the GIL for native
execution in the current Thread.static void pre(ThreadContext context, IRubyObject self, RubyModule klazz, java.lang.String name, Block block)
static void post(ThreadContext context)
GIL and pop the call frame and scope.final Native getNativeInstance()
public IRubyObject call(ThreadContext context, IRubyObject recv, RubyModule clazz, java.lang.String name, IRubyObject[] args)
DynamicMethodcall in class DynamicMethodcontext - The thread context for the currently executing threadrecv - The 'self' or 'receiver' object to use for this callname - The incoming name used to invoke this methodpublic IRubyObject call(ThreadContext context, IRubyObject recv, RubyModule clazz, java.lang.String name, IRubyObject[] args, Block block)
DynamicMethodcall in class DynamicMethodcontext - The thread context for the currently executing threadrecv - The 'self' or 'receiver' object to use for this callname - The incoming name used to invoke this methodargs - The argument list to this invocationblock - The block passed to this invocation