Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 256794 - [context][performance] fix usage of CopyOnWriteArrayList for activity event processing
Summary: [context][performance] fix usage of CopyOnWriteArrayList for activity event p...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.2   Edit
Assignee: Shawn Minto CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 272091 (view as bug list)
Depends on:
Blocks: 239667
  Show dependency tree
 
Reported: 2008-11-27 10:28 EST by Eugene Kuleshov CLA
Modified: 2009-08-13 20:22 EDT (History)
3 users (show)

See Also:


Attachments
proposed patch (4.29 KB, patch)
2009-05-07 18:00 EDT, Shawn Minto CLA
no flags Details | Diff
mylyn/context/zip (3.64 KB, application/octet-stream)
2009-05-07 18:00 EDT, Shawn Minto CLA
no flags Details
updated patch to synchronize on all collections (11.43 KB, patch)
2009-05-07 19:16 EDT, Steffen Pingel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Kuleshov CLA 2008-11-27 10:28:42 EST
I might we wrong, but from the context it seem like org.eclipse.mylyn.internal.context.core.InteractionContext is using mostly-add for the collected events. If that is indeed the case, it should not be using CopyOnWriteArrayList to deal with concurrency issues, because that is too costly. See corresponding javadoc at http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/CopyOnWriteArrayList.html

Here is fragment of thread dump I am seeing quite often (even when there is no active task).

"Worker-390" prio=6 tid=0x2d6c1400 nid=0xb3c runnable [0x3681f000..0x3681fd14]
   java.lang.Thread.State: RUNNABLE
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1175)
        at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
        at java.util.concurrent.CopyOnWriteArrayList.add(CopyOnWriteArrayList.java:391)
        at org.eclipse.mylyn.internal.context.core.InteractionContext.parseEvent(InteractionContext.java:69)
        at org.eclipse.mylyn.internal.context.core.InteractionContextManager.addAttentionEvents(InteractionContextManager.java:192)
        at org.eclipse.mylyn.internal.context.core.InteractionContextManager.collapseActivityMetaContext(InteractionContextManager.java:280)
        at org.eclipse.mylyn.internal.context.core.InteractionContextManager.saveActivityMetaContext(InteractionContextManager.java:725)
        at org.eclipse.mylyn.internal.tasks.ui.ActivityExternalizationParticipant.execute(ActivityExternalizationParticipant.java:51)
        at org.eclipse.mylyn.internal.tasks.core.externalization.ExternalizationManager$ExternalizationJob.run(ExternalizationManager.java:200)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Comment 1 Steffen Pingel CLA 2009-04-13 20:05:53 EDT
*** Bug 272091 has been marked as a duplicate of this bug. ***
Comment 2 Shawn Minto CLA 2009-05-01 19:38:06 EDT
I converted the CopyOnWriteArrayList to an ArrayList in my local workspace and haven't had any CME's.  By looking at the implementation, I have confirmed that all of the operations to the InteractionContext are performed on the UI thread (i.e. locking is already performed) or the context is only being written to (i.e. collapsing of the activity context[1]).  Since many handlers of interaction events (e.g. context listeners) assume that operations are performed on the UI thread, I think that it is safe to change this to ArrayList until the need for concurrency arises.  

Steffen, Mik, what are your thoughts?

fn1. The only potential problem is with InteractionContext.getInteractionHistory(), but returning a copy of the interaction history would solve this concern.
Comment 3 Steffen Pingel CLA 2009-05-06 03:13:59 EDT
How is this change going to affect InteractionContext.collapseActivityMetaContext()? As far as I can tell the method needs a copy of the interaction history and is not called on the UI thread so there is a chance of CMEs (even if a copy is made).
Comment 4 Shawn Minto CLA 2009-05-06 11:04:46 EDT
InteractionContextManager.collapseActivityMetaContext collapses one context into another.  The original context is iterated over (need the copy so no CME when adding an event to the activity meta context), and the second one is added to, so there shouldn't be a CME from that.  Let me know if I am wrong about this.
Comment 5 Steffen Pingel CLA 2009-05-06 12:26:41 EDT
The crucial moment is when the copy is made. If the list is modified at that same moment you might end up with an inconsistent data structure. 
Comment 6 Shawn Minto CLA 2009-05-06 13:36:41 EDT
Good point.  I will look over this again and see if this is a real problem or not, or if we should synchronize the context.
Comment 7 Shawn Minto CLA 2009-05-07 18:00:30 EDT
Created attachment 134895 [details]
proposed patch

Steffen, here is my proposed patch that synchronizes all accesses to the interaction history.  Is this what you had in mind?
Comment 8 Shawn Minto CLA 2009-05-07 18:00:53 EDT
Created attachment 134896 [details]
mylyn/context/zip
Comment 9 Steffen Pingel CLA 2009-05-07 19:16:32 EDT
Created attachment 134902 [details]
updated patch to synchronize on all collections
Comment 10 Steffen Pingel CLA 2009-05-07 19:17:42 EDT
Looks good. I have committed the attached patch which extends synchronization to all collections in InteractionContext to ensure that the state held in the class is always consistent.