Exemplo n.º 1
0
/**
 * Allocate an object and execute the constructor.
 *
 * @param cname the name of the class to be instantiated (may be 0 if cc is != 0)
 * @param loader the class loader that's to be used to lookup the class
 * @param cc the class to be instantiated (may be 0 if cname is != 0)
 * @param signature the signature of the constructor to be executed
 * @param argptr arguments to be passed to the constructor
 *
 * @throws InstantiationException if class is an interface or abstract
 * @throws NoSuchMethodError if the specified constructor cannot be found
 *
 * @return the newly allocated object
 */
Hjava_lang_Object*
execute_java_constructor_v(const char* cname, Hjava_lang_ClassLoader* loader,
	Hjava_lang_Class* cc, const char* signature, va_list argptr)
{
	Hjava_lang_Object* obj;
	Method* mb;
	jvalue retval;
	errorInfo info;
	Utf8Const* sig;

	if (cc == 0) {
		char *buf;

		/* Convert "." to "/" and lookup class */
		buf = checkPtr(KMALLOC(strlen(cname) + 1));
		classname2pathname(cname, buf);
		cc = lookupClass(buf, loader, &info);
		KFREE(buf);
		if (!cc) {
			throwError(&info);
		}
	}

	/* We cannot construct interfaces or abstract classes */
	if (CLASS_IS_INTERFACE(cc) || CLASS_IS_ABSTRACT(cc)) {
		throwException(InstantiationException(cc->name->data));
	}

	if (cc->state < CSTATE_USABLE) {
		if (processClass(cc, CSTATE_COMPLETE, &info) == false) {
			throwError(&info);
		}
	}

	sig = checkPtr(utf8ConstFromString(signature));
	mb = findMethodLocal(cc, constructor_name, sig);
	utf8ConstRelease(sig);
	if (mb == 0) {
		throwException(NoSuchMethodError(constructor_name->data));
	}

	obj = newObject(cc);
	assert(obj != 0);

	/* Make the call */
	KaffeVM_callMethodV(mb, METHOD_NATIVECODE(mb), obj, argptr, &retval);

	return (obj);
}
/*
 * Function that is called by the sections walker
 */
static int feedbackWalker(void *arg,
			  struct section_file *sf,
			  struct section_file_data *sfd)
{
	int retval = 1;

	/* Check for library section */
	if( sfd->sfd_type == &lib_section )
	{
		struct lib_section_data *lsd = (struct lib_section_data *)sfd;

		if( lsd->lsd_flags & LSDF_PRELOAD )
			loadNativeLibrary2(sfd->sfd_name, 0, 0, 0);
	}
	/* Check for jit-code section */
	else if( sfd->sfd_type == &jit_section )
	{
#if defined(TRANSLATOR)
		struct jit_section_data *jsd = (struct jit_section_data *)sfd;

		if( jsd->jsd_flags & JSDF_PRECOMPILE )
		{
			int len, lpc, sig_start = -1, meth_start = -1;
			Utf8Const *u8cname, *u8mname, *u8sig;
			Hjava_lang_Class *cls;
			char *full_name;

			/*
			 * Parse the name of the section to get the class,
			 * method, and signature
			 */
			full_name = sfd->sfd_name;
			len = strlen(full_name);
			for( lpc = len - 1;
			     (lpc >= 0) && (meth_start < 0);
			     lpc-- )
			{
				switch( full_name[lpc] )
				{
				case '(':
					sig_start = lpc;
					break;
				case '/':
					if( sig_start > 0 )
						meth_start = lpc + 1;
					break;
				}
			}
			if( (sig_start > 0) && (meth_start > 0) )
			{
				jobject loader = 0;
				errorInfo info;

				/* Get the right strings and find the class */
				u8cname = utf8ConstNew(full_name,
						       meth_start - 1);
				u8mname = utf8ConstNew(&full_name[meth_start],
						       sig_start - meth_start);
				u8sig = utf8ConstNew(&full_name[sig_start],
						     len - sig_start);
				if( u8cname && u8mname && u8sig &&
				    (cls = loadClass(u8cname, loader, &info)) )
				{
					Method *meth;

					if( (meth = findMethodLocal(cls,
								    u8mname,
								    u8sig)) &&
					    !(meth->accflags & ACC_NATIVE) )
					{
						if( translate(meth, &info) )
						{
						}
						else
						{
							dprintf(
								"Feedback: "
								" Precompile "
								"failed for "
								"%s!\n",
								full_name);
						}
					}
					else if( !meth )
					{
						dprintf(
							"Feedback: Didn't "
							"find method"
							" %s\n",
							full_name);
					}
				}
				else
				{
					dprintf(
						"Feedback: Couldn't load "
						"class %s\n",
						u8cname->data);
				}
				utf8ConstRelease(u8cname);
				utf8ConstRelease(u8mname);
				utf8ConstRelease(u8sig);
			}
			else
			{
				dprintf(
					"Feedback: Malformed method `%s'\n",
					full_name);
			}
		}
#else
		{
			static int precompile_msg = 0;

			if( !precompile_msg )
			{
				precompile_msg = 1;
				dprintf(
					"Feedback: Cannot precompile java for "
					"the interpreter\n");
			}
		}
#endif
	}
	return( retval );
}