Bug 25016 - Integer overflow in _Jv_CondWait
Summary: Integer overflow in _Jv_CondWait
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: unknown
: P3 critical
Target Milestone: 4.0.3
Assignee: Andrew Haley
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-24 11:47 UTC by Andrew Haley
Modified: 2005-11-29 17:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-11-24 11:54:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Haley 2005-11-24 11:47:37 UTC
_Jv_CondWait makes no allowances for the possibility of an integer
overflow, and this means we can return too early.

This causes very hard to track down bugs.  See https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=161483
Comment 1 Andrew Haley 2005-11-24 11:48:04 UTC
Consider this program:


public class TimedWait
{
  public static void main (String[] argv)
    throws InterruptedException
  {
    Object o = new Object();

    synchronized (o)
      {
        o.wait(Long.MAX_VALUE);
      }
  }
}


It's obvious that we never expect this program to terminate, because
the delay is some 292 million years.  However, try this on gcj and it
returns immediately -- because _Jv_CondWait is broken.
Comment 2 Andrew Haley 2005-11-24 11:48:36 UTC
Patch at http://gcc.gnu.org/ml/java-patches/2005-q4/msg00222.html
Comment 3 Andrew Overholt 2005-11-24 15:21:38 UTC
This test case does not work for me when I have not applied the patch.  After application and building, it does appear to run "forever" :)

Also, the Eclipse issue that spurred this on (referenced in comment #1) is fixed when I run with a patched gcc RPM set.
Comment 4 Andrew Haley 2005-11-25 16:18:22 UTC
Subject: Bug 25016

Author: aph
Date: Fri Nov 25 16:18:17 2005
New Revision: 107509

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107509
Log:
2005-11-25  Andrew Haley  <aph@redhat.com>

        PR libgcj/25016
        * posix-threads.cc (_Jv_CondWait): Rewrite calculation of the
        struct timespec we pass to pthread_cond_timedwait.


Modified:
    trunk/libjava/ChangeLog
    trunk/libjava/posix-threads.cc

Comment 5 Andrew Haley 2005-11-25 16:31:12 UTC
Subject: Bug 25016

Author: aph
Date: Fri Nov 25 16:31:09 2005
New Revision: 107510

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107510
Log:
2005-11-25  Andrew Haley  <aph@redhat.com>

        PR libgcj/25016
        * posix-threads.cc (_Jv_CondWait): Rewrite calculation of the
        struct timespec we pass to pthread_cond_timedwait.


Modified:
    branches/gcc-4_0-branch/libjava/ChangeLog
    branches/gcc-4_0-branch/libjava/posix-threads.cc

Comment 6 Andrew Haley 2005-11-25 17:20:13 UTC
Subject: Bug 25016

Author: aph
Date: Fri Nov 25 17:20:09 2005
New Revision: 107511

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107511
Log:
2005-11-25  Andrew Haley  <aph@redhat.com>

        PR libgcj/25016
        * posix-threads.cc (_Jv_CondWait): Rewrite calculation of the
        struct timespec we pass to pthread_cond_timedwait.


Modified:
    branches/gcc-4_1-branch/libjava/ChangeLog
    branches/gcc-4_1-branch/libjava/posix-threads.cc

Comment 7 Tom Tromey 2005-11-29 17:13:44 UTC
Fix checked in everywhere.