annotate src/share/vm/oops/fieldStreams.hpp @ 2702:e6b1331a51d2

7086585: make Java field injection more flexible Reviewed-by: jrose, twisti, kvn, coleenp
author never
date Sat, 10 Sep 2011 17:29:02 -0700
parents
children 71afdabfd05b
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;
never@2702 45
never@2702 46 FieldInfo* field() const { return FieldInfo::from_field_array(_fields(), _index); }
never@2702 47
never@2702 48 FieldStreamBase(typeArrayHandle fields, constantPoolHandle constants, int start, int limit) {
never@2702 49 _fields = fields;
never@2702 50 _constants = constants;
never@2702 51 _index = start;
never@2702 52 _limit = limit;
never@2702 53 }
never@2702 54
never@2702 55 FieldStreamBase(typeArrayHandle fields, constantPoolHandle constants) {
never@2702 56 _fields = fields;
never@2702 57 _constants = constants;
never@2702 58 _index = 0;
never@2702 59 _limit = fields->length() / FieldInfo::field_slots;
never@2702 60 }
never@2702 61
never@2702 62 public:
never@2702 63 FieldStreamBase(instanceKlass* klass) {
never@2702 64 _fields = klass->fields();
never@2702 65 _constants = klass->constants();
never@2702 66 _index = 0;
never@2702 67 _limit = klass->java_fields_count();
never@2702 68 }
never@2702 69 FieldStreamBase(instanceKlassHandle klass) {
never@2702 70 _fields = klass->fields();
never@2702 71 _constants = klass->constants();
never@2702 72 _index = 0;
never@2702 73 _limit = klass->java_fields_count();
never@2702 74 }
never@2702 75
never@2702 76 // accessors
never@2702 77 int index() const { return _index; }
never@2702 78
never@2702 79 void next() { _index += 1; }
never@2702 80 bool done() const { return _index >= _limit; }
never@2702 81
never@2702 82 // Accessors for current field
never@2702 83 AccessFlags access_flags() const {
never@2702 84 AccessFlags flags;
never@2702 85 flags.set_flags(field()->access_flags());
never@2702 86 return flags;
never@2702 87 }
never@2702 88
never@2702 89 void set_access_flags(u2 flags) const {
never@2702 90 field()->set_access_flags(flags);
never@2702 91 }
never@2702 92
never@2702 93 void set_access_flags(AccessFlags flags) const {
never@2702 94 set_access_flags(flags.as_short());
never@2702 95 }
never@2702 96
never@2702 97 Symbol* name() const {
never@2702 98 return field()->name(_constants);
never@2702 99 }
never@2702 100
never@2702 101 Symbol* signature() const {
never@2702 102 return field()->signature(_constants);
never@2702 103 }
never@2702 104
never@2702 105 Symbol* generic_signature() const {
never@2702 106 return field()->generic_signature(_constants);
never@2702 107 }
never@2702 108
never@2702 109 int offset() const {
never@2702 110 return field()->offset();
never@2702 111 }
never@2702 112
never@2702 113 void set_offset(int offset) {
never@2702 114 field()->set_offset(offset);
never@2702 115 }
never@2702 116 };
never@2702 117
never@2702 118 // Iterate over only the internal fields
never@2702 119 class JavaFieldStream : public FieldStreamBase {
never@2702 120 public:
never@2702 121 JavaFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
never@2702 122 JavaFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
never@2702 123
never@2702 124 int name_index() const {
never@2702 125 assert(!field()->is_internal(), "regular only");
never@2702 126 return field()->name_index();
never@2702 127 }
never@2702 128 void set_name_index(int index) {
never@2702 129 assert(!field()->is_internal(), "regular only");
never@2702 130 field()->set_name_index(index);
never@2702 131 }
never@2702 132 int signature_index() const {
never@2702 133 assert(!field()->is_internal(), "regular only");
never@2702 134 return field()->signature_index();
never@2702 135 }
never@2702 136 void set_signature_index(int index) {
never@2702 137 assert(!field()->is_internal(), "regular only");
never@2702 138 field()->set_signature_index(index);
never@2702 139 }
never@2702 140 int generic_signature_index() const {
never@2702 141 assert(!field()->is_internal(), "regular only");
never@2702 142 return field()->generic_signature_index();
never@2702 143 }
never@2702 144 void set_generic_signature_index(int index) {
never@2702 145 assert(!field()->is_internal(), "regular only");
never@2702 146 field()->set_generic_signature_index(index);
never@2702 147 }
never@2702 148 int initval_index() const {
never@2702 149 assert(!field()->is_internal(), "regular only");
never@2702 150 return field()->initval_index();
never@2702 151 }
never@2702 152 void set_initval_index(int index) {
never@2702 153 assert(!field()->is_internal(), "regular only");
never@2702 154 return field()->set_initval_index(index);
never@2702 155 }
never@2702 156 };
never@2702 157
never@2702 158
never@2702 159 // Iterate over only the internal fields
never@2702 160 class InternalFieldStream : public FieldStreamBase {
never@2702 161 public:
never@2702 162 InternalFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), k->all_fields_count()) {}
never@2702 163 InternalFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), k->all_fields_count()) {}
never@2702 164 };
never@2702 165
never@2702 166
never@2702 167 class AllFieldStream : public FieldStreamBase {
never@2702 168 public:
never@2702 169 AllFieldStream(typeArrayHandle fields, constantPoolHandle constants): FieldStreamBase(fields, constants) {}
never@2702 170 AllFieldStream(instanceKlass* k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 171 AllFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants()) {}
never@2702 172 };
never@2702 173
never@2702 174 #endif // SHARE_VM_OOPS_FIELDSTREAMS_HPP