Changeset 11213 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Nov 15, 2005, 5:45:12 PM (20 years ago)
Author:
ggaren
Message:

Reviewed by mjs.

  • Fixed <rdar://problem/4342216> Installer crash in KJS::ValueImp::marked() when garbage collector runs inside call to ConstantValues::init()

I took responsibility for initializing and marking ConstantValues away
from InterpreterImp, since it's possible to reference such a value
before any interpreter has been created and after the last interpreter
has been destroyed.

InterpreterImp::lock now initializes ConstantValues. It's a good
place for the initialization because you have to call it before
creating any objects. Since ::lock can be called more than once,
I added a check in ConstantValues::init to ensure that it executes
only once.

Collector:collect is now responsible for marking ConstantValues.

We no longer clear the ConstantValues since we can't guarantee that no
one has a reference to them.

FIXME: This is hackery. The long-term plan is to make ConstantValues
use immediate values that require no initialization.

  • ChangeLog:
  • kjs/collector.cpp: (KJS::Collector::collect):
  • kjs/internal.cpp: (KJS::InterpreterImp::InterpreterImp): (KJS::InterpreterImp::lock): (KJS::InterpreterImp::clear): (KJS::InterpreterImp::mark):
  • kjs/internal.h:
  • kjs/value.cpp: (KJS::ConstantValues::initIfNeeded):
  • kjs/value.h:
Location:
trunk/JavaScriptCore/kjs
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/collector.cpp

    r10713 r11213  
    404404    } while (scr != InterpreterImp::s_hook);
    405405  }
     406  ConstantValues::mark();
    406407
    407408  // MARK: first mark all referenced objects recursively starting out from the set of root objects
  • trunk/JavaScriptCore/kjs/internal.cpp

    r10713 r11213  
    435435InterpreterImp* InterpreterImp::s_hook = 0L;
    436436
    437 void InterpreterImp::globalInit()
    438 {
    439     ConstantValues::init();
    440 }
    441 
    442 void InterpreterImp::globalClear()
    443 {
    444     ConstantValues::clear();
    445 }
    446 
    447437typedef HashMap<ObjectImp *, InterpreterImp *, PointerHash<ObjectImp *> > InterpreterMap;
    448438
     
    470460    // This is the first interpreter
    471461    s_hook = next = prev = this;
    472     globalInit();
    473462  }
    474463
     
    488477{
    489478  lockInterpreter();
     479
     480  // FIXME: Hack-o-rama. To prevent construction of a global object with a null prototype (4342216),
     481  // we need to intialize our constants before the first object is constructed. InterpreterImp::lock()
     482  // is a good place to do this because you have to call it before doing any allocations. Once we change our
     483  // implementation to use immediate values, we should remove this code.
     484  ConstantValues::initIfNeeded();
    490485}
    491486
     
    639634    // This was the last interpreter
    640635    s_hook = 0L;
    641     globalClear();
    642636  }
    643637  interpreterMap().remove(global);
     
    646640void InterpreterImp::mark()
    647641{
    648   ConstantValues::mark();
    649642  if (m_interpreter)
    650643    m_interpreter->mark();
  • trunk/JavaScriptCore/kjs/internal.h

    r10757 r11213  
    247247    friend class Collector;
    248248  public:
    249     static void globalInit();
    250     static void globalClear();
    251 
    252249    InterpreterImp(Interpreter *interp, ObjectImp *glob);
    253250    ~InterpreterImp();
  • trunk/JavaScriptCore/kjs/value.cpp

    r10757 r11213  
    188188}
    189189
    190 void ConstantValues::init()
    191 {
     190void ConstantValues::initIfNeeded()
     191{
     192    if (undefined)
     193        return;
     194   
    192195    undefined = new UndefinedImp();
    193196    null = new NullImp();
     
    196199}
    197200
    198 void ConstantValues::clear()
    199 {
    200     undefined = NULL;
    201     null = NULL;
    202     jsTrue = NULL;
    203     jsFalse = NULL;
    204 }
    205 
    206201void ConstantValues::mark()
    207202{
  • trunk/JavaScriptCore/kjs/value.h

    r10757 r11213  
    197197    static AllocatedValueImp *jsTrue;
    198198
    199     static void init();
    200     static void clear();
     199    static void initIfNeeded();
    201200    static void mark();
    202201};
Note: See TracChangeset for help on using the changeset viewer.