Ignore:
Timestamp:
Sep 18, 2005, 11:57:28 PM (20 years ago)
Author:
mjs
Message:

Reviewed by Geoff.

  • fixed <rdar://problem/4214783> REGRESSION: kjs_fast_malloc crash due to lack of locking on multiple threads (seen selecting volumes in the installer)

Make sure to lock using the InterpreterLock class in all places that need it
(including anything that uses the collector, the parser, the protect count hash table,
and anything that allocates via fast_malloc).

Also added assertions to ensure that the locking rules are followed for the relevant
resources.

  • Makefile.am:
  • bindings/NP_jsobject.cpp: (identifierFromNPIdentifier): (_NPN_Invoke): (_NPN_Evaluate): (_NPN_GetProperty): (_NPN_SetProperty): (_NPN_RemoveProperty): (_NPN_HasProperty): (_NPN_HasMethod): (_NPN_SetException):
  • bindings/jni/jni_jsobject.cpp: (JSObject::call): (JSObject::eval): (JSObject::getMember): (JSObject::setMember): (JSObject::removeMember): (JSObject::getSlot): (JSObject::setSlot): (JSObject::toString): (JSObject::convertJObjectToValue):
  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject callWebScriptMethod:withArguments:]): (-[WebScriptObject evaluateWebScript:]): (-[WebScriptObject setValue:forKey:]): (-[WebScriptObject valueForKey:]): (-[WebScriptObject removeWebScriptKey:]): (-[WebScriptObject stringRepresentation]): (-[WebScriptObject webScriptValueAtIndex:]): (-[WebScriptObject setWebScriptValueAtIndex:value:]): (+[WebScriptObject _convertValueToObjcValue:KJS::originExecutionContext:Bindings::executionContext:Bindings::]):
  • bindings/runtime.cpp: (Instance::createRuntimeObject):
  • bindings/runtime_root.h:
  • bindings/testbindings.cpp: (main):
  • bindings/testbindings.mm: (main):
  • kjs/fast_malloc.cpp: (KJS::kjs_fast_malloc): (KJS::kjs_fast_calloc): (KJS::kjs_fast_free): (KJS::kjs_fast_realloc):
  • kjs/fast_malloc.h:
  • kjs/identifier.h:
  • kjs/internal.cpp: (InterpreterImp::InterpreterImp): (InterpreterImp::clear): (InterpreterImp::mark): (InterpreterImp::checkSyntax): (InterpreterImp::evaluate):
  • kjs/internal.h: (KJS::InterpreterImp::globalObject):
  • kjs/interpreter.cpp: (Interpreter::evaluate):
  • kjs/interpreter.h: (KJS::InterpreterLock::InterpreterLock): (KJS::InterpreterLock::~InterpreterLock):
  • kjs/nodes.h:
  • kjs/protect.h: (KJS::ProtectedValue::ProtectedValue): (KJS::ProtectedValue::~ProtectedValue): (KJS::ProtectedValue::operator=): (KJS::ProtectedObject::ProtectedObject): (KJS::ProtectedObject::~ProtectedObject): (KJS::ProtectedObject::operator=): (KJS::ProtectedReference::ProtectedReference): (KJS::ProtectedReference::~ProtectedReference): (KJS::ProtectedReference::operator=):
  • kjs/protected_object.h:
  • kjs/protected_values.cpp: (KJS::ProtectedValues::getProtectCount): (KJS::ProtectedValues::increaseProtectCount): (KJS::ProtectedValues::decreaseProtectCount):
  • kjs/string_object.cpp: (StringObjectImp::StringObjectImp):
  • kjs/testkjs.cpp: (main):
File:
1 edited

Legend:

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

    r10510 r10563  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    32 *  This file is part of the KDE libraries
     
    452451  // add this interpreter to the global chain
    453452  // as a root set for garbage collection
    454   lockInterpreter();
     453  InterpreterLock lock;
     454
    455455  m_interpreter = interp;
    456456  if (s_hook) {
     
    475475
    476476  recursion = 0;
    477   unlockInterpreter();
    478477}
    479478
     
    623622  //fprintf(stderr,"InterpreterImp::clear\n");
    624623  // remove from global chain (see init())
    625 #if APPLE_CHANGES
    626   lockInterpreter();
    627 #endif
     624  InterpreterLock lock;
     625
    628626  next->prev = prev;
    629627  prev->next = next;
     
    636634  }
    637635  InterpreterMap::removeInterpreterForGlobalObject(global);
    638 
    639 #if APPLE_CHANGES
    640   unlockInterpreter();
    641 #endif
    642636}
    643637
     
    649643  if (_context)
    650644    _context->mark();
     645  if (global)
     646      global->mark();
     647  if (globExec._exception)
     648      globExec._exception->mark();
    651649}
    652650
    653651bool InterpreterImp::checkSyntax(const UString &code)
    654652{
     653  InterpreterLock lock;
     654
    655655  // Parser::parse() returns 0 in a syntax error occurs, so we just check for that
    656656  SharedPtr<ProgramNode> progNode = Parser::parse(UString(), 0, code.data(),code.size(),0,0,0);
     
    660660Completion InterpreterImp::evaluate(const UString &code, ValueImp *thisV, const UString &sourceURL, int startingLineNumber)
    661661{
    662 #if APPLE_CHANGES
    663   lockInterpreter();
    664 #endif
     662  InterpreterLock lock;
     663
    665664  // prevent against infinite recursion
    666665  if (recursion >= 20) {
    667666#if APPLE_CHANGES
    668667    Completion result = Completion(Throw, Error::create(&globExec, GeneralError, "Recursion too deep"));
    669     unlockInterpreter();
    670668    return result;
    671669#else
     
    673671#endif
    674672  }
    675  
     673
    676674  // parse the source code
    677675  int sid;
     
    684682    bool cont = dbg->sourceParsed(&globExec, sid, sourceURL, code, errLine);
    685683    if (!cont)
    686 #if APPLE_CHANGES
    687       {
    688         unlockInterpreter();
    689         return Completion(Break);
    690       }
    691 #else
    692684      return Completion(Break);
    693 #endif
    694685  }
    695686 
     
    697688  if (!progNode) {
    698689    ObjectImp *err = Error::create(&globExec, SyntaxError, errMsg, errLine, sid, &sourceURL);
    699 #if APPLE_CHANGES
    700     unlockInterpreter();
    701 #endif
    702690    return Completion(Throw,err);
    703691  }
     
    728716    // execute the code
    729717    ContextImp ctx(globalObj, this, thisObj);
    730     ExecState newExec(m_interpreter,&ctx);
     718    ExecState newExec(m_interpreter, &ctx);
    731719    progNode->processVarDecls(&newExec);
    732720    res = progNode->execute(&newExec);
     
    735723  recursion--;
    736724
    737 #if APPLE_CHANGES
    738   unlockInterpreter();
    739 #endif
    740725  return res;
    741726}
Note: See TracChangeset for help on using the changeset viewer.