This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: java.lang.reflect.Proxy support with native code?


Hi Andrew,

> In my progress of porting my existing code to gcj, I've run into some > problems with java.lang.reflect.Proxy.
> When running the compiled code I get a java.lang.NoClassDefFoundError > exception thrown for "$Proxy0"...
> Is there an issue with java.lang.reflect.Proxy when running natively > compiled code?
I've used it quite a lot with native code. Let's have simple test
case, and we'll see what happens.
I've attached a simple example, and below is the outcome of executing:

---------------------
In cygwin with "GCJ (GCC) 3.3.1 (cygming special)" I get:

$ ./ProxyTest2.exe
1: starting...
2: classloader: gnu.gcj.runtime.VMClassLoader@1012f810
Exception in thread "main" 5 [main] ProxyTest2 2252 fhandler_base::fork_fixup: - Win32 error 6, handle io_handle<0x4B8>
=== SNIP ===
java.lang.InternalError: Unexpected: java.lang.NoClassDefFoundError: while resolving class: $Proxy0
<<No stacktrace available>>
Caused by: java.lang.NoClassDefFoundError: while resolving class: $Proxy0
<<No stacktrace available>>
Caused by: java.lang.ClassNotFoundException: java.lang.reflect.UndeclaredThrowableException not found in [file:./, core:/]
<<No stacktrace available>>



--------------------- With MinGW and "gcj.exe (GCC) 3.4.0 (mingw special)" I get:

$ ./ProxyTest2.exe
1: starting...
2: classloader: gnu.gcj.runtime.VMClassLoader@bbdfc0
Exception in thread "main" java.lang.InternalError: Unexpected: java.lang.NoClassDefFoundError: while resolving class: $Proxy0
=== SNIP ===



---------------------
With my gcj-crosscompiler "powerpc-405-linux-gnu-gcj (GCC) 3.4.0" I get all the way past 4), but then it dies:


# ./ProxyTest2
1: starting...
2: classloader: gnu.gcj.runtime.VMClassLoader@10073fc0
3: proxyClass: class $Proxy0
4: constructor: public $Proxy0(java.lang.reflect.InvocationHandler)
Illegal instruction


I wonder if the two initial tests die because these are static build, whereas the final one isn't.



public class ProxyTest2
{
	public static void main(String[] args)
		throws
			SecurityException,
			NoSuchMethodException,
			IllegalArgumentException,
			InstantiationException,
			IllegalAccessException,
			InvocationTargetException
	{
		System.out.println("1: starting...");

		ClassLoader classLoader = Runnable.class.getClassLoader();

		System.out.println("2: classloader: " + classLoader);

		Class proxyClass = Proxy.getProxyClass(classLoader, new Class[] { Runnable.class });

		System.out.println("3: proxyClass: " + proxyClass);

		Constructor constructor =
			proxyClass.getConstructor(new Class[] { InvocationHandler.class });

		System.out.println("4: constructor: " + constructor);

		InvocationHandler myHandler = new InvocationHandler()
		{
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
			{
				System.out.println("In invoke...: " + method.getName());
				return null;
			} // invoke
		}; // myHandler

		Runnable r = (Runnable) constructor.newInstance(new Object[] { myHandler });

		System.out.println("5: got proxy! About to invoke...");

		r.toString();
	} // main
} // ProxyTest2

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]