Ignore:
Timestamp:
Dec 13, 2005, 3:06:10 AM (19 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Eric.

  • added a new HashCountedSet class for the common pattern of mapping items to counts that can change
  • kxmlcore/HashCountedSet.h: Added. (KXMLCore::HashCountedSet::*): Implemented, on top of HashMap.
  • kxmlcore/HashMap.h: (KXMLCore::HashMap::add): New method - does not replace existing value if key already present but otherwise like set(). (KXMLCore::HashMap::set): Improved comments.
  • kxmlcore/HashMapPtrSpec.h: (KXMLCore::HashMap::add): Added to specializations too.
  • JavaScriptCore.xcodeproj/project.pbxproj: Add new file.
  • kxmlcore/HashFunctions.h: Added include of stdint.h
  • replaced the custom hashtable for values protected from GC with HashCountedSet
  • kjs/collector.cpp: (KJS::Collector::protect): Moved code here from ProtectedValues::increaseProtectCount since the code is so simple now. (KJS::Collector::unprotect): Ditto for ProtectedValues::decreaseProtectCount. (KJS::Collector::markProtectedObjects): Updated for new way of doing things, now simpler and safer. (KJS::Collector::numReferencedObjects): ditto (KJS::Collector::rootObjectClasses): ditto
  • kjs/collector.h: Added protect and unprotect static methods
  • kjs/protect.h: (KJS::gcProtect): Updated for removal of ProtectedValues class (KJS::gcUnprotect): likewise
  • kjs/protected_values.cpp: Removed.
  • kjs/protected_values.h: Removed.

WebCore:

Reviewed by Eric.

  • updated for new HashCountedSet class
  • ForwardingHeaders/kxmlcore/HashCountedSet.h: Added forwarding header.
  • khtml/ecma/kjs_binding.cpp: Moved #define to disable pointer specialization higher in the file.
File:
1 edited

Legend:

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

    r11527 r11561  
    2525#include <kxmlcore/FastMalloc.h>
    2626#include <kxmlcore/FastMallocInternal.h>
     27#include <kxmlcore/HashCountedSet.h>
    2728#include "internal.h"
    2829#include "list.h"
     
    379380}
    380381
     382typedef HashCountedSet<JSCell *, PointerHash<JSCell *> > ProtectCounts;
     383
     384static ProtectCounts& protectedValues()
     385{
     386    static ProtectCounts pv;
     387    return pv;
     388}
     389
     390void Collector::protect(JSValue *k)
     391{
     392    assert(k);
     393    assert(JSLock::lockCount() > 0);
     394
     395    if (SimpleNumber::is(k))
     396      return;
     397
     398    protectedValues().insert(k->downcast());
     399}
     400
     401void Collector::unprotect(JSValue *k)
     402{
     403    assert(k);
     404    assert(JSLock::lockCount() > 0);
     405
     406    if (SimpleNumber::is(k))
     407      return;
     408
     409    protectedValues().remove(k->downcast());
     410}
     411
    381412void Collector::markProtectedObjects()
    382413{
    383   typedef ProtectedValues::KeyValue Entry;
    384   Entry *table = ProtectedValues::_table;
    385   Entry *end = table + ProtectedValues::_tableSize;
    386   for (Entry *entry = table; entry != end; ++entry) {
    387     JSCell *val = entry->key;
    388     if (val && !val->marked()) {
     414  ProtectCounts& pv = protectedValues();
     415  ProtectCounts::iterator end = pv.end();
     416  for (ProtectCounts::iterator it = pv.begin(); it != end; ++it) {
     417    JSCell *val = it->first;
     418    if (!val->marked())
    389419      val->mark();
    390     }
    391420  }
    392421}
     
    559588size_t Collector::numReferencedObjects()
    560589{
    561   size_t count = 0;
    562 
    563   size_t size = ProtectedValues::_tableSize;
    564   ProtectedValues::KeyValue *table = ProtectedValues::_table;
    565   for (size_t i = 0; i < size; i++) {
    566     JSCell *val = table[i].key;
    567     if (val) {
    568       ++count;
    569     }
    570   }
    571 
    572   return count;
     590  return protectedValues().size();
    573591}
    574592
     
    607625const void *Collector::rootObjectClasses()
    608626{
     627  // FIXME: this should be a HashSet (or maybe even CountedHashSet)
    609628  CFMutableSetRef classes = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks);
    610629
    611   int size = ProtectedValues::_tableSize;
    612   ProtectedValues::KeyValue *table = ProtectedValues::_table;
    613   for (int i = 0; i < size; i++) {
    614     JSCell *val = table[i].key;
    615     if (val) {
    616       CFStringRef name = CFStringCreateWithCString(NULL, className(val), kCFStringEncodingASCII);
    617       CFSetAddValue(classes, name);
    618       CFRelease(name);
    619     }
    620   }
    621  
     630  ProtectCounts& pv = protectedValues();
     631  ProtectCounts::iterator end = pv.end();
     632  for (ProtectCounts::iterator it = pv.begin(); it != end; ++it) {
     633    JSCell *val = it->first;
     634    CFStringRef name = CFStringCreateWithCString(NULL, className(val), kCFStringEncodingASCII);
     635    CFSetAddValue(classes, name);
     636    CFRelease(name);
     637  }
     638
    622639  return classes;
    623640}
Note: See TracChangeset for help on using the changeset viewer.