1 /* |
1 /* |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
36 // iterates over fields that have been injected by the JVM. |
36 // iterates over fields that have been injected by the JVM. |
37 // AllFieldStream exposes all fields and should only be used in rare |
37 // AllFieldStream exposes all fields and should only be used in rare |
38 // cases. |
38 // cases. |
39 class FieldStreamBase : public StackObj { |
39 class FieldStreamBase : public StackObj { |
40 protected: |
40 protected: |
41 typeArrayHandle _fields; |
41 Array<u2>* _fields; |
42 constantPoolHandle _constants; |
42 constantPoolHandle _constants; |
43 int _index; |
43 int _index; |
44 int _limit; |
44 int _limit; |
45 int _generic_signature_slot; |
45 int _generic_signature_slot; |
46 |
46 |
47 FieldInfo* field() const { return FieldInfo::from_field_array(_fields(), _index); } |
47 FieldInfo* field() const { return FieldInfo::from_field_array(_fields, _index); } |
48 |
48 |
49 int init_generic_signature_start_slot() { |
49 int init_generic_signature_start_slot() { |
50 int length = _fields->length(); |
50 int length = _fields->length(); |
51 int num_fields = 0; |
51 int num_fields = 0; |
52 int skipped_generic_signature_slots = 0; |
52 int skipped_generic_signature_slots = 0; |
53 FieldInfo* fi; |
53 FieldInfo* fi; |
54 AccessFlags flags; |
54 AccessFlags flags; |
55 /* Scan from 0 to the current _index. Count the number of generic |
55 /* Scan from 0 to the current _index. Count the number of generic |
56 signature slots for field[0] to field[_index - 1]. */ |
56 signature slots for field[0] to field[_index - 1]. */ |
57 for (int i = 0; i < _index; i++) { |
57 for (int i = 0; i < _index; i++) { |
58 fi = FieldInfo::from_field_array(_fields(), i); |
58 fi = FieldInfo::from_field_array(_fields, i); |
59 flags.set_flags(fi->access_flags()); |
59 flags.set_flags(fi->access_flags()); |
60 if (flags.field_has_generic_signature()) { |
60 if (flags.field_has_generic_signature()) { |
61 length --; |
61 length --; |
62 skipped_generic_signature_slots ++; |
62 skipped_generic_signature_slots ++; |
63 } |
63 } |
64 } |
64 } |
65 /* Scan from the current _index. */ |
65 /* Scan from the current _index. */ |
66 for (int i = _index; i*FieldInfo::field_slots < length; i++) { |
66 for (int i = _index; i*FieldInfo::field_slots < length; i++) { |
67 fi = FieldInfo::from_field_array(_fields(), i); |
67 fi = FieldInfo::from_field_array(_fields, i); |
68 flags.set_flags(fi->access_flags()); |
68 flags.set_flags(fi->access_flags()); |
69 if (flags.field_has_generic_signature()) { |
69 if (flags.field_has_generic_signature()) { |
70 length --; |
70 length --; |
71 } |
71 } |
72 num_fields ++; |
72 num_fields ++; |
74 _generic_signature_slot = length + skipped_generic_signature_slots; |
74 _generic_signature_slot = length + skipped_generic_signature_slots; |
75 assert(_generic_signature_slot <= _fields->length(), ""); |
75 assert(_generic_signature_slot <= _fields->length(), ""); |
76 return num_fields; |
76 return num_fields; |
77 } |
77 } |
78 |
78 |
79 FieldStreamBase(typeArrayHandle fields, constantPoolHandle constants, int start, int limit) { |
79 FieldStreamBase(Array<u2>* fields, constantPoolHandle constants, int start, int limit) { |
80 _fields = fields; |
80 _fields = fields; |
81 _constants = constants; |
81 _constants = constants; |
82 _index = start; |
82 _index = start; |
83 int num_fields = init_generic_signature_start_slot(); |
83 int num_fields = init_generic_signature_start_slot(); |
84 if (limit < start) { |
84 if (limit < start) { |
86 } else { |
86 } else { |
87 _limit = limit; |
87 _limit = limit; |
88 } |
88 } |
89 } |
89 } |
90 |
90 |
91 FieldStreamBase(typeArrayHandle fields, constantPoolHandle constants) { |
91 FieldStreamBase(Array<u2>* fields, constantPoolHandle constants) { |
92 _fields = fields; |
92 _fields = fields; |
93 _constants = constants; |
93 _constants = constants; |
94 _index = 0; |
94 _index = 0; |
95 _limit = init_generic_signature_start_slot(); |
95 _limit = init_generic_signature_start_slot(); |
96 } |
96 } |
97 |
97 |
98 public: |
98 public: |
99 FieldStreamBase(instanceKlass* klass) { |
99 FieldStreamBase(InstanceKlass* klass) { |
100 _fields = klass->fields(); |
100 _fields = klass->fields(); |
101 _constants = klass->constants(); |
101 _constants = klass->constants(); |
102 _index = 0; |
102 _index = 0; |
103 _limit = klass->java_fields_count(); |
103 _limit = klass->java_fields_count(); |
104 init_generic_signature_start_slot(); |
104 init_generic_signature_start_slot(); |
147 } |
147 } |
148 |
148 |
149 Symbol* generic_signature() const { |
149 Symbol* generic_signature() const { |
150 if (access_flags().field_has_generic_signature()) { |
150 if (access_flags().field_has_generic_signature()) { |
151 assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
151 assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
152 int index = _fields->short_at(_generic_signature_slot); |
152 int index = _fields->at(_generic_signature_slot); |
153 return _constants->symbol_at(index); |
153 return _constants->symbol_at(index); |
154 } else { |
154 } else { |
155 return NULL; |
155 return NULL; |
156 } |
156 } |
157 } |
157 } |
166 }; |
166 }; |
167 |
167 |
168 // Iterate over only the internal fields |
168 // Iterate over only the internal fields |
169 class JavaFieldStream : public FieldStreamBase { |
169 class JavaFieldStream : public FieldStreamBase { |
170 public: |
170 public: |
171 JavaFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {} |
|
172 JavaFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {} |
171 JavaFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {} |
173 |
172 |
174 int name_index() const { |
173 int name_index() const { |
175 assert(!field()->is_internal(), "regular only"); |
174 assert(!field()->is_internal(), "regular only"); |
176 return field()->name_index(); |
175 return field()->name_index(); |
189 } |
188 } |
190 int generic_signature_index() const { |
189 int generic_signature_index() const { |
191 assert(!field()->is_internal(), "regular only"); |
190 assert(!field()->is_internal(), "regular only"); |
192 if (access_flags().field_has_generic_signature()) { |
191 if (access_flags().field_has_generic_signature()) { |
193 assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
192 assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
194 return _fields->short_at(_generic_signature_slot); |
193 return _fields->at(_generic_signature_slot); |
195 } else { |
194 } else { |
196 return 0; |
195 return 0; |
197 } |
196 } |
198 } |
197 } |
199 void set_generic_signature_index(int index) { |
198 void set_generic_signature_index(int index) { |
200 assert(!field()->is_internal(), "regular only"); |
199 assert(!field()->is_internal(), "regular only"); |
201 if (access_flags().field_has_generic_signature()) { |
200 if (access_flags().field_has_generic_signature()) { |
202 assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
201 assert(_generic_signature_slot < _fields->length(), "out of bounds"); |
203 _fields->short_at_put(_generic_signature_slot, index); |
202 _fields->at_put(_generic_signature_slot, index); |
204 } |
203 } |
205 } |
204 } |
206 int initval_index() const { |
205 int initval_index() const { |
207 assert(!field()->is_internal(), "regular only"); |
206 assert(!field()->is_internal(), "regular only"); |
208 return field()->initval_index(); |
207 return field()->initval_index(); |
215 |
214 |
216 |
215 |
217 // Iterate over only the internal fields |
216 // Iterate over only the internal fields |
218 class InternalFieldStream : public FieldStreamBase { |
217 class InternalFieldStream : public FieldStreamBase { |
219 public: |
218 public: |
220 InternalFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {} |
219 InternalFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {} |
221 InternalFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {} |
220 InternalFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {} |
222 }; |
221 }; |
223 |
222 |
224 |
223 |
225 class AllFieldStream : public FieldStreamBase { |
224 class AllFieldStream : public FieldStreamBase { |
226 public: |
225 public: |
227 AllFieldStream(typeArrayHandle fields, constantPoolHandle constants): FieldStreamBase(fields, constants) {} |
226 AllFieldStream(Array<u2>* fields, constantPoolHandle constants): FieldStreamBase(fields, constants) {} |
228 AllFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants()) {} |
227 AllFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants()) {} |
229 AllFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants()) {} |
228 AllFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants()) {} |
230 }; |
229 }; |
231 |
230 |
232 #endif // SHARE_VM_OOPS_FIELDSTREAMS_HPP |
231 #endif // SHARE_VM_OOPS_FIELDSTREAMS_HPP |