Index: vm/gc_gen/src/common/gc_for_vm.cpp =================================================================== --- vm/gc_gen/src/common/gc_for_vm.cpp (revision 523246) +++ vm/gc_gen/src/common/gc_for_vm.cpp (working copy) @@ -166,6 +166,26 @@ return (int64)((POINTER_SIZE_INT)gc_gen_total_memory_size((GC_Gen*)p_global_gc)); } +int64 gc_get_collection_count() +{ + GC* gc = p_global_gc; + if (gc != NULL) { + return (int64) gc->num_collections; + } else { + return -1; + } +} + +int64 gc_get_collection_time() +{ + GC* gc = p_global_gc; + if (gc != NULL) { + return (int64) gc->time_collections; + } else { + return -1; + } +} + void gc_vm_initialized() { return; } Index: vm/include/open/gc.h =================================================================== --- vm/include/open/gc.h (revision 523246) +++ vm/include/open/gc.h (working copy) @@ -521,6 +521,37 @@ GCExport void gc_class_prepared(Class_Handle ch, VTable_Handle vth); +/* + * ***** + * * + * * Routines to handle the java.lang.management requests. + * * + * ***** + */ + +/** + *

+ * The number of collections that have been executed by this collector. A + * value of -1 means that collection counts are undefined for + * this collector. + *

+ * + * @return The number of collections executed. + */ +GCExport int64 gc_get_collection_count(); + +/** + *

+ * The approximate, cumulative time (in microseconds) spent executing + * collections for this collector. + *

+ * + * @return The time spent collecting garbage. + */ +GCExport int64 gc_get_collection_time(); + + + #else /* #if defined(USE_GC_STATIC) || defined(BUILDING_GC) */ /** @@ -534,6 +565,8 @@ extern void (*gc_add_weak_root_set_entry)(Managed_Object_Handle *ref1, Boolean is_pinned,Boolean is_short_weak); extern void (*gc_add_root_set_entry_managed_pointer)(void **slot, Boolean is_pinned); extern void (*gc_class_prepared)(Class_Handle ch, VTable_Handle vth); +extern int64 (*gc_get_collection_count)(); +extern int64 (*gc_get_collection_time)(); VMEXPORT extern void (*gc_force_gc)(); VMEXPORT extern int64 (*gc_free_memory)(); extern int (*gc_init)(); Index: vm/vmcore/src/gc/dll_gc.cpp =================================================================== --- vm/vmcore/src/gc/dll_gc.cpp (revision 523246) +++ vm/vmcore/src/gc/dll_gc.cpp (working copy) @@ -79,6 +79,8 @@ void (*gc_add_root_set_entry_interior_pointer)(void **slot, int offset, Boolean is_pinned) = 0; void (*gc_add_root_set_entry_managed_pointer)(void **slot, Boolean is_pinned) = 0; void (*gc_class_prepared)(Class_Handle ch, VTable_Handle vth) = 0; +int64 (*gc_get_collection_count)() = 0; +int64 (*gc_get_collection_time)() = 0; void (*gc_force_gc)() = 0; int64 (*gc_free_memory)() = 0; void (*gc_heap_slot_write_ref)(Managed_Object_Handle p_base_of_object_with_slot, @@ -197,6 +199,8 @@ dllName, (apr_dso_handle_sym_t)default_gc_add_root_set_entry_managed_pointer); gc_class_prepared = (void (*)(Class_Handle ch, VTable_Handle vth)) getFunction(handle, "gc_class_prepared", dllName); + gc_get_collection_count = (int64 (*)()) getFunction(handle, "gc_get_collection_count", dllName); + gc_get_collection_time = (int64 (*)()) getFunction(handle, "gc_get_collection_time", dllName); gc_force_gc = (void (*)()) getFunction(handle, "gc_force_gc", dllName); gc_free_memory = (int64 (*)()) getFunction(handle, "gc_free_memory", dllName); gc_heap_slot_write_ref = (void (*)(Managed_Object_Handle p_base_of_object_with_slot, Index: vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_GarbageCollectorMXBeanImpl.cpp =================================================================== --- vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_GarbageCollectorMXBeanImpl.cpp (revision 523246) +++ vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_GarbageCollectorMXBeanImpl.cpp (working copy) @@ -28,6 +28,7 @@ */ #include +#include #include "org_apache_harmony_lang_management_GarbageCollectorMXBeanImpl.h" /* @@ -36,9 +37,8 @@ JNIEXPORT jlong JNICALL Java_org_apache_harmony_lang_management_GarbageCollectorMXBeanImpl_getCollectionCountImpl(JNIEnv *, jobject) { - // TODO implement this method stub correctly - TRACE2("management","getCollectionCountImpl stub invocation"); - return 7L; + TRACE2("management","GarbageCollectorMXBeanImpl_getCollectionCountImpl invocation"); + return gc_get_collection_count(); }; /* @@ -47,9 +47,8 @@ JNIEXPORT jlong JNICALL Java_org_apache_harmony_lang_management_GarbageCollectorMXBeanImpl_getCollectionTimeImpl(JNIEnv *, jobject) { - // TODO implement this method stub correctly - TRACE2("management","getCollectionTimeImpl stub invocation"); - return 2L<<17; + TRACE2("management","GarbageCollectorMXBeanImpl_getCollectionTimeImpl invocation"); + return gc_get_collection_time()/1000; }; Index: vm/gc_cc/src/gc_for_vm.cpp =================================================================== --- vm/gc_cc/src/gc_for_vm.cpp (revision 523246) +++ vm/gc_cc/src/gc_for_vm.cpp (working copy) @@ -398,6 +398,16 @@ return (int64) ((heap.allocation_region_end() - heap.pos) + (heap.old_objects.end - heap.old_objects.pos)); } +int64 gc_get_collection_count() +{ + return (int64) gc_num; +} + +int64 gc_get_collection_time() +{ + return (int64) total_gc_time; +} + void gc_pin_object (Managed_Object_Handle* p_object) { #if 0 // FIXME: overflow check and handling