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 static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.*; 26 27 import java.lang.invoke.*; 28 29 import jdk.vm.ci.inittimer.*; 30 import jdk.vm.ci.meta.*; 31 32 /** 33 * Represents a constant non-{@code null} object reference, within the compiler and across the 34 * compiler/runtime interface. 35 */ 36 public final class HotSpotObjectConstantImpl implements HotSpotObjectConstant, HotSpotProxified { 37 38 public static JavaConstant forObject(Object object) { 39 return forObject(object, false); 40 } 41 42 static JavaConstant forObject(Object object, boolean compressed) { 43 if (object == null) { 44 return compressed ? HotSpotCompressedNullConstant.COMPRESSED_NULL : JavaConstant.NULL_POINTER; 45 } else { 46 return new HotSpotObjectConstantImpl(object, compressed); 47 } 48 } 49 50 static JavaConstant forStableArray(Object object, int stableDimension, boolean isDefaultStable) { 51 if (object == null) { 52 return JavaConstant.NULL_POINTER; 53 } else { 54 assert object.getClass().isArray(); 55 return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); 56 } 57 } 58 89 assert stableDimension >= 0 && stableDimension <= 255; 90 assert !isDefaultStable || stableDimension > 0; 91 } 92 93 private HotSpotObjectConstantImpl(Object object, boolean compressed) { 94 this(object, compressed, 0, false); 95 } 96 97 @Override 98 public JavaKind getJavaKind() { 99 return JavaKind.Object; 100 } 101 102 /** 103 * Package-private accessor for the object represented by this constant. 104 */ 105 Object object() { 106 return object; 107 } 108 109 /** 110 * Determines if the object represented by this constant is {@link Object#equals(Object) equal} 111 * to a given object. 112 */ 113 public boolean isEqualTo(Object obj) { 114 return object.equals(obj); 115 } 116 117 /** 118 * Gets the class of the object represented by this constant. 119 */ 120 public Class<?> getObjectClass() { 121 return object.getClass(); 122 } 123 124 public boolean isCompressed() { 125 return compressed; 126 } 127 128 public JavaConstant compress() { 129 assert !compressed; 130 return new HotSpotObjectConstantImpl(object, true, stableDimension, isDefaultStable); 131 } 132 133 public JavaConstant uncompress() { 134 assert compressed; 135 return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); 136 } 137 138 public HotSpotResolvedObjectType getType() { 139 return fromObjectClass(object.getClass()); 140 } 141 142 public JavaConstant getClassLoader() { 143 if (object instanceof Class) { | 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 static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.fromObjectClass; 26 27 import java.lang.invoke.CallSite; 28 import java.lang.invoke.ConstantCallSite; 29 import java.lang.invoke.MethodHandle; 30 31 import jdk.vm.ci.inittimer.SuppressFBWarnings; 32 import jdk.vm.ci.meta.Assumptions; 33 import jdk.vm.ci.meta.Constant; 34 import jdk.vm.ci.meta.JavaConstant; 35 import jdk.vm.ci.meta.JavaKind; 36 import jdk.vm.ci.meta.ResolvedJavaType; 37 38 /** 39 * Represents a constant non-{@code null} object reference, within the compiler and across the 40 * compiler/runtime interface. 41 */ 42 final class HotSpotObjectConstantImpl implements HotSpotObjectConstant, HotSpotProxified { 43 44 static JavaConstant forObject(Object object) { 45 return forObject(object, false); 46 } 47 48 static JavaConstant forObject(Object object, boolean compressed) { 49 if (object == null) { 50 return compressed ? HotSpotCompressedNullConstant.COMPRESSED_NULL : JavaConstant.NULL_POINTER; 51 } else { 52 return new HotSpotObjectConstantImpl(object, compressed); 53 } 54 } 55 56 static JavaConstant forStableArray(Object object, int stableDimension, boolean isDefaultStable) { 57 if (object == null) { 58 return JavaConstant.NULL_POINTER; 59 } else { 60 assert object.getClass().isArray(); 61 return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); 62 } 63 } 64 95 assert stableDimension >= 0 && stableDimension <= 255; 96 assert !isDefaultStable || stableDimension > 0; 97 } 98 99 private HotSpotObjectConstantImpl(Object object, boolean compressed) { 100 this(object, compressed, 0, false); 101 } 102 103 @Override 104 public JavaKind getJavaKind() { 105 return JavaKind.Object; 106 } 107 108 /** 109 * Package-private accessor for the object represented by this constant. 110 */ 111 Object object() { 112 return object; 113 } 114 115 public boolean isCompressed() { 116 return compressed; 117 } 118 119 public JavaConstant compress() { 120 assert !compressed; 121 return new HotSpotObjectConstantImpl(object, true, stableDimension, isDefaultStable); 122 } 123 124 public JavaConstant uncompress() { 125 assert compressed; 126 return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable); 127 } 128 129 public HotSpotResolvedObjectType getType() { 130 return fromObjectClass(object.getClass()); 131 } 132 133 public JavaConstant getClassLoader() { 134 if (object instanceof Class) { |