1 /*
   2  * Copyright (c) 2009, 2014, 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 package jdk.vm.ci.code;
  24 
  25 import jdk.vm.ci.code.site.Call;
  26 import jdk.vm.ci.code.site.Mark;
  27 import jdk.vm.ci.meta.ResolvedJavaMethod;
  28 import jdk.vm.ci.meta.SpeculationLog;
  29 
  30 /**
  31  * Access to code cache related details and requirements.
  32  */
  33 public interface CodeCacheProvider {
  34 
  35     /**
  36      * Installs code for a given method based on a given compilation result without making it the
  37      * default implementation of the method.
  38      *
  39      * @param method a method implemented by the installed code
  40      * @param compiledCode the compiled code to be added
  41      * @param log the speculation log to be used
  42      * @param installedCode a predefined {@link InstalledCode} object to use as a reference to the
  43      *            installed code. If {@code null}, a new {@link InstalledCode} object will be
  44      *            created.
  45      * @return a reference to the ready-to-run code
  46      * @throws BailoutException if the code installation failed
  47      */
  48     default InstalledCode addCode(ResolvedJavaMethod method, CompiledCode compiledCode, SpeculationLog log, InstalledCode installedCode) {
  49         return installCode(method, compiledCode, installedCode, log, false);
  50     }
  51 
  52     /**
  53      * Installs code for a given method based on a given compilation result and makes it the default
  54      * implementation of the method.
  55      *
  56      * @param method a method implemented by the installed code and for which the installed code
  57      *            becomes the default implementation
  58      * @param compiledCode the compiled code to be added
  59      * @return a reference to the ready-to-run code
  60      * @throws BailoutException if the code installation failed
  61      */
  62     default InstalledCode setDefaultCode(ResolvedJavaMethod method, CompiledCode compiledCode) {
  63         return installCode(method, compiledCode, null, null, true);
  64     }
  65 
  66     /**
  67      * Installs code based on a given compilation result.
  68      *
  69      * @param method the method compiled to produce {@code compiledCode} or {@code null} if the
  70      *            input to {@code compResult} was not a {@link ResolvedJavaMethod}
  71      * @param compiledCode the compiled code to be added
  72      * @param installedCode a pre-allocated {@link InstalledCode} object to use as a reference to
  73      *            the installed code. If {@code null}, a new {@link InstalledCode} object will be
  74      *            created.
  75      * @param log the speculation log to be used
  76      * @param isDefault specifies if the installed code should be made the default implementation of
  77      *            {@code compRequest.getMethod()}. The default implementation for a method is the
  78      *            code executed for standard calls to the method. This argument is ignored if
  79      *            {@code compRequest == null}.
  80      * @return a reference to the compiled and ready-to-run installed code
  81      * @throws BailoutException if the code installation failed
  82      */
  83     InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compiledCode, InstalledCode installedCode, SpeculationLog log, boolean isDefault);
  84 
  85     /**
  86      * Invalidates {@code installedCode} such that {@link InvalidInstalledCodeException} will be
  87      * raised the next time {@code installedCode} is
  88      * {@linkplain InstalledCode#executeVarargs(Object...) executed}.
  89      */
  90     void invalidateInstalledCode(InstalledCode installedCode);
  91 
  92     /**
  93      * Gets a name for a {@link Mark} mark.
  94      */
  95     default String getMarkName(Mark mark) {
  96         return String.valueOf(mark.id);
  97     }
  98 
  99     /**
 100      * Gets a name for the {@linkplain Call#target target} of a {@link Call}.
 101      */
 102     default String getTargetName(Call call) {
 103         return String.valueOf(call.target);
 104     }
 105 
 106     /**
 107      * Gets the register configuration to use when compiling a given method.
 108      */
 109     RegisterConfig getRegisterConfig();
 110 
 111     /**
 112      * Minimum size of the stack area reserved for outgoing parameters. This area is reserved in all
 113      * cases, even when the compiled method has no regular call instructions.
 114      *
 115      * @return the minimum size of the outgoing parameter area in bytes
 116      */
 117     int getMinimumOutgoingSize();
 118 
 119     /**
 120      * Gets a description of the target architecture.
 121      */
 122     TargetDescription getTarget();
 123 
 124     /**
 125      * Create a new speculation log for the target runtime.
 126      */
 127     SpeculationLog createSpeculationLog();
 128 
 129     /**
 130      * Returns the maximum absolute offset of a PC relative call to a given address from any
 131      * position in the code cache or -1 when not applicable. Intended for determining the required
 132      * size of address/offset fields.
 133      */
 134     long getMaxCallTargetOffset(long address);
 135 
 136     /**
 137      * Determines if debug info should also be emitted at non-safepoint locations.
 138      */
 139     boolean shouldDebugNonSafepoints();
 140 }