28 Commits (3c42c64c14d912d5af31146d6dba435515b1defe)

Author SHA1 Message Date
David Chisnall abf629b1f7 Make some private symbols private. 7 years ago
David Chisnall a8e5f6ced0 Fix another bug in the hash table.
Clearing the secondMaps was incorrect for cases where the secondMaps
included a wrap around to the start of the table.
8 years ago
David Chisnall aa558900bd Fix an off-by-one error in the hash table.
When removing a hash entry that was in the cell assigned to its hash, we
would clear the first bit in the second maps.  If this entry was a
secondary value with the same hash, then this value became unreachable.

This very rarely showed up for two reasons.  First, most of the tables
are insert-only and so we never try to remove things from them.  Second,
it requires a particular sequence of inserts.  It occasionally caused
weak references to be susceptible to use after free.
8 years ago
David Chisnall 934cd13a7a Initial pass at Windows support.
All tests now pass with the new ABI on x86-64, with the new ABI.  Some
of the code is ugly and other platforms are probably broken.
8 years ago
Dustin L. Howett a0eec52bb8 fix a mismanagement of the hash table that could lead to data loss
This commit fixes a data loss bug in our hopscotch table implementation.
Removing values from the table can result in other values becoming
disconnected and lost.

Let A, B, and C be values that all hash to cell 0.
Assume the hopscotch distance factor H = 2.

   0     1     2
+-----+-----+-----+
|     |     |     |
+-----+-----+-----+

After adding A
   0     1     2
+-----+-----+-----+
|  A  |     |     |
+-----+-----+-----+
   |
   +-Neighbors =

After adding B
   0     1     2
+-----+-----+-----+
|  A  |  B  |     |
+-----+-----+-----+
   |
   +-Neighbors = 1

After adding C
   0     1     2
+-----+-----+-----+
|  A  |  B  |  C  |
+-----+-----+-----+
   |
   +-Neighbors = 1, 2

If we then remove B,
   0     1     2
+-----+-----+-----+
|  A  | [X] |  C  |
+-----+-----+-----+
   |
   +-Neighbors = 1, 2

* It is replaced with a placeholder [X].
* A's neighbor table is not updated to reflect the loss.

If we then remove A,
   0     1     2
+-----+-----+-----+
| [X] | [X] | [C] |
+-----+-----+-----+
   |
   +-Neighbors = 2

* The table is rebalanced to promote A's lowest neighbor to the primary
  cell position.
* C from cell 2 remains cell 0's neighbor.

The bug manifests if [X] the placeholder value passes the null check set
out in MAP_TABLE_VALUE_NULL; that is, the placeholder is "effectively
null".

Looking up the key that matches C will first evaluate its base cell, the
one that collided with the key in the first place. Since that is
placeholder [X], and [X] is "effectively null", the lookup stops.

C is never retrieved from the hash table.

---
The expedient solution to this bug is to update cell 0's neighbors when
B is first removed, effectively skipping the hole:

If we remove B as above,
   0     1     2
+-----+-----+-----+
|  A  | [X] |  C  |
+-----+-----+-----+
   |
   +-Neighbors = 2 <<< HERE

but clear the neighbor bit for cell 1, the promotion that happens when A
is later removed places C in cell 0.

   0     1     2
+-----+-----+-----+
|  C  | [X] | [X] |
+-----+-----+-----+
   |
   +-Neighbors =
8 years ago
David Chisnall 84c0bfe7b0 Fix two small bugs in the hopscotch hash that meant that moving elements near the end of the array sometimes caused them to become lost. 10 years ago
theraven d7df8c415b Move the selector table to being protected by a mutex for reads so that we can
recover memory from the smaller ones.  Selector lookups are not on the critical
path for message sends, so the cost of the extra memory is likely to be larger
than the cost of acquiring a lock in sel_getName().
13 years ago
theraven 6950cb8e55 A couple of small bug fixes. 14 years ago
theraven 85f1cd713e Tweak cleanup code. 14 years ago
theraven bc87ed22e1 Implemented support for __weak with ARC.
ARC functions are all now exposed in a header, but not yet documented.  See the ARC ABI spec for now:

