001/* 002 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.hotspot.nodes.type; 024 025import jdk.internal.jvmci.hotspot.*; 026import jdk.internal.jvmci.meta.*; 027 028import com.oracle.graal.compiler.common.type.*; 029 030public final class MethodPointerStamp extends MetaspacePointerStamp { 031 032 private static final MethodPointerStamp METHOD = new MethodPointerStamp(false, false); 033 034 private static final MethodPointerStamp METHOD_NON_NULL = new MethodPointerStamp(true, false); 035 036 private static final MethodPointerStamp METHOD_ALWAYS_NULL = new MethodPointerStamp(false, true); 037 038 public static MethodPointerStamp method() { 039 return METHOD; 040 } 041 042 public static MethodPointerStamp methodNonNull() { 043 return METHOD_NON_NULL; 044 } 045 046 private MethodPointerStamp(boolean nonNull, boolean alwaysNull) { 047 super(nonNull, alwaysNull); 048 } 049 050 @Override 051 protected AbstractPointerStamp copyWith(boolean newNonNull, boolean newAlwaysNull) { 052 if (newNonNull) { 053 assert !newAlwaysNull; 054 return METHOD_NON_NULL; 055 } else if (newAlwaysNull) { 056 return METHOD_ALWAYS_NULL; 057 } else { 058 return METHOD; 059 } 060 } 061 062 @Override 063 public boolean isCompatible(Stamp otherStamp) { 064 if (this == otherStamp) { 065 return true; 066 } 067 return otherStamp instanceof MethodPointerStamp; 068 } 069 070 @Override 071 public Stamp constant(Constant c, MetaAccessProvider meta) { 072 if (JavaConstant.NULL_POINTER.equals(c)) { 073 return METHOD_ALWAYS_NULL; 074 } else { 075 assert c instanceof HotSpotMetaspaceConstant; 076 return METHOD_NON_NULL; 077 } 078 } 079 080 @Override 081 public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) { 082 HotSpotMemoryAccessProvider hsProvider = (HotSpotMemoryAccessProvider) provider; 083 return hsProvider.readMethodPointerConstant(base, displacement); 084 } 085 086 @Override 087 public String toString() { 088 StringBuilder ret = new StringBuilder("Method*"); 089 appendString(ret); 090 return ret.toString(); 091 } 092}