1 /*
   2  * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.vm.ci.hotspot;
  24 
  25 import java.lang.invoke.CallSite;
  26 import java.util.Objects;
  27 
  28 import jdk.vm.ci.meta.Assumptions;
  29 import jdk.vm.ci.meta.JavaConstant;
  30 import jdk.vm.ci.meta.ResolvedJavaType;
  31 import jdk.vm.ci.meta.VMConstant;
  32 
  33 /**
  34  * Represents a constant non-{@code null} object reference, within the compiler and across the
  35  * compiler/runtime interface.
  36  */
  37 public interface HotSpotObjectConstant extends JavaConstant, HotSpotConstant, VMConstant {
  38 
  39     JavaConstant compress();
  40 
  41     JavaConstant uncompress();
  42 
  43     /**
  44      * Gets the resolved Java type of the object represented by this constant.
  45      */
  46     HotSpotResolvedObjectType getType();
  47 
  48     /**
  49      * Gets the result of {@link Class#getClassLoader()} for the {@link Class} object represented by
  50      * this constant.
  51      *
  52      * @return {@code null} if this constant does not represent a {@link Class} object
  53      */
  54     JavaConstant getClassLoader();
  55 
  56     /**
  57      * Gets the {@linkplain System#identityHashCode(Object) identity} has code for the object
  58      * represented by this constant.
  59      */
  60     int getIdentityHashCode();
  61 
  62     /**
  63      * Gets the result of {@link Class#getComponentType()} for the {@link Class} object represented
  64      * by this constant.
  65      *
  66      * @return {@code null} if this constant does not represent a {@link Class} object
  67      */
  68     JavaConstant getComponentType();
  69 
  70     /**
  71      * Gets the result of {@link Class#getSuperclass()} for the {@link Class} object represented by
  72      * this constant.
  73      *
  74      * @return {@code null} if this constant does not represent a {@link Class} object
  75      */
  76     JavaConstant getSuperclass();
  77 
  78     /**
  79      * Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented
  80      * by this constant.
  81      *
  82      * @param assumptions used to register an assumption that the {@link CallSite}'s target does not
  83      *            change
  84      * @return {@code null} if this constant does not represent a {@link CallSite} object
  85      */
  86     JavaConstant getCallSiteTarget(Assumptions assumptions);
  87 
  88     /**
  89      * Determines if this constant represents an {@linkplain String#intern() interned} string.
  90      */
  91     boolean isInternedString();
  92 
  93     /**
  94      * Gets the object represented by this constant represents if it is of a given type.
  95      *
  96      * @param type the expected type of the object represented by this constant. If the object is
  97      *            required to be of this type, then wrap the call to this method in
  98      *            {@link Objects#requireNonNull(Object)}.
  99      * @return the object value represented by this constant if it is an
 100      *         {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise
 101      *         {@code null}
 102      */
 103     <T> T asObject(Class<T> type);
 104 
 105     /**
 106      * Gets the object represented by this constant represents if it is of a given type.
 107      *
 108      * @param type the expected type of the object represented by this constant. If the object is
 109      *            required to be of this type, then wrap the call to this method in
 110      *            {@link Objects#requireNonNull(Object)}.
 111      * @return the object value represented by this constant if it is an
 112      *         {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise
 113      *         {@code null}
 114      */
 115     Object asObject(ResolvedJavaType type);
 116 }