1 /*
   2  * Copyright (c) 1999, 2006, 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 "incls/_precompiled.incl"
  26 #include "incls/_reflectionUtils.cpp.incl"
  27 
  28 KlassStream::KlassStream(instanceKlassHandle klass, bool local_only, bool classes_only) {
  29   _klass = klass;
  30   if (classes_only) {
  31     _interfaces = Universe::the_empty_system_obj_array();
  32   } else {
  33     _interfaces = klass->transitive_interfaces();
  34   }
  35   _interface_index = _interfaces->length();
  36   _local_only = local_only;
  37   _classes_only = classes_only;
  38 }
  39 
  40 bool KlassStream::eos() {
  41   if (index() >= 0) return false;
  42   if (_local_only) return true;
  43   if (!_klass->is_interface() && _klass->super() != NULL) {
  44     // go up superclass chain (not for interfaces)
  45     _klass = _klass->super();
  46   } else {
  47     if (_interface_index > 0) {
  48       _klass = klassOop(_interfaces->obj_at(--_interface_index));
  49     } else {
  50       return true;
  51     }
  52   }
  53   _index = length();
  54   next();
  55   return eos();
  56 }
  57 
  58 
  59 GrowableArray<FilteredField*> *FilteredFieldsMap::_filtered_fields =
  60   new (ResourceObj::C_HEAP) GrowableArray<FilteredField*>(3,true);
  61 
  62 
  63 void FilteredFieldsMap::initialize() {
  64   int offset;
  65   offset = java_lang_Throwable::get_backtrace_offset();
  66   _filtered_fields->append(new FilteredField(SystemDictionary::Throwable_klass(), offset));
  67   // The latest version of vm may be used with old jdk.
  68   if (JDK_Version::is_gte_jdk16x_version()) {
  69     // The following class fields do not exist in
  70     // previous version of jdk.
  71     offset = sun_reflect_ConstantPool::cp_oop_offset();
  72     _filtered_fields->append(new FilteredField(SystemDictionary::reflect_ConstantPool_klass(), offset));
  73     offset = sun_reflect_UnsafeStaticFieldAccessorImpl::base_offset();
  74     _filtered_fields->append(new FilteredField(SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass(), offset));
  75   }
  76 }
  77 
  78 int FilteredFieldStream::field_count() {
  79   int numflds = 0;
  80   for (;!eos(); next()) {
  81     numflds++;
  82   }
  83   return numflds;
  84 }