aoqi@0: /* aoqi@0: * Copyright (c) 2001, 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: #ifndef SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP aoqi@0: #define SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP aoqi@0: aoqi@0: #include "runtime/atomic.hpp" aoqi@0: #include "utilities/macros.hpp" aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: #include "gc_implementation/g1/g1_specialized_oop_closures.hpp" aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: // The following OopClosure types get specialized versions of aoqi@0: // "oop_oop_iterate" that invoke the closures' do_oop methods aoqi@0: // non-virtually, using a mechanism defined in this file. Extend these aoqi@0: // macros in the obvious way to add specializations for new closures. aoqi@0: aoqi@0: // Forward declarations. aoqi@0: class OopClosure; aoqi@0: class OopsInGenClosure; aoqi@0: // DefNew aoqi@0: class ScanClosure; aoqi@0: class FastScanClosure; aoqi@0: class FilteringClosure; aoqi@0: // ParNew aoqi@0: class ParScanWithBarrierClosure; aoqi@0: class ParScanWithoutBarrierClosure; aoqi@0: // CMS aoqi@0: class MarkRefsIntoAndScanClosure; aoqi@0: class Par_MarkRefsIntoAndScanClosure; aoqi@0: class PushAndMarkClosure; aoqi@0: class Par_PushAndMarkClosure; aoqi@0: class PushOrMarkClosure; aoqi@0: class Par_PushOrMarkClosure; aoqi@0: class CMSKeepAliveClosure; aoqi@0: class CMSInnerParMarkAndPushClosure; aoqi@0: // Misc aoqi@0: class NoHeaderExtendedOopClosure; aoqi@0: aoqi@0: // This macro applies an argument macro to all OopClosures for which we aoqi@0: // want specialized bodies of "oop_oop_iterate". The arguments to "f" are: aoqi@0: // "f(closureType, non_virtual)" aoqi@0: // where "closureType" is the name of the particular subclass of OopClosure, aoqi@0: // and "non_virtual" will be the string "_nv" if the closure type should aoqi@0: // have its "do_oop" method invoked non-virtually, or else the aoqi@0: // string "_v". ("OopClosure" itself will be the only class in the latter aoqi@0: // category.) aoqi@0: aoqi@0: // This is split into several because of a Visual C++ 6.0 compiler bug aoqi@0: // where very long macros cause the compiler to crash aoqi@0: aoqi@0: // Some other heap might define further specialized closures. aoqi@0: #ifndef FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES aoqi@0: #define FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) \ aoqi@0: /* None */ aoqi@0: #endif aoqi@0: aoqi@0: #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \ aoqi@0: f(ScanClosure,_nv) \ aoqi@0: f(FastScanClosure,_nv) \ aoqi@0: f(FilteringClosure,_nv) aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) \ aoqi@0: f(ParScanWithBarrierClosure,_nv) \ aoqi@0: f(ParScanWithoutBarrierClosure,_nv) aoqi@0: #else // INCLUDE_ALL_GCS aoqi@0: #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f) \ aoqi@0: f(NoHeaderExtendedOopClosure,_nv) \ aoqi@0: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \ aoqi@0: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) \ aoqi@0: f(MarkRefsIntoAndScanClosure,_nv) \ aoqi@0: f(Par_MarkRefsIntoAndScanClosure,_nv) \ aoqi@0: f(PushAndMarkClosure,_nv) \ aoqi@0: f(Par_PushAndMarkClosure,_nv) \ aoqi@0: f(PushOrMarkClosure,_nv) \ aoqi@0: f(Par_PushOrMarkClosure,_nv) \ aoqi@0: f(CMSKeepAliveClosure,_nv) \ aoqi@0: f(CMSInnerParMarkAndPushClosure,_nv) \ aoqi@0: FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) aoqi@0: #else // INCLUDE_ALL_GCS aoqi@0: #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: aoqi@0: // We separate these out, because sometime the general one has aoqi@0: // a different definition from the specialized ones, and sometimes it aoqi@0: // doesn't. aoqi@0: aoqi@0: #define ALL_OOP_OOP_ITERATE_CLOSURES_1(f) \ aoqi@0: f(ExtendedOopClosure,_v) \ aoqi@0: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f) aoqi@0: aoqi@0: #define ALL_OOP_OOP_ITERATE_CLOSURES_2(f) \ aoqi@0: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: // This macro applies an argument macro to all OopClosures for which we aoqi@0: // want specialized bodies of a family of methods related to aoqi@0: // "par_oop_iterate". The arguments to f are the same as above. aoqi@0: // The "root_class" is the most general class to define; this may be aoqi@0: // "OopClosure" in some applications and "OopsInGenClosure" in others. aoqi@0: aoqi@0: #define SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f) \ aoqi@0: f(MarkRefsIntoAndScanClosure,_nv) \ aoqi@0: f(PushAndMarkClosure,_nv) \ aoqi@0: f(Par_MarkRefsIntoAndScanClosure,_nv) \ aoqi@0: f(Par_PushAndMarkClosure,_nv) aoqi@0: aoqi@0: #define ALL_PAR_OOP_ITERATE_CLOSURES(f) \ aoqi@0: f(ExtendedOopClosure,_v) \ aoqi@0: SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f) aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: // This macro applies an argument macro to all OopClosures for which we aoqi@0: // want specialized bodies of a family of methods related to aoqi@0: // "oops_since_save_marks_do". The arguments to f are the same as above. aoqi@0: // The "root_class" is the most general class to define; this may be aoqi@0: // "OopClosure" in some applications and "OopsInGenClosure" in others. aoqi@0: aoqi@0: aoqi@0: // Some other heap might define further specialized closures. aoqi@0: #ifndef FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES aoqi@0: #define FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \ aoqi@0: /* None */ aoqi@0: #endif aoqi@0: aoqi@0: #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \ aoqi@0: f(ScanClosure,_nv) \ aoqi@0: f(FastScanClosure,_nv) aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) \ aoqi@0: f(ParScanWithBarrierClosure,_nv) \ aoqi@0: f(ParScanWithoutBarrierClosure,_nv) \ aoqi@0: FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) aoqi@0: #else // INCLUDE_ALL_GCS aoqi@0: #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f) \ aoqi@0: SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \ aoqi@0: SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) aoqi@0: aoqi@0: #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \ aoqi@0: SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f) aoqi@0: aoqi@0: // We separate these out, because sometime the general one has aoqi@0: // a different definition from the specialized ones, and sometimes it aoqi@0: // doesn't. aoqi@0: // NOTE: One of the valid criticisms of this aoqi@0: // specialize-oop_oop_iterate-for-specific-closures idiom is that it is aoqi@0: // easy to have a silent performance bug: if you fail to de-virtualize, aoqi@0: // things still work, just slower. The "SpecializationStats" mode is aoqi@0: // intended to at least make such a failure easy to detect. aoqi@0: // *Not* using the ALL_SINCE_SAVE_MARKS_CLOSURES(f) macro defined aoqi@0: // below means that *only* closures for which oop_oop_iterate specializations aoqi@0: // exist above may be applied to "oops_since_save_marks". That is, aoqi@0: // this form of the performance bug is caught statically. When you add aoqi@0: // a definition for the general type, this property goes away. aoqi@0: // Make sure you test with SpecializationStats to find such bugs aoqi@0: // when introducing a new closure where you don't want virtual dispatch. aoqi@0: aoqi@0: #define ALL_SINCE_SAVE_MARKS_CLOSURES(f) \ aoqi@0: f(OopsInGenClosure,_v) \ aoqi@0: SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) aoqi@0: aoqi@0: // For keeping stats on effectiveness. aoqi@0: #define ENABLE_SPECIALIZATION_STATS 0 aoqi@0: aoqi@0: aoqi@0: class SpecializationStats { aoqi@0: public: aoqi@0: enum Kind { aoqi@0: ik, // InstanceKlass aoqi@0: irk, // InstanceRefKlass aoqi@0: oa, // ObjArrayKlass aoqi@0: NUM_Kinds aoqi@0: }; aoqi@0: aoqi@0: #if ENABLE_SPECIALIZATION_STATS aoqi@0: private: aoqi@0: static bool _init; aoqi@0: static bool _wrapped; aoqi@0: static jint _numCallsAll; aoqi@0: aoqi@0: static jint _numCallsTotal[NUM_Kinds]; aoqi@0: static jint _numCalls_nv[NUM_Kinds]; aoqi@0: aoqi@0: static jint _numDoOopCallsTotal[NUM_Kinds]; aoqi@0: static jint _numDoOopCalls_nv[NUM_Kinds]; aoqi@0: public: aoqi@0: #endif aoqi@0: static void clear() PRODUCT_RETURN; aoqi@0: aoqi@0: static inline void record_call() PRODUCT_RETURN; aoqi@0: static inline void record_iterate_call_v(Kind k) PRODUCT_RETURN; aoqi@0: static inline void record_iterate_call_nv(Kind k) PRODUCT_RETURN; aoqi@0: static inline void record_do_oop_call_v(Kind k) PRODUCT_RETURN; aoqi@0: static inline void record_do_oop_call_nv(Kind k) PRODUCT_RETURN; aoqi@0: aoqi@0: static void print() PRODUCT_RETURN; aoqi@0: }; aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: #if ENABLE_SPECIALIZATION_STATS aoqi@0: aoqi@0: inline void SpecializationStats::record_call() { aoqi@0: Atomic::inc(&_numCallsAll); aoqi@0: } aoqi@0: inline void SpecializationStats::record_iterate_call_v(Kind k) { aoqi@0: Atomic::inc(&_numCallsTotal[k]); aoqi@0: } aoqi@0: inline void SpecializationStats::record_iterate_call_nv(Kind k) { aoqi@0: Atomic::inc(&_numCallsTotal[k]); aoqi@0: Atomic::inc(&_numCalls_nv[k]); aoqi@0: } aoqi@0: aoqi@0: inline void SpecializationStats::record_do_oop_call_v(Kind k) { aoqi@0: Atomic::inc(&_numDoOopCallsTotal[k]); aoqi@0: } aoqi@0: inline void SpecializationStats::record_do_oop_call_nv(Kind k) { aoqi@0: Atomic::inc(&_numDoOopCallsTotal[k]); aoqi@0: Atomic::inc(&_numDoOopCalls_nv[k]); aoqi@0: } aoqi@0: aoqi@0: #else // !ENABLE_SPECIALIZATION_STATS aoqi@0: aoqi@0: inline void SpecializationStats::record_call() {} aoqi@0: inline void SpecializationStats::record_iterate_call_v(Kind k) {} aoqi@0: inline void SpecializationStats::record_iterate_call_nv(Kind k) {} aoqi@0: inline void SpecializationStats::record_do_oop_call_v(Kind k) {} aoqi@0: inline void SpecializationStats::record_do_oop_call_nv(Kind k) {} aoqi@0: inline void SpecializationStats::clear() {} aoqi@0: inline void SpecializationStats::print() {} aoqi@0: aoqi@0: #endif // ENABLE_SPECIALIZATION_STATS aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: #endif // SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP