goops.mail 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From: Mikael Djurfeldt <mdj@mdj.nada.kth.se>
  2. Subject: Re: After GOOPS integration: Computation with native types!
  3. To: Keisuke Nishida <kxn30@po.cwru.edu>
  4. Cc: djurfeldt@nada.kth.se, guile@sourceware.cygnus.com
  5. Cc: djurfeldt@nada.kth.se
  6. Date: 17 Aug 2000 03:01:13 +0200
  7. Keisuke Nishida <kxn30@po.cwru.edu> writes:
  8. > Do I need to include some special feature in my VM? Hmm, but maybe
  9. > I shouldn't do that now...
  10. Probably not, so I probably shouldn't answer, but... :)
  11. You'll need to include some extremely efficient mechanism to do
  12. multi-method dispatch. The SCM_IM_DISPATCH form, with its
  13. implementation at line 2250 in eval.c, is the current basis for
  14. efficient dispatch in GOOPS.
  15. I think we should develop a new instruction for the VM which
  16. corresponds to the SCM_IM_DISPATCH form.
  17. This form serves both the purpose to map argument types to the correct
  18. code, and as a cache of compiled methods.
  19. Notice that I talk about cmethods below, not methods. In GOOPS, the
  20. GF has a set of methods, but each method has a "code-table" mapping
  21. argument types to code compiled for those particular concrete types.
  22. (So, in essence, GOOPS methods abstractly do a deeper level of type
  23. dispatch.)
  24. The SCM_IM_DISPATCH form has two shapes, depending on whether we use
  25. sequential search (few cmethods) or hashed lookup (many cmethods).
  26. Shape 1:
  27. (#@dispatch args N-SPECIALIZED #((TYPE1 ... ENV FORMALS FORM1 ...) ...) GF)
  28. Shape 2:
  29. (#@dispatch args N-SPECIALIZED HASHSET MASK
  30. #((TYPE1 ... ENV FORMALS FORM1 ...) ...)
  31. GF)
  32. `args' is (I hope!) a now historic obscure optimization.
  33. N-SPECIALIZED is the maximum number of arguments t do type checking
  34. on. This is used early termination of argument checking where the
  35. already checked arguments are enough to pick out the cmethod.
  36. The vector is the cache proper.
  37. During sequential search the argument types are simply checked against
  38. each entry.
  39. The method for hashed dispatch is described in:
  40. http://www.parc.xerox.com/csl/groups/sda/publications/papers/Kiczales-Andreas-PCL
  41. In this method, each class has a hash code. Dispatch means summing
  42. the hash codes for all arguments (up til N-SPECIALIZED) and using the
  43. sum to pick a location in the cache. The cache is sequentially
  44. searched for an argument type match from that point.
  45. Kiczales introduced a clever method to maximize the probability of a
  46. direct cache hit. We actually have 8 separate sets of hash codes for
  47. all types. The hash set to use is selected specifically per GF and is
  48. optimized to give fastest average hit.
  49. What we could try to do as soon as the VM is complete enough is to
  50. represent the cmethods as chunks of byte code. In the current GOOPS
  51. code, the compilation step (which is currently empty) is situated in
  52. `compile-cmethod' in guile-oops/compile.scm. [Apologies for the
  53. terrible code. That particular part was written at Arlanda airport
  54. after a sleepless night (packing luggage, not coding), on my way to
  55. visit Marius (who, BTW, didn't take GOOPS seriously. ;-)]