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 @Override 40 JavaConstant compress(); 41 42 @Override 43 JavaConstant uncompress(); 44 45 /** 46 * Gets the resolved Java type of the object represented by this constant. 47 */ 48 HotSpotResolvedObjectType getType(); 49 50 /** 51 * Gets the {@linkplain System#identityHashCode(Object) identity} has code for the object 52 * represented by this constant. 53 */ 54 int getIdentityHashCode(); 55 56 /** 57 * Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented 58 * by this constant. 59 * 60 * @param assumptions used to register an assumption that the {@link CallSite}'s target does not 61 * change 62 * @return {@code null} if this constant does not represent a {@link CallSite} object 63 */ 64 JavaConstant getCallSiteTarget(Assumptions assumptions); 65 66 /** 67 * Determines if this constant represents an {@linkplain String#intern() interned} string. 68 */ 69 boolean isInternedString(); 70 71 /** 72 * Gets the object represented by this constant represents if it is of a given type. 73 * 74 * @param type the expected type of the object represented by this constant. If the object is 75 * required to be of this type, then wrap the call to this method in 76 * {@link Objects#requireNonNull(Object)}. 77 * @return the object value represented by this constant if it is an 78 * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise 79 * {@code null} 80 */ 81 <T> T asObject(Class<T> type); 82 83 /** 84 * Gets the object represented by this constant represents if it is of a given type. 85 * 86 * @param type the expected type of the object represented by this constant. If the object is 87 * required to be of this type, then wrap the call to this method in 88 * {@link Objects#requireNonNull(Object)}. 89 * @return the object value represented by this constant if it is an 90 * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise 91 * {@code null} 92 */ 93 Object asObject(ResolvedJavaType type); 94 }