author | goetz |
Fri, 05 Jul 2013 22:17:47 +0200 | |
changeset 22819 | f88b9c394e42 |
parent 17376 | 4ee999c3c007 |
child 20017 | 81eba62e9048 |
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 |
// |
|
41 |
// for (KlassStream 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
|
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 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
49 |
Array<Klass*>* _interfaces; // transitive interfaces for initial class |
1 | 50 |
int _interface_index; // current interface being processed |
51 |
bool _local_only; // process initial class/interface only |
|
52 |
bool _classes_only; // process classes only (no interfaces) |
|
53 |
int _index; |
|
54 |
||
55 |
virtual int length() const = 0; |
|
56 |
||
57 |
public: |
|
58 |
// constructor |
|
59 |
KlassStream(instanceKlassHandle klass, bool local_only, bool classes_only); |
|
60 |
||
61 |
// testing |
|
62 |
bool eos(); |
|
63 |
||
64 |
// iterating |
|
65 |
virtual void next() = 0; |
|
66 |
||
67 |
// accessors |
|
68 |
instanceKlassHandle klass() const { return _klass; } |
|
69 |
int index() const { return _index; } |
|
70 |
}; |
|
71 |
||
72 |
||
73 |
// A MethodStream streams over all methods in a class, superclasses and (super)interfaces. |
|
74 |
// Streaming is done in reverse order (subclasses first, methods in reverse order) |
|
75 |
// Usage: |
|
76 |
// |
|
77 |
// 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
|
78 |
// Method* m = st.method(); |
1 | 79 |
// ... |
80 |
// } |
|
81 |
||
82 |
class MethodStream : public KlassStream { |
|
83 |
private: |
|
84 |
int length() const { return methods()->length(); } |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
85 |
Array<Method*>* methods() const { return _klass->methods(); } |
1 | 86 |
public: |
87 |
MethodStream(instanceKlassHandle klass, bool local_only, bool classes_only) |
|
88 |
: KlassStream(klass, local_only, classes_only) { |
|
89 |
_index = length(); |
|
90 |
next(); |
|
91 |
} |
|
92 |
||
93 |
void next() { _index--; } |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
94 |
Method* method() const { return methods()->at(index()); } |
1 | 95 |
}; |
96 |
||
97 |
||
98 |
// A FieldStream streams over all fields in a class, superclasses and (super)interfaces. |
|
99 |
// Streaming is done in reverse order (subclasses first, fields in reverse order) |
|
100 |
// Usage: |
|
101 |
// |
|
102 |
// 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
|
103 |
// Symbol* field_name = st.name(); |
1 | 104 |
// ... |
105 |
// } |
|
106 |
||
107 |
||
108 |
class FieldStream : public KlassStream { |
|
109 |
private: |
|
10546 | 110 |
int length() const { return _klass->java_fields_count(); } |
111 |
||
1 | 112 |
public: |
113 |
FieldStream(instanceKlassHandle klass, bool local_only, bool classes_only) |
|
114 |
: KlassStream(klass, local_only, classes_only) { |
|
115 |
_index = length(); |
|
116 |
next(); |
|
117 |
} |
|
118 |
||
10546 | 119 |
void next() { _index -= 1; } |
1 | 120 |
|
121 |
// Accessors for current field |
|
122 |
AccessFlags access_flags() const { |
|
123 |
AccessFlags flags; |
|
10546 | 124 |
flags.set_flags(_klass->field_access_flags(_index)); |
1 | 125 |
return flags; |
126 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
127 |
Symbol* name() const { |
10546 | 128 |
return _klass->field_name(_index); |
1 | 129 |
} |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
130 |
Symbol* signature() const { |
10546 | 131 |
return _klass->field_signature(_index); |
1 | 132 |
} |
133 |
// missing: initval() |
|
134 |
int offset() const { |
|
10546 | 135 |
return _klass->field_offset( index() ); |
1 | 136 |
} |
137 |
}; |
|
138 |
||
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17031
diff
changeset
|
139 |
class FilteredField : public CHeapObj<mtInternal> { |
1 | 140 |
private: |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
141 |
Klass* _klass; |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17031
diff
changeset
|
142 |
int _field_offset; |
1 | 143 |
|
144 |
public: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
145 |
FilteredField(Klass* klass, int field_offset) { |
1 | 146 |
_klass = klass; |
147 |
_field_offset = field_offset; |
|
148 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
149 |
Klass* klass() { return _klass; } |
1 | 150 |
int field_offset() { return _field_offset; } |
151 |
}; |
|
152 |
||
153 |
class FilteredFieldsMap : AllStatic { |
|
154 |
private: |
|
155 |
static GrowableArray<FilteredField *> *_filtered_fields; |
|
156 |
public: |
|
157 |
static void initialize(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
158 |
static bool is_filtered_field(Klass* klass, int field_offset) { |
1 | 159 |
for (int i=0; i < _filtered_fields->length(); i++) { |
160 |
if (klass == _filtered_fields->at(i)->klass() && |
|
161 |
field_offset == _filtered_fields->at(i)->field_offset()) { |
|
162 |
return true; |
|
163 |
} |
|
164 |
} |
|
165 |
return false; |
|
166 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
167 |
static int filtered_fields_count(Klass* klass, bool local_only) { |
1 | 168 |
int nflds = 0; |
169 |
for (int i=0; i < _filtered_fields->length(); i++) { |
|
170 |
if (local_only && klass == _filtered_fields->at(i)->klass()) { |
|
171 |
nflds++; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
172 |
} else if (klass->is_subtype_of(_filtered_fields->at(i)->klass())) { |
1 | 173 |
nflds++; |
174 |
} |
|
175 |
} |
|
176 |
return nflds; |
|
177 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
178 |
// Enhance Class Redefinition Support |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
179 |
static void classes_do(KlassClosure* f) { |
1 | 180 |
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
|
181 |
f->do_klass(_filtered_fields->at(i)->klass()); |
1 | 182 |
} |
183 |
} |
|
184 |
}; |
|
185 |
||
186 |
||
187 |
// A FilteredFieldStream streams over all fields in a class, superclasses and |
|
188 |
// (super)interfaces. Streaming is done in reverse order (subclasses first, |
|
189 |
// fields in reverse order) |
|
190 |
// |
|
191 |
// Usage: |
|
192 |
// |
|
193 |
// 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
|
194 |
// Symbol* field_name = st.name(); |
1 | 195 |
// ... |
196 |
// } |
|
197 |
||
198 |
class FilteredFieldStream : public FieldStream { |
|
199 |
private: |
|
200 |
int _filtered_fields_count; |
|
201 |
bool has_filtered_field() { return (_filtered_fields_count > 0); } |
|
202 |
||
203 |
public: |
|
204 |
FilteredFieldStream(instanceKlassHandle klass, bool local_only, bool classes_only) |
|
205 |
: FieldStream(klass, local_only, classes_only) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
206 |
_filtered_fields_count = FilteredFieldsMap::filtered_fields_count((Klass*)klass(), local_only); |
1 | 207 |
} |
208 |
int field_count(); |
|
209 |
void next() { |
|
10546 | 210 |
_index -= 1; |
1 | 211 |
if (has_filtered_field()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10546
diff
changeset
|
212 |
while (_index >=0 && FilteredFieldsMap::is_filtered_field((Klass*)_klass(), offset())) { |
10546 | 213 |
_index -= 1; |
1 | 214 |
} |
215 |
} |
|
216 |
} |
|
217 |
}; |
|
7397 | 218 |
|
219 |
#endif // SHARE_VM_RUNTIME_REFLECTIONUTILS_HPP |