hotspot/src/share/vm/oops/fieldInfo.hpp
author coleenp
Fri, 23 Mar 2012 11:16:05 -0400
changeset 12263 d20640f4f8fe
parent 10546 e79347eebbc5
child 12772 d317e5e08194
permissions -rw-r--r--
7150058: Allocate symbols from null boot loader to an arena for NMT Summary: Move symbol allocation to an arena so NMT doesn't have to track them at startup. Reviewed-by: never, kamg, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     1
/*
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     4
 *
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     8
 *
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    13
 * accompanied this code).
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    14
 *
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    18
 *
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    21
 * questions.
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    22
 *
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    23
 */
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    24
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    25
#ifndef SHARE_VM_OOPS_FIELDINFO_HPP
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    26
#define SHARE_VM_OOPS_FIELDINFO_HPP
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    27
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    28
#include "oops/typeArrayOop.hpp"
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    29
#include "classfile/vmSymbols.hpp"
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    30
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    31
// This class represents the field information contained in the fields
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    32
// array of an instanceKlass.  Currently it's laid on top an array of
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    33
// Java shorts but in the future it could simply be used as a real
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    34
// array type.  FieldInfo generally shouldn't be used directly.
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    35
// Fields should be queried either through instanceKlass or through
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    36
// the various FieldStreams.
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    37
class FieldInfo VALUE_OBJ_CLASS_SPEC {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    38
  friend class fieldDescriptor;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    39
  friend class JavaFieldStream;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    40
  friend class ClassFileParser;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    41
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    42
 public:
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    43
  // fields
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    44
  // Field info extracted from the class file and stored
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    45
  // as an array of 7 shorts
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    46
  enum FieldOffset {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    47
    access_flags_offset      = 0,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    48
    name_index_offset        = 1,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    49
    signature_index_offset   = 2,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    50
    initval_index_offset     = 3,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    51
    low_offset               = 4,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    52
    high_offset              = 5,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    53
    generic_signature_offset = 6,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    54
    field_slots              = 7
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    55
  };
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    56
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    57
 private:
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    58
  u2 _shorts[field_slots];
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    59
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    60
  void set_name_index(u2 val)                    { _shorts[name_index_offset] = val;         }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    61
  void set_signature_index(u2 val)               { _shorts[signature_index_offset] = val;    }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    62
  void set_initval_index(u2 val)                 { _shorts[initval_index_offset] = val;      }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    63
  void set_generic_signature_index(u2 val)       { _shorts[generic_signature_offset] = val;  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    64
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    65
  u2 name_index() const                          { return _shorts[name_index_offset];        }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    66
  u2 signature_index() const                     { return _shorts[signature_index_offset];   }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    67
  u2 initval_index() const                       { return _shorts[initval_index_offset];     }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    68
  u2 generic_signature_index() const             { return _shorts[generic_signature_offset]; }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    69
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    70
 public:
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    71
  static FieldInfo* from_field_array(typeArrayOop fields, int index) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    72
    return ((FieldInfo*)fields->short_at_addr(index * field_slots));
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    73
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    74
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    75
  void initialize(u2 access_flags,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    76
                  u2 name_index,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    77
                  u2 signature_index,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    78
                  u2 initval_index,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    79
                  u2 generic_signature_index,
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    80
                  u4 offset) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    81
    _shorts[access_flags_offset] = access_flags;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    82
    _shorts[name_index_offset] = name_index;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    83
    _shorts[signature_index_offset] = signature_index;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    84
    _shorts[initval_index_offset] = initval_index;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    85
    _shorts[generic_signature_offset] = generic_signature_index;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    86
    set_offset(offset);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    87
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    88
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    89
  u2 access_flags() const                        { return _shorts[access_flags_offset];            }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    90
  u4 offset() const                              { return build_int_from_shorts(_shorts[low_offset], _shorts[high_offset]); }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    91
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    92
  Symbol* name(constantPoolHandle cp) const {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    93
    int index = name_index();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    94
    if (is_internal()) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    95
      return lookup_symbol(index);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    96
    }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    97
    return cp->symbol_at(index);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    98
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
    99
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   100
  Symbol* signature(constantPoolHandle cp) const {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   101
    int index = signature_index();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   102
    if (is_internal()) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   103
      return lookup_symbol(index);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   104
    }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   105
    return cp->symbol_at(index);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   106
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   107
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   108
  Symbol* generic_signature(constantPoolHandle cp) const {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   109
    int index = generic_signature_index();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   110
    if (index == 0) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   111
      return NULL;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   112
    }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   113
    return cp->symbol_at(index);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   114
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   115
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   116
  void set_access_flags(u2 val)                  { _shorts[access_flags_offset] = val;             }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   117
  void set_offset(u4 val)                        {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   118
    _shorts[low_offset] = extract_low_short_from_int(val);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   119
    _shorts[high_offset] = extract_high_short_from_int(val);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   120
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   121
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   122
  bool is_internal() const {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   123
    return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   124
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   125
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   126
  Symbol* lookup_symbol(int symbol_index) const {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   127
    assert(is_internal(), "only internal fields");
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   128
    return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   129
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   130
};
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   131
e79347eebbc5 7086585: make Java field injection more flexible
never
parents:
diff changeset
   132
#endif // SHARE_VM_OOPS_FIELDINFO_HPP