001/*
002 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.code;
024
025import jdk.internal.jvmci.code.CompilationResult.*;
026import jdk.internal.jvmci.code.DataSection.*;
027import jdk.internal.jvmci.meta.*;
028
029/**
030 * Access to code cache related details and requirements.
031 */
032public interface CodeCacheProvider {
033
034    /**
035     * Adds the given compilation result as an implementation of the given method without making it
036     * the default implementation.
037     *
038     * @param method a method to which the executable code is begin added
039     * @param compResult the compilation result to be added
040     * @param speculationLog the speculation log to be used
041     * @return a reference to the compiled and ready-to-run code or throws a
042     *         {@link BailoutException} if the code installation failed
043     */
044    InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode);
045
046    /**
047     * Sets the given compilation result as the default implementation of the given method.
048     *
049     * @param method a method to which the executable code is begin added
050     * @param compResult the compilation result to be added
051     * @return a reference to the compiled and ready-to-run code or null if the code installation
052     *         failed
053     */
054    InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult);
055
056    /**
057     * Gets a name for a {@link Mark} mark.
058     */
059    default String getMarkName(Mark mark) {
060        return String.valueOf(mark.id);
061    }
062
063    /**
064     * Gets a name for the {@linkplain Call#target target} of a {@link Call}.
065     */
066    default String getTargetName(Call call) {
067        return String.valueOf(call.target);
068    }
069
070    /**
071     * Gets the register configuration to use when compiling a given method.
072     */
073    RegisterConfig getRegisterConfig();
074
075    /**
076     * Minimum size of the stack area reserved for outgoing parameters. This area is reserved in all
077     * cases, even when the compiled method has no regular call instructions.
078     *
079     * @return the minimum size of the outgoing parameter area in bytes
080     */
081    int getMinimumOutgoingSize();
082
083    /**
084     * Determines if a {@link DataPatch} should be created for a given primitive constant that is
085     * part of a {@link CompilationResult}. A data patch is always created for an object constant.
086     */
087    boolean needsDataPatch(JavaConstant constant);
088
089    /**
090     * Create a {@link Data} item for a {@link Constant}, that can be used in a {@link DataPatch}.
091     */
092    Data createDataItem(Constant constant);
093
094    /**
095     * Gets a description of the target architecture.
096     */
097    TargetDescription getTarget();
098
099    /**
100     * Create a new speculation log for the target runtime.
101     */
102    SpeculationLog createSpeculationLog();
103}