RFR: 8011760 assert(delta != 0) failed: dup pointer in MemBaseline::malloc_sort_by_addr

Daniel D. Daugherty daniel.daugherty at oracle.com
Wed Jul 10 06:34:53 PDT 2013


On 7/10/13 6:58 AM, David Holmes wrote:
> On 10/07/2013 9:38 PM, Zhengyu Gu wrote:
>> Hi David,
>>
>> On 7/10/2013 12:45 AM, David Holmes wrote:
>>> On 9/07/2013 3:23 AM, Zhengyu Gu wrote:
>>>> This is a simple fix to qsort's comparison function. The bug is
>>>> related to libc version, it only happens on Linux 32 bit with certain
>>>> versions of libc. The one I used to reproduce, is libc-2.11.1.so.
>>>>
>>>> Most of qsort algorithms do not compare element to itself, but
>>>> apparently it is not the case with certain version of Linux 32 libc
>>>> implementation.
>>>
>>> Sorry but I don't get it. You are asserting that the
>>> pointers/addresses should be distinct but you skip the assert if they
>>> are equal ???
>>>
>>>   int MemBaseline::malloc_sort_by_addr(const void* p1, const void* 
>>> p2) {
>>>     assert(MemTracker::is_on(), "Just check");
>>>     const MemPointerRecord* mp1 = (const MemPointerRecord*)p1;
>>>     const MemPointerRecord* mp2 = (const MemPointerRecord*)p2;
>>>     int delta = UNSIGNED_COMPARE(mp1->addr(), mp2->addr());
>>> !   assert(p1 == p2 || delta != 0, "dup pointer");
>>>     return delta;
>>>   }
>>>
>>> And is there some case where delta==0 but p1 != p2 ?
>>>
>> No, it should not. The snapshot contains "live" malloc records, which
>> memory block addresses have to be unique.
>>
>> This is the comparison function passed to qsort, most qsort
>> implementations do not compare an element to itself, so there will not
>> be p1 == p2. But on Linux x86 with some versions of libc, there are
>> exceptions.
>
> Okay now I get it. You want the assert to fire if p1 != p2 but 
> p1->addr() == p2->addr()

Exactly right on the assert.

Another way to do this fix would have been:

int MemBaseline::malloc_sort_by_addr(const void* p1, const void* p2) {
     assert(MemTracker::is_on(), "Just check");
     if (p1 == p2) {
       // matching objects so nothing to do
       return 0;
     }

but that would have changed non-assert code so increased the
risk for an HSX-24 fix.

Dan


>
> Thanks,
> David
>
>>
>> p1 and p2 are NOT pointers to real malloc addresses, they are pointers
>> to malloc bookkeeping record MemPointerRecord. mp1->addr() and
>> mp2->addr() are the real malloc addresses.
>>
>> Thanks,
>>
>> -Zhengyu
>>
>>> Thanks,
>>> David
>>>
>>>>
>>>> JBS:   https://jbs.oracle.com/bugs/browse/JDK-8011760
>>>> Public bug: not available
>>>> Webrev:  http://cr.openjdk.java.net/~zgu/8011760/webrev.00/
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> -Zhengyu
>>>>
>>



More information about the hotspot-runtime-dev mailing list