Request for review: Race conditions in java.nio.charset.Charset

David Holmes - Sun Microsystems David.Holmes at Sun.COM
Thu Oct 8 10:59:54 UTC 2009


Hi Ulf,

Ulf Zibis said the following on 10/08/09 20:07:
> Am 08.10.2009 06:35, David Holmes - Sun Microsystems schrieb:
>> Ulf Zibis said the following on 10/08/09 08:58:
>>> For my better understanding:
>>> Can you explain me the real bug in 
>>> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6881442.
>>> In my understanding, loading the "name" field twice is too only a 
>>> performance bug. Please correct me!
>>
>> Class.getName() could in theory return null and this is not allowed, 
>> hence this was a functional correctness issue.
> 
> Hm, my problem is, I can't see any condition, how Class.getName() could 
> return null, except native method getName0() would return null.
> But if native getName0() could return null, I can't see how the new code 
> would prevent method Class.getName() from returning null.

It's a memory model issue. The code is like this:

      public String getName() {
          if (name == null)
             name = getName0();
          return name;
      }

but in theory, accoridng to the JMM experts, it could act as if it does 
this:

   public String getName() {
     String tmp1 = name; // sees null
     String tmp2 = name; // sees non-null
     if (tmp2 == null)
       tmp1 = name = getName0();
     return tmp1;
   }

imagine the temporaries are registers.

David



More information about the core-libs-dev mailing list