Changeset 166013 in webkit


Ignore:
Timestamp:
Mar 20, 2014 4:08:30 PM (10 years ago)
Author:
fpizlo@apple.com
Message:

Implement stackmap header version check and support new stackmap formats
https://bugs.webkit.org/show_bug.cgi?id=130535
<rdar://problem/16164284>

Reviewed by Geoffrey Garen.

Add the notion of versioning so that LLVMers can happily implement new stackmap formats
without worrying about WebKit getting version-locked to LLVM. In the future, we will have
to implement parsing for a new LLVM stackmap format before it lands in LLVM, or we'll have
to have a "max usable LLVM revision" limit. But, thanks to versioning, we'll always be
happy to move backward in time to older versions of LLVM.

  • ftl/FTLStackMaps.cpp:

(JSC::FTL::readObject):
(JSC::FTL::StackMaps::Constant::parse):
(JSC::FTL::StackMaps::StackSize::parse):
(JSC::FTL::StackMaps::Location::parse):
(JSC::FTL::StackMaps::Record::parse):
(JSC::FTL::StackMaps::parse):
(JSC::FTL::StackMaps::dump):
(JSC::FTL::StackMaps::dumpMultiline):

  • ftl/FTLStackMaps.h:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r165999 r166013  
     12014-03-20  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Implement stackmap header version check and support new stackmap formats
     4        https://bugs.webkit.org/show_bug.cgi?id=130535
     5        <rdar://problem/16164284>
     6
     7        Reviewed by Geoffrey Garen.
     8       
     9        Add the notion of versioning so that LLVMers can happily implement new stackmap formats
     10        without worrying about WebKit getting version-locked to LLVM. In the future, we will have
     11        to implement parsing for a new LLVM stackmap format before it lands in LLVM, or we'll have
     12        to have a "max usable LLVM revision" limit. But, thanks to versioning, we'll always be
     13        happy to move backward in time to older versions of LLVM.
     14
     15        * ftl/FTLStackMaps.cpp:
     16        (JSC::FTL::readObject):
     17        (JSC::FTL::StackMaps::Constant::parse):
     18        (JSC::FTL::StackMaps::StackSize::parse):
     19        (JSC::FTL::StackMaps::Location::parse):
     20        (JSC::FTL::StackMaps::Record::parse):
     21        (JSC::FTL::StackMaps::parse):
     22        (JSC::FTL::StackMaps::dump):
     23        (JSC::FTL::StackMaps::dumpMultiline):
     24        * ftl/FTLStackMaps.h:
     25
    1262014-03-20  Filip Pizlo  <fpizlo@apple.com>
    227
  • trunk/Source/JavaScriptCore/ftl/FTLStackMaps.cpp

    r163842 r166013  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3737
    3838template<typename T>
    39 T readObject(DataView* view, unsigned& offset)
     39T readObject(StackMaps::ParseContext& context)
    4040{
    4141    T result;
    42     result.parse(view, offset);
     42    result.parse(context);
    4343    return result;
    4444}
    4545
    46 void StackMaps::Constant::parse(DataView* view, unsigned& offset)
    47 {
    48     integer = view->read<int64_t>(offset, true);
     46void StackMaps::Constant::parse(StackMaps::ParseContext& context)
     47{
     48    integer = context.view->read<int64_t>(context.offset, true);
    4949}
    5050
     
    5454}
    5555
    56 void StackMaps::StackSize::parse(DataView* view, unsigned& offset)
    57 {
    58     functionOffset = view->read<uint32_t>(offset, true);
    59     size = view->read<uint32_t>(offset, true);
     56void StackMaps::StackSize::parse(StackMaps::ParseContext& context)
     57{
     58    switch (context.version) {
     59    case 0:
     60        functionOffset = context.view->read<uint32_t>(context.offset, true);
     61        size = context.view->read<uint32_t>(context.offset, true);
     62        break;
     63       
     64    default:
     65        functionOffset = context.view->read<uint64_t>(context.offset, true);
     66        size = context.view->read<uint64_t>(context.offset, true);
     67        break;
     68    }
    6069}
    6170
     
    6574}
    6675
    67 void StackMaps::Location::parse(DataView* view, unsigned& offset)
    68 {
    69     kind = static_cast<Kind>(view->read<uint8_t>(offset, true));
    70     size = view->read<uint8_t>(offset, true);
    71     dwarfRegNum = view->read<uint16_t>(offset, true);
    72     this->offset = view->read<int32_t>(offset, true);
     76void StackMaps::Location::parse(StackMaps::ParseContext& context)
     77{
     78    kind = static_cast<Kind>(context.view->read<uint8_t>(context.offset, true));
     79    size = context.view->read<uint8_t>(context.offset, true);
     80    dwarfRegNum = context.view->read<uint16_t>(context.offset, true);
     81    this->offset = context.view->read<int32_t>(context.offset, true);
    7382}
    7483
     
    8998}
    9099
    91 bool StackMaps::Record::parse(DataView* view, unsigned& offset)
    92 {
    93     int64_t id = view->read<int64_t>(offset, true);
     100bool StackMaps::Record::parse(StackMaps::ParseContext& context)
     101{
     102    int64_t id = context.view->read<int64_t>(context.offset, true);
    94103    ASSERT(static_cast<int32_t>(id) == id);
    95104    patchpointID = static_cast<uint32_t>(id);
     
    97106        return false;
    98107   
    99     instructionOffset = view->read<uint32_t>(offset, true);
    100     flags = view->read<uint16_t>(offset, true);
    101    
    102     unsigned length = view->read<uint16_t>(offset, true);
     108    instructionOffset = context.view->read<uint32_t>(context.offset, true);
     109    flags = context.view->read<uint16_t>(context.offset, true);
     110   
     111    unsigned length = context.view->read<uint16_t>(context.offset, true);
    103112    while (length--)
    104         locations.append(readObject<Location>(view, offset));
    105    
    106     unsigned numLiveOuts = view->read<uint16_t>(offset, true);
     113        locations.append(readObject<Location>(context));
     114   
     115    if (context.version >= 1)
     116        context.view->read<uint16_t>(context.offset, true); // padding
     117    unsigned numLiveOuts = context.view->read<uint16_t>(context.offset, true);
    107118    while (numLiveOuts--) {
    108         view->read<uint16_t>(offset, true); // regnum
    109         view->read<uint8_t>(offset, true); // reserved
    110         view->read<uint8_t>(offset, true); // size in bytes
     119        context.view->read<uint16_t>(context.offset, true); // regnum
     120        context.view->read<uint8_t>(context.offset, true); // reserved
     121        context.view->read<uint8_t>(context.offset, true); // size in bytes
     122    }
     123    if (context.version >= 1) {
     124        if (context.offset & 7) {
     125            ASSERT(!(context.offset & 3));
     126            context.view->read<uint32_t>(context.offset, true); // padding
     127        }
    111128    }
    112129   
     
    123140bool StackMaps::parse(DataView* view)
    124141{
    125     unsigned offset = 0;
    126    
    127     view->read<uint32_t>(offset, true); // Reserved (header)
    128    
    129     uint32_t numFunctions = view->read<uint32_t>(offset, true);
    130     ASSERT(numFunctions == 1); // There should only be one stack size record
    131     while (numFunctions--) {
    132         stackSizes.append(readObject<StackSize>(view, offset));
    133     }
    134    
    135     uint32_t numConstants = view->read<uint32_t>(offset, true);
     142    ParseContext context;
     143    context.offset = 0;
     144    context.view = view;
     145   
     146    version = context.version = context.view->read<uint8_t>(context.offset, true);
     147
     148    context.view->read<uint8_t>(context.offset, true); // Reserved
     149    context.view->read<uint8_t>(context.offset, true); // Reserved
     150    context.view->read<uint8_t>(context.offset, true); // Reserved
     151
     152    uint32_t numFunctions;
     153    uint32_t numConstants;
     154    uint32_t numRecords;
     155   
     156    numFunctions = context.view->read<uint32_t>(context.offset, true);
     157    if (context.version >= 1) {
     158        numConstants = context.view->read<uint32_t>(context.offset, true);
     159        numRecords = context.view->read<uint32_t>(context.offset, true);
     160    }
     161    while (numFunctions--)
     162        stackSizes.append(readObject<StackSize>(context));
     163   
     164    if (!context.version)
     165        numConstants = context.view->read<uint32_t>(context.offset, true);
    136166    while (numConstants--)
    137         constants.append(readObject<Constant>(view, offset));
    138    
    139     uint32_t numRecords = view->read<uint32_t>(offset, true);
     167        constants.append(readObject<Constant>(context));
     168   
     169    if (!context.version)
     170        numRecords = context.view->read<uint32_t>(context.offset, true);
    140171    while (numRecords--) {
    141172        Record record;
    142         if (!record.parse(view, offset))
     173        if (!record.parse(context))
    143174            return false;
    144175        records.append(record);
     
    150181void StackMaps::dump(PrintStream& out) const
    151182{
    152     out.print("StackSizes[", listDump(stackSizes), "], Constants:[", listDump(constants), "], Records:[", listDump(records), "]");
     183    out.print("Version:", version, ", StackSizes[", listDump(stackSizes), "], Constants:[", listDump(constants), "], Records:[", listDump(records), "]");
    153184}
    154185
    155186void StackMaps::dumpMultiline(PrintStream& out, const char* prefix) const
    156187{
     188    out.print(prefix, "Version: ", version, "\n");
    157189    out.print(prefix, "StackSizes:\n");
    158190    for (unsigned i = 0; i < stackSizes.size(); ++i)
  • trunk/Source/JavaScriptCore/ftl/FTLStackMaps.h

    r164424 r166013  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4040
    4141struct StackMaps {
     42    struct ParseContext {
     43        unsigned version;
     44        DataView* view;
     45        unsigned offset;
     46    };
     47   
    4248    struct Constant {
    4349        int64_t integer;
    4450       
    45         void parse(DataView*, unsigned& offset);
     51        void parse(ParseContext&);
    4652        void dump(PrintStream& out) const;
    4753    };
    4854
    4955    struct StackSize {
    50         uint32_t functionOffset;
    51         uint32_t size;
     56        uint64_t functionOffset;
     57        uint64_t size;
    5258
    53         void parse(DataView*, unsigned& offset);
     59        void parse(ParseContext&);
    5460        void dump(PrintStream&) const;
    5561    };
     
    7076        int32_t offset;
    7177       
    72         void parse(DataView*, unsigned& offset);
     78        void parse(ParseContext&);
    7379        void dump(PrintStream& out) const;
    7480       
     
    8490        Vector<Location> locations;
    8591       
    86         bool parse(DataView*, unsigned& offset);
     92        bool parse(ParseContext&);
    8793        void dump(PrintStream&) const;
    8894    };
    8995
     96    unsigned version;
    9097    Vector<StackSize> stackSizes;
    9198    Vector<Constant> constants;
Note: See TracChangeset for help on using the changeset viewer.