1 /*
   2  * Copyright (c) 1997, 2014, 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 #ifndef SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
  26 #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
  27 
  28 #include "utilities/templateIdioms.hpp"
  29 #include "oops/instanceMirrorKlass.hpp"
  30 #include "oops/instanceKlass.inline.hpp"
  31 
  32 inline void InstanceMirrorKlass::init_offset_of_static_fields() {
  33   // Cache the offset of the static fields in the Class instance
  34   assert(_offset_of_static_fields == 0, "once");
  35   _offset_of_static_fields = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->size_helper() << LogHeapWordSize;
  36 }
  37 
  38 // Make sure metadata only gets dispatched for ExtendedOopClosure using SFINAE
  39 template <class OopClosureType>
  40 inline typename enable_if<is_kind_of<ExtendedOopClosure, OopClosureType>::value, void>::type
  41 InstanceMirrorKlass::do_metadata_if_applicable(oop obj, OopClosureType *cl) {
  42   if (OopClosureDispatcher::do_metadata<OopClosureType>(cl)) {
  43     OopClosureDispatcher::do_klass<OopClosureType>(cl, obj->klass());
  44   }
  45 }
  46 
  47 // Some dispatch functions for auto dispatching
  48 template<class OopType, class OopClosureType>
  49 inline void InstanceMirrorKlass::oop_iterate_and_dispatch_helper(oop obj, OopClosureType *closure) {
  50   OopType *current = (OopType*)start_of_static_fields(obj);
  51   OopType* const end = current + java_lang_Class::static_oop_field_count(obj);
  52   while (current < end) {
  53     assert_is_in_closed_subset(current);
  54     OopClosureDispatcher::do_oop<OopClosureType, OopType>(closure, current);
  55     current++;
  56   }
  57 }
  58 
  59 
  60 // Auto specailization
  61 template<class OopClosureType>
  62 inline int InstanceMirrorKlass::oop_iterate_and_dispatch(oop obj, OopClosureType *cl) {
  63   SpecializationStats::record_iterate_call_nv(SpecializationStats::irk);
  64   InstanceKlass::oop_iterate_and_dispatch<OopClosureType>(obj, cl);
  65 
  66   do_metadata_if_applicable(obj, cl);
  67 
  68   if (UseCompressedOops) {
  69     oop_iterate_and_dispatch_helper<narrowOop, OopClosureType>(obj, cl);
  70     return oop_size(obj);
  71   } else {
  72     oop_iterate_and_dispatch_helper<oop, OopClosureType>(obj, cl);
  73     return oop_size(obj);
  74   }
  75 }
  76 
  77 #endif // SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP 
  78