/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "memory/referencePolicy.hpp"
#include "memory/referenceProcessorStats.hpp"
#include "memory/referenceType.hpp"
#include "oops/instanceRefKlass.hpp"
class GCTimer;
// ReferenceProcessor class encapsulates the per-"collector" processing
// of java.lang.Reference objects for GC. The interface is useful for supporting
// a generational abstraction, in particular when there are multiple
// generations that are being independently collected -- possibly
// ReferenceProcessor class abstracts away from a generational setting
// by using only a heap interval (called "span" below), thus allowing
// its use in a straightforward manner in a general, non-generational
// setting.
//
// The basic idea is that each ReferenceProcessor object concerns
// itself with ("weak") reference processing in a specific "span"
// of the heap of interest to a specific collector. Currently,
// the span is a convex interval of the heap, but, efficiency
// apart, there seems to be no reason it couldn't be extended
// (with appropriate modifications) to any "non-convex interval".
// forward references
class ReferencePolicy;
class AbstractRefProcTaskExecutor;
// List of discovered references.
class DiscoveredList {
public:
}
}
if (UseCompressedOops) {
// Must compress the head ptr.
} else {
_oop_head = o;
}
}
private:
// Set value depending on UseCompressedOops. This could be a template class
// but then we have to fix all the instantiations and declarations that use this class.
};
// Iterator for the list of discovered references.
class DiscoveredListIterator {
private:
)
)
public:
#ifdef ASSERT
#endif
#ifndef PRODUCT
_processed(0),
_removed(0),
#endif
{ }
// End Of List.
// Get oop to the Reference object.
// Get oop to the referent object.
// Returns true if referent is alive.
inline bool is_referent_alive() const {
}
// Loads data for the current reference.
// The "allow_null_referent" argument tells us to allow for the possibility
// of a NULL referent in the discovered Reference object. This typically
// happens in the case of concurrent collectors that may have done the
// discovery concurrently, or interleaved, with mutator execution.
// Move to the next discovered reference.
inline void next() {
move_to_next();
}
// Remove the current reference from the list
void remove();
// Make the Reference object active again.
void make_active();
// Make the referent alive.
inline void make_referent_alive() {
if (UseCompressedOops) {
} else {
}
}
// Update the discovered field.
inline void update_discovered() {
// First _prev_next ref actually points into DiscoveredList (gross).
if (UseCompressedOops) {
}
} else {
}
}
}
// NULL out referent pointer.
void clear_referent();
// Statistics
)
inline void move_to_next() {
// End of the list.
} else {
}
}
};
private:
protected:
// Compatibility with pre-4965777 JDK's
static bool _pending_list_uses_discovered_field;
// The SoftReference master timestamp clock
// subject to wkref discovery
// other collectors in configuration
// If true, setting "next" field of a discovered refs list requires
// write barrier(s). (Must be true if used in a collector in which
// elements of a discovered list may be moved during discovery: for
// example, a collector like Garbage-First that moves objects during a
// long-term concurrent marking phase that does weak reference
// discovery.)
// reference processing is MT.
// support of work distribution
// For collectors that do not keep GC liveness information
// in the object header, this field holds a closure that
// helps the reference processor determine the reachability
// of an oop. It is currently initialized to NULL for all
// collectors except for CMS and G1.
// Soft ref clearing policies
// . the default policy
// . the "clear all" policy
// . the current policy below is either one of the above
// The discovered ref lists themselves
// The active MT'ness degree of the queues below
// The maximum MT'ness degree of the queues below
// Master array of discovered oops
// Arrays of lists of oops, one per thread (pointers into master array above)
public:
return _current_soft_ref_policy;
}
// Process references with a certain reachability level.
bool clear_referent,
// Work methods used by the method process_discovered_reflist
// Phase1: keep alive all those referents that are otherwise
// dead but which must be kept alive by policy (and their closure).
// Phase2: remove all those references whose referents are
// reachable.
if (discovery_is_atomic()) {
// complete_gc is ignored in this case for this phase
} else {
}
}
// Work methods in support of process_phase2
// Phase3: process the referents by either clearing them
// or keeping them alive (and their closure)
bool clear_referent,
// Enqueue references with a certain reachability level
// "Preclean" all the discovered reference lists
// by removing references with strongly reachable referents.
// The first argument is a predicate on an oop that indicates
// its (strong) reachability and the second is a closure that
// may be used to incrementalize or abort the precleaning process.
// The caller is responsible for taking care of potential
// interference with concurrent operations on these lists
// (or predicates involved) by other threads. Currently
// only used by the CMS collector. should_unload_classes is
// used to aid assertion checking when classes are collected.
bool should_unload_classes,
// Delete entries in the discovered lists that have
// either a null referent or are not active. Such
// Reference objects can result from the clearing
// or enqueueing of Reference objects concurrent
// with their discovery by a (concurrent) collector.
// For a definition of "active" see java.lang.ref.Reference;
// Refs are born active, become inactive when enqueued,
// and never become active again. The state of being
// active is encoded as follows: A Ref is active
// if and only if its "next" field is NULL.
void clean_up_discovered_references();
// Returns the name of the discovered reference list
// occupying the i / _num_q slot.
void enqueue_discovered_reflists(HeapWord* pending_list_addr, AbstractRefProcTaskExecutor* task_executor);
protected:
// Set the 'discovered' field of the given reference to
// the given value - emitting barriers depending upon
// the value of _discovered_list_needs_barrier.
// "Preclean" the given discovered reference list
// by removing references with strongly reachable referents.
// Currently used in support of CMS only.
// round-robin mod _num_q (not: _not_ mode _max_num_q)
_next_id = 0;
}
return id;
}
// Calculate the number of jni handles.
unsigned int count_jni_refs();
// Balances reference queues.
// Update (advance) the soft ref master clock field.
void update_soft_ref_master_clock();
public:
// constructor
_discovering_refs(false),
_discovery_is_atomic(true),
_enqueuing_is_done(false),
_discovery_is_mt(false),
_discovered_list_needs_barrier(false),
_num_q(0),
_max_num_q(0),
_processing_is_mt(false),
_next_id(0)
{ }
// Default parameters give you a vanilla reference processor.
bool atomic_discovery = true,
bool discovered_list_needs_barrier = false);
// RefDiscoveryPolicy values
enum DiscoveryPolicy {
};
static void init_statics();
public:
// get and set "is_alive_non_header" field
return _is_alive_non_header;
}
}
// get and set span
// start and stop weak ref discovery
// whether discovery is atomic wrt other collectors
// whether the JDK in which we are embedded is a pre-4965777 JDK,
// and thus whether or not it uses the discovered field to chain
// the entries in the pending list.
static bool pending_list_uses_discovered_field() {
}
// whether discovery is done by multiple threads same-old-timeously
// Whether we are in a phase when _processing_ is MT.
// whether all enqueuing of weak references is complete
// iterate over oops
// Balance each of the discovered lists.
void balance_all_queues();
// Discover a Reference object, using appropriate discovery criteria
// Process references found during GC (called by the garbage collector)
// Enqueue references at end of GC (called by the garbage collector)
// If a discovery is in process that is being superceded, abandon it: all
// the discovered lists will be empty, and all the objects on them will
// have NULL discovered fields. Must be called only at a safepoint.
void abandon_partial_discovery();
// debugging
// clear the discovered lists (unlinking each entry).
};
// A utility class to disable reference discovery in
// the scope which contains it, for given ReferenceProcessor.
private:
bool _was_discovering_refs;
public:
if (_was_discovering_refs) {
_rp->disable_discovery();
}
}
~NoRefDiscovery() {
if (_was_discovering_refs) {
}
}
};
// A utility class to temporarily mutate the span of the
// given ReferenceProcessor in the scope that contains it.
private:
public:
}
}
};
// A utility class to temporarily change the MT'ness of
// reference discovery for the given ReferenceProcessor
// in the scope that contains it.
private:
bool _saved_mt;
public:
bool mt):
}
}
};
// A utility class to temporarily change the disposition
// of the "is_alive_non_header" closure field of the
// given ReferenceProcessor in the scope that contains it.
private:
public:
}
}
};
// A utility class to temporarily change the disposition
// of the "discovery_is_atomic" field of the
// given ReferenceProcessor in the scope that contains it.
private:
bool _saved_atomic_discovery;
public:
bool atomic):
}
}
};
// A utility class to temporarily change the MT processing
// disposition of the given ReferenceProcessor instance
// in the scope that contains it.
private:
bool _saved_mt;
public:
bool mt):
}
}
};
// This class is an interface used to implement task execution for the
// reference processing.
class AbstractRefProcTaskExecutor {
public:
// Abstract tasks to execute.
class ProcessTask;
class EnqueueTask;
// Executes a task using worker threads.
// Switch to single threaded mode.
virtual void set_single_threaded_mode() { };
};
// Abstract reference processing task to execute.
protected:
bool marks_oops_alive)
{ }
public:
VoidClosure& complete_gc) = 0;
// Returns true if a task marks some oops as alive.
bool marks_oops_alive() const
{ return _marks_oops_alive; }
protected:
const bool _marks_oops_alive;
};
// Abstract reference processing task to execute.
protected:
int n_queues)
{ }
public:
protected:
int _n_queues;
};
#endif // SHARE_VM_MEMORY_REFERENCEPROCESSOR_HPP