1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.hotspot;
  26 
  27 import jdk.vm.ci.meta.InvokeTarget;
  28 
  29 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
  30 import org.graalvm.compiler.core.target.Backend;
  31 import org.graalvm.compiler.hotspot.stubs.Stub;
  32 import jdk.internal.vm.compiler.word.LocationIdentity;
  33 
  34 /**
  35  * The details required to link a HotSpot runtime or stub call.
  36  */
  37 public interface HotSpotForeignCallLinkage extends ForeignCallLinkage, InvokeTarget {
  38 
  39     /**
  40      * Constants for specifying whether a foreign call destroys or preserves registers. A foreign
  41      * call will always destroy {@link HotSpotForeignCallLinkage#getOutgoingCallingConvention() its}
  42      * {@linkplain ForeignCallLinkage#getTemporaries() temporary} registers.
  43      */
  44     enum RegisterEffect {
  45         DESTROYS_REGISTERS,
  46         PRESERVES_REGISTERS
  47     }
  48 
  49     /**
  50      * Constants for specifying whether a call is a leaf or not and whether a
  51      * {@code JavaFrameAnchor} prologue and epilogue is required around the call. A leaf function
  52      * does not lock, GC or throw exceptions.
  53      */
  54     enum Transition {
  55         /**
  56          * A call to a leaf function that is guaranteed to not use floating point registers.
  57          * Consequently, floating point registers cleanup will be waived. On AMD64, this means the
  58          * compiler will no longer emit vzeroupper instruction around the foreign call, which it
  59          * normally does for unknown foreign calls to avoid potential SSE-AVX transition penalty.
  60          * Besides, this foreign call will never have its caller stack inspected by the VM. That is,
  61          * {@code JavaFrameAnchor} management around the call can be omitted.
  62          */
  63         LEAF_NO_VZERO,
  64 
  65         /**
  66          * A call to a leaf function that might use floating point registers but will never have its
  67          * caller stack inspected. That is, {@code JavaFrameAnchor} management around the call can
  68          * be omitted.
  69          */
  70         LEAF,
  71 
  72         /**
  73          * A call to a leaf function that might use floating point registers and may have its caller
  74          * stack inspected. That is, {@code JavaFrameAnchor} management code around the call is
  75          * required.
  76          */
  77         STACK_INSPECTABLE_LEAF,
  78 
  79         /**
  80          * A function that may lock, GC or raise an exception and thus requires debug info to be
  81          * associated with a call site to the function. The execution stack may be inspected while
  82          * in the called function. That is, {@code JavaFrameAnchor} management code around the call
  83          * is required.
  84          */
  85         SAFEPOINT,
  86     }
  87 
  88     /**
  89      * Constants specifying when a foreign call or stub call is re-executable.
  90      */
  91     enum Reexecutability {
  92         /**
  93          * Denotes a call that cannot be re-executed. If an exception is raised, the call is
  94          * deoptimized and the exception is passed on to be dispatched. If the call can throw an
  95          * exception it needs to have a precise frame state.
  96          */
  97         NOT_REEXECUTABLE,
  98 
  99         /**
 100          * Denotes a call that can always be re-executed. If an exception is raised by the call it
 101          * may be cleared, compiled code deoptimized and reexecuted. Since the call has no side
 102          * effects it is assumed that the same exception will be thrown.
 103          */
 104         REEXECUTABLE
 105     }
 106 
 107     /**
 108      * Sentinel marker for a computed jump address.
 109      */
 110     long JUMP_ADDRESS = 0xDEADDEADBEEFBEEFL;
 111 
 112     /**
 113      * Determines if the call has side effects.
 114      */
 115     boolean isReexecutable();
 116 
 117     LocationIdentity[] getKilledLocations();
 118 
 119     void setCompiledStub(Stub stub);
 120 
 121     /**
 122      * Determines if this is a call to a compiled {@linkplain Stub stub}.
 123      */
 124     boolean isCompiledStub();
 125 
 126     /**
 127      * Gets the stub, if any, this foreign call links to.
 128      */
 129     Stub getStub();
 130 
 131     void finalizeAddress(Backend backend);
 132 
 133     long getAddress();
 134 
 135     /**
 136      * Determines if the runtime function or stub might use floating point registers. If the answer
 137      * is no, then no FPU state management prologue or epilogue needs to be emitted around the call.
 138      */
 139     boolean mayContainFP();
 140 
 141     /**
 142      * Determines if a {@code JavaFrameAnchor} needs to be set up and torn down around this call.
 143      */
 144     boolean needsJavaFrameAnchor();
 145 
 146     /**
 147      * Gets the VM symbol associated with the target {@linkplain #getAddress() address} of the call.
 148      */
 149     String getSymbol();
 150 
 151     /**
 152      * Identifies foreign calls which are guaranteed to include a safepoint check.
 153      */
 154     boolean isGuaranteedSafepoint();
 155 }