Ignore:
Timestamp:
Dec 22, 2009, 2:05:17 PM (15 years ago)
Author:
[email protected]
Message:

Fix a couple of problems with UntypedPtrAndBitfield.

Reviewed by Sam Weinig.

Add a m_leaksPtr to reduce false positives from leaks in debug builds
(this isn't perfect because we'd like a solution for release builds,
but this is now at least as good as a PtrAndFlags would be).

Switch SmallStringsto use a regular string for the base, rather than
a static one. UntypedPtrAndBitfield assumes all strings are at least
8 byte aligned; this migt not be true of static strings. Shared buffers
are heap allocated, as are all UStringImpls other than static strings.
Static strings cannot end up being the owner string of substrings,
since the only static strings are length 0.

  • runtime/SmallStrings.cpp:

(JSC::SmallStringsStorage::SmallStringsStorage):

  • runtime/UStringImpl.h:

(JSC::UntypedPtrAndBitfield::UntypedPtrAndBitfield):
(JSC::UStringImpl::UStringImpl):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UStringImpl.h

    r52470 r52500  
    4545    UntypedPtrAndBitfield(void* ptrValue, uintptr_t bitValue)
    4646        : m_value(reinterpret_cast<uintptr_t>(ptrValue) | bitValue)
     47#ifndef NDEBUG
     48        , m_leaksPtr(ptrValue)
     49#endif
    4750    {
    4851        ASSERT(ptrValue == asPtr<void*>());
     
    7376    static const uintptr_t s_alignmentMask = ~static_cast<uintptr_t>(0x7);
    7477    uintptr_t m_value;
     78#ifndef NDEBUG
     79        void* m_leaksPtr; // Only used to allow tools like leaks on OSX to detect that the memory is referenced.
     80#endif
    7581};
    7682
     
    217223        , m_dataBuffer(base.releaseRef(), BufferSubstring)
    218224    {
     225        // Do use static strings as a base for substrings; UntypedPtrAndBitfield assumes
     226        // that all pointers will be at least 8-byte aligned, we cannot guarantee that of
     227        // UStringImpls that are not heap allocated.
     228        ASSERT(m_dataBuffer.asPtr<UStringImpl*>()->size());
     229        ASSERT(!m_dataBuffer.asPtr<UStringImpl*>()->isStatic());
    219230        checkConsistency();
    220231    }
Note: See TracChangeset for help on using the changeset viewer.