1 /*
   2  * Copyright (c) 2012, 2014, 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 org.graalvm.compiler.core.common.type;
  24 
  25 import org.graalvm.compiler.core.common.LIRKind;
  26 import org.graalvm.compiler.core.common.spi.LIRKindTool;
  27 
  28 import jdk.vm.ci.meta.Constant;
  29 import jdk.vm.ci.meta.JavaConstant;
  30 import jdk.vm.ci.meta.MemoryAccessProvider;
  31 import jdk.vm.ci.meta.ResolvedJavaType;
  32 
  33 public class ObjectStamp extends AbstractObjectStamp {
  34 
  35     public ObjectStamp(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean alwaysNull) {
  36         super(type, exactType, nonNull, alwaysNull);
  37     }
  38 
  39     @Override
  40     protected ObjectStamp copyWith(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean alwaysNull) {
  41         return new ObjectStamp(type, exactType, nonNull, alwaysNull);
  42     }
  43 
  44     @Override
  45     public Stamp unrestricted() {
  46         return StampFactory.object();
  47     }
  48 
  49     @Override
  50     public String toString() {
  51         StringBuilder str = new StringBuilder();
  52         str.append('a');
  53         appendString(str);
  54         return str.toString();
  55     }
  56 
  57     @Override
  58     public boolean isCompatible(Stamp other) {
  59         if (this == other) {
  60             return true;
  61         }
  62         if (other instanceof ObjectStamp) {
  63             return true;
  64         }
  65         return false;
  66     }
  67 
  68     @Override
  69     public boolean isCompatible(Constant constant) {
  70         if (constant instanceof JavaConstant) {
  71             return ((JavaConstant) constant).getJavaKind().isObject();
  72         }
  73         return false;
  74     }
  75 
  76     @Override
  77     public LIRKind getLIRKind(LIRKindTool tool) {
  78         return tool.getObjectKind();
  79     }
  80 
  81     @Override
  82     public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) {
  83         return provider.readObjectConstant(base, displacement);
  84     }
  85 }