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
24
25 package org.graalvm.compiler.core.common.type;
26
27 import org.graalvm.compiler.core.common.LIRKind;
28 import org.graalvm.compiler.core.common.spi.LIRKindTool;
29
30 import jdk.vm.ci.meta.Constant;
31 import jdk.vm.ci.meta.JavaKind;
32 import jdk.vm.ci.meta.MemoryAccessProvider;
33 import jdk.vm.ci.meta.MetaAccessProvider;
34 import jdk.vm.ci.meta.ResolvedJavaType;
35
36 /**
37 * A stamp is the basis for a type system.
38 */
39 public abstract class Stamp {
40
41 protected Stamp() {
42 }
43
44 /**
45 * Returns the type of the stamp, guaranteed to be non-null. In some cases, this requires the
46 * lookup of class meta data, therefore the {@link MetaAccessProvider} is mandatory.
47 */
48 public abstract ResolvedJavaType javaType(MetaAccessProvider metaAccess);
49
50 public boolean alwaysDistinct(Stamp other) {
51 return join(other).isEmpty();
52 }
53
54 /**
55 * Gets a Java {@link JavaKind} that can be used to store a value of this stamp on the Java
56 * bytecode stack. Returns {@link JavaKind#Illegal} if a value of this stamp can not be stored
57 * on the bytecode stack.
58 */
59 public abstract JavaKind getStackKind();
168 *
169 * @param other the stamp that should be used to improve this stamp
170 * @return the newly improved stamp or {@code null} if an improvement was not possible
171 */
172 public final Stamp tryImproveWith(Stamp other) {
173 Stamp improved = improveWith(other);
174 if (improved.equals(this)) {
175 return null;
176 }
177 return improved;
178 }
179
180 public boolean neverDistinct(Stamp other) {
181 Constant constant = this.asConstant();
182 if (constant != null) {
183 Constant otherConstant = other.asConstant();
184 return otherConstant != null && constant.equals(otherConstant);
185 }
186 return false;
187 }
188 }
|
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
24
25 package org.graalvm.compiler.core.common.type;
26
27 import org.graalvm.compiler.core.common.LIRKind;
28 import org.graalvm.compiler.core.common.spi.LIRKindTool;
29 import org.graalvm.compiler.serviceprovider.SpeculationReasonGroup.SpeculationContextObject;
30
31 import jdk.vm.ci.meta.Constant;
32 import jdk.vm.ci.meta.JavaKind;
33 import jdk.vm.ci.meta.MemoryAccessProvider;
34 import jdk.vm.ci.meta.MetaAccessProvider;
35 import jdk.vm.ci.meta.ResolvedJavaType;
36
37 /**
38 * A stamp is the basis for a type system.
39 */
40 public abstract class Stamp implements SpeculationContextObject {
41
42 protected Stamp() {
43 }
44
45 /**
46 * Returns the type of the stamp, guaranteed to be non-null. In some cases, this requires the
47 * lookup of class meta data, therefore the {@link MetaAccessProvider} is mandatory.
48 */
49 public abstract ResolvedJavaType javaType(MetaAccessProvider metaAccess);
50
51 public boolean alwaysDistinct(Stamp other) {
52 return join(other).isEmpty();
53 }
54
55 /**
56 * Gets a Java {@link JavaKind} that can be used to store a value of this stamp on the Java
57 * bytecode stack. Returns {@link JavaKind#Illegal} if a value of this stamp can not be stored
58 * on the bytecode stack.
59 */
60 public abstract JavaKind getStackKind();
169 *
170 * @param other the stamp that should be used to improve this stamp
171 * @return the newly improved stamp or {@code null} if an improvement was not possible
172 */
173 public final Stamp tryImproveWith(Stamp other) {
174 Stamp improved = improveWith(other);
175 if (improved.equals(this)) {
176 return null;
177 }
178 return improved;
179 }
180
181 public boolean neverDistinct(Stamp other) {
182 Constant constant = this.asConstant();
183 if (constant != null) {
184 Constant otherConstant = other.asConstant();
185 return otherConstant != null && constant.equals(otherConstant);
186 }
187 return false;
188 }
189
190 /**
191 * Convert a Stamp into a representation that can be resolved symbolically into the original
192 * stamp. If this stamp contains no references to JVMCI types then simply return null.
193 */
194 public SymbolicJVMCIReference<? extends Stamp> makeSymbolic() {
195 return null;
196 }
197
198 @Override
199 public abstract String toString();
200 }
|