HotSpotNarrowOopStamp.java revision 13083:b9a173f12fe6
1/* 2 * Copyright (c) 2014, 2016, 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 */ 23package org.graalvm.compiler.hotspot.nodes.type; 24 25import org.graalvm.compiler.core.common.CompressEncoding; 26import org.graalvm.compiler.core.common.type.AbstractObjectStamp; 27import org.graalvm.compiler.core.common.type.ObjectStamp; 28import org.graalvm.compiler.core.common.type.Stamp; 29import org.graalvm.compiler.debug.GraalError; 30import org.graalvm.compiler.nodes.CompressionNode.CompressionOp; 31import org.graalvm.compiler.nodes.type.NarrowOopStamp; 32 33import jdk.vm.ci.hotspot.HotSpotCompressedNullConstant; 34import jdk.vm.ci.hotspot.HotSpotMemoryAccessProvider; 35import jdk.vm.ci.hotspot.HotSpotObjectConstant; 36import jdk.vm.ci.meta.Constant; 37import jdk.vm.ci.meta.JavaConstant; 38import jdk.vm.ci.meta.MemoryAccessProvider; 39import jdk.vm.ci.meta.ResolvedJavaType; 40 41public final class HotSpotNarrowOopStamp extends NarrowOopStamp { 42 private HotSpotNarrowOopStamp(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean alwaysNull, CompressEncoding encoding) { 43 super(type, exactType, nonNull, alwaysNull, encoding); 44 } 45 46 @Override 47 protected AbstractObjectStamp copyWith(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean alwaysNull) { 48 return new HotSpotNarrowOopStamp(type, exactType, nonNull, alwaysNull, getEncoding()); 49 } 50 51 public static Stamp compressed(AbstractObjectStamp stamp, CompressEncoding encoding) { 52 return new HotSpotNarrowOopStamp(stamp.type(), stamp.isExactType(), stamp.nonNull(), stamp.alwaysNull(), encoding); 53 } 54 55 @Override 56 public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) { 57 try { 58 HotSpotMemoryAccessProvider hsProvider = (HotSpotMemoryAccessProvider) provider; 59 return hsProvider.readNarrowOopConstant(base, displacement); 60 } catch (IllegalArgumentException e) { 61 return null; 62 } 63 } 64 65 @Override 66 public JavaConstant asConstant() { 67 if (alwaysNull()) { 68 return HotSpotCompressedNullConstant.COMPRESSED_NULL; 69 } else { 70 return null; 71 } 72 } 73 74 @Override 75 public boolean isCompatible(Constant other) { 76 if (other instanceof HotSpotObjectConstant) { 77 return ((HotSpotObjectConstant) other).isCompressed(); 78 } 79 return true; 80 } 81 82 public static Stamp mkStamp(CompressionOp op, Stamp input, CompressEncoding encoding) { 83 switch (op) { 84 case Compress: 85 if (input instanceof ObjectStamp) { 86 // compressed oop 87 return HotSpotNarrowOopStamp.compressed((ObjectStamp) input, encoding); 88 } else if (input instanceof KlassPointerStamp) { 89 // compressed klass pointer 90 return ((KlassPointerStamp) input).compressed(encoding); 91 } 92 break; 93 case Uncompress: 94 if (input instanceof NarrowOopStamp) { 95 // oop 96 assert encoding.equals(((NarrowOopStamp) input).getEncoding()); 97 return ((NarrowOopStamp) input).uncompressed(); 98 } else if (input instanceof KlassPointerStamp) { 99 // metaspace pointer 100 assert encoding.equals(((KlassPointerStamp) input).getEncoding()); 101 return ((KlassPointerStamp) input).uncompressed(); 102 } 103 break; 104 } 105 throw GraalError.shouldNotReachHere(String.format("Unexpected input stamp %s", input)); 106 } 107 108} 109