< prev index next >
src/hotspot/share/memory/metaspaceShared.cpp
Print this page
*** 34,43 ****
--- 34,44 ----
#include "classfile/symbolTable.hpp"
#include "classfile/stringTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "code/codeCache.hpp"
+ #include "gc/shared/gcLocker.hpp"
#include "gc/shared/softRefPolicy.hpp"
#include "interpreter/bytecodeStream.hpp"
#include "interpreter/bytecodes.hpp"
#include "logging/log.hpp"
#include "logging/logMessage.hpp"
*** 1227,1236 ****
--- 1228,1238 ----
void print_region_stats(FileMapInfo* map_info);
void print_bitmap_region_stats(size_t size, size_t total_size);
void print_heap_region_stats(GrowableArray<MemRegion> *heap_mem,
const char *name, size_t total_size);
void relocate_to_requested_base_address(CHeapBitMap* ptrmap);
+ void run_gc();
public:
VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
void doit(); // outline because gdb sucks
*** 1634,1644 ****
--- 1636,1665 ----
ptrmap->iterate(&patcher);
ArchivePtrMarker::compact(patcher.max_non_null_offset());
}
}
+ void VM_PopulateDumpSharedSpace::run_gc() {
+ if (HeapShared::is_heap_object_archiving_allowed()) {
+ // Avoid fragmentation while archiving heap objects.
+ // We do this inside a safepoint, so that no further allocation can happen after GC
+ // has finished.
+ if (GCLocker::is_active()) {
+ // This should not happen during -Xshare:dump. If you see this, probably the Java core lib
+ // has been modified such that JNI code is executed in some clean up threads after
+ // we have finished class loading.
+ log_warning(cds)("GC locker is held; GC is skipped. This may produce suboptimal archive heap regions.");
+ } else {
+ log_info(cds)("Run GC ...");
+ Universe::heap()->collect_as_vm_thread(GCCause::_archive_time_gc);
+ log_info(cds)("Run GC done");
+ }
+ }
+ }
+
void VM_PopulateDumpSharedSpace::doit() {
+ run_gc();
CHeapBitMap ptrmap;
MetaspaceShared::initialize_ptr_marker(&ptrmap);
// We should no longer allocate anything from the metaspace, so that:
//
*** 1953,1970 ****
// fails verification, all other interfaces that were not specified in the classlist but
// are implemented by K are not verified.
link_and_cleanup_shared_classes(CATCH);
log_info(cds)("Rewriting and linking classes: done");
- if (HeapShared::is_heap_object_archiving_allowed()) {
- // Avoid fragmentation while archiving heap objects.
- Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true);
- Universe::heap()->collect(GCCause::_archive_time_gc);
- Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
- }
-
VM_PopulateDumpSharedSpace op;
VMThread::execute(&op);
}
}
--- 1974,1986 ----
// fails verification, all other interfaces that were not specified in the classlist but
// are implemented by K are not verified.
link_and_cleanup_shared_classes(CATCH);
log_info(cds)("Rewriting and linking classes: done");
VM_PopulateDumpSharedSpace op;
+ MutexLocker ml(THREAD, HeapShared::is_heap_object_archiving_allowed() ?
+ Heap_lock : NULL); // needed for collect_as_vm_thread
VMThread::execute(&op);
}
}
< prev index next >