Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/ir/NullCheck.java @ 2509:16b9a8b5ad39
Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:50:44 +0200 |
parents | graal/Compiler/src/com/sun/c1x/ir/NullCheck.java@9ec15d6914ca |
children | 0f9eeb15e636 |
comparison
equal
deleted
inserted
replaced
2508:fea94949e0a2 | 2509:16b9a8b5ad39 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2011, 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 com.sun.c1x.ir; | |
24 | |
25 import com.sun.c1x.debug.*; | |
26 import com.sun.c1x.util.*; | |
27 import com.sun.c1x.value.*; | |
28 import com.sun.cri.bytecode.*; | |
29 import com.sun.cri.ri.*; | |
30 | |
31 /** | |
32 * The {@code NullCheck} class represents an explicit null check instruction. | |
33 * | |
34 * @author Ben L. Titzer | |
35 */ | |
36 public final class NullCheck extends StateSplit { | |
37 | |
38 Value object; | |
39 | |
40 /** | |
41 * Constructs a new NullCheck instruction. | |
42 * @param obj the instruction producing the object to check against null | |
43 * @param stateBefore the state before executing the null check | |
44 */ | |
45 public NullCheck(Value obj, FrameState stateBefore) { | |
46 super(obj.kind, stateBefore); | |
47 this.object = obj; | |
48 setFlag(Flag.NonNull); | |
49 if (object.isNonNull()) { | |
50 eliminateNullCheck(); | |
51 } | |
52 } | |
53 | |
54 /** | |
55 * Gets the instruction that produces the object tested against null. | |
56 * @return the instruction producing the object | |
57 */ | |
58 public Value object() { | |
59 return object; | |
60 } | |
61 | |
62 /** | |
63 * Checks whether this instruction can cause a trap. | |
64 * @return {@code true} if this instruction can cause a trap | |
65 */ | |
66 @Override | |
67 public boolean canTrap() { | |
68 return needsNullCheck(); | |
69 } | |
70 | |
71 @Override | |
72 public void inputValuesDo(ValueClosure closure) { | |
73 object = closure.apply(object); | |
74 } | |
75 | |
76 @Override | |
77 public void accept(ValueVisitor v) { | |
78 v.visitNullCheck(this); | |
79 } | |
80 | |
81 @Override | |
82 public int valueNumber() { | |
83 return Util.hash1(Bytecodes.IFNONNULL, object); | |
84 } | |
85 | |
86 @Override | |
87 public boolean valueEqual(Instruction i) { | |
88 if (i instanceof NullCheck) { | |
89 NullCheck o = (NullCheck) i; | |
90 return object == o.object; | |
91 } | |
92 return false; | |
93 } | |
94 | |
95 @Override | |
96 public RiType declaredType() { | |
97 // null check does not alter the type of the object | |
98 return object.declaredType(); | |
99 } | |
100 | |
101 @Override | |
102 public RiType exactType() { | |
103 // null check does not alter the type of the object | |
104 return object.exactType(); | |
105 } | |
106 | |
107 @Override | |
108 public void runtimeCheckCleared() { | |
109 clearState(); | |
110 } | |
111 | |
112 @Override | |
113 public void print(LogStream out) { | |
114 out.print("null_check(").print(object()).print(')'); | |
115 if (!canTrap()) { | |
116 out.print(" (eliminated)"); | |
117 } | |
118 } | |
119 } |