Bug 20768 - [4.0 only] Bytecode -> native code doesn't handle exception properly
Summary: [4.0 only] Bytecode -> native code doesn't handle exception properly
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.1
Assignee: Andrew Haley
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-04-05 18:11 UTC by Andrew Overholt
Modified: 2005-04-28 16:53 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.0
Known to fail: 4.0.0
Last reconfirmed: 2005-04-05 18:33:25


Attachments
Test case (boiled down from something we're seeing with Ecilpse) (355 bytes, text/x-java)
2005-04-05 18:12 UTC, Andrew Overholt
Details
ecj-generated bytecode (663 bytes, application/octet-stream)
2005-04-05 20:31 UTC, Andrew Overholt
Details
ecj-generated bytecode (304 bytes, application/octet-stream)
2005-04-05 20:32 UTC, Andrew Overholt
Details
ecj-generated bytecode (312 bytes, application/octet-stream)
2005-04-05 20:33 UTC, Andrew Overholt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Overholt 2005-04-05 18:11:52 UTC
With the test case I will attach, I get different behaviour if I compile it
first to bytecode *with ecj* and then natively compile it versus interpreting
the bytecode (I have also tried going directly from source to native and that's
the same behaviour as interpreted).

The error does not happen with bytecode generated by gcj -C or Sun's javac.

To duplicate (note:  javac == ecj in case 1 and Sun's javac in case 2)

1.

javac TestExceptionBug.java
gcj -fPIC -fjni -findirect-dispatch --main=TestExceptionBug -o TestExceptionBug
*.class
gcj -fPIC -fjni -findirect-dispatch --main=TestExceptionBug -o
nativeTestExceptionBug TestExceptionBug.java
echo "==== interpreted ===="; gij TestExceptionBug
echo "==== native (from source) ===="; ./nativeTestExceptionBug
echo "==== native (from bytecode) ===="; ./TestExceptionBug

Output:
==== interpreted ====
Finally! It's happened to me -- Ce Ce Penniston
Hi
==== native (from source) ====
Finally! It's happened to me -- Ce Ce Penniston
Hi
==== native (from bytecode) ====
Finally! It's happened to me -- Ce Ce Penniston
Exception in thread "main" TestExceptionBug$IndexedStoreException
   at TestExceptionBug.getIndex(java.lang.String) (Unknown Source)
   at TestExceptionBug.getIndex() (Unknown Source)
   at TestExceptionBug.main(java.lang.String[]) (Unknown Source)
   at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0)
   at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)

2.

javac TestExceptionBug.java
gcj -fPIC -fjni -findirect-dispatch --main=TestExceptionBug -o TestExceptionBug
*.class
gcj -fPIC -fjni -findirect-dispatch --main=TestExceptionBug -o
nativeTestExceptionBug TestExceptionBug.java
echo "==== interpreted ===="; gij TestExceptionBug
echo "==== native (from source) ===="; ./nativeTestExceptionBug
echo "==== native (from bytecode) ===="; ./TestExceptionBug

Output:
==== interpreted ====
Finally! It's happened to me -- Ce Ce Penniston
Hi
==== native (from source) ====
Finally! It's happened to me -- Ce Ce Penniston
Hi
==== native (from bytecode) ====
Finally! It's happened to me -- Ce Ce Penniston
Hi

$ gcj --version
gcj (GCC) 4.0.0 20050402 (Red Hat 4.0.0-0.39)

$ javac -version
Eclipse Java Compiler 0.537, pre-3.1.0 milestone-5, Copyright IBM Corp 2000,
2005. All rights reserved.
Comment 1 Andrew Overholt 2005-04-05 18:12:56 UTC
Created attachment 8537 [details]
Test case (boiled down from something we're seeing with Ecilpse)
Comment 2 Bryce McKinlay 2005-04-05 18:33:25 UTC
Confirmed. There seems to be something unique about the exception table
generated by ecj which confuses gcj. Note that this happens both with or without
optimization.
Comment 3 Tom Tromey 2005-04-05 20:15:40 UTC
Could you attach the ecj-generated bytecode for this file?
Comment 4 Andrew Overholt 2005-04-05 20:31:47 UTC
Created attachment 8540 [details]
ecj-generated bytecode
Comment 5 Andrew Overholt 2005-04-05 20:32:42 UTC
Created attachment 8541 [details]
ecj-generated bytecode
Comment 6 Andrew Overholt 2005-04-05 20:33:00 UTC
Created attachment 8542 [details]
ecj-generated bytecode
Comment 7 Andrew Haley 2005-04-19 12:33:57 UTC
Should be fixed by

2005-04-18  Andrew Haley  <aph@redhat.com>

        * java-except.h (struct eh_range.handler): Remove unused field.
        (handle_nested_ranges): Remove function declaration.
        (sanity_check_exception_range): Add function declaration.
        * verify.c (verify_jvm_instructions): Remove call to
        handle_nested_ranges.
        * verify-glue.c (verify_jvm_instructions_new): Call
        sanity_check_exception_range.
        * except.c (link_handler, eh_range_freelist, link_handler,
        handle_nested_ranges): Remove.
        (add_handler): Rewrite.
        (sanity_check_exception_range): New function.
        (print_ranges): New function.

Comment 8 Andrew Overholt 2005-04-26 14:54:36 UTC
I've verified this fix in the RPMs in Fedora rawhide (4.0.0-1).  I'm not sure if
this counts as a verification from gcc's standpoint, though.  I'll mark as FIXED
but feel free to change if I need to verify on HEAD or something.
Comment 9 Andrew Pinski 2005-04-26 16:20:32 UTC
Reopening since this is only fixed on the mainline, this should also be fixed for 4.0.1.
Comment 10 GCC Commits 2005-04-28 16:35:35 UTC
Subject: Bug 20768

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	aph@gcc.gnu.org	2005-04-28 16:35:25

Modified files:
	gcc/java       : expr.c java-except.h verify.c verify-glue.c 
	                 except.c ChangeLog 

Log message:
	2005-04-28  Andrew Haley  <aph@redhat.com>
	
	PR java/21115
	* expr.c (force_evaluation_order): Convert outgoing args smaller
	than integer.
	
	PR java/20768
	* java-except.h (struct eh_range.handler): Remove unused field.
	(handle_nested_ranges): Remove function declaration.
	(sanity_check_exception_range): Add function declaration.
	* verify.c (verify_jvm_instructions): Remove call to
	handle_nested_ranges.
	(start_pc_cmp): Remove function.
	(verify_jvm_instructions): Remove PC sorting of exception regions.
	* verify-glue.c (verify_jvm_instructions_new): Call
	sanity_check_exception_range.
	* except.c (link_handler, eh_range_freelist, link_handler,
	handle_nested_ranges): Remove.
	(add_handler): Rewrite.
	(sanity_check_exception_range): New function.
	(print_ranges): New function.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/expr.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.218.4.2&r2=1.218.4.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/java-except.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.18&r2=1.18.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/verify.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.69&r2=1.69.10.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/verify-glue.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4.2.1&r2=1.4.2.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/except.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.47&r2=1.47.10.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1556.2.16&r2=1.1556.2.17

Comment 11 Andrew Pinski 2005-04-28 16:53:47 UTC
Fixed.