You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Wendy Feng (JIRA)" <ji...@apache.org> on 2010/09/19 04:28:33 UTC

[jira] Created: (HARMONY-6653) Use instance lock to protect static share data in ObjID.java

Use instance lock to protect static share data in ObjID.java
------------------------------------------------------------

                 Key: HARMONY-6653
                 URL: https://issues.apache.org/jira/browse/HARMONY-6653
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
    Affects Versions: 6.0M1
         Environment: Window XP
            Reporter: Wendy Feng


I found unsafe synchonrization in ObjID.java as follow:

private static class NumberGenerator {
 static long numCounter = 65536; 
...
synchronized long nextLong() {
            return useRandom ? sGenerator.nextLong() : numCounter++;
        }
...
}

numCounter is a static class field. querySerialNumber increment (non-atomic) operation is in a synchronized method which means it is protected by "this".

Consequence: 
Different object instances will synchronize on different "this", numCounter increment is not protected by a uniform lock. It results in race condition in numCounter increment, thus having incorrect numCounter value.

It would be more proper to write the code as follows:
private static class NumberGenerator {
 static long numCounter = 65536; 
private static final Object monitor = new Object()
...
long nextLong() {
            synchornized(monitor)
                {
                    return useRandom ? sGenerator.nextLong() : numCounter++;
                  }
        }
...
}


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


[jira] Commented: (HARMONY-6653) Use instance lock to protect static share data in ObjID.java

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

Hudson commented on HARMONY-6653:
---------------------------------

Integrated in Harmony-select-1.5-head-linux-x86_64 #115 (See [https://hudson.apache.org/hudson/job/Harmony-select-1.5-head-linux-x86_64/115/])
    Apply fix for HARMONY-6653 (Use instance lock to protect static share data in ObjID.jav)


> Use instance lock to protect static share data in ObjID.java
> ------------------------------------------------------------
>
>                 Key: HARMONY-6653
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6653
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 6.0M1
>         Environment: Window XP
>            Reporter: Wendy Feng
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> I found unsafe synchonrization in ObjID.java as follow:
> private static class NumberGenerator {
>  static long numCounter = 65536; 
> ...
> synchronized long nextLong() {
>             return useRandom ? sGenerator.nextLong() : numCounter++;
>         }
> ...
> }
> numCounter is a static class field. querySerialNumber increment (non-atomic) operation is in a synchronized method which means it is protected by "this".
> Consequence: 
> Different object instances will synchronize on different "this", numCounter increment is not protected by a uniform lock. It results in race condition in numCounter increment, thus having incorrect numCounter value.
> It would be more proper to write the code as follows:
> private static class NumberGenerator {
>  static long numCounter = 65536; 
> private static final Object monitor = new Object()
> ...
> long nextLong() {
>             synchornized(monitor)
>                 {
>                     return useRandom ? sGenerator.nextLong() : numCounter++;
>                   }
>         }
> ...
> }

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


[jira] Resolved: (HARMONY-6653) Use instance lock to protect static share data in ObjID.java

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

Tim Ellison resolved HARMONY-6653.
----------------------------------

         Assignee: Tim Ellison
    Fix Version/s: 5.0M16
       Resolution: Fixed

Thanks Wendy.

Fix applied to RMI module at repo revision r999623.

Please verify it was fixed as you expected.


> Use instance lock to protect static share data in ObjID.java
> ------------------------------------------------------------
>
>                 Key: HARMONY-6653
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6653
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 6.0M1
>         Environment: Window XP
>            Reporter: Wendy Feng
>            Assignee: Tim Ellison
>             Fix For: 5.0M16
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> I found unsafe synchonrization in ObjID.java as follow:
> private static class NumberGenerator {
>  static long numCounter = 65536; 
> ...
> synchronized long nextLong() {
>             return useRandom ? sGenerator.nextLong() : numCounter++;
>         }
> ...
> }
> numCounter is a static class field. querySerialNumber increment (non-atomic) operation is in a synchronized method which means it is protected by "this".
> Consequence: 
> Different object instances will synchronize on different "this", numCounter increment is not protected by a uniform lock. It results in race condition in numCounter increment, thus having incorrect numCounter value.
> It would be more proper to write the code as follows:
> private static class NumberGenerator {
>  static long numCounter = 65536; 
> private static final Object monitor = new Object()
> ...
> long nextLong() {
>             synchornized(monitor)
>                 {
>                     return useRandom ? sGenerator.nextLong() : numCounter++;
>                   }
>         }
> ...
> }

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


[jira] Commented: (HARMONY-6653) Use instance lock to protect static share data in ObjID.java

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

Hudson commented on HARMONY-6653:
---------------------------------

Integrated in Harmony-1.5-head-linux-x86_64 #956 (See [https://hudson.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/956/])
    Apply fix for HARMONY-6653 (Use instance lock to protect static share data in ObjID.jav)


> Use instance lock to protect static share data in ObjID.java
> ------------------------------------------------------------
>
>                 Key: HARMONY-6653
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6653
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 6.0M1
>         Environment: Window XP
>            Reporter: Wendy Feng
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> I found unsafe synchonrization in ObjID.java as follow:
> private static class NumberGenerator {
>  static long numCounter = 65536; 
> ...
> synchronized long nextLong() {
>             return useRandom ? sGenerator.nextLong() : numCounter++;
>         }
> ...
> }
> numCounter is a static class field. querySerialNumber increment (non-atomic) operation is in a synchronized method which means it is protected by "this".
> Consequence: 
> Different object instances will synchronize on different "this", numCounter increment is not protected by a uniform lock. It results in race condition in numCounter increment, thus having incorrect numCounter value.
> It would be more proper to write the code as follows:
> private static class NumberGenerator {
>  static long numCounter = 65536; 
> private static final Object monitor = new Object()
> ...
> long nextLong() {
>             synchornized(monitor)
>                 {
>                     return useRandom ? sGenerator.nextLong() : numCounter++;
>                   }
>         }
> ...
> }

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