view graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/VirtualizerTool.java @ 7530:5e3d1a68664e

applied mx eclipseformat to all Java files
author Doug Simon <doug.simon@oracle.com>
date Wed, 23 Jan 2013 16:34:57 +0100
parents 94f032472c28
children 77c86cf33685
line wrap: on
line source

/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package com.oracle.graal.nodes.spi;

import com.oracle.graal.api.meta.*;
import com.oracle.graal.graph.*;
import com.oracle.graal.nodes.*;
import com.oracle.graal.nodes.spi.Virtualizable.State;
import com.oracle.graal.nodes.virtual.*;

/**
 * This tool can be used to query the current state (normal/virtualized/re-materialized) of values
 * and to describe the actions that would be taken for this state.
 * 
 * See also {@link Virtualizable}.
 */
public interface VirtualizerTool {

    /**
     * @return the {@link MetaAccessProvider} associated with the current compilation, which might
     *         be required for creating constants, etc.
     */
    MetaAccessProvider getMetaAccessProvider();

    /**
     * This method should be used to query the maximum size of virtualized objects before attempting
     * virtualization.
     * 
     * @return the maximum number of entries for virtualized objects.
     */
    int getMaximumEntryCount();

    /**
     * @return the next id for virtual objects (can be used for the VirtualObject constructor).
     */
    int getNextVirtualId();

    // methods working on virtualized/materialized objects

    /**
     * Introduces a new virtual object to the current state.
     * 
     * @param virtualObject the new virtual object.
     * @param entryState the initial state of the virtual object's fields.
     * @param lockCount the initial locking depth.
     */
    void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] entryState, int lockCount);

    /**
     * Queries the current state of the given value: if it is virtualized (thread-local and the
     * compiler knows all entries) or not.
     * 
     * @param value the value whose state should be queried.
     * @return the {@link State} representing the value if it has been virtualized at some point,
     *         null otherwise.
     */
    State getObjectState(ValueNode value);

    /**
     * Sets the entry (field or array element) with the given index in the virtualized object.
     * 
     * @param state the state.
     * @param index the index to be set.
     * @param value the new value for the given index.
     */
    void setVirtualEntry(State state, int index, ValueNode value);

    /**
     * Queries the current state of the given value: if it was materialized or not.
     * 
     * @param value the value whose state should be queried.
     * @return the materialized value (usually a MaterializeObjectNode or a {@link PhiNode}) if it
     *         was materialized, null otherwise.
     */
    ValueNode getMaterializedValue(ValueNode value);

    // scalar replacement

    /**
     * Replacements via {@link #replaceWithValue(ValueNode)} are not immediately committed. This
     * method can be used to determine if a value was replaced by another one (e.g., a load field by
     * the loaded value).
     * 
     * @param original the original input value.
     * @return the replacement value, or the original value if there is no replacement.
     */
    ValueNode getReplacedValue(ValueNode original);

    // operations on the current node

    /**
     * Deletes the current node and replaces it with the given virtualized object.
     * 
     * @param virtual the virtualized object that should replace the current node.
     */
    void replaceWithVirtual(VirtualObjectNode virtual);

    /**
     * Deletes the current node and replaces it with the given value.
     * 
     * @param replacement the value that should replace the current node.
     */
    void replaceWithValue(ValueNode replacement);

    /**
     * Deletes the current node.
     */
    void delete();

    /**
     * Replaces an input of the current node.
     * 
     * @param oldInput the old input value.
     * @param replacement the new input value.
     */
    void replaceFirstInput(Node oldInput, Node replacement);

    /**
     * Performs a custom action on the current node. This action will only be performed when, and
     * if, the changes are committed. Custom actions must not modify inputs of nodes.
     * 
     * @param action the custom action.
     */
    void customAction(Runnable action);

    /**
     * This method performs either {@link #replaceWithValue(ValueNode)} or
     * {@link #replaceWithVirtual(VirtualObjectNode)}, depending on the given value.
     * 
     * @param value the replacement value
     */
    void replaceWith(ValueNode value);
}