http://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime
15 years ago
theraven ff1e691c3b And some more... 15 years ago
theraven 4ffb19230f Make sure that the statics used to store internal tables are marked as roots. 15 years ago
theraven 0c72e2e418 Use typed allocations for the hash table entries. This makes sure that the GC won't treat the jump table bitfield as a pointer.
Store the refcount structures inside the hash table, rather than in a chained structure.  This uses less space and should be easier for the GC to scan (less cache used).
15 years ago
theraven 2d9f41aa94 If we're linking against Boehm GC, then we may as well allow it to collect the runtime's hash tables, rather than doing that manually. 15 years ago
theraven af90153d7f And fix the same bug in the other place. 15 years ago
theraven b9f9ce3bba Fix missing UNLOCK() in hash table. 15 years ago
theraven 8db63b976f Initial work on developer mode (allows classes to be replaced at run time with new versions, by cooperating IDEs). This support is part of ongoing work to provide fix-and-continue functionality with Clang / Cling and LanguageKit. 15 years ago
theraven 7f6f798074 Rewrote some of the class table code to be slightly cleaner. 16 years ago
theraven 2d84b96a72 Tidied up some bits by creating private headers for private data structures.
Imported selector table code frm the Étoilé runtime.  We can now make dispatch type dependent with a -D switch.  Not enabled yet, but it will be enabled in a warning mode soon - I consider preferable to the existing GNU and Apple solution of corrupting the stack.
16 years ago
theraven bfbd52709b Fixed off-by-one error in hash table enumerator, which was causing one class to fail to be resolved. 16 years ago
rfm 5786a73e46 I'm pretty sure that, when resizing a table, we want to copy the non-null nodes rather than the null ones. 16 years ago
theraven 81f0c58a86 Fixed const warning. 16 years ago
theraven 7c03c0d3f1 Fixed double-free problems in GCKit. Fixed removal from hash tables. Added enumerator helper for when you remove objects from a map while enumerating. Removed tracing statements that were identifying bugs that have now been fixed. 16 years ago
theraven 8642bf7b8d Fixed statement order in hash_table.h 16 years ago
theraven 5b1911b4f4 Initial commit of GCKit (moved from Étoilé and the missing 90% mostly implemented). GCKit implements cycle detection on the heap and tracing on the stack and designated heap regions, with support for weak references. It is designed for implementing OS X 10.5-compatible GC semantics.
Although GCKit is mostly finished, it is still not well tested.  It contains bugs, and possibly dragons.  Do not use it.  If you disregard this advice, do not file any bug reports.  If you disregard this instruction, then I will point and laugh at you.
16 years ago
theraven c1a637a990 Allowed hash tables to dynamically resize. This uses toydispatch to free the old version of the table after copying all of the data into the new one, after waiting enough time to allow all potential readers to finish. There are theoretical cases when this can fail, but hopefully no practical ones. The theoretical cases can be removed by making the garbage thread run at a lower priority than all of the other threads in the system.
The protocols table and the class table will now grow as required.  Protocols are now added to the protocols table as they are created, so you should get something sensible and introspectable back when you look up a protocol by name.
16 years ago
theraven 8310615a7c Bug fixes in hash_table.h 16 years ago
theraven bdf97cf64e Added hopscotch table implementation and rewrote the class table to use it. This is done so that the class table and protocol tables can share the same code (currently there is no protocol table).
Note that concurrent resizing has not yet been implemented.  That means that there is a hard limit on the number of classes that can be loaded.  This is currently set to quite a small number for testing, to stress the hash table.  If you're experiencing problems as a result, then please let me know and I will increase it.
16 years ago