This is the mail archive of the
java-prs@sourceware.cygnus.com
mailing list for the Java project.
gcj/107: Bad array or type conversion bug when compiling bytecode
- To: java-gnats at sourceware dot cygnus dot com
- Subject: gcj/107: Bad array or type conversion bug when compiling bytecode
- From: mdw at cs dot berkeley dot edu
- Date: 22 Nov 1999 05:44:40 -0000
- Cc: bryce at albatross dot co dot nz
- Reply-To: mdw at cs dot berkeley dot edu
- Resent-Cc: java-prs at sourceware dot cygnus dot com, green at cygnus dot com, bryce at albatross dot co dot nz
- Resent-Reply-To: java-gnats@sourceware.cygnus.com, mdw@cs.berkeley.edu
>Number: 107
>Category: gcj
>Synopsis: Bad array or type conversion bug when compiling bytecode
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: apbianco
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Nov 21 21:50:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator: Matt Welsh <mdw@cs.berkeley.edu>
>Release: gcc 2.95.2
>Organization:
>Environment:
Linux x86 Red Hat 6.0
>Description:
Apparently there is a bug in either array references or type
conversion which occurs only when compiling Java bytecode,
and varies depending on the level of optimization used. In
this example, code compiled with -O2 exhibits the bug, but
-O does not.
The code which exhibits this bug is rather simple; it is a
routine which takes a 'short' and writes two bytes of the
short into a byte array (it is part of a hand-coded
serialization routine). Note the use of a loop to do the
array reference as well as the ugly type-casting; I realize
that this is not beautiful code but it does show the bug
in a simple test case.
>How-To-Repeat:
Compile the given test program with 'javac' or 'jikes' to
bytecode. Compile with gcj 2.95.2 with:
'gcj -O2 --main=PutShort -o PutShort PutShort.class'
Then run 'PutShort'.
The program calls 'put_short' in a loop to write the
values 0..50 to a byte array containing 100 bytes, and
then prints out the contents of the byte array. Correct
output should be the hex values for the shorts 0..50 in
sequence; incorrect output is usually random bytes.
>Fix:
Unknown. Possible workaround is to disable optimization
during compilation, however, this doesn't work in all cases!
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="PutShort.java"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="PutShort.java"
cHVibGljIGNsYXNzIFB1dFNob3J0IHsKCiAgcHJpdmF0ZSBzdGF0aWMgdm9pZCBwdXRfc2hvcnQo
c2hvcnQgcywgYnl0ZVtdIGJ1ZiwgaW50IG9mZnNldCkgewogICAgZm9yIChpbnQgaT0wOyBpPDI7
IGkrKykgewogICAgICBidWZbb2Zmc2V0ICsgKDEtaSldID0gKGJ5dGUpIChzICYgMHgwMEZGKTsK
ICAgICAgcyA+Pj0gODsKICAgIH0KICB9CgogIHByaXZhdGUgc3RhdGljIHZvaWQgcHV0X3Nob3J0
X2RlYnVnKHNob3J0IHMsIGJ5dGVbXSBidWYsIGludCBvZmZzZXQpIHsKICAgIFN5c3RlbS5lcnIu
cHJpbnRsbigicHV0X3Nob3J0OiBwdXR0aW5nICIrSW50ZWdlci50b0hleFN0cmluZyhzICYgMHhm
ZmZmKSsiIGF0IG9mZnNldCAiK29mZnNldCk7CiAgICBmb3IgKGludCBpPTA7IGk8MjsgaSsrKSB7
CiAgICAgIGJ1ZltvZmZzZXQgKyAoMS1pKV0gPSAoYnl0ZSkgKHMgJiAweDAwRkYpOwogICAgICBT
eXN0ZW0uZXJyLnByaW50bG4oInB1dF9zaG9ydDogb2Zmc2V0ICIrKG9mZnNldCsoMS1pKSkrIjog
IitJbnRlZ2VyLnRvSGV4U3RyaW5nKCBidWZbb2Zmc2V0KygxLWkpXSAmIDB4ZmYgKSApOwogICAg
ICBzID4+PSA4OwogICAgfQogIH0KCiAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nIGFy
Z3NbXSkgewogICAgICBpbnQgaTsgICAgIAogICAgICBieXRlIGJhcnJbXSA9IG5ldyBieXRlWzEw
MF07CiAgICAgIGZvciAoaSA9IDA7IGkgPCA1MDsgaSsrKSB7CiAgICAgICAgcHV0X3Nob3J0KChz
aG9ydClpLCBiYXJyLCBpKjIpOwogICAgICB9CgogICAgICBmb3IgKGkgPSAwOyBpIDwgMTAwOyBp
KyspIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCIweCIrSW50ZWdlci50b0hleFN0cmluZygg
YmFycltpXSAmIDB4ZmYgKSsiICIpOwogICAgICB9CiAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigi
Iik7CiAgfQoKfQo=