001/*
002 * Copyright (c) 2009, 2015, 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.hotspot;
024
025import java.lang.invoke.*;
026import java.util.*;
027
028import jdk.internal.jvmci.meta.*;
029
030/**
031 * Represents a constant non-{@code null} object reference, within the compiler and across the
032 * compiler/runtime interface.
033 */
034public interface HotSpotObjectConstant extends JavaConstant, HotSpotConstant, VMConstant {
035
036    JavaConstant compress();
037
038    JavaConstant uncompress();
039
040    /**
041     * Gets the resolved Java type of the object represented by this constant.
042     */
043    HotSpotResolvedObjectType getType();
044
045    /**
046     * Gets the result of {@link Class#getClassLoader()} for the {@link Class} object represented by
047     * this constant.
048     *
049     * @return {@code null} if this constant does not represent a {@link Class} object
050     */
051    JavaConstant getClassLoader();
052
053    /**
054     * Gets the {@linkplain System#identityHashCode(Object) identity} has code for the object
055     * represented by this constant.
056     */
057    int getIdentityHashCode();
058
059    /**
060     * Gets the result of {@link Class#getComponentType()} for the {@link Class} object represented
061     * by this constant.
062     *
063     * @return {@code null} if this constant does not represent a {@link Class} object
064     */
065    JavaConstant getComponentType();
066
067    /**
068     * Gets the result of {@link Class#getSuperclass()} for the {@link Class} object represented by
069     * this constant.
070     *
071     * @return {@code null} if this constant does not represent a {@link Class} object
072     */
073    JavaConstant getSuperclass();
074
075    /**
076     * Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented
077     * by this constant.
078     *
079     * @param assumptions used to register an assumption that the {@link CallSite}'s target does not
080     *            change
081     * @return {@code null} if this constant does not represent a {@link CallSite} object
082     */
083    JavaConstant getCallSiteTarget(Assumptions assumptions);
084
085    /**
086     * Determines if this constant represents an {@linkplain String#intern() interned} string.
087     */
088    boolean isInternedString();
089
090    /**
091     * Gets the object represented by this constant represents if it is of a given type.
092     *
093     * @param type the expected type of the object represented by this constant. If the object is
094     *            required to be of this type, then wrap the call to this method in
095     *            {@link Objects#requireNonNull(Object)}.
096     * @return the object value represented by this constant if it is an
097     *         {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise
098     *         {@code null}
099     */
100    <T> T asObject(Class<T> type);
101
102    /**
103     * Gets the object represented by this constant represents if it is of a given type.
104     *
105     * @param type the expected type of the object represented by this constant. If the object is
106     *            required to be of this type, then wrap the call to this method in
107     *            {@link Objects#requireNonNull(Object)}.
108     * @return the object value represented by this constant if it is an
109     *         {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise
110     *         {@code null}
111     */
112    Object asObject(ResolvedJavaType type);
113}