예제 #1
0
파일: exception.c 프로젝트: abak/jato
static struct vm_object *
new_exception(struct vm_class *vmc, const char *message)
{
	struct vm_object *message_str;
	struct vm_method *vmm;
	struct vm_object *obj;

	obj = vm_object_alloc(vmc);
	if (!obj)
		return rethrow_exception();

	if (message == NULL)
		message_str = NULL;
	else {
		message_str = vm_object_alloc_string_from_c(message);
		if (!message_str)
			return rethrow_exception();
	}

	vmm = vm_class_get_method(vmc, "<init>", "(Ljava/lang/String;)V");
	if (vmm) {
		vm_call_method(vmm, obj, message_str);

		return obj;
	}

	vmm = vm_class_get_method(vmc, "<init>", "()V");
	if (!vmm)
		error("constructor not found for %s", vmc->name);

	vm_call_method(vmm, obj);

	return obj;
}
예제 #2
0
파일: jato.c 프로젝트: headius/jato
static void __attribute__((noreturn)) vm_exit(int status)
{
	clear_exception();
	vm_call_method(vm_java_lang_System_exit, status);
	if (exception_occurred())
		vm_print_exception(exception_occurred());

	error("System.exit() returned");
}
/*
 * Class:     java/lang/reflect/VMMethod
 * Method:    getDefaultValue
 * Signature: ()Ljava/lang/Object;
 *
 * Parses the annotation default value and returnes it (boxed, if it's a primitive).
 */
JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_getDefaultValue(JNIEnv *env, jobject _this)
{
	static methodinfo *m_parseAnnotationDefault   = NULL; /* parser method (will be chached, therefore static) */
	Utf8String         utf_parseAnnotationDefault = NULL; /* parser method name                                */
	Utf8String         utf_desc        = NULL;            /* parser method descriptor (signature)              */

	if (_this == NULL) {
		exceptions_throw_nullpointerexception();
		return NULL;
	}

	// TODO Use a constructor.
	java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);

	if (h == NULL)
		return NULL;

	sun_reflect_ConstantPool cp(h);
	
	java_lang_reflect_VMMethod rvmm(_this);
	classinfo* declaringClass = rvmm.get_clazz();
	cp.set_constantPoolOop(declaringClass);

	/* only resolve the parser method the first time */
	if (m_parseAnnotationDefault == NULL) {
		utf_parseAnnotationDefault = Utf8String::from_utf8("parseAnnotationDefault");
		utf_desc = Utf8String::from_utf8(
			"(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;)"
			"Ljava/lang/Object;");

		if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
			/* out of memory */
			return NULL;
		}

		classinfo *referer = rvmm.get_Class();

		m_parseAnnotationDefault = class_resolveclassmethod(
			class_sun_reflect_annotation_AnnotationParser,
			utf_parseAnnotationDefault,
			utf_desc,
			referer,
			true);

		if (m_parseAnnotationDefault == NULL) {
			/* method not found */
			return NULL;
		}
	}

	java_lang_reflect_Method rm(rvmm.get_m());
	java_handle_bytearray_t* annotationDefault = rvmm.get_annotationDefault();

	java_handle_t* result = vm_call_method(m_parseAnnotationDefault, NULL, rm.get_handle(), annotationDefault, cp.get_handle());

	return (jobject) result;
}
/*
 * 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;
}