Changeset 227721 in webkit


Ignore:
Timestamp:
Jan 28, 2018 9:08:13 PM (6 years ago)
Author:
fpizlo@apple.com
Message:

LargeAllocation should do the same distancing as MarkedBlock
https://bugs.webkit.org/show_bug.cgi?id=182226

Reviewed by Saam Barati.

This makes LargeAllocation do the same exact distancing that MarkedBlock promises to do.

To make that possible, this patch first makes MarkedBlock know exactly how much distancing it
is doing:

  • I've rationalized the payloadSize calculation. In particular, I made MarkedSpace use the calculation done in MarkedBlock. MarkedSpace used to do the math a different way. This keeps the old way just for a static_assert.


  • The promised amount of distancing is now codified in HeapCell.h as minimumDistanceBetweenCellsFromDifferentOrigins. We assert that the footer size is at least as big as this. I didn't want to just use footer size for this constant because then, if you increased the size of the footer, you'd also add padding to every large allocation.


Then this patch just adds minimumDistanceBetweenCellsFromDifferentOrigins to each large
allocation. It also zeroes that slice of memory to prevent any information leaks that way.

This is perf neutral. Large allocations start out at ~8000 bytes. The amount of padding is
~300 bytes. That's 3.75% space overhead for objects that are ~8000 bytes, zero overhead for
smaller objects, and diminishing overhead for larger objects. We allocate very few large
objects, so we shouldn't have any real space overhead from this.

  • heap/HeapCell.h:
  • heap/LargeAllocation.cpp:

(JSC::LargeAllocation::tryCreate):

  • heap/MarkedBlock.h:
  • heap/MarkedSpace.h:
Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r227718 r227721  
     12018-01-28  Filip Pizlo  <fpizlo@apple.com>
     2
     3        LargeAllocation should do the same distancing as MarkedBlock
     4        https://bugs.webkit.org/show_bug.cgi?id=182226
     5
     6        Reviewed by Saam Barati.
     7
     8        This makes LargeAllocation do the same exact distancing that MarkedBlock promises to do.
     9       
     10        To make that possible, this patch first makes MarkedBlock know exactly how much distancing it
     11        is doing:
     12       
     13        - I've rationalized the payloadSize calculation. In particular, I made MarkedSpace use the
     14          calculation done in MarkedBlock. MarkedSpace used to do the math a different way. This
     15          keeps the old way just for a static_assert.
     16       
     17        - The promised amount of distancing is now codified in HeapCell.h as
     18          minimumDistanceBetweenCellsFromDifferentOrigins. We assert that the footer size is at least
     19          as big as this. I didn't want to just use footer size for this constant because then, if
     20          you increased the size of the footer, you'd also add padding to every large allocation.
     21       
     22        Then this patch just adds minimumDistanceBetweenCellsFromDifferentOrigins to each large
     23        allocation. It also zeroes that slice of memory to prevent any information leaks that way.
     24       
     25        This is perf neutral. Large allocations start out at ~8000 bytes. The amount of padding is
     26        ~300 bytes. That's 3.75% space overhead for objects that are ~8000 bytes, zero overhead for
     27        smaller objects, and diminishing overhead for larger objects. We allocate very few large
     28        objects, so we shouldn't have any real space overhead from this.
     29
     30        * heap/HeapCell.h:
     31        * heap/LargeAllocation.cpp:
     32        (JSC::LargeAllocation::tryCreate):
     33        * heap/MarkedBlock.h:
     34        * heap/MarkedSpace.h:
     35
    1362018-01-27  Filip Pizlo  <fpizlo@apple.com>
    237
  • trunk/Source/JavaScriptCore/heap/HeapCell.h

    r226822 r227721  
    11/*
    2  * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3737class VM;
    3838struct CellAttributes;
     39
     40static constexpr unsigned minimumDistanceBetweenCellsFromDifferentOrigins = sizeof(void*) == 8 ? 304 : 288;
    3941
    4042class HeapCell {
  • trunk/Source/JavaScriptCore/heap/LargeAllocation.cpp

    r220291 r227721  
    11/*
    2  * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3636LargeAllocation* LargeAllocation::tryCreate(Heap& heap, size_t size, Subspace* subspace)
    3737{
    38     void* space = subspace->alignedMemoryAllocator()->tryAllocateAlignedMemory(alignment, headerSize() + size);
     38    // This includes padding at the end of the allocation to maintain the distancing constraint.
     39    constexpr size_t distancing = minimumDistanceBetweenCellsFromDifferentOrigins;
     40    size_t sizeBeforeDistancing = headerSize() + size;
     41    size_t sizeIncludingDistancing = sizeBeforeDistancing + distancing;
     42   
     43    void* space = subspace->alignedMemoryAllocator()->tryAllocateAlignedMemory(alignment, sizeIncludingDistancing);
    3944    if (!space)
    4045        return nullptr;
     46   
     47    // Make sure that the padding does not contain useful things.
     48    memset(static_cast<char*>(space) + sizeBeforeDistancing, 0, distancing);
     49   
    4150    if (scribbleFreeCells())
    4251        scribble(space, size);
  • trunk/Source/JavaScriptCore/heap/MarkedBlock.h

    r227718 r227721  
    286286        Bitmap<atomsPerBlock> m_newlyAllocated;
    287287    };
    288        
     288   
    289289private:   
    290290    Footer& footer();
     
    293293public:
    294294    static constexpr size_t endAtom = (blockSize - sizeof(Footer)) / atomSize;
    295 
     295    static constexpr size_t payloadSize = endAtom * atomSize;
     296    static constexpr size_t footerSize = blockSize - payloadSize;
     297
     298    static_assert(payloadSize == ((blockSize - sizeof(MarkedBlock::Footer)) & ~(atomSize - 1)), "Payload size computed the alternate way should give the same result");
     299    static_assert(footerSize >= minimumDistanceBetweenCellsFromDifferentOrigins, "Footer is not big enough to create the necessary distance between objects from different origins");
     300   
    296301    static MarkedBlock::Handle* tryCreate(Heap&, AlignedMemoryAllocator*);
    297302       
  • trunk/Source/JavaScriptCore/heap/MarkedSpace.h

    r227717 r227721  
    5656    static constexpr size_t preciseCutoff = 80;
    5757   
    58     // The amount of available payload in a block is the block's size minus the footer. But the
    59     // header size might not be atom size aligned, so we round down the result accordingly.
    60     static constexpr size_t blockPayload = (MarkedBlock::blockSize - sizeof(MarkedBlock::Footer)) & ~(MarkedBlock::atomSize - 1);
     58    // The amount of available payload in a block is the block's size minus the footer.
     59    static constexpr size_t blockPayload = MarkedBlock::payloadSize;
    6160   
    6261    // The largest cell we're willing to allocate in a MarkedBlock the "normal way" (i.e. using size
Note: See TracChangeset for help on using the changeset viewer.