src/share/vm/oops/fieldStreams.hpp

Wed, 02 Jan 2013 20:28:09 -0500

author
coleenp
date
Wed, 02 Jan 2013 20:28:09 -0500
changeset 4395
cc6a617fffd2
parent 4037
da91efe96a93
child 4430
4a916f2ce331
permissions
-rw-r--r--

8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
Summary: Relocate functions with jsr's when rewriting so not repeated after reading shared archive
Reviewed-by: twisti, jrose

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

mercurial