runtime 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. * The Mono runtime
  2. The Mono runtime engine is considered feature complete.
  3. It implements a Just-in-Time compiler engine for the CIL
  4. virtual machine, the class loader, the garbage collector,
  5. threading system and metadata access libraries.
  6. We currently have two runtimes:
  7. <ul>
  8. * <b>mono:</b> Our Just-in-Time and Ahead-of-Time code
  9. generator for maximum performance.
  10. * <b>mint:</b> The Mono interpreter. This is an
  11. easy-to-port runtime engine.
  12. </ul>
  13. We are using the Boehm conservative garbage collector.
  14. The Mono runtime can be used as a stand-alone process, or it
  15. can be <a href="embedded-api.html">embedded into applications</a> (see
  16. the documentation in mono/samples/embed for more details).
  17. Embedding the Mono runtime allows applications to be extended
  18. in C# while reusing all of the existing C and C++ code.
  19. Paolo Molaro did a presentation on the current JIT engine and
  20. the new JIT engine. You can find his <a
  21. href="http://primates.ximian.com/~lupus/slides/jit/">slides
  22. here</a>
  23. ** Current JIT Engine: technical details (<b>updated, June 28th, 2003</b>)
  24. We have re-written our JIT compiler. We wanted to support a
  25. number of features that were missing:
  26. <ul>
  27. * Ahead-of-time compilation.
  28. The idea is to allow developers to pre-compile their code
  29. to native code to reduce startup time, and the working
  30. set that is used at runtime in the just-in-time compiler.
  31. Although in Mono this has not been a visible problem, we
  32. wanted to pro-actively address this problem.
  33. When an assembly (a Mono/.NET executable) is installed in
  34. the system, it would then be possible to pre-compile the
  35. code, and have the JIT compiler tune the generated code
  36. to the particular CPU on which the software is
  37. installed.
  38. This is done in the Microsoft.NET world with a tool
  39. called ngen.exe
  40. * Have a good platform for doing code optimizations.
  41. The design called for a good architecture that would
  42. enable various levels of optimizations: some
  43. optimizations are better performed on high-level
  44. intermediate representations, some on medium-level and
  45. some at low-level representations.
  46. Also it should be possible to conditionally turn these on
  47. or off. Some optimizations are too expensive to be used
  48. in just-in-time compilation scenarios, but these
  49. expensive optimizations can be turned on for
  50. ahead-of-time compilations or when using profile-guided
  51. optimizations on a subset of the executed methods.
  52. * Reduce the effort required to port the Mono code
  53. generator to new architectures.
  54. For Mono to gain wide adoption in the Unix world, it is
  55. necessary that the JIT engine works in most of today's
  56. commercial hardware platforms.
  57. </ul>
  58. The JIT engine implements a number of optimizations:
  59. <ul>
  60. * Opcode cost estimates (our architecture allows
  61. us to generate different code paths depending
  62. on the target CPU dynamically).
  63. * Inlining.
  64. * Constant folding, copy propagation, dead code elimination.
  65. Although compilers typically do
  66. constant folding, the combination of inlining with
  67. constant folding gives some very good results.
  68. * Linear scan register allocation. In the past,
  69. register allocation was our achilles heel, but now
  70. we have left this problem behind.
  71. * SSA-based framework. Various optimizations are
  72. implemented on top of this framework
  73. </ul>
  74. There are a couple of books that deal with this technique: "A
  75. Retargetable C Compiler" and "Advanced Compiler Design and
  76. Implementation" are good references. You can also get a
  77. technical description of <a
  78. href="http://research.microsoft.com/copyright/accept.asp?path=http://www.research.microsoft.com/~drh/pubs/iburg.pdf&pub=ACM">lbrug</a>.
  79. The new JIT engines uses three intermediate representations:
  80. the source is the CIL which is transformed into a forest of
  81. trees; This is fed into a BURS instruction selector that
  82. generates the final low-level intermediate representation.
  83. The instruction selector is documented in the following
  84. papers:
  85. <ul>
  86. * <a href="http://research.microsoft.com/copyright/accept.asp?path=http://www.research.microsoft.com/~drh/pubs/interface.pdf&pub=wiley">A code generation interface for ANSI C</a>
  87. * <a href="http://research.microsoft.com/copyright/accept.asp?path=http://www.research.microsoft.com/~drh/pubs/iburg.pdf&pub=ACM">Engineering efficient code generators using tree matching and dynamic programming.</a>
  88. </ul>
  89. ** Garbage Collection
  90. We are using the Boehm conservative GC. We might consider
  91. adopting other GC engines in the future, like the Intel ORP GC
  92. engine. The Intel ORP GC engine as it provides a precise
  93. garbage collector engine, similar to what is available on the
  94. .NET environment.
  95. <ul>
  96. * Garbage collection list and FAQ:<br>
  97. <a href="http://www.iecc.com/gclist/">http://www.iecc.com/gclist/</a>
  98. * "GC points in a Threaded Environment":<br>
  99. <a href="http://research.sun.com/techrep/1998/abstract-70.html">
  100. http://research.sun.com/techrep/1998/abstract-70.html</a>
  101. * "A Generational Mostly-concurrent Garbage Collector":
  102. <a href="http://research.sun.com/techrep/2000/abstract-88.html">
  103. http://research.sun.com/techrep/2000/abstract-88.html</a>
  104. * Details on The Microsoft .NET Garbage Collection Implementation:<br>
  105. <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI.asp</a>
  106. <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI2.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI2.asp</a>
  107. </ul>
  108. ** IO and threading
  109. The ECMA runtime and the .NET runtime assume an IO model and a
  110. threading model that is very similar to the Win32 API.
  111. Dick Porter has developed WAPI: the Mono abstraction layer
  112. that allows our runtime to execute code that depend on this
  113. behaviour.
  114. ** Useful links
  115. Paolo Molaro found a few interesting links:
  116. <ul>
  117. * On compilation of stack-based languages:<br>
  118. <a href="http://www.complang.tuwien.ac.at/projects/rafts.html">
  119. http://www.complang.tuwien.ac.at/projects/rafts.html</a>
  120. * A paper on fast JIT compilation of a stack-based language:<br>
  121. <a href="http://www.research.microsoft.com/~cwfraser/pldi99codegen.pdf">
  122. http://www.research.microsoft.com/~cwfraser/pldi99codegen.pdf</a>
  123. * Vmgen generates much of the code for efficient virtual machine (VM)
  124. interpreters from simple descriptions of the VM instructions:<br>
  125. <a href="http://www.complang.tuwien.ac.at/anton/vmgen/">
  126. http://www.complang.tuwien.ac.at/anton/vmgen</a>
  127. </ul>
  128. ** PInvoke
  129. PInvoke is the mechanism we are using to wrap Unix API calls
  130. as well as talking to system libraries.
  131. Initially we used libffi, but it was fairly slow, so we have
  132. reused parts of the JIT work to create efficient PInvoke
  133. trampolines.
  134. ** Remoting
  135. Mono has support for remoting and proxy objects, just like
  136. .NET does. The runtime provides these facilities.
  137. ** Porting
  138. If you are interested in porting the Mono runtime to other
  139. platforms, you might find the pre-compiled <a
  140. href="archive/mono-tests.tar.gz">Mono regression test
  141. suite</a> useful to debug your implementation.
  142. * COM and XPCOM
  143. We plan on adding support for XPCOM on Unix and COM on Microsoft
  144. Windows later in our development process.