src/hotspot/share/runtime/reflectionUtils.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 51329 9c68699bebe5
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51329
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51329
diff changeset
    25
#ifndef SHARE_RUNTIME_REFLECTIONUTILS_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51329
diff changeset
    26
#define SHARE_RUNTIME_REFLECTIONUTILS_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/instanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/objArrayOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oopsHierarchy.hpp"
49361
1956d0ec092a 8199319: Remove handles.inline.hpp include from reflectionUtils.hpp
stefank
parents: 47216
diff changeset
    32
#include "runtime/handles.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/reflection.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/accessFlags.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "utilities/globalDefinitions.hpp"
49361
1956d0ec092a 8199319: Remove handles.inline.hpp include from reflectionUtils.hpp
stefank
parents: 47216
diff changeset
    36
#include "utilities/growableArray.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// A KlassStream is an abstract stream for streaming over self, superclasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// and (super)interfaces. Streaming is done in reverse order (subclasses first,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// interfaces last).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    42
//    for (KlassStream st(k, false, false, false); !st.eos(); st.next()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
    43
//      Klass* k = st.klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//      ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 49361
diff changeset
    47
class KlassStream {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
 protected:
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
    49
  InstanceKlass*      _klass;           // current klass/interface iterated over
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
    50
  InstanceKlass*      _base_klass;      // initial klass/interface to iterate over
51329
9c68699bebe5 8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents: 49364
diff changeset
    51
  Array<InstanceKlass*>*_interfaces;    // transitive interfaces for initial class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  int                 _interface_index; // current interface being processed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  bool                _local_only;      // process initial class/interface only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  bool                _classes_only;    // process classes only (no interfaces)
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    55
  bool                _walk_defaults;   // process default methods
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    56
  bool                _base_class_search_defaults; // time to process default methods
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    57
  bool                _defaults_checked; // already checked for default methods
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int                 _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    60
  virtual int length() = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // constructor
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
    64
  KlassStream(InstanceKlass* klass, bool local_only, bool classes_only, bool walk_defaults);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // testing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  bool eos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // iterating
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  virtual void next() = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // accessors
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
    73
  InstanceKlass* klass() const      { return _klass; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  int index() const                 { return _index; }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    75
  bool base_class_search_defaults() const { return _base_class_search_defaults; }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    76
  void base_class_search_defaults(bool b) { _base_class_search_defaults = b; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// A MethodStream streams over all methods in a class, superclasses and (super)interfaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// Streaming is done in reverse order (subclasses first, methods in reverse order)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// Usage:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
//    for (MethodStream st(k, false, false); !st.eos(); st.next()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
    85
//      Method* m = st.method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
//      ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
//    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
class MethodStream : public KlassStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
 private:
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    91
  int length()                    { return methods()->length(); }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    92
  Array<Method*>* methods() {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    93
    if (base_class_search_defaults()) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    94
      base_class_search_defaults(false);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    95
      return _klass->default_methods();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    96
    } else {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    97
      return _klass->methods();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    98
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
    99
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
 public:
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
   101
  MethodStream(InstanceKlass* klass, bool local_only, bool classes_only)
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   102
    : KlassStream(klass, local_only, classes_only, true) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    _index = length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  void next() { _index--; }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   108
  Method* method() { return methods()->at(index()); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// A FieldStream streams over all fields in a class, superclasses and (super)interfaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// Streaming is done in reverse order (subclasses first, fields in reverse order)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// Usage:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
//    for (FieldStream st(k, false, false); !st.eos(); st.next()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   117
//      Symbol* field_name = st.name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
//      ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
//    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
class FieldStream : public KlassStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
 private:
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   124
  int length() { return _klass->java_fields_count(); }
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   125
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17376
diff changeset
   126
  fieldDescriptor _fd_buf;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17376
diff changeset
   127
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
 public:
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
   129
  FieldStream(InstanceKlass* klass, bool local_only, bool classes_only)
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   130
    : KlassStream(klass, local_only, classes_only, false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _index = length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   135
  void next() { _index -= 1; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // Accessors for current field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  AccessFlags access_flags() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    AccessFlags flags;
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   140
    flags.set_flags(_klass->field_access_flags(_index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    return flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   143
  Symbol* name() const {
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   144
    return _klass->field_name(_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   146
  Symbol* signature() const {
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   147
    return _klass->field_signature(_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // missing: initval()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  int offset() const {
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   151
    return _klass->field_offset( index() );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17376
diff changeset
   153
  // bridge to a heavier API:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17376
diff changeset
   154
  fieldDescriptor& field_descriptor() const {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17376
diff changeset
   155
    fieldDescriptor& field = const_cast<fieldDescriptor&>(_fd_buf);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
   156
    field.reinitialize(_klass, _index);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17376
diff changeset
   157
    return field;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17376
diff changeset
   158
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17031
diff changeset
   161
class FilteredField : public CHeapObj<mtInternal>  {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
   163
  Klass* _klass;
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17031
diff changeset
   164
  int    _field_offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
 public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
   167
  FilteredField(Klass* klass, int field_offset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    _klass = klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    _field_offset = field_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
   171
  Klass* klass() { return _klass; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  int  field_offset() { return _field_offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
class FilteredFieldsMap : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  static GrowableArray<FilteredField *> *_filtered_fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  static void initialize();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
   180
  static bool is_filtered_field(Klass* klass, int field_offset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    for (int i=0; i < _filtered_fields->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      if (klass == _filtered_fields->at(i)->klass() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        field_offset == _filtered_fields->at(i)->field_offset()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
   189
  static int  filtered_fields_count(Klass* klass, bool local_only) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    int nflds = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    for (int i=0; i < _filtered_fields->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      if (local_only && klass == _filtered_fields->at(i)->klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        nflds++;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10546
diff changeset
   194
      } else if (klass->is_subtype_of(_filtered_fields->at(i)->klass())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        nflds++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    return nflds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// A FilteredFieldStream streams over all fields in a class, superclasses and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
// (super)interfaces. Streaming is done in reverse order (subclasses first,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// fields in reverse order)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// Usage:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
//    for (FilteredFieldStream st(k, false, false); !st.eos(); st.next()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   210
//      Symbol* field_name = st.name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
//      ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
//    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
class FilteredFieldStream : public FieldStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  int  _filtered_fields_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  bool has_filtered_field() { return (_filtered_fields_count > 0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
 public:
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
   220
  FilteredFieldStream(InstanceKlass* klass, bool local_only, bool classes_only)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    : FieldStream(klass, local_only, classes_only) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
   222
    _filtered_fields_count = FilteredFieldsMap::filtered_fields_count(klass, local_only);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  int field_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  void next() {
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   226
    _index -= 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    if (has_filtered_field()) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 20391
diff changeset
   228
      while (_index >=0 && FilteredFieldsMap::is_filtered_field((Klass*)_klass, offset())) {
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
   229
        _index -= 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   234
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51329
diff changeset
   235
#endif // SHARE_RUNTIME_REFLECTIONUTILS_HPP