bugKawa - Bugs: bug #8817, Race condition in ClassType.java...

 
 

bug #8817: Race condition in ClassType.java and cxr.java

Submitter:  Chris Dean <ctdean>
Submitted:  Thu 06 May 2004 04:08:22 AM UTC
   
 
Category:  Scheme language Severity:  3 - Normal
Item Group:  Run-time exception Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 13 May 2004 09:12:48 PM UTC, comment #5: 

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.

Per Bothner <bothner>
Group administrator
Fri 07 May 2004 06:11:20 AM UTC, comment #4: 

I check in a patch for cxr.java.

Per Bothner <bothner>
Group administrator
Thu 06 May 2004 05:54:15 AM UTC, comment #3: 

Patch to fix is attached.

Chris Dean <ctdean>
Thu 06 May 2004 05:15:34 AM UTC, comment #2: 

Sure, I'll make those changes and send you a patch.

Chris Dean <ctdean>
Thu 06 May 2004 05:04:36 AM UTC, comment #1: 

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.

Per Bothner <bothner>
Group administrator
Thu 06 May 2004 04:08:22 AM UTC, 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.

Chris Dean <ctdean>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #1289:  race.patch added by ctdean (4KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

Follow 3 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2004-05-13 bothner StatusNone Fixed
    Open/ClosedOpen Closed
2004-05-06 ctdean Attached File- Added race.patch, #1274

Back to the top

Powered by Savane 3.13-4b48.
Corresponding source code