Changeset 230566 in webkit


Ignore:
Timestamp:
Apr 12, 2018 6:40:57 AM (6 years ago)
Author:
Kocsen Chung
Message:

Cherry-pick r227692. rdar://problem/39337417

We should only append ParserArenaDeletable pointers to ParserArena::m_deletableObjects.
https://bugs.webkit.org/show_bug.cgi?id=182180
<rdar://problem/36460697>

Reviewed by Michael Saboff.

Some parser Node subclasses extend ParserArenaDeletable via multiple inheritance,
but not as the Node's first base class. ParserArena::m_deletableObjects is
expecting pointers to objects of the shape of ParserArenaDeletable. We ensure
this by allocating the Node subclass, and casting it to ParserArenaDeletable to
get the correct pointer to append to ParserArena::m_deletableObjects.

To simplify things, we introduce a JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED
(analogous to WTF_MAKE_FAST_ALLOCATED) for use in Node subclasses that extends
ParserArenaDeletable.

  • parser/NodeConstructors.h: (JSC::ParserArenaDeletable::operator new):
  • parser/Nodes.h:
  • parser/ParserArena.h: (JSC::ParserArena::allocateDeletable):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227692 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-605-branch/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-605-branch/Source/JavaScriptCore/ChangeLog

    r230537 r230566  
     12018-04-11  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r227692. rdar://problem/39337417
     4
     5    We should only append ParserArenaDeletable pointers to ParserArena::m_deletableObjects.
     6    https://bugs.webkit.org/show_bug.cgi?id=182180
     7    <rdar://problem/36460697>
     8   
     9    Reviewed by Michael Saboff.
     10   
     11    Some parser Node subclasses extend ParserArenaDeletable via multiple inheritance,
     12    but not as the Node's first base class.  ParserArena::m_deletableObjects is
     13    expecting pointers to objects of the shape of ParserArenaDeletable.  We ensure
     14    this by allocating the Node subclass, and casting it to ParserArenaDeletable to
     15    get the correct pointer to append to ParserArena::m_deletableObjects.
     16   
     17    To simplify things, we introduce a JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED
     18    (analogous to WTF_MAKE_FAST_ALLOCATED) for use in Node subclasses that extends
     19    ParserArenaDeletable.
     20   
     21    * parser/NodeConstructors.h:
     22    (JSC::ParserArenaDeletable::operator new):
     23    * parser/Nodes.h:
     24    * parser/ParserArena.h:
     25    (JSC::ParserArena::allocateDeletable):
     26   
     27   
     28   
     29    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     30
     31    2018-01-26  Mark Lam  <mark.lam@apple.com>
     32
     33            We should only append ParserArenaDeletable pointers to ParserArena::m_deletableObjects.
     34            https://bugs.webkit.org/show_bug.cgi?id=182180
     35            <rdar://problem/36460697>
     36
     37            Reviewed by Michael Saboff.
     38
     39            Some parser Node subclasses extend ParserArenaDeletable via multiple inheritance,
     40            but not as the Node's first base class.  ParserArena::m_deletableObjects is
     41            expecting pointers to objects of the shape of ParserArenaDeletable.  We ensure
     42            this by allocating the Node subclass, and casting it to ParserArenaDeletable to
     43            get the correct pointer to append to ParserArena::m_deletableObjects.
     44
     45            To simplify things, we introduce a JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED
     46            (analogous to WTF_MAKE_FAST_ALLOCATED) for use in Node subclasses that extends
     47            ParserArenaDeletable.
     48
     49            * parser/NodeConstructors.h:
     50            (JSC::ParserArenaDeletable::operator new):
     51            * parser/Nodes.h:
     52            * parser/ParserArena.h:
     53            (JSC::ParserArena::allocateDeletable):
     54
    1552018-04-10  Kocsen Chung  <kocsen_chung@apple.com>
    256
  • branches/safari-605-branch/Source/JavaScriptCore/parser/NodeConstructors.h

    r226851 r230566  
    3131    }
    3232
     33    template<typename T>
    3334    inline void* ParserArenaDeletable::operator new(size_t size, ParserArena& parserArena)
    3435    {
    35         return parserArena.allocateDeletable(size);
     36        return parserArena.allocateDeletable<T>(size);
    3637    }
    3738
  • branches/safari-605-branch/Source/JavaScriptCore/parser/Nodes.h

    r226851 r230566  
    114114        // ParserArenaDeletable objects are deleted when the arena is deleted.
    115115        // Clients must not call delete directly on such objects.
    116         void* operator new(size_t, ParserArena&);
    117     };
     116        template<typename T> void* operator new(size_t, ParserArena&);
     117    };
     118
     119#define JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED_IMPL(__classToNew) \
     120        void* operator new(size_t size, ParserArena& parserArena) \
     121        { \
     122            return ParserArenaDeletable::operator new<__classToNew>(size, parserArena); \
     123        }
     124
     125#define JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(__classToNew) \
     126    public: \
     127        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED_IMPL(__classToNew) \
     128    private: \
     129        typedef int __thisIsHereToForceASemicolonAfterThisMacro
    118130
    119131    class ParserArenaRoot {
     
    239251
    240252    class VariableEnvironmentNode : public ParserArenaDeletable {
     253        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(VariableEnvironmentNode);
    241254    public:
    242255        typedef DeclarationStacks::FunctionStack FunctionStack;
     
    14141427
    14151428    class BlockNode : public StatementNode, public VariableEnvironmentNode {
    1416     public:
    1417         using ParserArenaDeletable::operator new;
    1418 
     1429        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(BlockNode);
     1430    public:
    14191431        BlockNode(const JSTokenLocation&, SourceElements*, VariableEnvironment&, FunctionStack&&);
    14201432
     
    15371549
    15381550    class ForNode : public StatementNode, public VariableEnvironmentNode {
    1539     public:
    1540         using ParserArenaDeletable::operator new;
    1541 
     1551        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ForNode);
     1552    public:
    15421553        ForNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode*, VariableEnvironment&);
    15431554
     
    15541565   
    15551566    class EnumerationNode : public StatementNode, public ThrowableExpressionData, public VariableEnvironmentNode {
    1556     public:
    1557         using ParserArenaDeletable::operator new;
    1558 
     1567        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(EnumerationNode);
     1568    public:
    15591569        EnumerationNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*, VariableEnvironment&);
    15601570
     
    15691579   
    15701580    class ForInNode : public EnumerationNode {
     1581        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ForInNode);
    15711582    public:
    15721583        ForInNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*, VariableEnvironment&);
     
    15801591   
    15811592    class ForOfNode : public EnumerationNode {
     1593        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ForOfNode);
    15821594    public:
    15831595        ForOfNode(bool, const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*, VariableEnvironment&);
     
    16691681
    16701682    class TryNode : public StatementNode, public VariableEnvironmentNode {
    1671     public:
    1672         using ParserArenaDeletable::operator new;
    1673 
     1683        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(TryNode);
     1684    public:
    16741685        TryNode(const JSTokenLocation&, StatementNode* tryBlock, DestructuringPatternNode* catchPattern, StatementNode* catchBlock, VariableEnvironment& catchEnvironment, StatementNode* finallyBlock);
    16751686
     
    16851696    class ScopeNode : public StatementNode, public ParserArenaRoot, public VariableEnvironmentNode {
    16861697    public:
     1698        // ScopeNode is never directly instantiate. The life-cycle of its derived classes are
     1699        // managed using std::unique_ptr. Hence, though ScopeNode extends VariableEnvironmentNode,
     1700        // which in turn extends ParserArenaDeletable, we don't want to use ParserArenaDeletable's
     1701        // new for allocation.
     1702        using ParserArenaRoot::operator new;
    16871703
    16881704        ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, bool inStrictContext);
    16891705        ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, const SourceCode&, SourceElements*, VariableEnvironment&, FunctionStack&&, VariableEnvironment&, UniquedStringImplPtrSet&&, CodeFeatures, InnerArrowFunctionCodeFeatures, int numConstants);
    1690 
    1691         using ParserArenaRoot::operator new;
    16921706
    16931707        const SourceCode& source() const { return m_source; }
     
    18321846
    18331847    class ImportSpecifierListNode : public ParserArenaDeletable {
     1848        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ImportSpecifierListNode);
    18341849    public:
    18351850        typedef Vector<ImportSpecifierNode*, 3> Specifiers;
     
    19221937
    19231938    class ExportSpecifierListNode : public ParserArenaDeletable {
     1939        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ExportSpecifierListNode);
    19241940    public:
    19251941        typedef Vector<ExportSpecifierNode*, 3> Specifiers;
     
    19501966
    19511967    class FunctionMetadataNode final : public Node, public ParserArenaDeletable {
    1952     public:
    1953         using ParserArenaDeletable::operator new;
    1954 
     1968        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(FunctionMetadataNode);
     1969    public:
    19551970        FunctionMetadataNode(
    19561971            ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end,
     
    21212136
    21222137    class ClassExprNode final : public ExpressionNode, public VariableEnvironmentNode {
    2123     public:
    2124         using ParserArenaDeletable::operator new;
    2125 
     2138        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ClassExprNode);
     2139    public:
    21262140        ClassExprNode(const JSTokenLocation&, const Identifier&, const SourceCode& classSource,
    21272141            VariableEnvironment& classEnvironment, ExpressionNode* constructorExpresssion,
     
    21652179
    21662180    class ArrayPatternNode : public DestructuringPatternNode, public ThrowableExpressionData, public ParserArenaDeletable {
    2167     public:
    2168         using ParserArenaDeletable::operator new;
    2169 
     2181        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ArrayPatternNode);
     2182    public:
    21702183        ArrayPatternNode();
    21712184        enum class BindingType {
     
    21952208   
    21962209    class ObjectPatternNode : public DestructuringPatternNode, public ThrowableExpressionData, public ParserArenaDeletable {
    2197     public:
    2198         using ParserArenaDeletable::operator new;
    2199        
     2210        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ObjectPatternNode);
     2211    public:
    22002212        ObjectPatternNode();
    22012213        enum class BindingType {
     
    23132325
    23142326    class FunctionParameters : public ParserArenaDeletable {
     2327        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(FunctionParameters);
    23152328    public:
    23162329        FunctionParameters();
     
    24112424
    24122425    class SwitchNode : public StatementNode, public VariableEnvironmentNode {
    2413     public:
    2414         using ParserArenaDeletable::operator new;
    2415 
     2426        JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(SwitchNode);
     2427    public:
    24162428        SwitchNode(const JSTokenLocation&, ExpressionNode*, CaseBlockNode*, VariableEnvironment&, FunctionStack&&);
    24172429
  • branches/safari-605-branch/Source/JavaScriptCore/parser/ParserArena.h

    r206525 r230566  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#include "Identifier.h"
    3030#include <array>
     31#include <type_traits>
    3132#include <wtf/SegmentedVector.h>
    3233
     
    154155        }
    155156
     157        template<typename T, typename = std::enable_if_t<std::is_base_of<ParserArenaDeletable, T>::value>>
    156158        void* allocateDeletable(size_t size)
    157159        {
    158             ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(allocateFreeable(size));
     160            // T may extend ParserArenaDeletable via multiple inheritance, but not as T's first
     161            // base class. m_deletableObjects is expecting pointers to objects of the shape of
     162            // ParserArenaDeletable. We ensure this by allocating T, and casting it to
     163            // ParserArenaDeletable to get the correct pointer to append to m_deletableObjects.
     164            T* instance = static_cast<T*>(allocateFreeable(size));
     165            ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(instance);
    159166            m_deletableObjects.append(deletable);
    160             return deletable;
     167            return instance;
    161168        }
    162169
Note: See TracChangeset for help on using the changeset viewer.