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