You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Jesse Wilson (JIRA)" <ji...@apache.org> on 2009/08/17 22:49:14 UTC

[jira] Created: (HARMONY-6312) Concurrency problems in NIO

Concurrency problems in NIO
---------------------------

                 Key: HARMONY-6312
                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
         Environment: SVN Revision: 801399
            Reporter: Jesse Wilson


There's several potential concurrency problems in our NIO implementation...
 - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
 - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
 - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes

These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.

#Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759839#action_12759839 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------

Regis,

I examined your patches:
  The change to OSNetworkSystemLinux doesn't appear to honor the timeout properly, but I'm not familiar with this API.
  The fix to OSNetworkSystem.java is fantastic, although I don't see reason to keep the previous select() method. 
  The other changes continue to rely on indexing FDs. This brings no measurable performance improvement so I don't think it pulls its weight.

I'm currently testing a patch that builds upon your improvements to OSNetworkSystem. The forthcoming patch continues to use the strategy of iterating through all keys in the key set for each select(); I have measured that this has no negative impact on performance.

Aside: I found processing a .zip of git patches quite cumbersome to work with.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Mark Hindess (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12745233#action_12745233 ] 

Mark Hindess commented on HARMONY-6312:
---------------------------------------

I've applied the simple nio_char changes in r806001.  I'm still looking at the remaining parts.


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760192#action_12760192 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

Jesse,

In my understanding, SelectorBenchmark.java try to simulate a "real" scenario of using selector, so I picked benchmark from HARMONY-4879 which *only* test Selector.selectNow(), the result:

svn + no mapping
clients/active per    100      10
100                  1318    1102
500                  8325    7612
1000                20083   18235
1500                33486   29643

svn
clients/active per     100      10
100                    924     643
500                   6465    5206
1000                 16494   12250
1500                 28537   20684

the gap is obvious. While micro benchmark just said a side of words, we would like that it could work better in real world, I may need more time to do more test.

> The change to OSNetworkSystemLinux doesn't appear to honor the timeout properly
Yes, we need to find a better way to resolve this issue.

> I don't see reason to keep the previous select() method. 
I'd like the old one to call the new one, so other places depend on old interface can work without modifications.

> I found processing a .zip of git patches quite cumbersome to work with.
I just think small patches are easy to review, because one patch only do one simple thing. What form of patches do you prefer? I think git can help me to do that :)




> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jesse Wilson updated HARMONY-6312:
----------------------------------

    Attachment: NIO_Concurrency_issues_2.patch

When measured by my previously attached benchmark, the attached patch offers a slight (~3%) improvement over today's performance.

Overview of changes:
 - Permit extra space in the arrays sent to INetworkSystem
 - Move Javadoc from INetworkSystem implementation to interface
 - Reuse arrays rather than reallocating them for both input and output of INetworkSystem
 - Remove indices and iterate the selected set each select(). This saves 200+ lines of code and much complexity.
 - Add tests for keySet viewing modifications and keys cancelled during select

Regis, please apply this patch. Or as much of it that you see fit! 

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Regis Xu updated HARMONY-6312:
------------------------------

    Attachment: selector.zip

I propose patch serial in selector.zip, it is based on current HEAD.
This serial of patches keep the selector's way of handling keys, just bug fixing and improvement.

0001-remove-SelectionKeyImpl.hasCode-equals-the-old-impl.patch and 0002-synchronized-on-unmodifiableKeys.patch is from Jesse' patch, very thanks Jesse.

0003-keep-Selector.keysSet-reflect-keys-of-selector-consi.patch fix Selector.keysSet doesn't reflect keys consistently

0004-signal-workaround-for-drlvm.patch is workaround for a known issue of drlvm, thread blocked on io will be interrupted by unrelated signal. This patch make sure test in patch 0005 can be passed.

0005-remove-cancelledKeys-from-selectedKeys.patch and 0006-add-new-interface-accept-read-write-fd-count-to-avoi.patch is from my previous patches on this issue.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch, selector.zip
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by Regis <xu...@gmail.com>.
Regis wrote:
> Regis wrote:
> 
> Hi Jesse,
> 
> I proposed a serial of patches on JIRA, that combines part of work from 
> you, what are your options? Is it OK to commit them?
> 

I have committed 0001-remove-SelectionKeyImpl.hasCode-equals-the-old-impl.patch 
and 0002-synchronized-on-unmodifiableKeys.patch to repository at r817167 and 
r817169. I will hold the reset three patches for few days to wait suggestions.

-- 
Best Regards,
Regis.

Re: [jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by Regis <xu...@gmail.com>.
Regis wrote:
> Jesse Wilson (JIRA) wrote:
>>     [ 
>> https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12745221#action_12745221 
>> ]
>> Jesse Wilson commented on HARMONY-6312:
>> ---------------------------------------
>>
>> The patch includes a test fails on the original code, but passes on 
>> the RI and on the fixed code.
>>
>> The patch makes some major surgery to SelectionKeyImpl. The 
>> fundamental change is that instead of adjusting readableFDs and 
>> writableFDs as the keys and interest ops change, this adjusts them 
>> before each select() operation. Select is already an O(N) operation 
>> (in terms of the number of keys), so constructing this array will not 
>> hurt performance. It also guarantees that the two arrays are "resized" 
>> the minimum number of times possible. The old code may grow the arrays 
>> more than necessary, only to shrink them before the native call.
>>
>> That file also received a small bit of documentation and style 
>> cleanup. Once this patch is live, I volunteer to submit a follow up 
>> that will improve variable names.
>>
>>
>>> Concurrency problems in NIO
>>> ---------------------------
>>>
>>>                 Key: HARMONY-6312
>>>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>>>             Project: Harmony
>>>          Issue Type: Bug
>>>          Components: Classlib
>>>         Environment: SVN Revision: 801399
>>>            Reporter: Jesse Wilson
>>>         Attachments: NIO_Concurrency_issues.patch
>>>
>>>   Original Estimate: 72h
>>>  Remaining Estimate: 72h
>>>
>>> There's several potential concurrency problems in our NIO 
>>> implementation...
>>>  - Charset#isSupported isn't synchronized, but it accesses mutable 
>>> member cachedCharsetTable.
>>>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so 
>>> multiple SelectionKey instances may receive the same hash code. (Why 
>>> not use the default hash code?)
>>>  - In SelectorImpl, the unmodifiableKeys member is never synchronized 
>>> on. But the documentation specifies that clients can synchronize on 
>>> that set to guard against changes
>>> These are the obvious problems; I suspect there are more subtle 
>>> concurrency defects at play here. I'll prepare a patch to address the 
>>> major issues, and we should consider a rigorous approach (Findbugs?) 
>>> to discover concurrency problems.
>>> #Android
>>
> 
> Jesse, thanks for this patch, I believe it make selector code easier 
> understand and maintain, but I still have concerns with iterating keySet 
> in prepareChannels.
> 
> The more registered channels, the slower prepareChannels, even more, we 
> have to travel the whole set more than once! Current implementation 
> maintains several mapping to avoid this. So do you have any data to 
> prove this patch is good as old one when large number of channels are 
> registered?
> 
> For arrays "resize" in prepareChannels, it can be simple avoid by patch 
> [1]. in [1] I added a new interface to accept count of readable/writable 
> FDs, so readableFDs and writableFDs don't need to be resized. After 
> patch [1] nothing to be done before select.
> 
> Index: 
> modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java 
> 
> =====================================================================
> --- 
> modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java 
> 
> +++ 
> modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java 
> 
> @@ -157,6 +157,9 @@ public interface INetworkSystem {
>              FileDescriptor[] writeFDs, long timeout)
>              throws SocketException;
> 
> +    public int[] select(FileDescriptor[] readFDs,
> +            FileDescriptor[] writeFDs, int countRead, int countWrite, 
> long timeout)
> +            throws SocketException;
>      /*
>       * Query the IP stack for the local port to which this socket is 
> bound.
>       *
> Index: 
> modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java 
> 
> =====================================================================
> --- 
> modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java 
> 
> +++ 
> modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java 
> 
> @@ -376,6 +376,31 @@ final class OSNetworkSystem implements 
> INetworkSystem {
>          throw new SocketException();
>      }
> 
> +    public int[] select(FileDescriptor[] readFDs, FileDescriptor[] 
> writeFDs, int countRead, int countWrite,
> +            long timeout) throws SocketException {
> +        int result = 0;
> +        if (0 == countRead + countWrite) {
> +            return (new int[0]);
> +        }
> +        int[] flags = new int[countRead + countWrite];
> +
> +        assert validateFDs(readFDs, writeFDs, countRead, countWrite) : 
> "Invalid file descriptor arrays"; //$NON-NLS-1$
> +
> +        // handle timeout in native
> +        result = selectImpl(readFDs, writeFDs, countRead, countWrite, 
> flags,
> +                timeout);
> +
> +        if (0 <= result) {
> +            return flags;
> +        }
> +        if (ERRORCODE_SOCKET_TIMEOUT == result ||
> +            ERRORCODE_SOCKET_INTERRUPTED == result) {
> +            return new int[0];
> +        }
> +        throw new SocketException();
> +    }
> +
> +
>      private native int selectImpl(FileDescriptor[] readfd,
>              FileDescriptor[] writefd, int cread, int cwirte, int[] flags,
>              long timeout);
> @@ -497,6 +522,22 @@ final class OSNetworkSystem implements 
> INetworkSystem {
>          return true;
>      }
> 
> +    private boolean validateFDs(FileDescriptor[] readFDs,
> +            FileDescriptor[] writeFDs, int countRead, int countWrite) {
> +        for (int i = 0; i < countRead; ++i) {
> +            // Also checks fd not null
> +            if (!readFDs[i].valid()) {
> +                return false;
> +            }
> +        }
> +        for (int i = 0; i < countWrite; ++i) {
> +            if (!writeFDs[i].valid()) {
> +                return false;
> +            }
> +        }
> +        return true;
> +    }
> +
>      /**
>       * Write bytes from a byte array to a socket.
>       *
> Index: 
> modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java 
> 
> =====================================================================
> --- 
> modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java 
> 
> +++ 
> modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java 
> 
> @@ -469,13 +469,12 @@ final class SelectorImpl extends AbstractSelector {
>                      doCancel();
>                      int[] readyChannels = null;
>                      boolean isBlock = (SELECT_NOW != timeout);
> -                    prepareChannels();
>                      try {
>                          if (isBlock) {
>                              begin();
>                          }
>                          readyChannels = 
> Platform.getNetworkSystem().select(
> -                                readableFDs, writableFDs, timeout);
> +                                readableFDs, writableFDs, 
> readableKeysCount, writableKeysCount, timeout);
>                      } finally {
>                          if (isBlock) {
>                              end();
> 
> 

Hi Jesse,

I proposed a serial of patches on JIRA, that combines part of work from you, 
what are your options? Is it OK to commit them?

-- 
Best Regards,
Regis.

[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12745221#action_12745221 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------

The patch includes a test fails on the original code, but passes on the RI and on the fixed code.

The patch makes some major surgery to SelectionKeyImpl. The fundamental change is that instead of adjusting readableFDs and writableFDs as the keys and interest ops change, this adjusts them before each select() operation. Select is already an O(N) operation (in terms of the number of keys), so constructing this array will not hurt performance. It also guarantees that the two arrays are "resized" the minimum number of times possible. The old code may grow the arrays more than necessary, only to shrink them before the native call.

That file also received a small bit of documentation and style cleanup. Once this patch is live, I volunteer to submit a follow up that will improve variable names.


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>         Attachments: NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12766389#action_12766389 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

Thanks Jesse, fix applied at r825746, please verify.

About "maintaining indices", I can understand the memory is limited on embedded system and to be selected channel set usually is small,  so the overhead of iteration is not outstanding, it's better iteration than indeces. But on server, the memory for indeices is *really* not a big deal, and for high throughput server, the number of selected channel can be very large, it's not acceptable to iterate them all every select. 

The two ways fit different requirements and cases, it's best if we can find a common way that can be accepted by both embedded and server environments.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760521#action_12760521 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

Thanks Jesse, I'm taking look at the new patch.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jesse Wilson updated HARMONY-6312:
----------------------------------

    Attachment: harmony_svn_plus_patch_2009-08-19.html
                harmony_svn.html
                ri.html

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764981#action_12764981 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

I have committed part of the patch NIO_Concurrency_issues_2.patch at r824614, included:
 - Permit extra space in the arrays sent to INetworkSystem
 - Move Javadoc from INetworkSystem implementation to interface
 - Reuse arrays rather than reallocating them for both input and output of INetworkSystem
 - Add tests for keySet viewing modifications and keys cancelled during select 

"Remove indices" is still in discussion, need more tests and investigation.

I also add a timeout for select() in test case test_cancelledKeys, because there is time window main thread waked up and checked "!complete.get()" first, and then "complete" is set to "true", that will cause test case block forever.

Jesse, please verify if that was applied as you expected.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12766397#action_12766397 ] 

Hudson commented on HARMONY-6312:
---------------------------------

Integrated in Harmony-1.5-head-linux-x86_64 #503 (See [http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/503/])
    partial fix for : Concurrency problems in NIO

- change type of "keys" to SelectionKeyImpl[]
- minor doc fix


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Regis Xu updated HARMONY-6312:
------------------------------

    Attachment: cancelledkey.diff

this patch is based on the previous one.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764989#action_12764989 ] 

Hudson commented on HARMONY-6312:
---------------------------------

Integrated in Harmony-1.5-head-linux-x86_64 #495 (See [http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/495/])
    Apply partial part of patch NIO_Concurrency_issues_2.patch for : Concurrency problems in NIO

- Permit extra space in the arrays sent to INetworkSystem
- Move Javadoc from INetworkSystem implementation to interface
- Reuse arrays rather than reallocating them for both input and output of INetworkSystem
- Add tests for keySet viewing modifications and keys cancelled during select


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765226#action_12765226 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------

Thanks Regis!

Some minor comments on the update:
 - the keys array should probably be of type SelectionKeyImpl
 - the comment on SelectorImpl line 597 is out of date

Regardless of what approach Harmony uses, from my investigation I'm confident that maintaining indices to save HashSet iterations isn't appropriate for Android. I hope you'll come to the same conclusion after your investigation.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jesse Wilson closed HARMONY-6312.
---------------------------------

    Resolution: Fixed

Looks Good To Me. 

I still think the performance benefits of the indices won't hold up on a proper benchmark, but that's a separate problem. My concurrency concerns have all been addressed, so I'm closing this issue.

Thanks Regis!

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, NIO_Concurrency_issues_2.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12748602#action_12748602 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------

Regis, good call on the patch. You could simplify it slightly more by not synchronizing on the keyLock, since that's already held by the caller. Or just make the field package-private.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12748663#action_12748663 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------

Merging the two loops is clever, I dig.

But I'd prefer not to count numReadable and numWritable as-we-go. We'd have to track which ways the keys changed, which seems more complex than necessary. As is, the current loop is certainly not a bottleneck; we're already iterating through the keys several times.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760205#action_12760205 ] 

Tim Ellison commented on HARMONY-6312:
--------------------------------------

(Any chance you guys can move this conversation to the dev list?  It will be easier to follow and you'll likely get more interest in the discussion.)

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757843#action_12757843 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------

It's really my fault. I'd intended to get to the patches sooner, but I've been caught up in unrelated work. I'll give the latest stuff a look through on Monday, and report back here. Sorry for the delay guys. If it's any consolation, I've fixed a number of ZIP issues that I'm preparing to send upstream!

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch, selector.zip
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (HARMONY-6312) Concurrency problems in NIO

Posted by "Mark Hindess (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Hindess reassigned HARMONY-6312:
-------------------------------------

    Assignee: Regis Xu  (was: Mark Hindess)

Regis, what was the hurry that you couldn't ask why I had not applied the patches?  I had a good reason and I was also trying to give Jesse plenty of time to review your changes.


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch, selector.zip
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759321#action_12759321 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------

I've finally had time to take a look at this issue.

>From Regis' August 28 email to our dev@ list: "The more registered channels, the slower prepareChannels, even more, we have to travel the whole set more than once! Current implementation maintains several mapping to avoid this. So do you have any data to prove this patch is good as old one when large number of channels are registered?"

I benchmarked this code to test whether the mappings are worthwhile. The benchmark (which I'll attach) executes the following pseudocode:
  Create N pipes.
  Create a direct buffer of size X.
  while (true) {
    Register/deregister a random subset of the 2N channels (source and sink of N pipes).
    Select
    Read or write as much data as possible to/from the buffer
  }

Because of the many, many moving parts, there was a high amount of variance in this benchmark. Here's some typical results from my desktop:
  32 Pipes
    RI: 7.3ms per KB
    Hy with mappings: 14.3ms per KB
    Hy no mappings: 14.3ms per KB
  512 Pipes
    RI: 12.2ms per KB
    Hy with mappings: 21.9ms per KB
    Hy no mappings: 21.0ms per KB

Aside from the fact that DRLVM+working_classlib takes twice as long as the RI, the mappings yield no performance improvement and are not worth the additional complexity. Furthermore, the mappings will have a negative impact on performance for platforms where memory is constrained or garbage collection is slow (ie. embedded). 

Therefore I'm going to prepare a patch to remove the mappings. Let me know if you see mistakes in this analysis or flaws in the benchmark.

Cheers,
Jesse

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760360#action_12760360 ] 

Jesse Wilson commented on HARMONY-6312:
---------------------------------------



>From a quick glance, this microbenchmark doesn't appear to test changes to
the selected keys set. Since that's the reason for maintaining the indices,
it doesn't feel like a representative benchmark.

That said, the benchmark does show that iterating the full keyset has its
cost.



There's only one other caller, so I'd prefer to just fix that.




Cool, and I agree that compartmentalized changes are good. Applying and
diffing six patches just seemed labour-intensive for what I think of as one
logical change.


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jesse Wilson updated HARMONY-6312:
----------------------------------

    Attachment: SelectorBenchmark.java

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, harmony_svn.html, harmony_svn_plus_patch_2009-08-19.html, NIO_Concurrency_issues.patch, ri.html, selector.zip, SelectorBenchmark.java
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757851#action_12757851 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

> your commit messages didn't mention the names of the patches (you used the 'Subject:' from the patch I think) you 
> committed which would make it easier for others to follow.
Agree, the patch named by what it did, but it still helpful to point out the exact name in commit message.

> In commit r817167, you applied your patch (0001...patch) which makes it look like your work but this change comes entirely 
> from the patch Jesse contributed so in reality it is his work.
I mentioned that in JIRA comments,  and I never claim they are my work. I apologize for not clarifying it in commit message.

> I would prefer (for the benefit of the project if we ever need to defend our work) that commits more accurately reflect the 
> origins of the code being committed. 
Agree.


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch, selector.zip
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12748644#action_12748644 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

Jesse, do you mean the lock in interestOpsNoCheck ? The method is also used by processSelectResult which doesn't synchronized on keyLock.

The new prepareChannels() is a little heavy than old code. It uses three loops, one count numReadable/Writeable, two consutruct readableFDs/writableFDs. The two construct loop can be merged to one:
<code>
            // populate the readable and writeable FDs, including the mock channel
            int r = 0;
            int w = 0;
            readableFDs[r] = sourcefd;
            readyKeys[r] = null;
            r++;
            for (SelectionKeyImpl key : mutableKeys) {
                int op = key.interestOpsNoCheck();
                FileDescriptor fd = ((FileDescriptorHandler) key.channel()).getFD();
                if ((ACCEPT_OR_READ & op) != 0) {
                    readableFDs[r] = fd;
                    readyKeys[r] = key;
                    r++;
                }
                if ((CONNECT_OR_WRITE & op) != 0) {
                    writableFDs[w] = fd;
                    readyKeys[w + numReadable] = key;
                    w++;
                }
            }
</code>

And if we can count numReadable/Writeable correctly when changing interestOps and canceling keys, the counting loop can be saved.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757846#action_12757846 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

Sorry Mark, the patches has been for a long time and no one response the issue on dev-list, so I think I should push it a little :)
And I just committed 0001 and 0002, other patches are still in discussion, I didn't commit them.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch, selector.zip
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-6312) Concurrency problems in NIO

Posted by "Jesse Wilson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jesse Wilson updated HARMONY-6312:
----------------------------------

    Attachment: NIO_Concurrency_issues.patch

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>         Attachments: NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757848#action_12757848 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

Thanks Jesse, hope commits r817167 and r817169 are applied as you expected, if not, feel free to speak out.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch, selector.zip
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Mark Hindess (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757850#action_12757850 ] 

Mark Hindess commented on HARMONY-6312:
---------------------------------------

A long time?  You commented on the dev list on Sept 11th so it's only been a little over a week.  It took you 12 days (between Aug 27th and Sept 8th according to JIRA comments) to come up with the patches so allowing others at least that much time is not unreasonable.

I read the commit messages and I had read the patches so I know what you committed but your commit messages didn't mention the names of the patches (you used the 'Subject:' from the patch I think) you committed which would make it easier for others to follow.

However, the main problem I have is with respect to the origin of the work you are committing.  In commit r817167, you applied your patch (0001...patch) which makes it look like your work but this change comes entirely from the patch Jesse contributed so in reality it is his work.  I would prefer (for the benefit of the project if we ever need to defend our work) that commits more accurately reflect the origins of the code being committed.


> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Regis Xu
>         Attachments: cancelledkey.diff, NIO_Concurrency_issues.patch, selector.zip
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (HARMONY-6312) Concurrency problems in NIO

Posted by "Mark Hindess (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Hindess reassigned HARMONY-6312:
-------------------------------------

    Assignee: Mark Hindess

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6312) Concurrency problems in NIO

Posted by "Regis Xu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12748242#action_12748242 ] 

Regis Xu commented on HARMONY-6312:
-----------------------------------

I noticed there is time window between doCancel() and prepareChannels() in selectInternal, if other thread cancel keys to be selected in this window, may cause CancelledKeyException when calling key.interestOps() in prepareChannels(). That may also happen in processSelectResult. 

Maybe we can add a method to SelectionKey which get interestOps but doesn't check  validation, because there is no harm to select cancelled keys.  From spec:
"If any keys were added to the cancelled-key set while step (2) was in progress then they are processed as in step (1). "
so we must make sure returned selected key set doesn't contain cancelled key. I'll try to make a patch for this.

> Concurrency problems in NIO
> ---------------------------
>
>                 Key: HARMONY-6312
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6312
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: SVN Revision: 801399
>            Reporter: Jesse Wilson
>            Assignee: Mark Hindess
>         Attachments: NIO_Concurrency_issues.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> There's several potential concurrency problems in our NIO implementation...
>  - Charset#isSupported isn't synchronized, but it accesses mutable member cachedCharsetTable.
>  - In SelectionKeyImpl, stHash++ is a non-atomic operation so multiple SelectionKey instances may receive the same hash code. (Why not use the default hash code?)
>  - In SelectorImpl, the unmodifiableKeys member is never synchronized on. But the documentation specifies that clients can synchronize on that set to guard against changes
> These are the obvious problems; I suspect there are more subtle concurrency defects at play here. I'll prepare a patch to address the major issues, and we should consider a rigorous approach (Findbugs?) to discover concurrency problems.
> #Android

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.