comparison graal/GraalCompiler/src/com/sun/c1x/ir/LoadField.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/LoadField.java@9ec15d6914ca
children c480605ef068
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.*;
26 import com.sun.c1x.debug.*;
27 import com.sun.c1x.value.*;
28 import com.sun.cri.ci.*;
29 import com.sun.cri.ri.*;
30
31 /**
32 * The {@code LoadField} instruction represents a read of a static or instance field.
33 *
34 * @author Ben L. Titzer
35 */
36 public final class LoadField extends AccessField {
37
38 /**
39 * Creates a new LoadField instance.
40 * @param object the receiver object
41 * @param field the compiler interface field
42 * @param isStatic indicates if the field is static
43 * @param stateBefore the state before the field access
44 * @param isLoaded indicates if the class is loaded
45 */
46 public LoadField(Value object, RiField field, boolean isStatic, FrameState stateBefore, boolean isLoaded) {
47 super(field.kind().stackKind(), object, field, isStatic, stateBefore, isLoaded);
48 }
49
50 /**
51 * Gets the declared type of the field being accessed.
52 * @return the declared type of the field being accessed.
53 */
54 @Override
55 public RiType declaredType() {
56 return field().type();
57 }
58
59 /**
60 * Gets the exact type of the field being accessed. If the field type is
61 * a primitive array or an instance class and the class is loaded and final,
62 * then the exact type is the same as the declared type. Otherwise it is {@code null}
63 * @return the exact type of the field if known; {@code null} otherwise
64 */
65 @Override
66 public RiType exactType() {
67 RiType declaredType = declaredType();
68 return declaredType.isResolved() ? declaredType.exactType() : null;
69 }
70
71 @Override
72 public void accept(ValueVisitor v) {
73 v.visitLoadField(this);
74 }
75
76 /**
77 * Gets a constant value to which this load can be reduced.
78 *
79 * @return {@code null} if this load cannot be reduced to a constant
80 */
81 public CiConstant constantValue() {
82 if (!C1XOptions.CanonicalizeConstantFields) {
83 return null;
84 }
85 if (isStatic()) {
86 return field.constantValue(null);
87 } else if (object().isConstant()) {
88 CiConstant cons = field.constantValue(object().asConstant());
89 if (cons != null) {
90 return cons;
91 }
92 return cons;
93 }
94 return null;
95 }
96
97 @Override
98 public void print(LogStream out) {
99 out.print(object()).
100 print(".").
101 print(field.name()).
102 print(" [field: ").
103 print(CiUtil.format("%h.%n:%t", field, false)).
104 print("]");
105 }
106 }