Mercurial > hg > truffle
comparison graal/Compiler/src/com/sun/c1x/ir/AccessField.java @ 2507:9ec15d6914ca
Pull over of compiler from maxine repository.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:43:22 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2506:4a3bf8a5bf41 | 2507:9ec15d6914ca |
---|---|
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 java.lang.reflect.*; | |
26 | |
27 import com.sun.c1x.*; | |
28 import com.sun.c1x.value.*; | |
29 import com.sun.cri.ci.*; | |
30 import com.sun.cri.ri.*; | |
31 | |
32 /** | |
33 * The base class of all instructions that access fields. | |
34 * | |
35 * @author Ben L. Titzer | |
36 */ | |
37 public abstract class AccessField extends StateSplit { | |
38 | |
39 private Value object; | |
40 protected final RiField field; | |
41 | |
42 /** | |
43 * Constructs a new access field object. | |
44 * @param kind the result kind of the access | |
45 * @param object the instruction producing the receiver object | |
46 * @param field the compiler interface representation of the field | |
47 * @param isStatic indicates if the field is static | |
48 * @param stateBefore the state before the field access | |
49 * @param isLoaded indicates if the class is loaded | |
50 */ | |
51 public AccessField(CiKind kind, Value object, RiField field, boolean isStatic, FrameState stateBefore, boolean isLoaded) { | |
52 super(kind, stateBefore); | |
53 this.object = object; | |
54 this.field = field; | |
55 if (!isLoaded || (C1XOptions.TestPatching && !Modifier.isVolatile(field.accessFlags()))) { | |
56 // require patching if the field is not loaded (i.e. resolved), | |
57 // or if patch testing is turned on (but not if the field is volatile) | |
58 setFlag(Flag.NeedsPatching); | |
59 } | |
60 initFlag(Flag.IsLoaded, isLoaded); | |
61 initFlag(Flag.IsStatic, isStatic); | |
62 if (isLoaded && object.isNonNull()) { | |
63 eliminateNullCheck(); | |
64 } | |
65 assert object != null : "every field access must reference some object"; | |
66 } | |
67 | |
68 /** | |
69 * Gets the instruction that produces the receiver object of this field access | |
70 * (for instance field accesses). | |
71 * @return the instruction that produces the receiver object | |
72 */ | |
73 public Value object() { | |
74 return object; | |
75 } | |
76 | |
77 /** | |
78 * Gets the compiler interface field for this field access. | |
79 * @return the compiler interface field for this field access | |
80 */ | |
81 public RiField field() { | |
82 return field; | |
83 } | |
84 | |
85 /** | |
86 * Checks whether this field access is an access to a static field. | |
87 * @return {@code true} if this field access is to a static field | |
88 */ | |
89 public boolean isStatic() { | |
90 return checkFlag(Flag.IsStatic); | |
91 } | |
92 | |
93 /** | |
94 * Checks whether the class of the field of this access is loaded. | |
95 * @return {@code true} if the class is loaded | |
96 */ | |
97 public boolean isLoaded() { | |
98 return checkFlag(Flag.IsLoaded); | |
99 } | |
100 | |
101 /** | |
102 * Checks whether this field is declared volatile. | |
103 * @return {@code true} if the field is resolved and declared volatile | |
104 */ | |
105 public boolean isVolatile() { | |
106 return isLoaded() && Modifier.isVolatile(field.accessFlags()); | |
107 } | |
108 | |
109 @Override | |
110 public void runtimeCheckCleared() { | |
111 if (isLoaded()) { | |
112 clearState(); | |
113 } | |
114 } | |
115 | |
116 /** | |
117 * Checks whether this field access will require patching. | |
118 * @return {@code true} if this field access will require patching | |
119 */ | |
120 public boolean needsPatching() { | |
121 return checkFlag(Flag.NeedsPatching); | |
122 } | |
123 | |
124 /** | |
125 * Checks whether this field access may cause a trap or an exception, which | |
126 * is if it either requires a null check or needs patching. | |
127 * @return {@code true} if this field access can cause a trap | |
128 */ | |
129 @Override | |
130 public boolean canTrap() { | |
131 return needsPatching() || needsNullCheck(); | |
132 } | |
133 | |
134 @Override | |
135 public void inputValuesDo(ValueClosure closure) { | |
136 object = closure.apply(object); | |
137 } | |
138 } |