annotate src/share/vm/oops/fieldStreams.hpp @ 3602:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 71afdabfd05b
children 4a916f2ce331
rev   line source
never@2702 1 /*
coleenp@3602 2 * Copyright (c) 2011, 2012, 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:
coleenp@3602 41 Array<u2>* _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
coleenp@3602 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++) {
coleenp@3602 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++) {
coleenp@3602 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
coleenp@3602 79 FieldStreamBase(Array<u2>* 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
coleenp@3602 91 FieldStreamBase(Array<u2>* 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:
coleenp@3602 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");
coleenp@3602 152 int index = _fields->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(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
never@2702 172
never@2702 173 int name_index() const {
never@2702 174 assert(!field()->is_internal(), "regular only");
never@2702 175 return field()->name_index();
never@2702 176 }
never@2702 177 void set_name_index(int index) {
never@2702 178 assert(!field()->is_internal(), "regular only");
never@2702 179 field()->set_name_index(index);
never@2702 180 }
never@2702 181 int signature_index() const {
never@2702 182 assert(!field()->is_internal(), "regular only");
never@2702 183 return field()->signature_index();
never@2702 184 }
never@2702 185 void set_signature_index(int index) {
never@2702 186 assert(!field()->is_internal(), "regular only");
never@2702 187 field()->set_signature_index(index);
never@2702 188 }
never@2702 189 int generic_signature_index() const {
never@2702 190 assert(!field()->is_internal(), "regular only");
jiangli@3368 191 if (access_flags().field_has_generic_signature()) {
jiangli@3368 192 assert(_generic_signature_slot < _fields->length(), "out of bounds");
coleenp@3602 193 return _fields->at(_generic_signature_slot);
jiangli@3368 194 } else {
jiangli@3368 195 return 0;
jiangli@3368 196 }
never@2702 197 }
never@2702 198 void set_generic_signature_index(int index) {
never@2702 199 assert(!field()->is_internal(), "regular only");
jiangli@3368 200 if (access_flags().field_has_generic_signature()) {
jiangli@3368 201 assert(_generic_signature_slot < _fields->length(), "out of bounds");
coleenp@3602 202 _fields->at_put(_generic_signature_slot, index);
jiangli@3368 203 }
never@2702 204 }
never@2702 205 int initval_index() const {
never@2702 206 assert(!field()->is_internal(), "regular only");
never@2702 207 return field()->initval_index();
never@2702 208 }
never@2702 209 void set_initval_index(int index) {
never@2702 210 assert(!field()->is_internal(), "regular only");
never@2702 211 return field()->set_initval_index(index);
never@2702 212 }
never@2702 213 };
never@2702 214
never@2702 215
never@2702 216 // Iterate over only the internal fields
never@2702 217 class InternalFieldStream : public FieldStreamBase {
never@2702 218 public:
coleenp@3602 219 InternalFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
jiangli@3368 220 InternalFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
never@2702 221 };
never@2702 222
never@2702 223
never@2702 224 class AllFieldStream : public FieldStreamBase {
never@2702 225 public:
coleenp@3602 226 AllFieldStream(Array<u2>* fields, constantPoolHandle constants): FieldStreamBase(fields, constants) {}
coleenp@3602 227 AllFieldStream(InstanceKlass* k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 228 AllFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 229 };
never@2702 230
never@2702 231 #endif // SHARE_VM_OOPS_FIELDSTREAMS_HPP