comparison graal/Runtime/src/com/sun/hotspot/c1x/HotSpotField.java @ 2297:099e697d8934

Renaming c1x4hotspotsrc => graal and HotSpotVM => Runtime
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 22 Apr 2011 15:08:53 +0200
parents
children 4e5515d09314
comparison
equal deleted inserted replaced
2296:34354e2e40a3 2297:099e697d8934
1 /*
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved.
3 *
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 * that is described in this document. In particular, and without limitation, these intellectual property
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 * more additional patents or pending patent applications in the U.S. and in other countries.
8 *
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 * supplements.
12 *
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 * U.S. and other countries.
17 *
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 * Company, Ltd.
20 */
21
22 package com.sun.hotspot.c1x;
23
24 import java.lang.reflect.*;
25
26 import com.sun.c1x.*;
27 import com.sun.cri.ci.CiConstant;
28 import com.sun.cri.ci.CiKind;
29 import com.sun.cri.ri.RiField;
30 import com.sun.cri.ri.RiType;
31
32 /**
33 * Represents a field in a HotSpot type.
34 *
35 * @author Thomas Wuerthinger, Lukas Stadler
36 */
37 public class HotSpotField extends CompilerObject implements RiField {
38
39 private final RiType holder;
40 private final String name;
41 private final RiType type;
42 private final int offset;
43 private CiConstant constant;
44
45 public HotSpotField(Compiler compiler, RiType holder, String name, RiType type, int offset) {
46 super(compiler);
47 this.holder = holder;
48 this.name = name;
49 this.type = type;
50 this.offset = offset;
51 }
52
53 @Override
54 public int accessFlags() {
55 // TODO Auto-generated method stub
56 return 0;
57 }
58
59 @Override
60 public CiConstant constantValue(CiConstant receiver) {
61 if (receiver == null) {
62 if (constant == null && holder.isResolved() && holder.isSubtypeOf(compiler.getVMEntries().getType(C1XOptions.class))) {
63 Field f;
64 try {
65 f = C1XOptions.class.getField(name);
66 } catch (SecurityException e1) {
67 return null;
68 } catch (NoSuchFieldException e1) {
69 return null;
70 }
71 f.setAccessible(true);
72 if (Modifier.isStatic(f.getModifiers())) {
73 CiKind kind = CiKind.fromJavaClass(f.getType());
74 Object value;
75 try {
76 value = f.get(null);
77 } catch (IllegalArgumentException e) {
78 return null;
79 } catch (IllegalAccessException e) {
80 return null;
81 }
82 constant = CiConstant.forBoxed(kind, value);
83 }
84 }
85
86 // Constant part only valid for static fields.
87 return constant;
88 }
89 return null;
90 }
91
92 @Override
93 public RiType holder() {
94 return holder;
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (obj instanceof HotSpotField) {
100 HotSpotField other = (HotSpotField) obj;
101 return other.offset == offset && other.holder.equals(holder());
102 }
103 return false;
104 }
105
106 @Override
107 public boolean isResolved() {
108 return offset != -1;
109 }
110
111 @Override
112 public CiKind kind() {
113 return type().kind();
114 }
115
116 @Override
117 public String name() {
118 return name;
119 }
120
121 @Override
122 public RiType type() {
123 return type;
124 }
125
126 public int offset() {
127 return offset;
128 }
129
130 @Override
131 public String toString() {
132 return "HotSpotField<" + holder.name() + "." + name + ">";
133 }
134
135 }