made a copy
[strongtalk-kjk.git] / documentation / tour / compilationcontrol.html
blobf794d17077a571ee0795a5973bfff68c94631103
1 <html>
3 <head>
4 <meta http-equiv="Content-Type"
5 content="text/html; charset=iso-8859-1">
6 <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
7 <title>The Virtual Machine</title>
8 </head>
10 <body bgcolor="#FFFFFF">
11 <h3 align="right"><a href="virtualmachine3.html">&lt;== Previous</a> |
12 <a href="toc.html">Contents</a> |
13 <a href="virtualmachine4.html"><strong>Next ==&gt;</strong></a></h3>
14 <h2 align="left">Examining Compilation and Controlling Compiled
15 Code</h2>
17 <h3 align="left">Looking at Compiled Code Space Usage</h3>
19 <p align="left">The fact that the compiler inlines and customizes
20 methods means that methods can potentially have many compiled
21 versions, each in a different inlining or customization context.
22 This brings up an important point: it would seem like this might
23 consume a large amount of space for compiled code. In practice,
24 the opposite is true: the system uses a remarkably small amount
25 of space for compiled code. This is because only performance
26 critical code is optimized, and most systems spend most of their
27 time running a quite small set of performance critical code, as
28 mentioned before. </p>
30 <p align="left">You can tell the VM to print a summary of the
31 compiled code space usage, which appears in the console window
32 (not the Trancript). This is done using the
33 &quot;System/Compiler/Print Compiled Code Space Usage
34 (Zone)&quot; menu item on the Launcher. The first number is the
35 total size of the compiled code space, including unused space.
36 The size of this area is fixed at startup, but can be changed
37 using the CodeSize option in the <a
38 doit="(CodeEditor on: (FilePath for: '.strongtalkrc')) launch">.strongtalkrc</a>
39 startup options file. The third line contains the most important
40 information, which is the number of compiled top-level methods
41 (not counting methods inlined into them), and how much space they
42 use. Typically compiled code occupies 1-3 megabytes for a
43 programming session.</p>
45 <h3 align="left">Showing Compilations</h3>
47 <p align="left">You can tell the VM to show every method it is
48 compiling, which is an interesting way to watch the adaptive
49 optimization process in action. This is done by selecting
50 &quot;System/Compiler/Print Compilations&quot; from the Launcher
51 menu.</p>
53 <h3 align="left">Changing the Compilation Threshold</h3>
55 <p align="left">The threshold at which code is considered to be
56 performance-sensitive, and thus compiled, can be changed. This is
57 done by setting a different value for InvocationCounterLimit in
58 the <a
59 doit="(CodeEditor on: (FilePath for: '.strongtalkrc')) launch">.strongtalkrc</a>
60 file. This value is 10000 by default. The number indicates the
61 number of times a method or loop body must execute before the
62 compiler tries to produce an optimized version of that code (and
63 perhaps the calling and called code too). Increasing this value
64 will cause a smaller amount of compiled code to be compiled, and
65 decreasing it will cause more code to be compiled. The
66 performance effect of changing it is not so obvious. The most
67 performance critical code will be compiled for almost any
68 reasonable value, so peak performance is not affected. Code that
69 is marginally performance sensitive is the most affected by
70 changing the limit. Increasing the limit also has the effect of
71 making the system somewhat more stable, since less of the system
72 is compiled.</p>
74 <h3 align="left">The Inlining Database</h3>
76 <p align="left">Because of the adaptive nature of the compiler,
77 the compiled code naturally differs depending on the way that the
78 system is being used. Thus, subtle changes in the way that a user
79 interacts with the system can cause slightly different
80 optimization results. For production application deployment, this
81 may not be a desirable feature, since the exact compiled code
82 produced can vary every single time the system is run, and that
83 may make the testing team uncomfortable.</p>
85 <p align="left">To deal with these sorts of issues, the
86 Strongtalk VM is capable of storing in an external directory
87 structure the exact inlining format that the system is using, and
88 can be told to reuse that same inlining structure on subsequent
89 runs. This can make the performance of the system more
90 predictable, and in fact, you can even turn off all compilation
91 for any method not in the inlining database, so that the compiled
92 code is virtually identical between runs. Or, you can allow the
93 compiler to run normally, in addition to using the inlining
94 database.</p>
96 <p align="left">To create an inlining database, you run the
97 system until you have the system in a state where the code you
98 care about has been optimized. Then, you dump the inlining
99 database using the Launcher menu item
100 &quot;System/Compiler/Create Inlining Database&quot;. This will
101 create a directory called &quot;Inlining&quot; under the
102 strongtalk home directory. The directory contains a subdirectory
103 for each class that has optimized code associated with it, and in
104 those directories there is a file for each optimized method,
105 containing the inlining structure in the same format we saw on
106 the previous page.</p>
108 <p align="left">Once you have created an inlining database, there
109 are several flags that control the inlining database operation.
110 These flags are in the <a
111 doit="(CodeEditor on: (FilePath for: '.strongtalkrc')) launch">.strongtalkrc</a> file.
112 The options have either a + before them to enable them, or a - to
113 disable them.</p>
115 <ul>
116 <li><p align="left"><strong>UseInliningDatabase</strong>:
117 this option indicates whether or not the inlining
118 database should be used.</p>
119 </li>
120 <li><p align="left"><strong>UseInliningDatabaseEagerly</strong>:
121 this option indicates whether the inlining database
122 should be used eagerly or not. When this flag is off, the
123 inlining database is referred to only when a method has
124 been used enough to become performance critical, and it
125 is then compiled using the database inlining structure.
126 When the database is used eagerly, two things happen: the
127 method is compiled using the inlining database structure
128 immediately the first time it is invoked, and a
129 background process starts when the system starts up to
130 eagerly compile all the code in the inlining database.
131 Eager use of the database can cause the system to start
132 up a little bit slower, since compilation happens
133 up-front, but the system then reaches top performance
134 much sooner and more predictably than when using the
135 database lazily.</p>
136 </li>
137 <li><p align="left"><strong>UseRecompilation</strong>: This
138 flag actually isn't directly for the inlining database,
139 but it interacts with it. This is the master flag that
140 tells the system whether to compile performance critical
141 code. If this is off, the system runs in interpreted
142 mode, except for any methods in the inlining database (if
143 it is enabled), which are the only ones optimized. If the
144 compiler is on, then the optimizer runs normally,
145 although the inlining database is referred to for those
146 methods it contains.</p>
147 </li>
148 </ul>
150 <p align="left">The inlining database is also a great tool for
151 exploring exactly what the adaptive compiler has done. Try
152 dumping the inlining database and looking at its contents if you
153 are interested in the adaptive compiler. One important thing to
154 note is that sometimes there is no entry in the database for a
155 method you are sure is performance critical. This can happen
156 because the inlining database may have inlined that method into
157 the body of some <em>other</em> calling method instead, so it may
158 not need its own top-level compiled method. Adaptive optimization
159 may compile many different versions of a method, either
160 customized for different subclasses, or inlined into different
161 optimized calling methods.</p>
163 <h3 align="right"><a href="virtualmachine4.html"><strong>Continue
164 with the tour ==&gt;</strong></a></h3>
165 </body>
166 </html>