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

## [Java] Class InvokerFactory

- 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
    Modifiers | Name | Description
    --- | --- | ---
    `static long` | `DEFAULT_THRESHOLD` | Default for PROPERTY_THRESHOLD.
    `static String` | `PROPERTY_DISABLE` | Kill switch.
    `static String` | `PROPERTY_THRESHOLD` | Hits before generation.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static boolean` | `generationAllowed()` Package-visible predicate.
    `` | `public static DirectInvoker` | `tryCreate(CachedMethod method)` Attempts to bind a trampoline for `method`.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final long DEFAULT_THRESHOLD

      Default for PROPERTY_THRESHOLD.

    - #### public static final String PROPERTY_DISABLE

      Kill switch. Default `false`.

    - #### 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.

  - ### Method Detail

    - #### 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

    - #### 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`