Ignore:
Timestamp:
Aug 10, 2009, 9:35:02 PM (16 years ago)
Author:
[email protected]
Message:

Stack overflow crash in JavaScript garbage collector mark pass
https://bugs.webkit.org/show_bug.cgi?id=12216

Reviewed by Gavin Barraclough and Sam Weinig

Make the GC mark phase iterative by using an explicit mark stack.
To do this marking any single object is performed in multiple stages

  • The object is appended to the MarkStack, this sets the marked bit for the object using the new markDirect() function, and then returns
  • When the MarkStack is drain()ed the object is popped off the stack and markChildren(MarkStack&) is called on the object to collect all of its children. drain() then repeats until the stack is empty.

Additionally I renamed a number of methods from 'mark' to 'markAggregate'
in order to make it more clear that marking of those object was not
going to result in an actual recursive mark.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSActivation.cpp

    r45609 r47022  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5050}
    5151
    52 void JSActivation::mark()
     52void JSActivation::markChildren(MarkStack& markStack)
    5353{
    54     Base::mark();
     54    Base::markChildren(markStack);
    5555
    5656    Register* registerArray = d()->registerArray.get();
     
    6060    size_t numParametersMinusThis = d()->functionBody->generatedBytecode().m_numParameters - 1;
    6161
    62     size_t i = 0;
    63     size_t count = numParametersMinusThis;
    64     for ( ; i < count; ++i) {
    65         Register& r = registerArray[i];
    66         if (!r.marked())
    67             r.mark();
    68     }
     62    size_t count = numParametersMinusThis;
     63    markStack.appendValues(registerArray, count);
    6964
    7065    size_t numVars = d()->functionBody->generatedBytecode().m_numVars;
    7166
    7267    // Skip the call frame, which sits between the parameters and vars.
    73     i += RegisterFile::CallFrameHeaderSize;
    74     count += RegisterFile::CallFrameHeaderSize + numVars;
    75 
    76     for ( ; i < count; ++i) {
    77         Register& r = registerArray[i];
    78         if (r.jsValue() && !r.marked())
    79             r.mark();
    80     }
     68    markStack.appendValues(registerArray + count + RegisterFile::CallFrameHeaderSize, numVars, MayContainNullValues);
    8169}
    8270
Note: See TracChangeset for help on using the changeset viewer.