author | coleenp |
Wed, 13 Nov 2019 08:23:23 -0500 | |
changeset 59056 | 15936b142f86 |
parent 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
10546 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
10546 | 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 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
25 |
#ifndef SHARE_OOPS_FIELDSTREAMS_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
26 |
#define SHARE_OOPS_FIELDSTREAMS_HPP |
10546 | 27 |
|
28 |
#include "oops/instanceKlass.hpp" |
|
29 |
#include "oops/fieldInfo.hpp" |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
30 |
#include "runtime/fieldDescriptor.hpp" |
10546 | 31 |
|
32 |
// The is the base class for iteration over the fields array |
|
33 |
// describing the declared fields in the class. Several subclasses |
|
34 |
// are provided depending on the kind of iteration required. The |
|
35 |
// JavaFieldStream is for iterating over regular Java fields and it |
|
36 |
// generally the preferred iterator. InternalFieldStream only |
|
37 |
// iterates over fields that have been injected by the JVM. |
|
38 |
// AllFieldStream exposes all fields and should only be used in rare |
|
39 |
// cases. |
|
40 |
class FieldStreamBase : public StackObj { |
|
41 |
protected: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
42 |
Array<u2>* _fields; |
10546 | 43 |
constantPoolHandle _constants; |
44 |
int _index; |
|
45 |
int _limit; |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
46 |
int _generic_signature_slot; |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
47 |
fieldDescriptor _fd_buf; |
10546 | 48 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
49 |
FieldInfo* field() const { return FieldInfo::from_field_array(_fields, _index); } |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
50 |
InstanceKlass* field_holder() const { return _constants->pool_holder(); } |
10546 | 51 |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
52 |
int init_generic_signature_start_slot() { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
53 |
int length = _fields->length(); |
28396
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
20017
diff
changeset
|
54 |
int num_fields = _index; |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
55 |
int skipped_generic_signature_slots = 0; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
56 |
FieldInfo* fi; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
57 |
AccessFlags flags; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
58 |
/* Scan from 0 to the current _index. Count the number of generic |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
59 |
signature slots for field[0] to field[_index - 1]. */ |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
60 |
for (int i = 0; i < _index; i++) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
61 |
fi = FieldInfo::from_field_array(_fields, i); |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
62 |
flags.set_flags(fi->access_flags()); |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
63 |
if (flags.field_has_generic_signature()) { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
64 |
length --; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
65 |
skipped_generic_signature_slots ++; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
66 |
} |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
67 |
} |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
68 |
/* Scan from the current _index. */ |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
69 |
for (int i = _index; i*FieldInfo::field_slots < length; i++) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
70 |
fi = FieldInfo::from_field_array(_fields, i); |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
71 |
flags.set_flags(fi->access_flags()); |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
72 |
if (flags.field_has_generic_signature()) { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
73 |
length --; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
74 |
} |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
75 |
num_fields ++; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
76 |
} |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
77 |
_generic_signature_slot = length + skipped_generic_signature_slots; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
78 |
assert(_generic_signature_slot <= _fields->length(), ""); |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
79 |
return num_fields; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
80 |
} |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
81 |
|
59056
15936b142f86
8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents:
53244
diff
changeset
|
82 |
inline FieldStreamBase(Array<u2>* fields, ConstantPool* constants, int start, int limit); |
10546 | 83 |
|
59056
15936b142f86
8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents:
53244
diff
changeset
|
84 |
inline FieldStreamBase(Array<u2>* fields, ConstantPool* constants); |
10546 | 85 |
public: |
59056
15936b142f86
8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents:
53244
diff
changeset
|
86 |
inline FieldStreamBase(InstanceKlass* klass); |
10546 | 87 |
|
88 |
// accessors |
|
89 |
int index() const { return _index; } |
|
90 |
||
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
91 |
void next() { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
92 |
if (access_flags().field_has_generic_signature()) { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
93 |
_generic_signature_slot ++; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
94 |
assert(_generic_signature_slot <= _fields->length(), ""); |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
95 |
} |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
96 |
_index += 1; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
97 |
} |
10546 | 98 |
bool done() const { return _index >= _limit; } |
99 |
||
100 |
// Accessors for current field |
|
101 |
AccessFlags access_flags() const { |
|
102 |
AccessFlags flags; |
|
103 |
flags.set_flags(field()->access_flags()); |
|
104 |
return flags; |
|
105 |
} |
|
106 |
||
107 |
void set_access_flags(u2 flags) const { |
|
108 |
field()->set_access_flags(flags); |
|
109 |
} |
|
110 |
||
111 |
void set_access_flags(AccessFlags flags) const { |
|
112 |
set_access_flags(flags.as_short()); |
|
113 |
} |
|
114 |
||
115 |
Symbol* name() const { |
|
59056
15936b142f86
8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents:
53244
diff
changeset
|
116 |
return field()->name(_constants()); |
10546 | 117 |
} |
118 |
||
119 |
Symbol* signature() const { |
|
59056
15936b142f86
8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents:
53244
diff
changeset
|
120 |
return field()->signature(_constants()); |
10546 | 121 |
} |
122 |
||
123 |
Symbol* generic_signature() const { |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
124 |
if (access_flags().field_has_generic_signature()) { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
125 |
assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
126 |
int index = _fields->at(_generic_signature_slot); |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
127 |
return _constants->symbol_at(index); |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
128 |
} else { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
129 |
return NULL; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
130 |
} |
10546 | 131 |
} |
132 |
||
133 |
int offset() const { |
|
134 |
return field()->offset(); |
|
135 |
} |
|
136 |
||
15193
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
137 |
int allocation_type() const { |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
138 |
return field()->allocation_type(); |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
139 |
} |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
140 |
|
10546 | 141 |
void set_offset(int offset) { |
142 |
field()->set_offset(offset); |
|
143 |
} |
|
15193
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
144 |
|
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
145 |
bool is_offset_set() const { |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
146 |
return field()->is_offset_set(); |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
147 |
} |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
148 |
|
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
149 |
bool is_contended() const { |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
150 |
return field()->is_contended(); |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
151 |
} |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
152 |
|
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
153 |
int contended_group() const { |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
154 |
return field()->contended_group(); |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
155 |
} |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
13728
diff
changeset
|
156 |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
157 |
// bridge to a heavier API: |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
158 |
fieldDescriptor& field_descriptor() const { |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
159 |
fieldDescriptor& field = const_cast<fieldDescriptor&>(_fd_buf); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
160 |
field.reinitialize(field_holder(), _index); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
161 |
return field; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
15193
diff
changeset
|
162 |
} |
10546 | 163 |
}; |
164 |
||
165 |
// Iterate over only the internal fields |
|
166 |
class JavaFieldStream : public FieldStreamBase { |
|
167 |
public: |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
33593
diff
changeset
|
168 |
JavaFieldStream(const InstanceKlass* k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {} |
10546 | 169 |
|
170 |
int name_index() const { |
|
171 |
assert(!field()->is_internal(), "regular only"); |
|
172 |
return field()->name_index(); |
|
173 |
} |
|
174 |
void set_name_index(int index) { |
|
175 |
assert(!field()->is_internal(), "regular only"); |
|
176 |
field()->set_name_index(index); |
|
177 |
} |
|
178 |
int signature_index() const { |
|
179 |
assert(!field()->is_internal(), "regular only"); |
|
180 |
return field()->signature_index(); |
|
181 |
} |
|
182 |
void set_signature_index(int index) { |
|
183 |
assert(!field()->is_internal(), "regular only"); |
|
184 |
field()->set_signature_index(index); |
|
185 |
} |
|
186 |
int generic_signature_index() const { |
|
187 |
assert(!field()->is_internal(), "regular only"); |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
188 |
if (access_flags().field_has_generic_signature()) { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
189 |
assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
190 |
return _fields->at(_generic_signature_slot); |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
191 |
} else { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
192 |
return 0; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
193 |
} |
10546 | 194 |
} |
195 |
void set_generic_signature_index(int index) { |
|
196 |
assert(!field()->is_internal(), "regular only"); |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
197 |
if (access_flags().field_has_generic_signature()) { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
198 |
assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
199 |
_fields->at_put(_generic_signature_slot, index); |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
10546
diff
changeset
|
200 |
} |
10546 | 201 |
} |
202 |
int initval_index() const { |
|
203 |
assert(!field()->is_internal(), "regular only"); |
|
204 |
return field()->initval_index(); |
|
205 |
} |
|
206 |
void set_initval_index(int index) { |
|
207 |
assert(!field()->is_internal(), "regular only"); |
|
208 |
return field()->set_initval_index(index); |
|
209 |
} |
|
210 |
}; |
|
211 |
||
212 |
||
213 |
// Iterate over only the internal fields |
|
214 |
class InternalFieldStream : public FieldStreamBase { |
|
215 |
public: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
216 |
InternalFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {} |
10546 | 217 |
}; |
218 |
||
219 |
||
220 |
class AllFieldStream : public FieldStreamBase { |
|
221 |
public: |
|
59056
15936b142f86
8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents:
53244
diff
changeset
|
222 |
AllFieldStream(Array<u2>* fields, ConstantPool* constants): FieldStreamBase(fields, constants) {} |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12772
diff
changeset
|
223 |
AllFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants()) {} |
10546 | 224 |
}; |
225 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
226 |
#endif // SHARE_OOPS_FIELDSTREAMS_HPP |