annotate src/share/vm/oops/fieldStreams.hpp @ 5297:b2e698d2276c

8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation Summary: Enhance method resolution and resulting data structures, plus some refactoring. Reviewed-by: twisti, acorn, jrose
author drchase
date Fri, 13 Sep 2013 22:38:02 -0400
parents 4a916f2ce331
children
rev   line source
never@2702 1 /*
drchase@5297 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
never@2702 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
never@2702 4 *
never@2702 5 * This code is free software; you can redistribute it and/or modify it
never@2702 6 * under the terms of the GNU General Public License version 2 only, as
never@2702 7 * published by the Free Software Foundation.
never@2702 8 *
never@2702 9 * This code is distributed in the hope that it will be useful, but WITHOUT
never@2702 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
never@2702 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
never@2702 12 * version 2 for more details (a copy is included in the LICENSE file that
never@2702 13 * accompanied this code).
never@2702 14 *
never@2702 15 * You should have received a copy of the GNU General Public License version
never@2702 16 * 2 along with this work; if not, write to the Free Software Foundation,
never@2702 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
never@2702 18 *
never@2702 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
never@2702 20 * or visit www.oracle.com if you need additional information or have any
never@2702 21 * questions.
never@2702 22 *
never@2702 23 */
never@2702 24
never@2702 25 #ifndef SHARE_VM_OOPS_FIELDSTREAMS_HPP
never@2702 26 #define SHARE_VM_OOPS_FIELDSTREAMS_HPP
never@2702 27
never@2702 28 #include "oops/instanceKlass.hpp"
never@2702 29 #include "oops/fieldInfo.hpp"
drchase@5297 30 #include "runtime/fieldDescriptor.hpp"
never@2702 31
never@2702 32 // The is the base class for iteration over the fields array
never@2702 33 // describing the declared fields in the class. Several subclasses
never@2702 34 // are provided depending on the kind of iteration required. The
never@2702 35 // JavaFieldStream is for iterating over regular Java fields and it
never@2702 36 // generally the preferred iterator. InternalFieldStream only
never@2702 37 // iterates over fields that have been injected by the JVM.
never@2702 38 // AllFieldStream exposes all fields and should only be used in rare
never@2702 39 // cases.
never@2702 40 class FieldStreamBase : public StackObj {
never@2702 41 protected:
coleenp@3602 42 Array<u2>* _fields;
never@2702 43 constantPoolHandle _constants;
never@2702 44 int _index;
never@2702 45 int _limit;
jiangli@3368 46 int _generic_signature_slot;
drchase@5297 47 fieldDescriptor _fd_buf;
never@2702 48
coleenp@3602 49 FieldInfo* field() const { return FieldInfo::from_field_array(_fields, _index); }
drchase@5297 50 InstanceKlass* field_holder() const { return _constants->pool_holder(); }
never@2702 51
jiangli@3368 52 int init_generic_signature_start_slot() {
jiangli@3368 53 int length = _fields->length();
jiangli@3368 54 int num_fields = 0;
jiangli@3368 55 int skipped_generic_signature_slots = 0;
jiangli@3368 56 FieldInfo* fi;
jiangli@3368 57 AccessFlags flags;
jiangli@3368 58 /* Scan from 0 to the current _index. Count the number of generic
jiangli@3368 59 signature slots for field[0] to field[_index - 1]. */
jiangli@3368 60 for (int i = 0; i < _index; i++) {
coleenp@3602 61 fi = FieldInfo::from_field_array(_fields, i);
jiangli@3368 62 flags.set_flags(fi->access_flags());
jiangli@3368 63 if (flags.field_has_generic_signature()) {
jiangli@3368 64 length --;
jiangli@3368 65 skipped_generic_signature_slots ++;
jiangli@3368 66 }
jiangli@3368 67 }
jiangli@3368 68 /* Scan from the current _index. */
jiangli@3368 69 for (int i = _index; i*FieldInfo::field_slots < length; i++) {
coleenp@3602 70 fi = FieldInfo::from_field_array(_fields, i);
jiangli@3368 71 flags.set_flags(fi->access_flags());
jiangli@3368 72 if (flags.field_has_generic_signature()) {
jiangli@3368 73 length --;
jiangli@3368 74 }
jiangli@3368 75 num_fields ++;
jiangli@3368 76 }
jiangli@3368 77 _generic_signature_slot = length + skipped_generic_signature_slots;
jiangli@3368 78 assert(_generic_signature_slot <= _fields->length(), "");
jiangli@3368 79 return num_fields;
jiangli@3368 80 }
jiangli@3368 81
coleenp@3602 82 FieldStreamBase(Array<u2>* fields, constantPoolHandle constants, int start, int limit) {
never@2702 83 _fields = fields;
never@2702 84 _constants = constants;
never@2702 85 _index = start;
jiangli@3368 86 int num_fields = init_generic_signature_start_slot();
jiangli@3368 87 if (limit < start) {
jiangli@3368 88 _limit = num_fields;
jiangli@3368 89 } else {
jiangli@3368 90 _limit = limit;
jiangli@3368 91 }
never@2702 92 }
never@2702 93
coleenp@3602 94 FieldStreamBase(Array<u2>* fields, constantPoolHandle constants) {
never@2702 95 _fields = fields;
never@2702 96 _constants = constants;
never@2702 97 _index = 0;
jiangli@3368 98 _limit = init_generic_signature_start_slot();
never@2702 99 }
never@2702 100
never@2702 101 public:
coleenp@3602 102 FieldStreamBase(InstanceKlass* klass) {
never@2702 103 _fields = klass->fields();
never@2702 104 _constants = klass->constants();
never@2702 105 _index = 0;
never@2702 106 _limit = klass->java_fields_count();
jiangli@3368 107 init_generic_signature_start_slot();
drchase@5297 108 assert(klass == field_holder(), "");
never@2702 109 }
never@2702 110 FieldStreamBase(instanceKlassHandle klass) {
never@2702 111 _fields = klass->fields();
never@2702 112 _constants = klass->constants();
never@2702 113 _index = 0;
never@2702 114 _limit = klass->java_fields_count();
jiangli@3368 115 init_generic_signature_start_slot();
drchase@5297 116 assert(klass == field_holder(), "");
never@2702 117 }
never@2702 118
never@2702 119 // accessors
never@2702 120 int index() const { return _index; }
never@2702 121
jiangli@3368 122 void next() {
jiangli@3368 123 if (access_flags().field_has_generic_signature()) {
jiangli@3368 124 _generic_signature_slot ++;
jiangli@3368 125 assert(_generic_signature_slot <= _fields->length(), "");
jiangli@3368 126 }
jiangli@3368 127 _index += 1;
jiangli@3368 128 }
never@2702 129 bool done() const { return _index >= _limit; }
never@2702 130
never@2702 131 // Accessors for current field
never@2702 132 AccessFlags access_flags() const {
never@2702 133 AccessFlags flags;
never@2702 134 flags.set_flags(field()->access_flags());
never@2702 135 return flags;
never@2702 136 }
never@2702 137
never@2702 138 void set_access_flags(u2 flags) const {
never@2702 139 field()->set_access_flags(flags);
never@2702 140 }
never@2702 141
never@2702 142 void set_access_flags(AccessFlags flags) const {
never@2702 143 set_access_flags(flags.as_short());
never@2702 144 }
never@2702 145
never@2702 146 Symbol* name() const {
never@2702 147 return field()->name(_constants);
never@2702 148 }
never@2702 149
never@2702 150 Symbol* signature() const {
never@2702 151 return field()->signature(_constants);
never@2702 152 }
never@2702 153
never@2702 154 Symbol* generic_signature() const {
jiangli@3368 155 if (access_flags().field_has_generic_signature()) {
jiangli@3368 156 assert(_generic_signature_slot < _fields->length(), "out of bounds");
coleenp@3602 157 int index = _fields->at(_generic_signature_slot);
jiangli@3368 158 return _constants->symbol_at(index);
jiangli@3368 159 } else {
jiangli@3368 160 return NULL;
jiangli@3368 161 }
never@2702 162 }
never@2702 163
never@2702 164 int offset() const {
never@2702 165 return field()->offset();
never@2702 166 }
never@2702 167
jwilhelm@3995 168 int allocation_type() const {
jwilhelm@3995 169 return field()->allocation_type();
jwilhelm@3995 170 }
jwilhelm@3995 171
never@2702 172 void set_offset(int offset) {
never@2702 173 field()->set_offset(offset);
never@2702 174 }
jwilhelm@3995 175
jwilhelm@3995 176 bool is_offset_set() const {
jwilhelm@3995 177 return field()->is_offset_set();
jwilhelm@3995 178 }
jwilhelm@3995 179
jwilhelm@3995 180 bool is_contended() const {
jwilhelm@3995 181 return field()->is_contended();
jwilhelm@3995 182 }
jwilhelm@3995 183
jwilhelm@3995 184 int contended_group() const {
jwilhelm@3995 185 return field()->contended_group();
jwilhelm@3995 186 }
jwilhelm@3995 187
drchase@5297 188 // bridge to a heavier API:
drchase@5297 189 fieldDescriptor& field_descriptor() const {
drchase@5297 190 fieldDescriptor& field = const_cast<fieldDescriptor&>(_fd_buf);
drchase@5297 191 field.reinitialize(field_holder(), _index);
drchase@5297 192 return field;
drchase@5297 193 }
never@2702 194 };
never@2702 195
never@2702 196 // Iterate over only the internal fields
never@2702 197 class JavaFieldStream : public FieldStreamBase {
never@2702 198 public:
never@2702 199 JavaFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
never@2702 200
never@2702 201 int name_index() const {
never@2702 202 assert(!field()->is_internal(), "regular only");
never@2702 203 return field()->name_index();
never@2702 204 }
never@2702 205 void set_name_index(int index) {
never@2702 206 assert(!field()->is_internal(), "regular only");
never@2702 207 field()->set_name_index(index);
never@2702 208 }
never@2702 209 int signature_index() const {
never@2702 210 assert(!field()->is_internal(), "regular only");
never@2702 211 return field()->signature_index();
never@2702 212 }
never@2702 213 void set_signature_index(int index) {
never@2702 214 assert(!field()->is_internal(), "regular only");
never@2702 215 field()->set_signature_index(index);
never@2702 216 }
never@2702 217 int generic_signature_index() const {
never@2702 218 assert(!field()->is_internal(), "regular only");
jiangli@3368 219 if (access_flags().field_has_generic_signature()) {
jiangli@3368 220 assert(_generic_signature_slot < _fields->length(), "out of bounds");
coleenp@3602 221 return _fields->at(_generic_signature_slot);
jiangli@3368 222 } else {
jiangli@3368 223 return 0;
jiangli@3368 224 }
never@2702 225 }
never@2702 226 void set_generic_signature_index(int index) {
never@2702 227 assert(!field()->is_internal(), "regular only");
jiangli@3368 228 if (access_flags().field_has_generic_signature()) {
jiangli@3368 229 assert(_generic_signature_slot < _fields->length(), "out of bounds");
coleenp@3602 230 _fields->at_put(_generic_signature_slot, index);
jiangli@3368 231 }
never@2702 232 }
never@2702 233 int initval_index() const {
never@2702 234 assert(!field()->is_internal(), "regular only");
never@2702 235 return field()->initval_index();
never@2702 236 }
never@2702 237 void set_initval_index(int index) {
never@2702 238 assert(!field()->is_internal(), "regular only");
never@2702 239 return field()->set_initval_index(index);
never@2702 240 }
never@2702 241 };
never@2702 242
never@2702 243
never@2702 244 // Iterate over only the internal fields
never@2702 245 class InternalFieldStream : public FieldStreamBase {
never@2702 246 public:
coleenp@3602 247 InternalFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
jiangli@3368 248 InternalFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
never@2702 249 };
never@2702 250
never@2702 251
never@2702 252 class AllFieldStream : public FieldStreamBase {
never@2702 253 public:
coleenp@3602 254 AllFieldStream(Array<u2>* fields, constantPoolHandle constants): FieldStreamBase(fields, constants) {}
coleenp@3602 255 AllFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 256 AllFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 257 };
never@2702 258
never@2702 259 #endif // SHARE_VM_OOPS_FIELDSTREAMS_HPP