annotate src/share/vm/oops/fieldStreams.hpp @ 3368:71afdabfd05b

7168280: Eliminate the generic signature index slot from field array for field without generic signature. Summary: Only allocate the generic signature index slot in the field array for field with generic signature attribute. Reviewed-by: coleenp, dlong
author jiangli
date Mon, 21 May 2012 14:10:35 -0400
parents e6b1331a51d2
children da91efe96a93
rev   line source
never@2702 1 /*
never@2702 2 * Copyright (c) 2011, 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"
never@2702 30
never@2702 31 // The is the base class for iteration over the fields array
never@2702 32 // describing the declared fields in the class. Several subclasses
never@2702 33 // are provided depending on the kind of iteration required. The
never@2702 34 // JavaFieldStream is for iterating over regular Java fields and it
never@2702 35 // generally the preferred iterator. InternalFieldStream only
never@2702 36 // iterates over fields that have been injected by the JVM.
never@2702 37 // AllFieldStream exposes all fields and should only be used in rare
never@2702 38 // cases.
never@2702 39 class FieldStreamBase : public StackObj {
never@2702 40 protected:
never@2702 41 typeArrayHandle _fields;
never@2702 42 constantPoolHandle _constants;
never@2702 43 int _index;
never@2702 44 int _limit;
jiangli@3368 45 int _generic_signature_slot;
never@2702 46
never@2702 47 FieldInfo* field() const { return FieldInfo::from_field_array(_fields(), _index); }
never@2702 48
jiangli@3368 49 int init_generic_signature_start_slot() {
jiangli@3368 50 int length = _fields->length();
jiangli@3368 51 int num_fields = 0;
jiangli@3368 52 int skipped_generic_signature_slots = 0;
jiangli@3368 53 FieldInfo* fi;
jiangli@3368 54 AccessFlags flags;
jiangli@3368 55 /* Scan from 0 to the current _index. Count the number of generic
jiangli@3368 56 signature slots for field[0] to field[_index - 1]. */
jiangli@3368 57 for (int i = 0; i < _index; i++) {
jiangli@3368 58 fi = FieldInfo::from_field_array(_fields(), i);
jiangli@3368 59 flags.set_flags(fi->access_flags());
jiangli@3368 60 if (flags.field_has_generic_signature()) {
jiangli@3368 61 length --;
jiangli@3368 62 skipped_generic_signature_slots ++;
jiangli@3368 63 }
jiangli@3368 64 }
jiangli@3368 65 /* Scan from the current _index. */
jiangli@3368 66 for (int i = _index; i*FieldInfo::field_slots < length; i++) {
jiangli@3368 67 fi = FieldInfo::from_field_array(_fields(), i);
jiangli@3368 68 flags.set_flags(fi->access_flags());
jiangli@3368 69 if (flags.field_has_generic_signature()) {
jiangli@3368 70 length --;
jiangli@3368 71 }
jiangli@3368 72 num_fields ++;
jiangli@3368 73 }
jiangli@3368 74 _generic_signature_slot = length + skipped_generic_signature_slots;
jiangli@3368 75 assert(_generic_signature_slot <= _fields->length(), "");
jiangli@3368 76 return num_fields;
jiangli@3368 77 }
jiangli@3368 78
never@2702 79 FieldStreamBase(typeArrayHandle fields, constantPoolHandle constants, int start, int limit) {
never@2702 80 _fields = fields;
never@2702 81 _constants = constants;
never@2702 82 _index = start;
jiangli@3368 83 int num_fields = init_generic_signature_start_slot();
jiangli@3368 84 if (limit < start) {
jiangli@3368 85 _limit = num_fields;
jiangli@3368 86 } else {
jiangli@3368 87 _limit = limit;
jiangli@3368 88 }
never@2702 89 }
never@2702 90
never@2702 91 FieldStreamBase(typeArrayHandle fields, constantPoolHandle constants) {
never@2702 92 _fields = fields;
never@2702 93 _constants = constants;
never@2702 94 _index = 0;
jiangli@3368 95 _limit = init_generic_signature_start_slot();
never@2702 96 }
never@2702 97
never@2702 98 public:
never@2702 99 FieldStreamBase(instanceKlass* klass) {
never@2702 100 _fields = klass->fields();
never@2702 101 _constants = klass->constants();
never@2702 102 _index = 0;
never@2702 103 _limit = klass->java_fields_count();
jiangli@3368 104 init_generic_signature_start_slot();
never@2702 105 }
never@2702 106 FieldStreamBase(instanceKlassHandle klass) {
never@2702 107 _fields = klass->fields();
never@2702 108 _constants = klass->constants();
never@2702 109 _index = 0;
never@2702 110 _limit = klass->java_fields_count();
jiangli@3368 111 init_generic_signature_start_slot();
never@2702 112 }
never@2702 113
never@2702 114 // accessors
never@2702 115 int index() const { return _index; }
never@2702 116
jiangli@3368 117 void next() {
jiangli@3368 118 if (access_flags().field_has_generic_signature()) {
jiangli@3368 119 _generic_signature_slot ++;
jiangli@3368 120 assert(_generic_signature_slot <= _fields->length(), "");
jiangli@3368 121 }
jiangli@3368 122 _index += 1;
jiangli@3368 123 }
never@2702 124 bool done() const { return _index >= _limit; }
never@2702 125
never@2702 126 // Accessors for current field
never@2702 127 AccessFlags access_flags() const {
never@2702 128 AccessFlags flags;
never@2702 129 flags.set_flags(field()->access_flags());
never@2702 130 return flags;
never@2702 131 }
never@2702 132
never@2702 133 void set_access_flags(u2 flags) const {
never@2702 134 field()->set_access_flags(flags);
never@2702 135 }
never@2702 136
never@2702 137 void set_access_flags(AccessFlags flags) const {
never@2702 138 set_access_flags(flags.as_short());
never@2702 139 }
never@2702 140
never@2702 141 Symbol* name() const {
never@2702 142 return field()->name(_constants);
never@2702 143 }
never@2702 144
never@2702 145 Symbol* signature() const {
never@2702 146 return field()->signature(_constants);
never@2702 147 }
never@2702 148
never@2702 149 Symbol* generic_signature() const {
jiangli@3368 150 if (access_flags().field_has_generic_signature()) {
jiangli@3368 151 assert(_generic_signature_slot < _fields->length(), "out of bounds");
jiangli@3368 152 int index = _fields->short_at(_generic_signature_slot);
jiangli@3368 153 return _constants->symbol_at(index);
jiangli@3368 154 } else {
jiangli@3368 155 return NULL;
jiangli@3368 156 }
never@2702 157 }
never@2702 158
never@2702 159 int offset() const {
never@2702 160 return field()->offset();
never@2702 161 }
never@2702 162
never@2702 163 void set_offset(int offset) {
never@2702 164 field()->set_offset(offset);
never@2702 165 }
never@2702 166 };
never@2702 167
never@2702 168 // Iterate over only the internal fields
never@2702 169 class JavaFieldStream : public FieldStreamBase {
never@2702 170 public:
never@2702 171 JavaFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
never@2702 172 JavaFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
never@2702 173
never@2702 174 int name_index() const {
never@2702 175 assert(!field()->is_internal(), "regular only");
never@2702 176 return field()->name_index();
never@2702 177 }
never@2702 178 void set_name_index(int index) {
never@2702 179 assert(!field()->is_internal(), "regular only");
never@2702 180 field()->set_name_index(index);
never@2702 181 }
never@2702 182 int signature_index() const {
never@2702 183 assert(!field()->is_internal(), "regular only");
never@2702 184 return field()->signature_index();
never@2702 185 }
never@2702 186 void set_signature_index(int index) {
never@2702 187 assert(!field()->is_internal(), "regular only");
never@2702 188 field()->set_signature_index(index);
never@2702 189 }
never@2702 190 int generic_signature_index() const {
never@2702 191 assert(!field()->is_internal(), "regular only");
jiangli@3368 192 if (access_flags().field_has_generic_signature()) {
jiangli@3368 193 assert(_generic_signature_slot < _fields->length(), "out of bounds");
jiangli@3368 194 return _fields->short_at(_generic_signature_slot);
jiangli@3368 195 } else {
jiangli@3368 196 return 0;
jiangli@3368 197 }
never@2702 198 }
never@2702 199 void set_generic_signature_index(int index) {
never@2702 200 assert(!field()->is_internal(), "regular only");
jiangli@3368 201 if (access_flags().field_has_generic_signature()) {
jiangli@3368 202 assert(_generic_signature_slot < _fields->length(), "out of bounds");
jiangli@3368 203 _fields->short_at_put(_generic_signature_slot, index);
jiangli@3368 204 }
never@2702 205 }
never@2702 206 int initval_index() const {
never@2702 207 assert(!field()->is_internal(), "regular only");
never@2702 208 return field()->initval_index();
never@2702 209 }
never@2702 210 void set_initval_index(int index) {
never@2702 211 assert(!field()->is_internal(), "regular only");
never@2702 212 return field()->set_initval_index(index);
never@2702 213 }
never@2702 214 };
never@2702 215
never@2702 216
never@2702 217 // Iterate over only the internal fields
never@2702 218 class InternalFieldStream : public FieldStreamBase {
never@2702 219 public:
jiangli@3368 220 InternalFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
jiangli@3368 221 InternalFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
never@2702 222 };
never@2702 223
never@2702 224
never@2702 225 class AllFieldStream : public FieldStreamBase {
never@2702 226 public:
never@2702 227 AllFieldStream(typeArrayHandle fields, constantPoolHandle constants): FieldStreamBase(fields, constants) {}
never@2702 228 AllFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 229 AllFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 230 };
never@2702 231
never@2702 232 #endif // SHARE_VM_OOPS_FIELDSTREAMS_HPP