src/share/vm/oops/fieldInfo.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/oops/fieldInfo.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,257 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_OOPS_FIELDINFO_HPP
    1.29 +#define SHARE_VM_OOPS_FIELDINFO_HPP
    1.30 +
    1.31 +#include "oops/constantPool.hpp"
    1.32 +#include "oops/typeArrayOop.hpp"
    1.33 +#include "classfile/vmSymbols.hpp"
    1.34 +
    1.35 +// This class represents the field information contained in the fields
    1.36 +// array of an InstanceKlass.  Currently it's laid on top an array of
    1.37 +// Java shorts but in the future it could simply be used as a real
    1.38 +// array type.  FieldInfo generally shouldn't be used directly.
    1.39 +// Fields should be queried either through InstanceKlass or through
    1.40 +// the various FieldStreams.
    1.41 +class FieldInfo VALUE_OBJ_CLASS_SPEC {
    1.42 +  friend class fieldDescriptor;
    1.43 +  friend class JavaFieldStream;
    1.44 +  friend class ClassFileParser;
    1.45 +
    1.46 + public:
    1.47 +  // fields
    1.48 +  // Field info extracted from the class file and stored
    1.49 +  // as an array of 6 shorts.
    1.50 +
    1.51 +#define FIELDINFO_TAG_SIZE             2
    1.52 +#define FIELDINFO_TAG_BLANK            0
    1.53 +#define FIELDINFO_TAG_OFFSET           1
    1.54 +#define FIELDINFO_TAG_TYPE_PLAIN       2
    1.55 +#define FIELDINFO_TAG_TYPE_CONTENDED   3
    1.56 +#define FIELDINFO_TAG_MASK             3
    1.57 +
    1.58 +  // Packed field has the tag, and can be either of:
    1.59 +  //    hi bits <--------------------------- lo bits
    1.60 +  //   |---------high---------|---------low---------|
    1.61 +  //    ..........................................00  - blank
    1.62 +  //    [------------------offset----------------]01  - real field offset
    1.63 +  //    ......................[-------type-------]10  - plain field with type
    1.64 +  //    [--contention_group--][-------type-------]11  - contended field with type and contention group
    1.65 +  enum FieldOffset {
    1.66 +    access_flags_offset      = 0,
    1.67 +    name_index_offset        = 1,
    1.68 +    signature_index_offset   = 2,
    1.69 +    initval_index_offset     = 3,
    1.70 +    low_packed_offset        = 4,
    1.71 +    high_packed_offset       = 5,
    1.72 +    field_slots              = 6
    1.73 +  };
    1.74 +
    1.75 + private:
    1.76 +  u2 _shorts[field_slots];
    1.77 +
    1.78 +  void set_name_index(u2 val)                    { _shorts[name_index_offset] = val;         }
    1.79 +  void set_signature_index(u2 val)               { _shorts[signature_index_offset] = val;    }
    1.80 +  void set_initval_index(u2 val)                 { _shorts[initval_index_offset] = val;      }
    1.81 +
    1.82 +  u2 name_index() const                          { return _shorts[name_index_offset];        }
    1.83 +  u2 signature_index() const                     { return _shorts[signature_index_offset];   }
    1.84 +  u2 initval_index() const                       { return _shorts[initval_index_offset];     }
    1.85 +
    1.86 + public:
    1.87 +  static FieldInfo* from_field_array(Array<u2>* fields, int index) {
    1.88 +    return ((FieldInfo*)fields->adr_at(index * field_slots));
    1.89 +  }
    1.90 +  static FieldInfo* from_field_array(u2* fields, int index) {
    1.91 +    return ((FieldInfo*)(fields + index * field_slots));
    1.92 +  }
    1.93 +
    1.94 +  void initialize(u2 access_flags,
    1.95 +                  u2 name_index,
    1.96 +                  u2 signature_index,
    1.97 +                  u2 initval_index) {
    1.98 +    _shorts[access_flags_offset] = access_flags;
    1.99 +    _shorts[name_index_offset] = name_index;
   1.100 +    _shorts[signature_index_offset] = signature_index;
   1.101 +    _shorts[initval_index_offset] = initval_index;
   1.102 +    _shorts[low_packed_offset] = 0;
   1.103 +    _shorts[high_packed_offset] = 0;
   1.104 +  }
   1.105 +
   1.106 +  u2 access_flags() const                        { return _shorts[access_flags_offset];            }
   1.107 +  u4 offset() const {
   1.108 +    u2 lo = _shorts[low_packed_offset];
   1.109 +    switch(lo & FIELDINFO_TAG_MASK) {
   1.110 +      case FIELDINFO_TAG_OFFSET:
   1.111 +        return build_int_from_shorts(_shorts[low_packed_offset], _shorts[high_packed_offset]) >> FIELDINFO_TAG_SIZE;
   1.112 +#ifndef PRODUCT
   1.113 +      case FIELDINFO_TAG_TYPE_PLAIN:
   1.114 +        fatal("Asking offset for the plain type field");
   1.115 +      case FIELDINFO_TAG_TYPE_CONTENDED:
   1.116 +        fatal("Asking offset for the contended type field");
   1.117 +      case FIELDINFO_TAG_BLANK:
   1.118 +        fatal("Asking offset for the blank field");
   1.119 +#endif
   1.120 +    }
   1.121 +    ShouldNotReachHere();
   1.122 +    return 0;
   1.123 +  }
   1.124 +
   1.125 +  bool is_contended() const {
   1.126 +    u2 lo = _shorts[low_packed_offset];
   1.127 +    switch(lo & FIELDINFO_TAG_MASK) {
   1.128 +      case FIELDINFO_TAG_TYPE_PLAIN:
   1.129 +        return false;
   1.130 +      case FIELDINFO_TAG_TYPE_CONTENDED:
   1.131 +        return true;
   1.132 +#ifndef PRODUCT
   1.133 +      case FIELDINFO_TAG_OFFSET:
   1.134 +        fatal("Asking contended flag for the field with offset");
   1.135 +      case FIELDINFO_TAG_BLANK:
   1.136 +        fatal("Asking contended flag for the blank field");
   1.137 +#endif
   1.138 +    }
   1.139 +    ShouldNotReachHere();
   1.140 +    return false;
   1.141 +  }
   1.142 +
   1.143 +  u2 contended_group() const {
   1.144 +    u2 lo = _shorts[low_packed_offset];
   1.145 +    switch(lo & FIELDINFO_TAG_MASK) {
   1.146 +      case FIELDINFO_TAG_TYPE_PLAIN:
   1.147 +        return 0;
   1.148 +      case FIELDINFO_TAG_TYPE_CONTENDED:
   1.149 +        return _shorts[high_packed_offset];
   1.150 +#ifndef PRODUCT
   1.151 +      case FIELDINFO_TAG_OFFSET:
   1.152 +        fatal("Asking the contended group for the field with offset");
   1.153 +      case FIELDINFO_TAG_BLANK:
   1.154 +        fatal("Asking the contended group for the blank field");
   1.155 +#endif
   1.156 +    }
   1.157 +    ShouldNotReachHere();
   1.158 +    return 0;
   1.159 + }
   1.160 +
   1.161 +  u2 allocation_type() const {
   1.162 +    u2 lo = _shorts[low_packed_offset];
   1.163 +    switch(lo & FIELDINFO_TAG_MASK) {
   1.164 +      case FIELDINFO_TAG_TYPE_PLAIN:
   1.165 +      case FIELDINFO_TAG_TYPE_CONTENDED:
   1.166 +        return (lo >> FIELDINFO_TAG_SIZE);
   1.167 +#ifndef PRODUCT
   1.168 +      case FIELDINFO_TAG_OFFSET:
   1.169 +        fatal("Asking the field type for field with offset");
   1.170 +      case FIELDINFO_TAG_BLANK:
   1.171 +        fatal("Asking the field type for the blank field");
   1.172 +#endif
   1.173 +    }
   1.174 +    ShouldNotReachHere();
   1.175 +    return 0;
   1.176 +  }
   1.177 +
   1.178 +  bool is_offset_set() const {
   1.179 +    return (_shorts[low_packed_offset] & FIELDINFO_TAG_MASK) == FIELDINFO_TAG_OFFSET;
   1.180 +  }
   1.181 +
   1.182 +  Symbol* name(constantPoolHandle cp) const {
   1.183 +    int index = name_index();
   1.184 +    if (is_internal()) {
   1.185 +      return lookup_symbol(index);
   1.186 +    }
   1.187 +    return cp->symbol_at(index);
   1.188 +  }
   1.189 +
   1.190 +  Symbol* signature(constantPoolHandle cp) const {
   1.191 +    int index = signature_index();
   1.192 +    if (is_internal()) {
   1.193 +      return lookup_symbol(index);
   1.194 +    }
   1.195 +    return cp->symbol_at(index);
   1.196 +  }
   1.197 +
   1.198 +  void set_access_flags(u2 val)                  { _shorts[access_flags_offset] = val;             }
   1.199 +  void set_offset(u4 val)                        {
   1.200 +    val = val << FIELDINFO_TAG_SIZE; // make room for tag
   1.201 +    _shorts[low_packed_offset] = extract_low_short_from_int(val) | FIELDINFO_TAG_OFFSET;
   1.202 +    _shorts[high_packed_offset] = extract_high_short_from_int(val);
   1.203 +  }
   1.204 +
   1.205 +  void set_allocation_type(int type) {
   1.206 +    u2 lo = _shorts[low_packed_offset];
   1.207 +    switch(lo & FIELDINFO_TAG_MASK) {
   1.208 +      case FIELDINFO_TAG_BLANK:
   1.209 +        _shorts[low_packed_offset] = ((type << FIELDINFO_TAG_SIZE)) & 0xFFFF;
   1.210 +        _shorts[low_packed_offset] &= ~FIELDINFO_TAG_MASK;
   1.211 +        _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_PLAIN;
   1.212 +        return;
   1.213 +#ifndef PRODUCT
   1.214 +      case FIELDINFO_TAG_TYPE_PLAIN:
   1.215 +      case FIELDINFO_TAG_TYPE_CONTENDED:
   1.216 +      case FIELDINFO_TAG_OFFSET:
   1.217 +        fatal("Setting the field type with overwriting");
   1.218 +#endif
   1.219 +    }
   1.220 +    ShouldNotReachHere();
   1.221 +  }
   1.222 +
   1.223 +  void set_contended_group(u2 val) {
   1.224 +    u2 lo = _shorts[low_packed_offset];
   1.225 +    switch(lo & FIELDINFO_TAG_MASK) {
   1.226 +      case FIELDINFO_TAG_TYPE_PLAIN:
   1.227 +        _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_CONTENDED;
   1.228 +        _shorts[high_packed_offset] = val;
   1.229 +        return;
   1.230 +#ifndef PRODUCT
   1.231 +      case FIELDINFO_TAG_TYPE_CONTENDED:
   1.232 +        fatal("Overwriting contended group");
   1.233 +      case FIELDINFO_TAG_BLANK:
   1.234 +        fatal("Setting contended group for the blank field");
   1.235 +      case FIELDINFO_TAG_OFFSET:
   1.236 +        fatal("Setting contended group for field with offset");
   1.237 +#endif
   1.238 +    }
   1.239 +    ShouldNotReachHere();
   1.240 +  }
   1.241 +
   1.242 +  bool is_internal() const {
   1.243 +    return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;
   1.244 +  }
   1.245 +
   1.246 +  bool is_stable() const {
   1.247 +    return (access_flags() & JVM_ACC_FIELD_STABLE) != 0;
   1.248 +  }
   1.249 +  void set_stable(bool z) {
   1.250 +    if (z) _shorts[access_flags_offset] |=  JVM_ACC_FIELD_STABLE;
   1.251 +    else   _shorts[access_flags_offset] &= ~JVM_ACC_FIELD_STABLE;
   1.252 +  }
   1.253 +
   1.254 +  Symbol* lookup_symbol(int symbol_index) const {
   1.255 +    assert(is_internal(), "only internal fields");
   1.256 +    return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
   1.257 +  }
   1.258 +};
   1.259 +
   1.260 +#endif // SHARE_VM_OOPS_FIELDINFO_HPP

mercurial