|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
SF.net SVN: jikesrvm:[15701] rvmroot/trunkRevision: 15701
http://jikesrvm.svn.sourceforge.net/jikesrvm/?rev=15701&view=rev Author: dgrove-oss Date: 2009-06-08 14:34:10 +0000 (Mon, 08 Jun 2009) Log Message: ----------- RVM-814 : Inconsistent wrapping of Exceptions in InvocationTargetException Fix underlying bug instead of compensating for symptoms. I believe the root cause of the problem is that the bytecode-generating reflection implementation did not match the exception handling behavior of the original out-of-line invoke implementation. These two implementations have to have the same exception behavior, or there is no way for Reflection.invoke to be correct as it conditionally calls one or the other depending on various configuration parameters. Modified Paths: -------------- rvmroot/trunk/libraryInterface/Common/src/java/lang/Class.java rvmroot/trunk/libraryInterface/Common/src/java/lang/reflect/VMCommonLibrarySupport.java rvmroot/trunk/rvm/src/org/jikesrvm/runtime/Reflection.java rvmroot/trunk/rvm/src/org/jikesrvm/runtime/ReflectionBase.java rvmroot/trunk/rvm/src/org/jikesrvm/scheduler/MainThread.java Modified: rvmroot/trunk/libraryInterface/Common/src/java/lang/Class.java =================================================================== --- rvmroot/trunk/libraryInterface/Common/src/java/lang/Class.java 2009-06-01 00:19:26 UTC (rev 15700) +++ rvmroot/trunk/libraryInterface/Common/src/java/lang/Class.java 2009-06-08 14:34:10 UTC (rev 15701) @@ -867,14 +867,7 @@ T obj = (T)RuntimeEntrypoints.resolvedNewScalar(cls); // Run the default constructor on the it. - try { - Reflection.invoke(defaultConstructor, null, obj, null, true); - } catch(InvocationTargetException e) { - // This suppresses compiler checking for the InvokeTargetException. - // Note that JDk 1.6 does not declare the InvokeTargetException for the newInstance - // method of the java.lang.Class. - RuntimeEntrypoints.athrow(e.getCause()); - } + Reflection.invoke(defaultConstructor, null, obj, null, true); return obj; } Modified: rvmroot/trunk/libraryInterface/Common/src/java/lang/reflect/VMCommonLibrarySupport.java =================================================================== --- rvmroot/trunk/libraryInterface/Common/src/java/lang/reflect/VMCommonLibrarySupport.java 2009-06-01 00:19:26 UTC (rev 15700) +++ rvmroot/trunk/libraryInterface/Common/src/java/lang/reflect/VMCommonLibrarySupport.java 2009-06-08 14:34:10 UTC (rev 15701) @@ -199,7 +199,11 @@ } // Invoke method - return Reflection.invoke(method, invoker, receiver, args, true); + try { + return Reflection.invoke(method, invoker, receiver, args, true); + } catch (Throwable t) { + throw new InvocationTargetException(t); + } } @Inline(value=Inline.When.ArgumentsAreConstant, arguments={2}) @@ -225,7 +229,11 @@ method = C.findVirtualMethod(method.getName(), method.getDescriptor()); // Invoke method - return Reflection.invoke(method, invoker, receiver, args, false); + try { + return Reflection.invoke(method, invoker, receiver, args, false); + } catch (Throwable t) { + throw new InvocationTargetException(t); + } } @Inline(value=Inline.When.ArgumentsAreConstant, arguments={1}) @@ -424,7 +432,11 @@ // Allocate an uninitialized instance; Object obj = RuntimeEntrypoints.resolvedNewScalar(cls); // Run the constructor on the instance. - Reflection.invoke(constructor, invoker, obj, args, true); + try { + Reflection.invoke(constructor, invoker, obj, args, true); + } catch (Throwable e) { + throw new InvocationTargetException(e); + } return obj; } /* ---- Constructor/Method Support ---- */ Modified: rvmroot/trunk/rvm/src/org/jikesrvm/runtime/Reflection.java =================================================================== --- rvmroot/trunk/rvm/src/org/jikesrvm/runtime/Reflection.java 2009-06-01 00:19:26 UTC (rev 15700) +++ rvmroot/trunk/rvm/src/org/jikesrvm/runtime/Reflection.java 2009-06-08 14:34:10 UTC (rev 15701) @@ -25,7 +25,6 @@ import org.vmmagic.pragma.NoInline; import org.vmmagic.unboxed.Address; import org.vmmagic.unboxed.WordArray; -import java.lang.reflect.InvocationTargetException; import static org.jikesrvm.Configuration.BuildForSSE2Full; @@ -66,7 +65,7 @@ @Inline public static Object invoke(RVMMethod method, ReflectionBase invoker, Object thisArg, Object[] otherArgs, - boolean isNonvirtual) throws InvocationTargetException { + boolean isNonvirtual) { // NB bytecode reflection doesn't care about isNonvirtual if (!bytecodeReflection && !cacheInvokerInJavaLangReflect) { return outOfLineInvoke(method, thisArg, otherArgs, isNonvirtual); Modified: rvmroot/trunk/rvm/src/org/jikesrvm/runtime/ReflectionBase.java =================================================================== --- rvmroot/trunk/rvm/src/org/jikesrvm/runtime/ReflectionBase.java 2009-06-01 00:19:26 UTC (rev 15700) +++ rvmroot/trunk/rvm/src/org/jikesrvm/runtime/ReflectionBase.java 2009-06-08 14:34:10 UTC (rev 15701) @@ -12,10 +12,9 @@ */ package org.jikesrvm.runtime; +import org.jikesrvm.classloader.RVMMethod; import org.vmmagic.pragma.Inline; import org.vmmagic.pragma.NoInline; -import org.jikesrvm.classloader.RVMMethod; -import java.lang.reflect.InvocationTargetException; /** * Base class for all reflective method invoker classes, contains utility @@ -172,36 +171,22 @@ * @param args arguments to method call * @return the object that is the result of the invoke */ - public final Object invoke(RVMMethod method, Object obj, Object[] args) throws InvocationTargetException { + public final Object invoke(RVMMethod method, Object obj, Object[] args) { int argsLength = args == null ? 0 : args.length; if (method.getParameterTypes().length != argsLength) { throwIllegalArgumentException(); } - Throwable x; try { return invokeInternal(obj, args); - } catch (IllegalArgumentException e) { - x = e; - } catch (NullPointerException e) { - x = e; } catch (ClassCastException e) { - x = e; - } catch (Exception e) { - throw new InvocationTargetException(e); - } - // was this caused by casting an argument or in the invoked method? - // TODO: this test can give false positives - if (x.getStackTrace().length == (new Throwable()).getStackTrace().length+6) { - // error in invocation - if (x instanceof ClassCastException) { - throw new IllegalArgumentException("argument type mismatch", x); - } else if (x instanceof NullPointerException) { - throw (NullPointerException)x; + // FIXME: This is fragile and ill-advised way to handle this situation + // I think A more robust way to handle it would be to put in the appropriate + // try/catch structure in the generated bytecodes and handle it there. + if (e.getStackTrace().length == (new Throwable()).getStackTrace().length+6) { + throw new IllegalArgumentException("argument type mismatch", e); } else { - throw (IllegalArgumentException)x; + throw e; } - } else { - throw new InvocationTargetException(x); } } Modified: rvmroot/trunk/rvm/src/org/jikesrvm/scheduler/MainThread.java =================================================================== --- rvmroot/trunk/rvm/src/org/jikesrvm/scheduler/MainThread.java 2009-06-01 00:19:26 UTC (rev 15700) +++ rvmroot/trunk/rvm/src/org/jikesrvm/scheduler/MainThread.java 2009-06-08 14:34:10 UTC (rev 15701) @@ -17,16 +17,16 @@ import java.lang.reflect.Method; import java.util.jar.JarFile; import java.util.jar.Manifest; -import org.jikesrvm.VM; + import org.jikesrvm.Callbacks; import org.jikesrvm.CommandLineArgs; +import org.jikesrvm.VM; import org.jikesrvm.classloader.Atom; import org.jikesrvm.classloader.RVMClass; import org.jikesrvm.classloader.RVMClassLoader; import org.jikesrvm.classloader.RVMMethod; import org.jikesrvm.classloader.TypeReference; import org.jikesrvm.runtime.Reflection; -import org.jikesrvm.runtime.RuntimeEntrypoints; import org.vmmagic.pragma.Entrypoint; /** @@ -198,15 +198,7 @@ if (dbg) VM.sysWriteln("[MainThread.run() invoking \"main\" method... "); // invoke "main" method with argument list - try { - Reflection.invoke(mainMethod, null, null, new Object[]{mainArgs}, true); - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - if (cause == null) { - cause = e; - } - RuntimeEntrypoints.athrow(cause); - } + Reflection.invoke(mainMethod, null, null, new Object[]{mainArgs}, true); if (dbg) VM.sysWriteln(" MainThread.run(): \"main\" method completed.]"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ Jikesrvm-commits mailing list Jikesrvm-commits@... https://lists.sourceforge.net/lists/listinfo/jikesrvm-commits |
| Free embeddable forum powered by Nabble | Forum Help |