Example #1
0
/*
 * static final native String mapLibraryName(String)
 */
_jc_object * _JC_JCNI_ATTR
JCNI_java_lang_VMRuntime_mapLibraryName(_jc_env *env, _jc_object *string)
{
	size_t name_len;
	char *fname;
	char *name;

	/* Check for null */
	if (string == NULL) {
		_jc_post_exception(env, _JC_NullPointerException);
		_jc_throw_exception(env);
	}

	/* Decode string */
	name_len = _jc_decode_string_utf8(env, string, NULL);
	if ((name = _JC_STACK_ALLOC(env, name_len + 1)) == NULL) {
		_jc_post_exception_info(env);
		_jc_throw_exception(env);
	}
	_jc_decode_string_utf8(env, string, name);

	/* Format filename */
	if ((fname = _JC_FORMAT_STRING(env, _JC_LIBRARY_FMT, name)) == NULL) {
		_jc_post_exception_info(env);
		_jc_throw_exception(env);
	}

	/* Create new String object */
	if ((string = _jc_new_string(env, fname, strlen(fname))) == NULL)
		_jc_throw_exception(env);

	/* Done */
	return string;
}
Example #2
0
/*
 * public static final native boolean compileClass(Class)
 */
jboolean _JC_JCNI_ATTR
JCNI_java_lang_VMCompiler_compileClass(_jc_env *env, _jc_object *cl)
{
	_jc_jvm *const vm = env->vm;
	_jc_type *type;

	/* Check for null */
	if (cl == NULL) {
		_jc_post_exception(env, _JC_NullPointerException);
		_jc_throw_exception(env);
	}

	/* Get type */
	type = *_JC_VMFIELD(vm, cl, Class, vmdata, _jc_type *);
	_JC_ASSERT(type != NULL);

	/* Generate ELF object */
	if (_jc_generate_object(env, type->loader, type->name) != JNI_OK)
		_jc_throw_exception(env);
	return JNI_TRUE;
}
Example #3
0
/*
 * static final native int nativeLoad(String, ClassLoader)
 */
jint _JC_JCNI_ATTR
JCNI_java_lang_VMRuntime_nativeLoad(_jc_env *env,
	_jc_object *string, _jc_object *clobj)
{
	_jc_jvm *const vm = env->vm;
	_jc_class_loader *loader;
	char *filename;
	size_t len;

	/* Check for null */
	if (string == NULL) {
		_jc_post_exception(env, _JC_NullPointerException);
		_jc_throw_exception(env);
	}

	/* Convert String to UTF-8 */
	len = _jc_decode_string_utf8(env, string, NULL);
	if ((filename = _JC_STACK_ALLOC(env, len + 1)) == NULL) {
		_jc_post_exception_info(env);
		_jc_throw_exception(env);
	}
	_jc_decode_string_utf8(env, string, filename);

	/* Get class loader */
	if (clobj == NULL)
		loader = vm->boot.loader;
	else if ((loader = _jc_get_loader(env, clobj)) == NULL)
		_jc_throw_exception(env);

	/* Open native library */
	if (_jc_load_native_library(env, loader, filename) != JNI_OK) {
		_jc_post_exception_info(env);
		_jc_throw_exception(env);
	}

	/* OK */
	return 1;
}
Example #4
0
/*
 * Find the internal _jc_class_loader structure corresponding to
 * a ClassLoader object. Create one if it doesn't already exist,
 * but do so atomically.
 *
 * Posts an exception on failure.
 */
_jc_class_loader *
_jc_get_loader(_jc_env *env, _jc_object *obj)
{
	_jc_jvm *const vm = env->vm;
	jboolean vm_locked = JNI_FALSE;
	_jc_class_loader *loader;
	_jc_resolve_info info;

	/* Check for null */
	if (obj == NULL) {
		_jc_post_exception(env, _JC_NullPointerException);
		return NULL;
	}
	_JC_ASSERT(_jc_subclass_of(obj, vm->boot.types.ClassLoader));

	/* Lock VM */
	_JC_MUTEX_LOCK(env, vm->mutex);
	vm_locked = JNI_TRUE;

	/* See if loader structure already exists */
	if ((loader = _jc_get_vm_pointer(vm, obj,
	    vm->boot.fields.ClassLoader.vmdata)) != NULL)
		goto done;

	/* Create a new loader structure */
	if ((loader = _jc_create_loader(env)) == NULL) {
		_jc_post_exception_info(env);
		goto done;
	}
	loader->instance = obj;

	/* Set the ClassLoader.vmdata field */
	if (_jc_set_vm_pointer(env, obj,
	    vm->boot.fields.ClassLoader.vmdata, loader) != JNI_OK) {
	    	_jc_destroy_loader(vm, &loader);
	    	goto done;
	}

	/* Unlock VM */
	_JC_MUTEX_UNLOCK(env, vm->mutex);
	vm_locked = JNI_FALSE;

	/* Create reference list with one reference */
	memset(&info, 0, sizeof(info));
	info.loader = loader,
	info.implicit_refs = &loader->instance;
	info.num_implicit_refs = 1;

	/* Put ClassLoader object on implicit reference list */
	if (_jc_merge_implicit_refs(env, &info) != JNI_OK) {
		_jc_destroy_loader(vm, &loader);
		_jc_post_exception_info(env);
		goto done;
	}

done:
	/* Unlock VM */
	if (vm_locked)
		_JC_MUTEX_UNLOCK(env, vm->mutex);

	/* Done */
	return loader;
}