experiments/little-smalltalk/run.cc
changeset 436 f519b01f759b
parent 435 8cad65af7913
child 437 f3b04d3ef973
equal deleted inserted replaced
435:8cad65af7913 436:f519b01f759b
   112   uint8_t *__bytecode;
   112   uint8_t *__bytecode;
   113 
   113 
   114   Root *rootStack;
   114   Root *rootStack;
   115 
   115 
   116   primitive_handler_t primitiveTable[256];
   116   primitive_handler_t primitiveTable[256];
       
   117 
       
   118   static unsigned const methodCacheCount = 2039;
       
   119   static unsigned const methodCacheLimit = 3 * methodCacheCount;
       
   120   obj methodCache[methodCacheLimit];
   117 
   121 
   118   struct timespec mutatorStart;
   122   struct timespec mutatorStart;
   119 
   123 
   120   inline obj objClass(obj o) {
   124   inline obj objClass(obj o) {
   121     return isSmi(o) ? _Integer : *classAddr(o);
   125     return isSmi(o) ? _Integer : *classAddr(o);
   567   void sendMessage_i_j(obj c) {
   571   void sendMessage_i_j(obj c) {
   568     storeRegisters();
   572     storeRegisters();
   569     // cerr << "Sending " << bvString(_j) << " via " << className(c) << " to ";
   573     // cerr << "Sending " << bvString(_j) << " via " << className(c) << " to ";
   570     // print(cerr, slotAt(_i, 0));
   574     // print(cerr, slotAt(_i, 0));
   571     // cerr << endl;
   575     // cerr << endl;
   572     obj method = lookupMethod(c, _j);
   576     unsigned probe = ((((intptr_t) c) * 5 + ((intptr_t) _j)) % methodCacheCount) * 3;
       
   577     obj method;
       
   578     if ((methodCache[probe] == c) && (methodCache[probe + 1] == _j)) {
       
   579       method = methodCache[probe + 2];
       
   580     } else {
       
   581       method = lookupMethod(c, _j);
       
   582       methodCache[probe] = c;
       
   583       methodCache[probe + 1] = _j;
       
   584       methodCache[probe + 2] = method;
       
   585     }
   573     if (method == 0) {
   586     if (method == 0) {
   574       cerr << "DNU ";
   587       cerr << "DNU ";
   575       print(cerr, slotAt(_i, 0));
   588       print(cerr, slotAt(_i, 0));
   576       cerr << ' ';
   589       cerr << ' ';
   577       print(cerr, _j);
   590       print(cerr, _j);