/*
 * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
 * Method:    getHeapMemoryUsage
 * Signature: ()Ljava/lang/management/MemoryUsage;
 */
JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz)
{
	classinfo                        *class_java_lang_management_MemoryUsage;
	java_objectheader                *o;
	java_lang_management_MemoryUsage *mu;
	methodinfo                       *m;
	s8                                init;
	s8                                used;
	s8                                commited;
	s8                                maximum;

	/* get the class */
	/* XXX optimize me! sometime... */

	if (!(class_java_lang_management_MemoryUsage = load_class_bootstrap(utf_new_char("java/lang/management/MemoryUsage"))))
		return false;

	/* create the object */

	o = builtin_new(class_java_lang_management_MemoryUsage);
	
	if (o == NULL)
		return NULL;

	/* cast the object to a MemoryUsage object (for debugability) */

	mu = (java_lang_management_MemoryUsage *) o;

	/* find initializer */

	m = class_findmethod(class_java_lang_management_MemoryUsage,
						 utf_init, utf_new_char("(JJJJ)V"));
	                      	                      
	/* initializer not found */

	if (m == NULL)
		return NULL;

	/* get values from the VM */
	/* XXX if we ever support more than one VM, change this */

	init     = opt_heapstartsize;
	used     = gc_get_total_bytes();
	commited = gc_get_heap_size();
	maximum  = gc_get_max_heap_size();

	/* call initializer */

	(void) vm_call_method(m, o, init, used, commited, maximum);

	return mu;
}
示例#2
0
void statistics_print_gc_memory_usage(void)
{
	static int64_t count = 0;
	int64_t max;
	int64_t size;
	int64_t free;
	int64_t used;
	int64_t total;

	count++;

	max   = gc_get_max_heap_size();
	size  = gc_get_heap_size();
	free  = gc_get_free_bytes();
	used  = size - free;
	total = gc_get_total_bytes();

	if (opt_ProfileMemoryUsageGNUPlot) {
		if (count == 1)
			fprintf(opt_ProfileMemoryUsageGNUPlot, "plot \"profile.dat\" using 1:2 with lines title \"max. Java heap size\", \"profile.dat\" using 1:3 with lines title \"Java heap size\", \"profile.dat\" using 1:4 with lines title \"used\", \"profile.dat\" using 1:5 with lines title \"free\"\n");

		fprintf(opt_ProfileMemoryUsageGNUPlot,
				"%" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 "\n",
				count, max, size, used, free);

		fflush(opt_ProfileMemoryUsageGNUPlot);
	}
	else {
		log_println("GC memory usage -------------------");
		log_println("");
		log_println("max. Java heap size: %10lld", max);
		log_println("");
		log_println("Java heap size:      %10lld", size);
		log_println("used:                %10lld", used);
		log_println("free:                %10lld", free);
		log_println("totally used:        %10lld", total);
		log_println("");
	}
}