Package org.apache.groovy.internal.runtime.invoke

# Class InvokerFactory

java.lang.Object
org.apache.groovy.internal.runtime.invoke.InvokerFactory

public final class InvokerFactory extends Object
Factory for `DirectInvoker` instances bound to one `CachedMethod`.

Not user API. `CachedMethod.invoke` is the only production caller. Package-visible helpers exist so tests can drive generation without going through the hit-count hook.

Define path (one order):

1. InvokerFactory nestmate + `INVOKE*` when the member is publicly invocable from this class and every type is resolvable here (`String.startsWith`).
2. Declaring-class nestmate + `INVOKE*` when `privateLookupIn` is worth attempting and the host can resolve `DirectInvoker`.
3. InvokerFactory nestmate + classData `MethodHandle` when this loader can resolve the erased `invokeExact` types.
4. `ClassLoaderForClassArtifacts` visible class, only when that loader can resolve `DirectInvoker` — never for bootstrap hosts.

Failures sticky-return `null`; they must not propagate to `CachedMethod.invoke`.

Since:
  6.0.0

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final long`
  `DEFAULT_THRESHOLD`
  Default for `PROPERTY_THRESHOLD`.
  `static final String`
  `PROPERTY_DISABLE`
  Kill switch.
  `static final String`
  `PROPERTY_THRESHOLD`
  Hits before generation.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `generationAllowed()`
  Package-visible predicate.
  `static DirectInvoker`
  `tryCreate(CachedMethod method)`
  Attempts to bind a trampoline for `method`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### PROPERTY_THRESHOLD

    public static final String PROPERTY_THRESHOLD
    Hits before generation. Default `DEFAULT_THRESHOLD` — the same order as `groovy.indy.optimize.threshold`, so a method that stays on `doMethodInvoke` long enough to look hot also qualifies for a trampoline.
    See Also:
      - Constant Field Values

  - ### DEFAULT_THRESHOLD

    public static final long DEFAULT_THRESHOLD
    Default for `PROPERTY_THRESHOLD`.
    See Also:
      - Constant Field Values

  - ### PROPERTY_DISABLE

    public static final String PROPERTY_DISABLE
    Kill switch. Default `false`.
    See Also:
      - Constant Field Values

- ## Method Details

  - ### tryCreate

    public static DirectInvoker tryCreate(CachedMethod method)
    Attempts to bind a trampoline for `method`. Returns `null` on any failure (sticky-fail). Public so `CachedMethod` in another package can call it; not user API (`Internal`, `internal` package). Tests in this package also drive generation through this method without going through the hit-count hook.
    Parameters:
      `method` - the cached method to bind
    Returns:
      a trampoline, or `null`

  - ### generationAllowed

    public static boolean generationAllowed()
    Package-visible predicate. Android cannot be flipped with a property (`AndroidSupport.isRunningAndroid()` is `Class.forName( "android.app.Activity")` captured at class-init). Native image is `HiddenClassDefiner.isEnabled()` — do not also gate on `AotDispatch.isAotLinkRequested()`, which is true on HotSpot when `-Dgroovy.indy.aot.link=true` and would silently disable generation in AOT-dispatch unit tests.
    Returns:
      `true` when generation may be attempted