author | coleenp |
Thu, 27 Jan 2011 16:11:27 -0800 (2011-01-28) | |
changeset 8076 | 96d498ec7ae1 |
parent 7397 | 5b173b4ca846 |
child 10265 | 4c869854aebd |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_CI_CIFIELD_HPP |
26 |
#define SHARE_VM_CI_CIFIELD_HPP |
|
27 |
||
28 |
#include "ci/ciClassList.hpp" |
|
29 |
#include "ci/ciConstant.hpp" |
|
30 |
#include "ci/ciFlags.hpp" |
|
31 |
#include "ci/ciInstance.hpp" |
|
32 |
||
1 | 33 |
// ciField |
34 |
// |
|
35 |
// This class represents the result of a field lookup in the VM. |
|
36 |
// The lookup may not succeed, in which case the information in |
|
37 |
// the ciField will be incomplete. |
|
38 |
class ciField : public ResourceObj { |
|
39 |
CI_PACKAGE_ACCESS |
|
40 |
friend class ciEnv; |
|
41 |
friend class ciInstanceKlass; |
|
42 |
friend class NonStaticFieldFiller; |
|
43 |
||
44 |
private: |
|
45 |
ciFlags _flags; |
|
46 |
ciInstanceKlass* _holder; |
|
47 |
ciSymbol* _name; |
|
48 |
ciSymbol* _signature; |
|
49 |
ciType* _type; |
|
50 |
int _offset; |
|
51 |
bool _is_constant; |
|
52 |
ciInstanceKlass* _known_to_link_with; |
|
53 |
ciConstant _constant_value; |
|
54 |
||
55 |
// Used for will_link |
|
56 |
int _cp_index; |
|
57 |
||
58 |
ciType* compute_type(); |
|
59 |
ciType* compute_type_impl(); |
|
60 |
||
61 |
ciField(ciInstanceKlass* klass, int index); |
|
62 |
ciField(fieldDescriptor* fd); |
|
63 |
||
64 |
// shared constructor code |
|
65 |
void initialize_from(fieldDescriptor* fd); |
|
66 |
||
67 |
// The implementation of the print method. |
|
68 |
void print_impl(outputStream* st); |
|
69 |
||
70 |
public: |
|
71 |
ciFlags flags() { return _flags; } |
|
72 |
||
73 |
// Of which klass is this field a member? |
|
74 |
// |
|
75 |
// Usage note: the declared holder of a field is the class |
|
76 |
// referenced by name in the bytecodes. The canonical holder |
|
77 |
// is the most general class which holds the field. This |
|
78 |
// method returns the canonical holder. The declared holder |
|
79 |
// can be accessed via a method in ciBytecodeStream. |
|
80 |
// |
|
81 |
// Ex. |
|
82 |
// class A { |
|
83 |
// public int f = 7; |
|
84 |
// } |
|
85 |
// class B extends A { |
|
86 |
// public void test() { |
|
87 |
// System.out.println(f); |
|
88 |
// } |
|
89 |
// } |
|
90 |
// |
|
91 |
// A java compiler is permitted to compile the access to |
|
92 |
// field f as: |
|
93 |
// |
|
94 |
// getfield B.f |
|
95 |
// |
|
96 |
// In that case the declared holder of f would be B and |
|
97 |
// the canonical holder of f would be A. |
|
98 |
ciInstanceKlass* holder() { return _holder; } |
|
99 |
||
100 |
// Name of this field? |
|
101 |
ciSymbol* name() { return _name; } |
|
102 |
||
103 |
// Signature of this field? |
|
104 |
ciSymbol* signature() { return _signature; } |
|
105 |
||
106 |
// Of what type is this field? |
|
107 |
ciType* type() { return (_type == NULL) ? compute_type() : _type; } |
|
108 |
||
109 |
// How is this field actually stored in memory? |
|
110 |
BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; } |
|
111 |
||
112 |
// How big is this field in memory? |
|
202
dc13bf0e5d5d
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
1
diff
changeset
|
113 |
int size_in_bytes() { return type2aelembytes(layout_type()); } |
1 | 114 |
|
115 |
// What is the offset of this field? |
|
116 |
int offset() { |
|
117 |
assert(_offset >= 1, "illegal call to offset()"); |
|
118 |
return _offset; |
|
119 |
} |
|
120 |
||
121 |
// Same question, explicit units. (Fields are aligned to the byte level.) |
|
122 |
int offset_in_bytes() { |
|
123 |
return offset(); |
|
124 |
} |
|
125 |
||
126 |
// Is this field shared? |
|
127 |
bool is_shared() { |
|
128 |
// non-static fields of shared holders are cached |
|
129 |
return _holder->is_shared() && !is_static(); |
|
130 |
} |
|
131 |
||
132 |
// Is this field a constant? |
|
133 |
// |
|
134 |
// Clarification: A field is considered constant if: |
|
135 |
// 1. The field is both static and final |
|
136 |
// 2. The canonical holder of the field has undergone |
|
137 |
// static initialization. |
|
138 |
// 3. If the field is an object or array, then the oop |
|
139 |
// in question is allocated in perm space. |
|
140 |
// 4. The field is not one of the special static/final |
|
141 |
// non-constant fields. These are java.lang.System.in |
|
142 |
// and java.lang.System.out. Abomination. |
|
143 |
// |
|
144 |
// Note: the check for case 4 is not yet implemented. |
|
145 |
bool is_constant() { return _is_constant; } |
|
146 |
||
147 |
// Get the constant value of this field. |
|
148 |
ciConstant constant_value() { |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
149 |
assert(is_static() && is_constant(), "illegal call to constant_value()"); |
1 | 150 |
return _constant_value; |
151 |
} |
|
152 |
||
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
153 |
// Get the constant value of non-static final field in the given |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
154 |
// object. |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
155 |
ciConstant constant_value_of(ciObject* object) { |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
156 |
assert(!is_static() && is_constant(), "only if field is non-static constant"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
157 |
assert(object->is_instance(), "must be instance"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
158 |
return object->as_instance()->field_value(this); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
159 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
670
diff
changeset
|
160 |
|
1 | 161 |
// Check for link time errors. Accessing a field from a |
162 |
// certain class via a certain bytecode may or may not be legal. |
|
163 |
// This call checks to see if an exception may be raised by |
|
164 |
// an access of this field. |
|
165 |
// |
|
166 |
// Usage note: if the same field is accessed multiple times |
|
167 |
// in the same compilation, will_link will need to be checked |
|
168 |
// at each point of access. |
|
169 |
bool will_link(ciInstanceKlass* accessing_klass, |
|
170 |
Bytecodes::Code bc); |
|
171 |
||
172 |
// Java access flags |
|
173 |
bool is_public () { return flags().is_public(); } |
|
174 |
bool is_private () { return flags().is_private(); } |
|
175 |
bool is_protected () { return flags().is_protected(); } |
|
176 |
bool is_static () { return flags().is_static(); } |
|
177 |
bool is_final () { return flags().is_final(); } |
|
178 |
bool is_volatile () { return flags().is_volatile(); } |
|
179 |
bool is_transient () { return flags().is_transient(); } |
|
180 |
||
181 |
// Debugging output |
|
182 |
void print(); |
|
183 |
void print_name_on(outputStream* st); |
|
184 |
}; |
|
7397 | 185 |
|
186 |
#endif // SHARE_VM_CI_CIFIELD_HPP |