# HG changeset patch # User tschatzl # Date 1408632281 -7200 # Node ID 4bfc44ba0d193610fea06e1b972ca7d584fa5a83 # Parent 47e8e40b94d3d5c47df9351320ac70ebd9ced05f 8055098: WB API should be extended to provide information about size and age of object. Summary: Extend the WhiteBox API to provide information about the size and age of objects. Further add a mechanism to trigger a young GC. Reviewed-by: tschatzl, sjohanss Contributed-by: Leonid Mesnik diff -r 47e8e40b94d3 -r 4bfc44ba0d19 src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Mon Aug 25 17:05:18 2014 -0400 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Thu Aug 21 16:44:41 2014 +0200 @@ -2531,7 +2531,7 @@ } } } else { - if (cause == GCCause::_gc_locker + if (cause == GCCause::_gc_locker || cause == GCCause::_wb_young_gc DEBUG_ONLY(|| cause == GCCause::_scavenge_alot)) { // Schedule a standard evacuation pause. We're setting word_size diff -r 47e8e40b94d3 -r 4bfc44ba0d19 src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.cpp --- a/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.cpp Mon Aug 25 17:05:18 2014 -0400 +++ b/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.cpp Thu Aug 21 16:44:41 2014 +0200 @@ -70,7 +70,7 @@ "must be a ParallelScavengeHeap"); GCCauseSetter gccs(heap, _gc_cause); - if (_gc_cause == GCCause::_gc_locker + if (_gc_cause == GCCause::_gc_locker || _gc_cause == GCCause::_wb_young_gc DEBUG_ONLY(|| _gc_cause == GCCause::_scavenge_alot)) { // If (and only if) the scavenge fails, this will invoke a full gc. heap->invoke_scavenge(); diff -r 47e8e40b94d3 -r 4bfc44ba0d19 src/share/vm/gc_interface/gcCause.cpp --- a/src/share/vm/gc_interface/gcCause.cpp Mon Aug 25 17:05:18 2014 -0400 +++ b/src/share/vm/gc_interface/gcCause.cpp Thu Aug 21 16:44:41 2014 +0200 @@ -51,6 +51,9 @@ case _heap_dump: return "Heap Dump Initiated GC"; + case _wb_young_gc: + return "WhiteBox Initiated Young GC"; + case _no_gc: return "No GC"; diff -r 47e8e40b94d3 -r 4bfc44ba0d19 src/share/vm/gc_interface/gcCause.hpp --- a/src/share/vm/gc_interface/gcCause.hpp Mon Aug 25 17:05:18 2014 -0400 +++ b/src/share/vm/gc_interface/gcCause.hpp Thu Aug 21 16:44:41 2014 +0200 @@ -46,6 +46,7 @@ _gc_locker, _heap_inspection, _heap_dump, + _wb_young_gc, /* implementation independent, but reserved for GC use */ _no_gc, diff -r 47e8e40b94d3 -r 4bfc44ba0d19 src/share/vm/memory/genCollectedHeap.cpp --- a/src/share/vm/memory/genCollectedHeap.cpp Mon Aug 25 17:05:18 2014 -0400 +++ b/src/share/vm/memory/genCollectedHeap.cpp Thu Aug 21 16:44:41 2014 +0200 @@ -718,15 +718,18 @@ #else // INCLUDE_ALL_GCS ShouldNotReachHere(); #endif // INCLUDE_ALL_GCS + } else if (cause == GCCause::_wb_young_gc) { + // minor collection for WhiteBox API + collect(cause, 0); } else { #ifdef ASSERT - if (cause == GCCause::_scavenge_alot) { - // minor collection only - collect(cause, 0); - } else { - // Stop-the-world full collection - collect(cause, n_gens() - 1); - } + if (cause == GCCause::_scavenge_alot) { + // minor collection only + collect(cause, 0); + } else { + // Stop-the-world full collection + collect(cause, n_gens() - 1); + } #else // Stop-the-world full collection collect(cause, n_gens() - 1); diff -r 47e8e40b94d3 -r 4bfc44ba0d19 src/share/vm/prims/whitebox.cpp --- a/src/share/vm/prims/whitebox.cpp Mon Aug 25 17:05:18 2014 -0400 +++ b/src/share/vm/prims/whitebox.cpp Thu Aug 21 16:44:41 2014 +0200 @@ -43,6 +43,7 @@ #include "utilities/exceptions.hpp" #if INCLUDE_ALL_GCS +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" #include "gc_implementation/g1/concurrentMark.hpp" #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" #include "gc_implementation/g1/heapRegionRemSet.hpp" @@ -221,6 +222,30 @@ (size_t) magnitude, (size_t) iterations); WB_END +WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj)) + oop p = JNIHandles::resolve(obj); +#if INCLUDE_ALL_GCS + if (UseG1GC) { + G1CollectedHeap* g1 = G1CollectedHeap::heap(); + const HeapRegion* hr = g1->heap_region_containing(p); + if (hr == NULL) { + return false; + } + return !(hr->is_young()); + } else if (UseParallelGC) { + ParallelScavengeHeap* psh = ParallelScavengeHeap::heap(); + return !psh->is_in_young(p); + } +#endif // INCLUDE_ALL_GCS + GenCollectedHeap* gch = GenCollectedHeap::heap(); + return !gch->is_in_young(p); +WB_END + +WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj)) + oop p = JNIHandles::resolve(obj); + return p->size() * HeapWordSize; +WB_END + #if INCLUDE_ALL_GCS WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) G1CollectedHeap* g1 = G1CollectedHeap::heap(); @@ -668,6 +693,9 @@ Universe::heap()->collect(GCCause::_last_ditch_collection); WB_END +WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) + Universe::heap()->collect(GCCause::_wb_young_gc); +WB_END WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) // static+volatile in order to force the read to happen @@ -811,6 +839,8 @@ static JNINativeMethod methods[] = { {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, + {CC"getObjectSize", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize }, + {CC"isObjectInOldGen", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen }, {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, {CC"parseCommandLine", @@ -885,6 +915,7 @@ (void*)&WB_GetStringVMFlag}, {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, {CC"fullGC", CC"()V", (void*)&WB_FullGC }, + {CC"youngGC", CC"()V", (void*)&WB_YoungGC }, {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, {CC"allocateMetaspace", CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace }, diff -r 47e8e40b94d3 -r 4bfc44ba0d19 test/testlibrary/whitebox/sun/hotspot/WhiteBox.java --- a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Mon Aug 25 17:05:18 2014 -0400 +++ b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Thu Aug 21 16:44:41 2014 +0200 @@ -69,6 +69,8 @@ // Memory public native long getObjectAddress(Object o); public native int getHeapOopSize(); + public native boolean isObjectInOldGen(Object o); + public native long getObjectSize(Object o); // Runtime // Make sure class name is in the correct format @@ -145,6 +147,9 @@ public native long allocateMetaspace(ClassLoader classLoader, long size); public native void freeMetaspace(ClassLoader classLoader, long addr, long size); + // force Young GC + public native void youngGC(); + // force Full GC public native void fullGC();