Package org.codehaus.groovy.vmplugin.v8

# Class CacheableCallSite

java.lang.Object
java.lang.invoke.CallSite
java.lang.invoke.MutableCallSite
org.codehaus.groovy.vmplugin.v8.CacheableCallSite

public class CacheableCallSite extends MutableCallSite
Represents a cacheable call site, which can reduce the cost of resolving methods

Since:
  3.0.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CacheableCallSite(MethodType type, MethodHandles.Lookup lookup)`
  Creates a cacheable call site for the supplied type and lookup context.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper`
  `getAndPut(String className, MemoizeCache.ValueProvider<? super String,? extends org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper> valueProvider)`
  Returns a cached method-handle wrapper for the receiver class, computing and storing it if needed.
  `MethodHandle`
  `getDefaultTarget()`
  Returns the default target currently installed on this call site.
  `AtomicLong`
  `getFallbackRound()`
  Returns the fallback round counter.
  `MethodHandle`
  `getFallbackTarget()`
  Returns the fallback target used when guards fail.
  `org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper`
  `getIfPresent(String className)`
  Read-only PIC lookup: the cached wrapper for the receiver class, or `null` when absent or its soft reference has been cleared.
  `MethodHandles.Lookup`
  `getLookup()`
  Returns the lookup associated with this call site.
  `long`
  `incrementFallbackCount()`
  Increments the number of fallback executions for this call site.
  `boolean`
  `isAotLinked()`
  Whether this site was linked in AOT mode (GraalVM native image, or the `groovy.indy.aot.link` diagnostic knob): the site is wrapped in a `ConstantCallSite` over the cache-consulting default path, is never retargeted, and cache freshness is carried by the `AotDispatch` stamp instead of SwitchPoints.
  `org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper`
  `put(String name, org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper mhw)`
  Stores a method-handle wrapper under the supplied cache key.
  `void`
  `resetFallbackCount()`
  Resets the fallback count and advances the fallback round marker.
  `void`
  `setDefaultTarget(MethodHandle defaultTarget)`
  Stores the default target for this call site.
  `void`
  `setFallbackTarget(MethodHandle fallbackTarget)`
  Stores the fallback target used when guards fail.
  `void`
  `setTarget(MethodHandle newTarget)`
  Fails fast on any retarget attempt in AOT mode.

  ### Methods inherited from class java.lang.invoke.MutableCallSite

  `dynamicInvoker, getTarget, syncAll`

  ### Methods inherited from class java.lang.invoke.CallSite

  `type`

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

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

- ## Constructor Details

  - ### CacheableCallSite

    public CacheableCallSite(MethodType type, MethodHandles.Lookup lookup)
    Creates a cacheable call site for the supplied type and lookup context.
    Parameters:
      `type` - the call-site type
      `lookup` - the lookup used to unreflect targets

- ## Method Details

  - ### isAotLinked

    public boolean isAotLinked()
    Whether this site was linked in AOT mode (GraalVM native image, or the `groovy.indy.aot.link` diagnostic knob): the site is wrapped in a `ConstantCallSite` over the cache-consulting default path, is never retargeted, and cache freshness is carried by the `AotDispatch` stamp instead of SwitchPoints.

  - ### setTarget

    public void setTarget(MethodHandle newTarget)
    Fails fast on any retarget attempt in AOT mode. Under a real native image `setTarget` throws `UnsupportedFeatureError` anyway — and worse, execution would continue with the stale target if that error were swallowed — so a missed gate is a bug on every platform; this surfaces it on the JVM, where tests run with the diagnostic knob.
    Overrides:
      `setTarget` in class `MutableCallSite`

  - ### getIfPresent

    public org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper getIfPresent(String className)
    Read-only PIC lookup: the cached wrapper for the receiver class, or `null` when absent or its soft reference has been cleared. Used by the AOT dispatch path, which resolves misses itself and must not pay for a value-provider allocation per call.
    Parameters:
      `className` - the receiver cache key
    Returns:
      the cached wrapper or `null`

  - ### getAndPut

    public org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper getAndPut(String className, MemoizeCache.ValueProvider<? super String,? extends org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper> valueProvider)
    Returns a cached method-handle wrapper for the receiver class, computing and storing it if needed.
    Parameters:
      `className` - the receiver cache key
      `valueProvider` - the provider used to compute a missing entry
    Returns:
      the cached or newly created wrapper

  - ### put

    public org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper put(String name, org.codehaus.groovy.vmplugin.v8.MethodHandleWrapper mhw)
    Stores a method-handle wrapper under the supplied cache key.
    Parameters:
      `name` - the receiver cache key
      `mhw` - the wrapper to cache
    Returns:
      the previously cached wrapper, or `null` if none existed

  - ### incrementFallbackCount

    public long incrementFallbackCount()
    Increments the number of fallback executions for this call site.
    Returns:
      the updated fallback count

  - ### resetFallbackCount

    public void resetFallbackCount()
    Resets the fallback count and advances the fallback round marker.

  - ### getFallbackRound

    public AtomicLong getFallbackRound()
    Returns the fallback round counter.
    Returns:
      the fallback round counter

  - ### getDefaultTarget

    public MethodHandle getDefaultTarget()
    Returns the default target currently installed on this call site.
    Returns:
      the default target

  - ### setDefaultTarget

    public void setDefaultTarget(MethodHandle defaultTarget)
    Stores the default target for this call site.
    Parameters:
      `defaultTarget` - the default target handle

  - ### getFallbackTarget

    public MethodHandle getFallbackTarget()
    Returns the fallback target used when guards fail.
    Returns:
      the fallback target

  - ### setFallbackTarget

    public void setFallbackTarget(MethodHandle fallbackTarget)
    Stores the fallback target used when guards fail.
    Parameters:
      `fallbackTarget` - the fallback target handle

  - ### getLookup

    public MethodHandles.Lookup getLookup()
    Returns the lookup associated with this call site.
    Returns:
      the call-site lookup