Path: blob/master/src/hotspot/share/oops/instanceRefKlass.hpp
40951 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_OOPS_INSTANCEREFKLASS_HPP25#define SHARE_OOPS_INSTANCEREFKLASS_HPP2627#include "oops/instanceKlass.hpp"28#include "utilities/macros.hpp"2930class ClassFileParser;3132// An InstanceRefKlass is a specialized InstanceKlass for Java33// classes that are subclasses of java/lang/ref/Reference.34//35// These classes are used to implement soft/weak/final/phantom36// references and finalization, and need special treatment by the37// garbage collector.38//39// During GC discovered reference objects are added (chained) to one40// of the four lists below, depending on the type of reference.41// The linked occurs through the next field in class java/lang/ref/Reference.42//43// Afterwards, the discovered references are processed in decreasing44// order of reachability. Reference objects eligible for notification45// are linked to the static pending_list in class java/lang/ref/Reference,46// and the pending list lock object in the same class is notified.474849class InstanceRefKlass: public InstanceKlass {50friend class InstanceKlass;51public:52static const KlassID ID = InstanceRefKlassID;5354private:55InstanceRefKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_reference, ID) {}5657public:58InstanceRefKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }5960// Oop fields (and metadata) iterators61//62// The InstanceRefKlass iterators also support reference processing.636465// Forward iteration66// Iterate over all oop fields and metadata.67template <typename T, class OopClosureType>68inline void oop_oop_iterate(oop obj, OopClosureType* closure);6970// Reverse iteration71// Iterate over all oop fields and metadata.72template <typename T, class OopClosureType>73inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure);7475// Bounded range iteration76// Iterate over all oop fields and metadata.77template <typename T, class OopClosureType>78inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);7980private:8182// Reference processing part of the iterators.8384template <typename T, class OopClosureType, class Contains>85inline void oop_oop_iterate_ref_processing(oop obj, OopClosureType* closure, Contains& contains);8687// Only perform reference processing if the referent object is within mr.88template <typename T, class OopClosureType>89inline void oop_oop_iterate_ref_processing_bounded(oop obj, OopClosureType* closure, MemRegion mr);9091// Reference processing92template <typename T, class OopClosureType>93inline void oop_oop_iterate_ref_processing(oop obj, OopClosureType* closure);9495// Building blocks for specialized handling.96template <typename T, class OopClosureType, class Contains>97static void do_referent(oop obj, OopClosureType* closure, Contains& contains);9899template <typename T, class OopClosureType, class Contains>100static void do_next(oop obj, OopClosureType* closure, Contains& contains);101102template <typename T, class OopClosureType, class Contains>103static void do_discovered(oop obj, OopClosureType* closure, Contains& contains);104105template <typename T, class OopClosureType>106static bool try_discover(oop obj, ReferenceType type, OopClosureType* closure);107108// Do discovery while handling InstanceRefKlasses. Reference discovery109// is only done if the closure provides a ReferenceProcessor.110template <typename T, class OopClosureType, class Contains>111static void oop_oop_iterate_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains);112113// Used for a special case in G1 where the closure needs to be applied114// to the discovered field. Reference discovery is also done if the115// closure provides a ReferenceProcessor.116template <typename T, class OopClosureType, class Contains>117static void oop_oop_iterate_discovered_and_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains);118119// Apply the closure to all fields. No reference discovery is done.120template <typename T, class OopClosureType, class Contains>121static void oop_oop_iterate_fields(oop obj, OopClosureType* closure, Contains& contains);122123// Apply the closure to all fields, except the referent field. No reference discovery is done.124template <typename T, class OopClosureType, class Contains>125static void oop_oop_iterate_fields_except_referent(oop obj, OopClosureType* closure, Contains& contains);126127template <typename T>128static void trace_reference_gc(const char *s, oop obj) NOT_DEBUG_RETURN;129130public:131// Update non-static oop maps so 'referent', 'nextPending' and132// 'discovered' will look like non-oops133static void update_nonstatic_oop_maps(Klass* k);134135public:136// Verification137void oop_verify_on(oop obj, outputStream* st);138};139140#endif // SHARE_OOPS_INSTANCEREFKLASS_HPP141142143