1 /* 2 * Copyright (c) 2014, 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 org.graalvm.compiler.hotspot.nodes.type; 24 25 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant; 26 import jdk.vm.ci.meta.Constant; 27 import jdk.vm.ci.meta.JavaConstant; 28 import jdk.vm.ci.meta.MemoryAccessProvider; 29 import jdk.vm.ci.meta.MetaAccessProvider; 30 31 import org.graalvm.compiler.core.common.type.AbstractPointerStamp; 32 import org.graalvm.compiler.core.common.type.Stamp; 33 34 public final class MethodCountersPointerStamp extends MetaspacePointerStamp { 35 36 private static final MethodCountersPointerStamp METHOD_COUNTERS = new MethodCountersPointerStamp(false, false); 37 38 private static final MethodCountersPointerStamp METHOD_COUNTERS_NON_NULL = new MethodCountersPointerStamp(true, false); 39 40 private static final MethodCountersPointerStamp METHOD_COUNTERS_ALWAYS_NULL = new MethodCountersPointerStamp(false, true); 41 42 public static MethodCountersPointerStamp methodCounters() { 43 return METHOD_COUNTERS; 44 } 45 46 public static MethodCountersPointerStamp methodCountersNonNull() { 47 return METHOD_COUNTERS_NON_NULL; 48 } 49 50 private MethodCountersPointerStamp(boolean nonNull, boolean alwaysNull) { 51 super(nonNull, alwaysNull); 52 } 53 54 @Override 55 protected AbstractPointerStamp copyWith(boolean newNonNull, boolean newAlwaysNull) { 56 if (newNonNull) { 57 assert !newAlwaysNull; 58 return METHOD_COUNTERS_NON_NULL; 59 } else if (newAlwaysNull) { 60 return METHOD_COUNTERS_ALWAYS_NULL; 61 } else { 62 return METHOD_COUNTERS; 63 } 64 } 65 66 @Override 67 public boolean isCompatible(Stamp otherStamp) { 68 if (this == otherStamp) { 69 return true; 70 } 71 return otherStamp instanceof MethodCountersPointerStamp; 72 } 73 74 @Override 75 public Stamp constant(Constant c, MetaAccessProvider meta) { 76 if (JavaConstant.NULL_POINTER.equals(c)) { 77 return METHOD_COUNTERS_ALWAYS_NULL; 78 } else { 79 assert c instanceof HotSpotMetaspaceConstant; 80 return METHOD_COUNTERS_NON_NULL; 81 } 82 } 83 84 @Override 85 public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) { 86 return null; 87 } 88 89 @Override 90 public String toString() { 91 StringBuilder ret = new StringBuilder("MethodCounters*"); 92 appendString(ret); 93 return ret.toString(); 94 } 95 }