|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
[rvm-research] A bug in reflection?It appears that Jikes RVM has a bug in the implementation of its reflection. For the detail, look at the patch and the test case: reflection.patch and Reflection.java. Try the following. 1. To see the bug, try the following three command lines. $javac ReflectionTest.java $java -showversion ReflectionTest java version "1.6.0_10" Java(TM) SE Runtime Environment (build 1.6.0_10-b33) Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode) newInstance: pass invokeVirtual: pass invokeStatic: pass $rvm ReflectionTest ... newInstance: pass invokeVirtual: fail unexpected cause of the Invocation target exception: java.lang.reflect.InvocationTargetException ... invokeStatic: fail unexpected cause of the Invocation target exception: 2. To correct the bug, try the following. * Apply the patch: reflection.patch * Build Jikes RVM * Run it $rvm ReflectionTest newInstance: pass invokeVirtual: pass invokeStatic: pass Cheers, Byeong [reflection.patch] Index: libraryInterface/Common/src/java/lang/Class.java =================================================================== --- libraryInterface/Common/src/java/lang/Class.java (revision 15651) +++ libraryInterface/Common/src/java/lang/Class.java (working copy) @@ -834,7 +834,7 @@ @Inline(value=Inline.When.ArgumentsAreConstant, arguments={0}) public T newInstance() throws IllegalAccessException, InstantiationException, - InvocationTargetException, ExceptionInInitializerError, SecurityException { + ExceptionInInitializerError, SecurityException { // Basic checks checkMemberAccess(Member.PUBLIC); @@ -867,7 +867,14 @@ T obj = (T)RuntimeEntrypoints.resolvedNewScalar(cls); // Run the default constructor on the it. - Reflection.invoke(defaultConstructor, null, obj, null, true); + 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()); + } return obj; } Index: libraryInterface/Common/src/java/lang/reflect/VMCommonLibrarySupport.java =================================================================== --- libraryInterface/Common/src/java/lang/reflect/VMCommonLibrarySupport.java (revision 15651) +++ libraryInterface/Common/src/java/lang/reflect/VMCommonLibrarySupport.java (working copy) @@ -199,11 +199,7 @@ } // Invoke method - try { - return Reflection.invoke(method, invoker, receiver, args, true); - } catch (Throwable t) { - throw new InvocationTargetException(t); - } + return Reflection.invoke(method, invoker, receiver, args, true); } @Inline(value=Inline.When.ArgumentsAreConstant, arguments={2}) @@ -229,11 +225,7 @@ method = C.findVirtualMethod(method.getName(), method.getDescriptor()); // Invoke method - try { - return Reflection.invoke(method, invoker, receiver, args, false); - } catch (Throwable t) { - throw new InvocationTargetException(t); - } + return Reflection.invoke(method, invoker, receiver, args, false); } @Inline(value=Inline.When.ArgumentsAreConstant, arguments={1}) [ReflectionTest.java] import java.lang.reflect.*; public class ReflectionTest { static class MyException extends RuntimeException {} public static void main(String[] args) { checkNewInstance(); checkInvokeVirtual(); checkInvokeStatic(); } // "Note that this method propagates any exception thrown by the nullary // constructor, including a checked exception." // [http://java.sun.com/javase/6/docs/api/java/lang/Class.html#newInstance()] static void checkNewInstance() { try { ReflectionTest.class.newInstance(); } catch(MyException e) { System.out.println("newInstance: pass"); } catch(Throwable e) { System.out.println("newInstance: fail"); System.out.println(" An unexpected expected exception thrown"); e.printStackTrace(); } } // For correct behavior, see the class description of the // following documentation: // http://java.sun.com/javase/6/docs/api/java/lang/reflect/Method.html#invoke(java.lang.Object,%20java.lang.Object...) // http://java.sun.com/javase/6/docs/api/java/lang/reflect/InvocationTargetException.html static void checkInvokeVirtual() { try { ReflectionTest r = new ReflectionTest(0); Method mFoo = ReflectionTest.class.getMethod("foo"); mFoo.invoke(r); } catch (InvocationTargetException e) { if (e.getCause() instanceof MyException) { System.out.println("invokeVirtual: pass"); } else { System.out.println("invokeVirtual: fail"); System.out.println("unexpected cause of the Invocation target exception: "); e.printStackTrace(); } } catch (Throwable e) { System.out.println("invokeVirtual: fail"); System.out.println(" An unexpected expected exception thrown"); e.printStackTrace(); } } // For correct behavior, see the class description of the // following documentation: // http://java.sun.com/javase/6/docs/api/java/lang/reflect/Method.html#invoke(java.lang.Object,%20java.lang.Object...) // http://java.sun.com/javase/6/docs/api/java/lang/reflect/InvocationTargetException.html static void checkInvokeStatic() { try { ReflectionTest r = new ReflectionTest(0); Method mFoo = ReflectionTest.class.getMethod("bar"); mFoo.invoke(null); } catch (InvocationTargetException e) { if (e.getCause() instanceof MyException) { System.out.println("invokeStatic: pass"); } else { System.out.println("invokeStatic: fail"); System.out.println("unexpected cause of the Invocation target exception: "); e.printStackTrace(); } } catch (Throwable e) { System.out.println("invokeStatic: fail"); System.out.println(" An unexpected expected exception thrown"); e.printStackTrace(); } } public ReflectionTest() {throw new MyException();} public ReflectionTest(int i) {} public void foo() {throw new MyException();} public static void bar() {throw new MyException();} } ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Jikesrvm-researchers mailing list Jikesrvm-researchers@... https://lists.sourceforge.net/lists/listinfo/jikesrvm-researchers |
|
|
Re: [rvm-research] A bug in reflection?Byeong Lee <bclee@...> wrote on 04/13/2009 06:29:33 PM: |
|
|
Re: [rvm-research] A bug in reflection?Nice catch Byeong,
the bug stems from the bytecode reflection code added last year. I've created a new tracker that I'll tackle [1] (your patch will fix the bytecode case but not the out-of-line). I've linked it into other related bugs that have been closed in MRP in order to get SPECjvm2008 running. Regards, Ian [1] http://jira.codehaus.org/browse/MRP-3 -- Building a better RVM at http://mrp.codehaus.org/ 2009/4/13 Byeong Lee <bclee@...>
------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Jikesrvm-researchers mailing list Jikesrvm-researchers@... https://lists.sourceforge.net/lists/listinfo/jikesrvm-researchers |
|
|
Re: [rvm-research] A bug in reflection?It's RVM-814: http://jira.codehaus.org/browse/RVM-814. On Mon, 13 Apr 2009, David P Grove wrote: > > Byeong Lee <bclee@...> wrote on 04/13/2009 06:29:33 PM: > > > > It appears that Jikes RVM has a bug in the implementation of its > > reflection. For the detail, look at the patch and the test case: > > reflection.patch and Reflection.java. Try the following. > > Could you open a JIRA with the patch, test case, and a contribution > statement? I suspect this may be in an area where the class libraries > may have changed. Most of our reflection implementation and test cases > were originally coded to Java 1.2 APIs and probably some parts never got > updated. > > thanks, > > --dave > > > This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Jikesrvm-researchers mailing list Jikesrvm-researchers@... https://lists.sourceforge.net/lists/listinfo/jikesrvm-researchers |
| Free embeddable forum powered by Nabble | Forum Help |