aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/javaClasses.hpp" aoqi@0: #include "memory/universe.inline.hpp" aoqi@0: #include "runtime/reflectionUtils.hpp" aoqi@0: aoqi@0: KlassStream::KlassStream(instanceKlassHandle klass, bool local_only, aoqi@0: bool classes_only, bool walk_defaults) { aoqi@0: _klass = _base_klass = klass; aoqi@0: _base_class_search_defaults = false; aoqi@0: _defaults_checked = false; aoqi@0: if (classes_only) { aoqi@0: _interfaces = Universe::the_empty_klass_array(); aoqi@0: } else { aoqi@0: _interfaces = klass->transitive_interfaces(); aoqi@0: } aoqi@0: _interface_index = _interfaces->length(); aoqi@0: _local_only = local_only; aoqi@0: _classes_only = classes_only; aoqi@0: _walk_defaults = walk_defaults; aoqi@0: } aoqi@0: aoqi@0: bool KlassStream::eos() { aoqi@0: if (index() >= 0) return false; aoqi@0: if (_local_only) return true; aoqi@0: if (!_klass->is_interface() && _klass->super() != NULL) { aoqi@0: // go up superclass chain (not for interfaces) aoqi@0: _klass = _klass->super(); aoqi@0: // Next for method walks, walk default methods aoqi@0: } else if (_walk_defaults && (_defaults_checked == false) && (_base_klass->default_methods() != NULL)) { aoqi@0: _base_class_search_defaults = true; aoqi@0: _klass = _base_klass; aoqi@0: _defaults_checked = true; aoqi@0: } else { aoqi@0: // Next walk transitive interfaces aoqi@0: if (_interface_index > 0) { aoqi@0: _klass = _interfaces->at(--_interface_index); aoqi@0: } else { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: _index = length(); aoqi@0: next(); aoqi@0: return eos(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: GrowableArray *FilteredFieldsMap::_filtered_fields = aoqi@0: new (ResourceObj::C_HEAP, mtInternal) GrowableArray(3,true); aoqi@0: aoqi@0: aoqi@0: void FilteredFieldsMap::initialize() { aoqi@0: int offset; aoqi@0: offset = java_lang_Throwable::get_backtrace_offset(); aoqi@0: _filtered_fields->append(new FilteredField(SystemDictionary::Throwable_klass(), offset)); aoqi@0: // The latest version of vm may be used with old jdk. aoqi@0: if (JDK_Version::is_gte_jdk16x_version()) { aoqi@0: // The following class fields do not exist in aoqi@0: // previous version of jdk. aoqi@0: offset = sun_reflect_ConstantPool::oop_offset(); aoqi@0: _filtered_fields->append(new FilteredField(SystemDictionary::reflect_ConstantPool_klass(), offset)); aoqi@0: offset = sun_reflect_UnsafeStaticFieldAccessorImpl::base_offset(); aoqi@0: _filtered_fields->append(new FilteredField(SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass(), offset)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: int FilteredFieldStream::field_count() { aoqi@0: int numflds = 0; aoqi@0: for (;!eos(); next()) { aoqi@0: numflds++; aoqi@0: } aoqi@0: return numflds; aoqi@0: }