/*
* 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 "precompiled.hpp"
#include "classfile/javaClasses.hpp"
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "code/codeCache.hpp"
#include "code/icBuffer.hpp"
#include "gc_implementation/shared/gcHeapSummary.hpp"
#include "gc_implementation/shared/gcTimer.hpp"
#include "gc_implementation/shared/gcTrace.hpp"
#include "gc_implementation/shared/gcTraceTime.hpp"
#include "gc_interface/collectedHeap.inline.hpp"
#include "memory/genCollectedHeap.hpp"
#include "memory/genMarkSweep.hpp"
#include "memory/genOopClosures.inline.hpp"
#include "memory/generation.inline.hpp"
#include "memory/modRefBarrierSet.hpp"
#include "memory/referencePolicy.hpp"
#include "oops/instanceRefKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "runtime/fprofiler.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/synchronizer.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/events.hpp"
#ifdef TARGET_OS_FAMILY_linux
# include "thread_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "thread_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "thread_windows.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "thread_bsd.inline.hpp"
#endif
bool clear_all_softrefs) {
#ifdef ASSERT
}
#endif
// hook up weak ref data so it can be used during Mark-Sweep
_ref_processor = rp;
// When collecting the permanent generation methodOops may be moving,
// so we either have to flush all bcp data or convert it into bci.
CodeCache::gc_prologue();
Threads::gc_prologue();
// Increment the invocation count for the permanent generation, since it is
// implicitly collected whenever we do a full mark sweep collection.
// Capture heap size before collection for printing.
// Some of the card table updates below assume that the perm gen is
// also being collected.
"All generations are being collected, ergo perm gen too.");
// Capture used regions for each generation that will be
// subject to collection, so that card table adjustments can
// be made intelligently (see clear / invalidate further below).
// Don't add any more derived pointers during phase3
if (ValidateMarkSweep) {
}
)
if (ValidateMarkSweep) {
"should be the same size");
}
)
// Set saved marks for allocation profiler (and other things? -- dld)
// (Should this be in general part?)
gch->save_marks();
// If compaction completely evacuated all generations younger than this
// one, then we can clear the card table. Otherwise, we must invalidate
// it (consider all cards dirty). In the future, we might consider doing
// compaction within generations only, and doing card-table sliding.
bool all_empty = true;
}
// Clear/invalidate below make use of the "prev_used_regions" saved earlier.
if (all_empty) {
// We've evacuated all generations below us.
} else {
// Invalidate the cards corresponding to the currently used
// region and clear those corresponding to the evacuated region
// of all generations just collected (i.e. level and younger).
true /* younger */,
true /* perm */);
}
Threads::gc_epilogue();
CodeCache::gc_epilogue();
if (PrintGC && !PrintGCDetails) {
}
// refs processing: clean slate
// Update heap occupancy information which is used as
// input to soft ref clearing policy at the next gc.
// Update time of last gc for all generations we collected
// (which curently is all the generations in the heap).
// We need to use a monotonically non-deccreasing time in ms
// or we will see time-warp warnings and os::javaTimeMillis()
// does not guarantee monotonicity.
}
// Scratch request on behalf of oldest generation; will do no
// allocation.
// $$$ To cut a corner, we'll only use the first scratch block, and then
// revert to malloc.
} else {
_preserved_count_max = 0;
}
_preserved_count = 0;
#ifdef VALIDATE_MARK_SWEEP
if (ValidateMarkSweep) {
}
if (RecordMarkSweepCompaction) {
if (_cur_gc_live_oops == NULL) {
} else {
}
}
#endif
}
if (!UseG1GC) {
gch->release_scratch();
}
_preserved_mark_stack.clear(true);
_preserved_oop_stack.clear(true);
_objarray_stack.clear(true);
_revisit_klass_stack.clear(true);
_revisit_mdo_stack.clear(true);
#ifdef VALIDATE_MARK_SWEEP
if (ValidateMarkSweep) {
delete _root_refs_stack;
delete _other_refs_stack;
delete _adjusted_pointers;
delete _live_oops;
delete _live_oops_size;
delete _live_oops_moved_to;
_live_oops_index = 0;
}
#endif
}
bool clear_all_softrefs) {
// Recursively traverse all live objects and mark them
trace(" 1");
// Because follow_root_closure is created statically, cannot
// use OopsInGenClosure constructor which takes a generation,
// as the Universe has not been created when the static constructors
// are run.
false, // Younger gens are not roots.
true, // activate StrongRootsScope
true, // Collecting permanent generation.
true, // walk code active on stacks
// Process reference objects found during marking
{
}
// Follow system dictionary roots and unload classes
// Follow code cache roots
follow_stack(); // Flush marking stack
// Update subklass/sibling/implementor links of live klasses
// Visit memoized MDO's and clear any unmarked weak refs
// Visit interned string tables and delete unmarked oops
// Clean up unreferenced symbols in symbol table.
SymbolTable::unlink();
}
// Now all live objects are marked, compute the new object addresses.
// It is imperative that we traverse perm_gen LAST. If dead space is
// allowed a range of dead object may get overwritten by a dead int
// array. If perm_gen is not traversed last a klassOop may get
// overwritten. This is fine since it is dead, but if the class has dead
// instances we have to skip them, and in order to find their size we
// need the klassOop!
//
// It is not required that we traverse spaces in the same order in
// phase2, phase3 and phase4, but the ValidateMarkSweep live oops
// tracking expects us to do so. See comment under phase4.
trace("2");
}
public:
gen->adjust_pointers();
}
};
// Adjust the pointers to reflect the new locations
trace("3");
// Needs to be done before the system dictionary is adjusted.
// Because the two closures below are created statically, cannot
// use OopsInGenClosure constructor which takes a generation,
// as the Universe has not been created when the static constructors
// are run.
false, // Younger gens are not roots.
true, // activate StrongRootsScope
true, // Collecting permanent generation.
false, // do not walk code
// Now adjust pointers in remaining weak roots. (All of which should
// have been cleared if they pointed to non-surviving objects.)
/*do_marking=*/ false);
adjust_marks();
pg->adjust_pointers();
}
public:
}
};
// All pointers are now adjusted, move objects accordingly
// It is imperative that we traverse perm_gen first in phase4. All
// classes must be allocated earlier than their instances, and traversing
// perm_gen first makes sure that all klassOops have moved to their new
// location before any instance does a dispatch through it's klass!
// The ValidateMarkSweep live oops tracking expects us to traverse spaces
// in the same order in phase2, phase3 and phase4. We don't quite do that
// here (perm_gen first rather than last), so we tell the validate code
// to use a higher index (saved from phase2) when verifying perm_gen.
trace("4");
}