|
1 /* |
|
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
|
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 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 #include "precompiled.hpp" |
|
26 #include "classfile/javaClasses.hpp" |
|
27 #include "memory/universe.inline.hpp" |
|
28 #include "runtime/reflectionUtils.hpp" |
|
29 |
|
30 KlassStream::KlassStream(instanceKlassHandle klass, bool local_only, |
|
31 bool classes_only, bool walk_defaults) { |
|
32 _klass = _base_klass = klass; |
|
33 _base_class_search_defaults = false; |
|
34 _defaults_checked = false; |
|
35 if (classes_only) { |
|
36 _interfaces = Universe::the_empty_klass_array(); |
|
37 } else { |
|
38 _interfaces = klass->transitive_interfaces(); |
|
39 } |
|
40 _interface_index = _interfaces->length(); |
|
41 _local_only = local_only; |
|
42 _classes_only = classes_only; |
|
43 _walk_defaults = walk_defaults; |
|
44 } |
|
45 |
|
46 bool KlassStream::eos() { |
|
47 if (index() >= 0) return false; |
|
48 if (_local_only) return true; |
|
49 if (!_klass->is_interface() && _klass->super() != NULL) { |
|
50 // go up superclass chain (not for interfaces) |
|
51 _klass = _klass->super(); |
|
52 // Next for method walks, walk default methods |
|
53 } else if (_walk_defaults && (_defaults_checked == false) && (_base_klass->default_methods() != NULL)) { |
|
54 _base_class_search_defaults = true; |
|
55 _klass = _base_klass; |
|
56 _defaults_checked = true; |
|
57 } else { |
|
58 // Next walk transitive interfaces |
|
59 if (_interface_index > 0) { |
|
60 _klass = _interfaces->at(--_interface_index); |
|
61 } else { |
|
62 return true; |
|
63 } |
|
64 } |
|
65 _index = length(); |
|
66 next(); |
|
67 return eos(); |
|
68 } |
|
69 |
|
70 |
|
71 GrowableArray<FilteredField*> *FilteredFieldsMap::_filtered_fields = |
|
72 new (ResourceObj::C_HEAP, mtInternal) GrowableArray<FilteredField*>(3,true); |
|
73 |
|
74 |
|
75 void FilteredFieldsMap::initialize() { |
|
76 int offset; |
|
77 offset = java_lang_Throwable::get_backtrace_offset(); |
|
78 _filtered_fields->append(new FilteredField(SystemDictionary::Throwable_klass(), offset)); |
|
79 // The latest version of vm may be used with old jdk. |
|
80 if (JDK_Version::is_gte_jdk16x_version()) { |
|
81 // The following class fields do not exist in |
|
82 // previous version of jdk. |
|
83 offset = sun_reflect_ConstantPool::oop_offset(); |
|
84 _filtered_fields->append(new FilteredField(SystemDictionary::reflect_ConstantPool_klass(), offset)); |
|
85 offset = sun_reflect_UnsafeStaticFieldAccessorImpl::base_offset(); |
|
86 _filtered_fields->append(new FilteredField(SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass(), offset)); |
|
87 } |
|
88 } |
|
89 |
|
90 int FilteredFieldStream::field_count() { |
|
91 int numflds = 0; |
|
92 for (;!eos(); next()) { |
|
93 numflds++; |
|
94 } |
|
95 return numflds; |
|
96 } |