bug-kawa
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-kawa] [bugs #8817] Race condition in ClassType.java and cxr.java


From: Per Bothner
Subject: [Bug-kawa] [bugs #8817] Race condition in ClassType.java and cxr.java
Date: Thu, 13 May 2004 17:13:32 -0400
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.6) Gecko/20040113

This mail is an automated notification from the bugs tracker
 of the project: Kawa.

/**************************************************************************/
[bugs #8817] Latest Modifications:

Changes by: 
                Per Bothner <address@hidden>
'Date: 
                Thu 05/13/04 at 21:12 (GMT)

            What     | Removed                   | Added
---------------------------------------------------------------------------
          Resolution | None                      | Fixed
              Status | Open                      | Closed


------------------ Additional Follow-up Comments ----------------------------
I don't think Chris's patch is safe according to the memory model:  A thread 
may call addMethods, and then the flags fields might get written out from cache 
to main memory *before* the newly constructed Method objects are.

The solution (alas) is to always synchronize.
See http://www.javaworld.com/jw-02-2001/jw-0209-double.html
and JSR 133 http://www.jcp.org/en/jsr/detail?id=133.

I checked in a patch.






/**************************************************************************/
[bugs #8817] Full Item Snapshot:

URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=8817>
Project: Kawa
Submitted by: Chris Dean
On: Thu 05/06/04 at 04:08

Category:  Scheme language
Severity:  5 - Average
Item Group:  Run-time exception
Resolution:  Fixed
Assigned to:  None
Status:  Closed


Summary:  Race condition in ClassType.java and cxr.java

Original Submission:  There are two race conditions that I'm seeing when 
running under heavy multi-threaded scenarios.

In ClassType.java we have a few test/set blocks that need a syncronized block 
around them.  For example:
  public Method getDeclaredMethods()
  {
    if ((flags & (ADD_METHODS_DONE|EXISTING_CLASS)) == EXISTING_CLASS)
      addMethods(getReflectClass());
    return methods;
  }

A similar situation exists in cxr.java:
 public Object apply1 (Object arg1)
  {
    if (count == 0)
      program(getName().toString());
   ...

I can provide patches if you'de like.

Follow-up Comments
------------------


-------------------------------------------------------
Date: Thu 05/13/04 at 21:12         By: bothner
I don't think Chris's patch is safe according to the memory model:  A thread 
may call addMethods, and then the flags fields might get written out from cache 
to main memory *before* the newly constructed Method objects are.

The solution (alas) is to always synchronize.
See http://www.javaworld.com/jw-02-2001/jw-0209-double.html
and JSR 133 http://www.jcp.org/en/jsr/detail?id=133.

I checked in a patch.

-------------------------------------------------------
Date: Fri 05/07/04 at 06:11         By: bothner
I check in a patch for cxr.java.

-------------------------------------------------------
Date: Thu 05/06/04 at 05:54         By: ctdean
Patch to fix is attached.

-------------------------------------------------------
Date: Thu 05/06/04 at 05:15         By: ctdean
Sure, I'll make those changes and send you a patch.

-------------------------------------------------------
Date: Thu 05/06/04 at 05:04         By: bothner
For addMethods, I'd make that synchronized, and add an extra
  if ((flags & ADD_METHODS_DONE) != 0)  return;
We need to do the same for addFields.
One caveat: is this prey to the warnings about "double-locking" and does tha 
matter in practice?

For cxr.java, I don't think we need locking.  Just replace the mask and count 
variables in the program method by local variables, and then set mask and then 
finally count at the end.






File Attachments
-------------------

-------------------------------------------------------
Date: Thu 05/06/04 at 05:54  Name: race.patch  Size: 4KB   By: ctdean

http://savannah.gnu.org/bugs/download.php?item_id=8817&amp;item_file_id=1274






For detailed info, follow this link:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=8817>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/







reply via email to

[Prev in Thread] Current Thread [Next in Thread]