001/*
002 * Copyright (c) 2012, 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.meta;
024
025/**
026 * Provides memory access operations for the target VM.
027 */
028public interface MemoryAccessProvider {
029
030    /**
031     * Reads a value of this kind using a base address and a displacement. No bounds checking or
032     * type checking is performed. Returns {@code null} if the value is not available at this point.
033     *
034     * @param base the base address from which the value is read.
035     * @param displacement the displacement within the object in bytes
036     * @return the read value encapsulated in a {@link JavaConstant} object, or {@code null} if the
037     *         value cannot be read.
038     */
039    JavaConstant readUnsafeConstant(Kind kind, JavaConstant base, long displacement);
040
041    /**
042     * Reads a primitive value using a base address and a displacement.
043     *
044     * @param kind the {@link Kind} of the returned {@link JavaConstant} object
045     * @param base the base address from which the value is read
046     * @param displacement the displacement within the object in bytes
047     * @param bits the number of bits to read from memory
048     * @return the read value encapsulated in a {@link JavaConstant} object of {@link Kind} kind
049     */
050    JavaConstant readPrimitiveConstant(Kind kind, Constant base, long displacement, int bits);
051
052    /**
053     * Reads a Java {@link Object} value using a base address and a displacement.
054     *
055     * @param base the base address from which the value is read
056     * @param displacement the displacement within the object in bytes
057     * @return the read value encapsulated in a {@link Constant} object
058     */
059    JavaConstant readObjectConstant(Constant base, long displacement);
060}