0N/A/*
1879N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP
1879N/A#define SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP
1879N/A
1879N/A#include "runtime/atomic.hpp"
1879N/A#ifndef SERIALGC
1879N/A#include "gc_implementation/g1/g1_specialized_oop_closures.hpp"
1879N/A#endif
1879N/A
0N/A// The following OopClosure types get specialized versions of
0N/A// "oop_oop_iterate" that invoke the closures' do_oop methods
0N/A// non-virtually, using a mechanism defined in this file. Extend these
0N/A// macros in the obvious way to add specializations for new closures.
0N/A
0N/A// Forward declarations.
0N/Aclass OopClosure;
0N/Aclass OopsInGenClosure;
0N/A// DefNew
0N/Aclass ScanClosure;
0N/Aclass FastScanClosure;
0N/Aclass FilteringClosure;
0N/A// ParNew
0N/Aclass ParScanWithBarrierClosure;
0N/Aclass ParScanWithoutBarrierClosure;
0N/A// CMS
0N/Aclass MarkRefsIntoAndScanClosure;
0N/Aclass Par_MarkRefsIntoAndScanClosure;
0N/Aclass PushAndMarkClosure;
0N/Aclass Par_PushAndMarkClosure;
0N/Aclass PushOrMarkClosure;
0N/Aclass Par_PushOrMarkClosure;
0N/Aclass CMSKeepAliveClosure;
0N/Aclass CMSInnerParMarkAndPushClosure;
0N/A
0N/A// This macro applies an argument macro to all OopClosures for which we
0N/A// want specialized bodies of "oop_oop_iterate". The arguments to "f" are:
0N/A// "f(closureType, non_virtual)"
0N/A// where "closureType" is the name of the particular subclass of OopClosure,
0N/A// and "non_virtual" will be the string "_nv" if the closure type should
0N/A// have its "do_oop" method invoked non-virtually, or else the
0N/A// string "_v". ("OopClosure" itself will be the only class in the latter
0N/A// category.)
0N/A
0N/A// This is split into several because of a Visual C++ 6.0 compiler bug
0N/A// where very long macros cause the compiler to crash
0N/A
342N/A// Some other heap might define further specialized closures.
342N/A#ifndef FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES
342N/A#define FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) \
342N/A /* None */
342N/A#endif
342N/A
0N/A#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
0N/A f(ScanClosure,_nv) \
0N/A f(FastScanClosure,_nv) \
0N/A f(FilteringClosure,_nv)
0N/A
0N/A#ifndef SERIALGC
0N/A#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) \
0N/A f(ParScanWithBarrierClosure,_nv) \
0N/A f(ParScanWithoutBarrierClosure,_nv)
0N/A#else // SERIALGC
0N/A#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
0N/A#endif // SERIALGC
0N/A
0N/A#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f) \
0N/A SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
0N/A SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
0N/A
0N/A#ifndef SERIALGC
342N/A#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) \
0N/A f(MarkRefsIntoAndScanClosure,_nv) \
0N/A f(Par_MarkRefsIntoAndScanClosure,_nv) \
0N/A f(PushAndMarkClosure,_nv) \
0N/A f(Par_PushAndMarkClosure,_nv) \
0N/A f(PushOrMarkClosure,_nv) \
0N/A f(Par_PushOrMarkClosure,_nv) \
0N/A f(CMSKeepAliveClosure,_nv) \
342N/A f(CMSInnerParMarkAndPushClosure,_nv) \
342N/A FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f)
0N/A#else // SERIALGC
342N/A#define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f)
0N/A#endif // SERIALGC
0N/A
342N/A
0N/A// We separate these out, because sometime the general one has
0N/A// a different definition from the specialized ones, and sometimes it
0N/A// doesn't.
0N/A
0N/A#define ALL_OOP_OOP_ITERATE_CLOSURES_1(f) \
0N/A f(OopClosure,_v) \
0N/A SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f)
0N/A
342N/A#define ALL_OOP_OOP_ITERATE_CLOSURES_2(f) \
342N/A SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f)
0N/A
0N/A#ifndef SERIALGC
0N/A// This macro applies an argument macro to all OopClosures for which we
0N/A// want specialized bodies of a family of methods related to
0N/A// "par_oop_iterate". The arguments to f are the same as above.
0N/A// The "root_class" is the most general class to define; this may be
0N/A// "OopClosure" in some applications and "OopsInGenClosure" in others.
0N/A
0N/A#define SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f) \
0N/A f(MarkRefsIntoAndScanClosure,_nv) \
0N/A f(PushAndMarkClosure,_nv) \
0N/A f(Par_MarkRefsIntoAndScanClosure,_nv) \
0N/A f(Par_PushAndMarkClosure,_nv)
0N/A
0N/A#define ALL_PAR_OOP_ITERATE_CLOSURES(f) \
0N/A f(OopClosure,_v) \
0N/A SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
0N/A#endif // SERIALGC
0N/A
0N/A// This macro applies an argument macro to all OopClosures for which we
0N/A// want specialized bodies of a family of methods related to
0N/A// "oops_since_save_marks_do". The arguments to f are the same as above.
0N/A// The "root_class" is the most general class to define; this may be
0N/A// "OopClosure" in some applications and "OopsInGenClosure" in others.
0N/A
342N/A
342N/A// Some other heap might define further specialized closures.
342N/A#ifndef FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES
342N/A#define FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \
342N/A /* None */
342N/A#endif
342N/A
0N/A#define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \
0N/A f(ScanClosure,_nv) \
0N/A f(FastScanClosure,_nv)
0N/A
0N/A#ifndef SERIALGC
0N/A#define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) \
0N/A f(ParScanWithBarrierClosure,_nv) \
342N/A f(ParScanWithoutBarrierClosure,_nv) \
342N/A FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)
0N/A#else // SERIALGC
0N/A#define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
0N/A#endif // SERIALGC
0N/A
0N/A#define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f) \
0N/A SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \
0N/A SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
0N/A
0N/A#define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \
0N/A SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f)
0N/A
0N/A// We separate these out, because sometime the general one has
0N/A// a different definition from the specialized ones, and sometimes it
0N/A// doesn't.
0N/A// NOTE: One of the valid criticisms of this
0N/A// specialize-oop_oop_iterate-for-specific-closures idiom is that it is
0N/A// easy to have a silent performance bug: if you fail to de-virtualize,
0N/A// things still work, just slower. The "SpecializationStats" mode is
0N/A// intended to at least make such a failure easy to detect.
0N/A// *Not* using the ALL_SINCE_SAVE_MARKS_CLOSURES(f) macro defined
0N/A// below means that *only* closures for which oop_oop_iterate specializations
0N/A// exist above may be applied to "oops_since_save_marks". That is,
0N/A// this form of the performance bug is caught statically. When you add
0N/A// a definition for the general type, this property goes away.
0N/A// Make sure you test with SpecializationStats to find such bugs
0N/A// when introducing a new closure where you don't want virtual dispatch.
0N/A
0N/A#define ALL_SINCE_SAVE_MARKS_CLOSURES(f) \
0N/A f(OopsInGenClosure,_v) \
0N/A SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)
0N/A
0N/A// For keeping stats on effectiveness.
0N/A#define ENABLE_SPECIALIZATION_STATS 0
0N/A
0N/A
0N/Aclass SpecializationStats {
0N/Apublic:
0N/A enum Kind {
0N/A ik, // instanceKlass
0N/A irk, // instanceRefKlass
0N/A oa, // objArrayKlass
0N/A NUM_Kinds
0N/A };
0N/A
0N/A#if ENABLE_SPECIALIZATION_STATS
0N/Aprivate:
342N/A static bool _init;
342N/A static bool _wrapped;
342N/A static jint _numCallsAll;
0N/A
342N/A static jint _numCallsTotal[NUM_Kinds];
342N/A static jint _numCalls_nv[NUM_Kinds];
0N/A
342N/A static jint _numDoOopCallsTotal[NUM_Kinds];
342N/A static jint _numDoOopCalls_nv[NUM_Kinds];
0N/Apublic:
0N/A#endif
0N/A static void clear() PRODUCT_RETURN;
0N/A
0N/A static inline void record_call() PRODUCT_RETURN;
0N/A static inline void record_iterate_call_v(Kind k) PRODUCT_RETURN;
0N/A static inline void record_iterate_call_nv(Kind k) PRODUCT_RETURN;
0N/A static inline void record_do_oop_call_v(Kind k) PRODUCT_RETURN;
0N/A static inline void record_do_oop_call_nv(Kind k) PRODUCT_RETURN;
0N/A
0N/A static void print() PRODUCT_RETURN;
0N/A};
0N/A
0N/A#ifndef PRODUCT
0N/A#if ENABLE_SPECIALIZATION_STATS
0N/A
0N/Ainline void SpecializationStats::record_call() {
342N/A Atomic::inc(&_numCallsAll);
0N/A}
0N/Ainline void SpecializationStats::record_iterate_call_v(Kind k) {
342N/A Atomic::inc(&_numCallsTotal[k]);
0N/A}
0N/Ainline void SpecializationStats::record_iterate_call_nv(Kind k) {
342N/A Atomic::inc(&_numCallsTotal[k]);
342N/A Atomic::inc(&_numCalls_nv[k]);
0N/A}
0N/A
0N/Ainline void SpecializationStats::record_do_oop_call_v(Kind k) {
342N/A Atomic::inc(&_numDoOopCallsTotal[k]);
0N/A}
0N/Ainline void SpecializationStats::record_do_oop_call_nv(Kind k) {
342N/A Atomic::inc(&_numDoOopCallsTotal[k]);
342N/A Atomic::inc(&_numDoOopCalls_nv[k]);
0N/A}
0N/A
0N/A#else // !ENABLE_SPECIALIZATION_STATS
0N/A
0N/Ainline void SpecializationStats::record_call() {}
0N/Ainline void SpecializationStats::record_iterate_call_v(Kind k) {}
0N/Ainline void SpecializationStats::record_iterate_call_nv(Kind k) {}
0N/Ainline void SpecializationStats::record_do_oop_call_v(Kind k) {}
0N/Ainline void SpecializationStats::record_do_oop_call_nv(Kind k) {}
0N/Ainline void SpecializationStats::clear() {}
0N/Ainline void SpecializationStats::print() {}
0N/A
0N/A#endif // ENABLE_SPECIALIZATION_STATS
0N/A#endif // !PRODUCT
1879N/A
1879N/A#endif // SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP