You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Anatoli Kazatchkov (JIRA)" <ji...@apache.org> on 2009/01/30 03:56:59 UTC

[jira] Created: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
--------------------------------------------------------------------------------------

                 Key: FELIX-908
                 URL: https://issues.apache.org/jira/browse/FELIX-908
             Project: Felix
          Issue Type: Improvement
          Components: Framework
    Affects Versions: felix-1.2.1

            Reporter: Anatoli Kazatchkov
            Priority: Minor
         Attachments: bundle_info.patch

Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Resolved: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Posted by "Richard S. Hall (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-908?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Richard S. Hall resolved FELIX-908.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: felix-1.6.0
         Assignee: Richard S. Hall

I committed a patch to trunk to make access to bundle state volatile. Please close this issue if you are satisfied.

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Assignee: Richard S. Hall
>            Priority: Minor
>             Fix For: felix-1.6.0
>
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Commented: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Posted by "Karl Pauls (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12668803#action_12668803 ] 

Karl Pauls commented on FELIX-908:
----------------------------------

Making the member volatile and removing the synchronization is fine in this case (we only have on writer at a time). 

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Priority: Minor
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Updated: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

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

Anatoli Kazatchkov updated FELIX-908:
-------------------------------------

    Attachment: bundle_info.patch

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Priority: Minor
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Commented: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12668851#action_12668851 ] 

Felix Meschberger commented on FELIX-908:
-----------------------------------------

Thanks Stuart to enlighten (and correct) me.

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Priority: Minor
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Commented: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Posted by "Richard S. Hall (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12669121#action_12669121 ] 

Richard S. Hall commented on FELIX-908:
---------------------------------------

Out of curiosity, what scenario is causing Bundle.getState() to get invoked so often?

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Priority: Minor
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Commented: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12668798#action_12668798 ] 

Felix Meschberger commented on FELIX-908:
-----------------------------------------

IIRC assignment of an int is an atomic operation (in contrast to long assignment which is not atomic), so synchronization is not required at, either the state field has the new or the old value, but never something in-between.

Also IIRC, the handling of volatile fields has changed with the Java 5 memory model. So using a volatile field here might create an implicit dependency on Java 5, right ?

I may be completely wrong here ;-)

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Priority: Minor
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Commented: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Posted by "Stuart McCulloch (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12668800#action_12668800 ] 

Stuart McCulloch commented on FELIX-908:
----------------------------------------

A plain int field is still different from a volatile int, because in the Java Memory Model different threads could see different values in the same int field because of caching, etc. (of course in reality this might never happen, it depends on the actual architecture of the OS, etc.) Marking a field as volatile implies a memory fence, and also stops the JIT from re-ordering statements, which could also break assumptions about the field. So there is a difference, but it's not always obvious.

Pre-Java 5 this was all a bit of a mess, and many JVMs didn't support volatile longs properly - with Java 5 things are much better, and the semantics are cleaner.
See http://jeremymanson.blogspot.com/2008/11/what-volatile-means-in-java.html for a nice overview and http://gee.cs.oswego.edu/dl/jmm/cookbook.html for the gory details :)

Getting back to the issue, using volatile doesn't imply a dependency on Java 5 - unless you're relying on specific assumptions (like the double-checked locking idiom). We already use volatile in other places in Felix that have high contention, the question here is whether using volatile will break the bundle state machine - will need to look more closely at this code to be sure. ie. if only one thread is writing to the state and all other threads read it then volatile is fine, the problem is if two or more threads need to both read and write to it concurrently.

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Priority: Minor
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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


[jira] Commented: (FELIX-908) Unsynchronize access to bundle state inside BundleInfo by making the variable volatile

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12669133#action_12669133 ] 

Don Brown commented on FELIX-908:
---------------------------------

The cause is how our plugin system interacts with OSGi, not so much as a technical requirement but legacy design decision.  There are a number of situations where the plugin system will iterate through every plugin (which may or may not be an OSGi bundle) looking for something, with the first call going to isEnabled(), where the bundle state check happens for OSGi plugins.

> Unsynchronize access to bundle state inside BundleInfo by making the variable volatile
> --------------------------------------------------------------------------------------
>
>                 Key: FELIX-908
>                 URL: https://issues.apache.org/jira/browse/FELIX-908
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-1.2.1

>            Reporter: Anatoli Kazatchkov
>            Priority: Minor
>         Attachments: bundle_info.patch
>
>
> Synchronized access to bundle state inside {{BundleInfo}} class creates an unnecessary contention point in environments where {{bundle.getState()}} is called a lot.
> Declaring {{m_state}} variable volatile and removing synchronization from {{setState()}} and {{getState()}} will do the trick.I will attach the patch.

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