Class OptimizedCallTarget

java.lang.Object
com.oracle.truffle.runtime.OptimizedCallTarget
All Implemented Interfaces:
com.oracle.truffle.api.CallTarget, com.oracle.truffle.api.ReplaceObserver, com.oracle.truffle.api.RootCallTarget, com.oracle.truffle.compiler.TruffleCompilable
Direct Known Subclasses:
HotSpotOptimizedCallTarget

public abstract class OptimizedCallTarget extends Object implements com.oracle.truffle.compiler.TruffleCompilable, com.oracle.truffle.api.RootCallTarget, com.oracle.truffle.api.ReplaceObserver
Call target that is optimized by Graal upon surpassing a specific invocation threshold. That is, this is a Truffle AST that can be optimized via partial evaluation and compiled to machine code. Note: PartialEvaluator looks up this class and a number of its methods by name. The end-goal of executing a OptimizedCallTarget is executing its root node. The following call-graph shows all the paths that can be taken from calling a call target (through all the public call* methods) to the execution of the root node depending on the type of call.
              OptimizedRuntimeSupport#callProfiled                    OptimizedRuntimeSupport#callInlined
                                |                                               |
                                |                                               V
  PUBLIC   call -> callIndirect | callOSR   callDirect <================> callInlined
                           |  +-+    |           |             ^                |
                           |  |  +---+           |     substituted by the       |
                           V  V  V               |     compiler if inlined      |
  PROTECTED               doInvoke <-------------+                              |
                             |                                                  |
                             | <= Jump to installed code                        |
                             V                                                  |
  PROTECTED              callBoundary                                           |
                             |                                                  |
                             | <= Tail jump to installed code in Int.           |
                             V                                                  |
  PROTECTED           profiledPERoot                                            |
                             |                                                  |
  PRIVATE                    +----------> executeRootNode <---------------------+
                                                 |
                                                 V
                                         rootNode.execute()
 
  • Field Details

    • initialized

      protected volatile boolean initialized
      Whether this call target was cloned, compiled or called.
    • engine

      public final EngineData engine
      The engine data associated with this call target. Used to cache option lookups and to gather engine specific statistics.
    • speculationLog

      protected volatile jdk.vm.ci.meta.SpeculationLog speculationLog
      The speculation log to keep track of assumptions taken and failed for previous compilations.
    • id

      public final long id
  • Constructor Details

    • OptimizedCallTarget

      protected OptimizedCallTarget(OptimizedCallTarget sourceCallTarget, com.oracle.truffle.api.nodes.RootNode rootNode)
    • OptimizedCallTarget

      protected OptimizedCallTarget(EngineData engine)
  • Method Details

    • highestCompiledTier

      public final int highestCompiledTier()
    • prepareForCompilation

      public final void prepareForCompilation()
      Specified by:
      prepareForCompilation in interface com.oracle.truffle.compiler.TruffleCompilable
    • isTrivial

      public boolean isTrivial()
      Specified by:
      isTrivial in interface com.oracle.truffle.compiler.TruffleCompilable
    • dequeueInlined

      public final void dequeueInlined()
      We intentionally do not synchronize here since as it's not worth the sync costs.
    • getRootNode

      public final com.oracle.truffle.api.nodes.RootNode getRootNode()
      Specified by:
      getRootNode in interface com.oracle.truffle.api.RootCallTarget
    • resetCompilationProfile

      public final void resetCompilationProfile()
    • call

      public final Object call(Object... args)
      Specified by:
      call in interface com.oracle.truffle.api.CallTarget
    • call

      public final Object call(com.oracle.truffle.api.nodes.Node location, Object... args)
      Specified by:
      call in interface com.oracle.truffle.api.CallTarget
    • callIndirect

      public final Object callIndirect(com.oracle.truffle.api.nodes.Node location, Object... args)
    • callDirect

      public final Object callDirect(com.oracle.truffle.api.nodes.Node location, Object... args)
      In compiled code, this is only used if the callee is not inlined. If the callee is inlined, callInlined(Node, Object...) is used instead, which does not profile arguments, as it is estimated redundant. See the docs of OptimizedCallTarget.
    • callInlined

      public final Object callInlined(com.oracle.truffle.api.nodes.Node location, Object... arguments)
    • callOSR

      public final Object callOSR(Object... args)
    • doInvoke

      protected Object doInvoke(Object[] args)
      Overridden by SVM.
    • callBoundary

      protected final Object callBoundary(Object[] args)
    • scaledThreshold

      public static int scaledThreshold(int callAndLoopThresholdInInterpreter)
    • shouldCompile

      public final boolean shouldCompile()
    • wasExecuted

      public final boolean wasExecuted()
    • profiledPERoot

      protected final Object profiledPERoot(Object[] originalArguments)
    • runtime

      protected static OptimizedTruffleRuntime runtime()
    • isInitialized

      public final boolean isInitialized()
    • getOptionValues

      public final org.graalvm.options.OptionValues getOptionValues()
    • getOptionValue

      public final <T> T getOptionValue(org.graalvm.options.OptionKey<T> key)
    • compile

      public final boolean compile(boolean lastTierCompilation)
      Returns true if the call target was already compiled or was compiled synchronously. Returns false if compilation was not scheduled or is happening in the background. Use isSubmittedForCompilation() to find out whether it is submitted for compilation.
    • maybeWaitForTask

      public final boolean maybeWaitForTask(CompilationTask task)
    • needsCompile

      public final boolean needsCompile(boolean isLastTierCompilation)
    • isSubmittedForCompilation

      public final boolean isSubmittedForCompilation()
    • waitForCompilation

      public final void waitForCompilation()
    • getCodeAddress

      public abstract long getCodeAddress()
      Gets the address of the machine code for this call target. A non-zero return value denotes the contiguous memory block containing the machine code but does not necessarily represent an entry point for the machine code or even the address of executable instructions. This value is only for informational purposes (e.g., use in a log message).
    • isValid

      public abstract boolean isValid()
      Determines if this call target has valid machine code that can be entered attached to it.
    • isValidLastTier

      public abstract boolean isValidLastTier()
      Determines if this call target has valid machine code attached to it, and that this code was compiled in the last tier.
    • invalidate

      public final boolean invalidate(CharSequence reason)
      Invalidates this call target by invalidating any machine code attached to it.
      Parameters:
      reason - a textual description of the reason why the machine code was invalidated. May be null.
      Returns:
      imprecise: whether code has possibly been invalidated or a compilation has been cancelled. Returns false only if both are guaranteed to not have happened, true otherwise.
    • getSpeculationLog

      public jdk.vm.ci.meta.SpeculationLog getSpeculationLog()
      Gets the speculation log used to collect all failed speculations in the compiled code for this call target. Note that this may differ from the speculation log used for compilation.
    • asJavaConstant

      public final jdk.vm.ci.meta.JavaConstant asJavaConstant()
      Specified by:
      asJavaConstant in interface com.oracle.truffle.compiler.TruffleCompilable
    • isSameOrSplit

      public final boolean isSameOrSplit(com.oracle.truffle.compiler.TruffleCompilable ast)
      Specified by:
      isSameOrSplit in interface com.oracle.truffle.compiler.TruffleCompilable
    • cancelCompilation

      public boolean cancelCompilation(CharSequence reason)
      Specified by:
      cancelCompilation in interface com.oracle.truffle.compiler.TruffleCompilable
    • computeBlockCompilations

      public final boolean computeBlockCompilations()
      Computes block compilation using BlockNode APIs. If no block node is used in the AST or block node compilation is disabled then this method always returns false.
    • onInvalidate

      public final boolean onInvalidate(Object source, CharSequence reason, boolean wasActive)
      Specified by:
      onInvalidate in interface com.oracle.truffle.compiler.TruffleCompilable
    • onCompilationFailed

      public final void onCompilationFailed(Supplier<String> serializedException, boolean silent, boolean bailout, boolean permanentBailout, boolean graphTooBig)
      Specified by:
      onCompilationFailed in interface com.oracle.truffle.compiler.TruffleCompilable
    • log

      public final void log(String message)
    • getKnownCallSiteCount

      public final int getKnownCallSiteCount()
      Specified by:
      getKnownCallSiteCount in interface com.oracle.truffle.compiler.TruffleCompilable
    • getSourceCallTarget

      public final OptimizedCallTarget getSourceCallTarget()
    • getName

      public final String getName()
      Specified by:
      getName in interface com.oracle.truffle.compiler.TruffleCompilable
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • createFrame

      public static com.oracle.truffle.api.impl.FrameWithoutBoxing createFrame(com.oracle.truffle.api.frame.FrameDescriptor descriptor, Object[] args)
      Intrinsifiable compiler directive for creating a frame.
    • nodeReplaced

      public final boolean nodeReplaced(com.oracle.truffle.api.nodes.Node oldNode, com.oracle.truffle.api.nodes.Node newNode, CharSequence reason)
      Specified by:
      nodeReplaced in interface com.oracle.truffle.api.ReplaceObserver
    • accept

      public final void accept(com.oracle.truffle.api.nodes.NodeVisitor visitor)
    • getNonTrivialNodeCount

      public final int getNonTrivialNodeCount()
      Specified by:
      getNonTrivialNodeCount in interface com.oracle.truffle.compiler.TruffleCompilable
    • getCallCount

      public final int getCallCount()
      Specified by:
      getCallCount in interface com.oracle.truffle.compiler.TruffleCompilable
    • getCallAndLoopCount

      public final int getCallAndLoopCount()
    • getInitializedTimestamp

      public final long getInitializedTimestamp()
    • getDebugProperties

      public final Map<String,Object> getDebugProperties()
    • countDirectCallNodes

      public int countDirectCallNodes()
      Specified by:
      countDirectCallNodes in interface com.oracle.truffle.compiler.TruffleCompilable
    • getInitializedArgumentsProfile

      protected final OptimizedCallTarget.ArgumentsProfile getInitializedArgumentsProfile()
    • getInitializedReturnProfile

      protected final OptimizedCallTarget.ReturnProfile getInitializedReturnProfile()
    • isSourceCallTarget

      public final boolean isSourceCallTarget()
    • isSplit

      public final boolean isSplit()
    • getCallSiteForSplit

      public final OptimizedDirectCallNode getCallSiteForSplit()
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • isSingleCaller

      public final boolean isSingleCaller()
    • getSingleCallNode

      public final OptimizedDirectCallNode getSingleCallNode()
    • resetNeedsSplit

      public final void resetNeedsSplit()
    • prepareForAOT

      public final boolean prepareForAOT()
    • engineId

      public long engineId()
      Specified by:
      engineId in interface com.oracle.truffle.compiler.TruffleCompilable
    • getCompilerOptions

      public Map<String,String> getCompilerOptions()
      Specified by:
      getCompilerOptions in interface com.oracle.truffle.compiler.TruffleCompilable