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
025import java.lang.reflect.*;
026
027/**
028 * Provides access to the metadata of a class typically provided in a class file.
029 */
030public interface MetaAccessProvider {
031
032    /**
033     * Returns the resolved Java type representing a given Java class.
034     *
035     * @param clazz the Java class object
036     * @return the resolved Java type object
037     */
038    ResolvedJavaType lookupJavaType(Class<?> clazz);
039
040    /**
041     * Returns the resolved Java types representing some given Java classes.
042     *
043     * @param classes the Java class objects
044     * @return the resolved Java type objects
045     */
046    default ResolvedJavaType[] lookupJavaTypes(Class<?>[] classes) {
047        ResolvedJavaType[] result = new ResolvedJavaType[classes.length];
048        for (int i = 0; i < result.length; i++) {
049            result[i] = lookupJavaType(classes[i]);
050        }
051        return result;
052    }
053
054    /**
055     * Provides the {@link ResolvedJavaMethod} for a {@link Method} or {@link Constructor} obtained
056     * via reflection.
057     */
058    ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod);
059
060    /**
061     * Provides the {@link ResolvedJavaField} for a {@link Field} obtained via reflection.
062     */
063    ResolvedJavaField lookupJavaField(Field reflectionField);
064
065    /**
066     * Returns the resolved Java type of the given {@link JavaConstant} object.
067     *
068     * @return {@code null} if {@code constant.isNull() || !constant.kind.isObject()}
069     */
070    ResolvedJavaType lookupJavaType(JavaConstant constant);
071
072    /**
073     * Returns the number of bytes occupied by this constant value or constant object.
074     *
075     * @param constant the constant whose bytes should be measured
076     * @return the number of bytes occupied by this constant
077     */
078    long getMemorySize(JavaConstant constant);
079
080    /**
081     * Parses a <a
082     * href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.3">method
083     * descriptor</a> into a {@link Signature}. The behavior of this method is undefined if the
084     * method descriptor is not well formed.
085     */
086    Signature parseMethodDescriptor(String methodDescriptor);
087
088    /**
089     * Encodes a deoptimization action and a deoptimization reason in an integer value.
090     *
091     * @param debugId an integer that can be used to track the origin of a deoptimization at
092     *            runtime. There is no guarantee that the runtime will use this value. The runtime
093     *            may even keep fewer than 32 bits.
094     *
095     * @return the encoded value as an integer
096     */
097    JavaConstant encodeDeoptActionAndReason(DeoptimizationAction action, DeoptimizationReason reason, int debugId);
098
099    DeoptimizationReason decodeDeoptReason(JavaConstant constant);
100
101    DeoptimizationAction decodeDeoptAction(JavaConstant constant);
102
103    int decodeDebugId(JavaConstant constant);
104}