Top Description Inners Fields Constructors Methods
org.python.core

pack-priv final Enum MethodSignature

extends Enum<MethodSignature>
Class Inheritance
Static Imports
java.lang.invoke.MethodHandles.filterArguments, .MethodHandles.filterReturnValue, org.python.core.ClassShorthand.O, .ClassShorthand.OA

The enum MethodSignature enumerates the method signatures for which an optimised implementation is possible. Sub-classes of PyJavaFunction and PyMethodDescr correspond to these values. It is not required that each value have a distinct optimised sub-class. This enum is used internally to choose between these sub-classes.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MethodSignature.Util

Handle utilities, supporting signature creation.

Field Summary

Modifier and TypeField and Description
pack-priv final MethodType
boundType

The type of method handles matching this method signature when it describes a bound or static method.

pack-priv final MethodHandle
empty

Handle to throw a Slot.

public static final MethodSignature
GENERAL

Full generality of ArgParser allowed, after self when describing an unbound method.

pack-priv final MethodType
instanceType

The type of method handles matching this method signature when it describes an instance method.

public static final MethodSignature
NOARGS

No arguments allowed after self.

public static final MethodSignature
O1

One argument allowed, possibly after self.

public static final MethodSignature
O2

Two arguments allowed, possibly after self.

public static final MethodSignature
O3

Three arguments allowed, possibly after self.

public static final MethodSignature
POSITIONAL

Only positional arguments allowed, after self when describing an unbound method.

private final boolean
useArray

The second parameter is an object array.

Constructor Summary

AccessConstructor and Description
private
MethodSignature(Class<?>... ptypes)

Method Summary

Modifier and TypeMethod and Description
pack-priv static final MethodHandle

Returns:

handle compatible with methodDef
adapt
(MethodHandle
the handle to be prepared (or null for empty)
raw
,
int
index in the type at which to start.
pos
)

Adapt an arbitrary method handle to one that expects arguments from a given position onwards to be Object, and returns Object, using the conversions defined in Clinic.

pack-priv static MethodSignature

Returns:

a chosen MethodSignature
from
(MethodType
to look for
mt
)

Choose a MethodSignature based on a MethodType.

pack-priv static MethodSignature

Returns:

a chosen MethodSignature
fromParser
(ArgParser
argument parser describing the method
ap
)

Choose a MethodSignature based on the argument parser.

private static MethodSignature

Returns:

chosen method signature
positional
(int
number of arguments
n
)

Select a (potential) optimisation for a method that accepts arguments only by position.

pack-priv MethodHandle

Returns:

handle consistent with this MethodSignature
prepare
(ArgParser
to which the handle is made to conform
ap
,
MethodHandle
handle representing the Java implementation
raw
)

Prepare a raw method handle, consistent with this MethodSignature, so that it matches the type implied by the parser, and may be called in an optimised way.

pack-priv MethodHandle

Returns:

handle consistent with this MethodSignature
prepareBound
(ArgParser
to which the handle is made to conform
ap
,
MethodHandle
handle representing the Java implementation
raw
,
Object
to bind as the first argument if not Python static
self
)

Prepare and bind a provided raw method handle, consistent with this MethodSignature, so that it matches the type implied by the parser, and may be called in an optimised way.

public static MethodSignature
public static MethodSignature[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

boundTypeback to summary
pack-priv final MethodType boundType

The type of method handles matching this method signature when it describes a bound or static method. For POSITIONAL this is the type (O[])O.

emptyback to summary
pack-priv final MethodHandle empty

Handle to throw a Slot.EmptyException, and having the signature instanceType for this MethodSignature.

GENERALback to summary
public static final MethodSignature GENERAL

Full generality of ArgParser allowed, after self when describing an unbound method.

instanceTypeback to summary
pack-priv final MethodType instanceType

The type of method handles matching this method signature when it describes an instance method. This differs from boundType by a preceding O. For POSITIONAL this is the type (O, O[])O.

NOARGSback to summary
public static final MethodSignature NOARGS

No arguments allowed after self.

O1back to summary
public static final MethodSignature O1

One argument allowed, possibly after self.

O2back to summary
public static final MethodSignature O2

Two arguments allowed, possibly after self.

O3back to summary
public static final MethodSignature O3

Three arguments allowed, possibly after self.

POSITIONALback to summary
public static final MethodSignature POSITIONAL

Only positional arguments allowed, after self when describing an unbound method.

useArrayback to summary
private final boolean useArray

The second parameter is an object array.

Constructor Detail

MethodSignatureback to summary
private MethodSignature(Class<?>... ptypes)

Method Detail

adaptback to summary
pack-priv static final MethodHandle adapt(MethodHandle raw, int pos)

Adapt an arbitrary method handle to one that expects arguments from a given position onwards to be Object, and returns Object, using the conversions defined in Clinic.

Parameters
raw:MethodHandle

the handle to be prepared (or null for empty)

pos:int

index in the type at which to start.

Returns:MethodHandle

handle compatible with methodDef

fromback to summary
pack-priv static MethodSignature from(MethodType mt)

Choose a MethodSignature based on a MethodType.

Parameters
mt:MethodType

to look for

Returns:MethodSignature

a chosen MethodSignature

fromParserback to summary
pack-priv static MethodSignature fromParser(ArgParser ap)

Choose a MethodSignature based on the argument parser. Note that in a PyMethodDescr, the ArgParser describes the arguments after self, even if the implementation is declared static in Java, so that the self argument is explicit.

Parameters
ap:ArgParser

argument parser describing the method

Returns:MethodSignature

a chosen MethodSignature

positionalback to summary
private static MethodSignature positional(int n)

Select a (potential) optimisation for a method that accepts arguments only by position. Signatures that allow only positional arguments (optionally with default values for trailing parameters not filled by the argument) may be optimised if the number is not too great.

Parameters
n:int

number of arguments

Returns:MethodSignature

chosen method signature

prepareback to summary
pack-priv MethodHandle prepare(ArgParser ap, MethodHandle raw)

Prepare a raw method handle, consistent with this MethodSignature, so that it matches the type implied by the parser, and may be called in an optimised way.

Parameters
ap:ArgParser

to which the handle is made to conform

raw:MethodHandle

handle representing the Java implementation

Returns:MethodHandle

handle consistent with this MethodSignature

prepareBoundback to summary
pack-priv MethodHandle prepareBound(ArgParser ap, MethodHandle raw, Object self)

Prepare and bind a provided raw method handle, consistent with this MethodSignature, so that it matches the type implied by the parser, and may be called in an optimised way. This has the right semantics for methods in a JavaModule, where ap.methodKind==STATIC means there is no module argument to bind.

Parameters
ap:ArgParser

to which the handle is made to conform

raw:MethodHandle

handle representing the Java implementation

self:Object

to bind as the first argument if not Python static

Returns:MethodHandle

handle consistent with this MethodSignature

valueOfback to summary
public static MethodSignature valueOf(String name)
valuesback to summary
public static MethodSignature[] values()
org.python.core back to summary

private Class MethodSignature.Util

extends Object
Class Inheritance

Handle utilities, supporting signature creation.

Field Summary

Modifier and TypeField and Description
private static final Slot.EmptyException
EMPTY

Single re-used instance of Slot.

pack-priv static final MethodHandle
THROW_EMPTY

A handle with signature ()O that throws a single re-used instance of Slot.EmptyException.

Constructor Summary

AccessConstructor and Description
private
Util()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTYback to summary
private static final Slot.EmptyException EMPTY

Single re-used instance of Slot.EmptyException

THROW_EMPTYback to summary
pack-priv static final MethodHandle THROW_EMPTY

A handle with signature ()O that throws a single re-used instance of Slot.EmptyException. We use this in sub-class constructors when given a null raw method handle, to ensure it is always safe to invoke PyMethodDescr#method. If the signature is to be believed, EMPTY returns Object, although it never actually returns at all.

Constructor Detail

Utilback to summary
private Util()