Java Reference
In-Depth Information
for i =
1 to N do
3
for j =
1 to N do
Result [ i , j ]
4
0
for k =
1 to N do
Result [ i , j ]
Result [ i , j ]
+ B [ i , k ]
× C [ k , j ]
5
for i =
1 to N do
for j =
6
1 to N do
A [ i , j ]
Result [ i , j ]
Figure 14.2: Inlining the overloaded operators.
of Matrix , then the result of a virtual function dispatch on these methods
may be predictable at compile time.
Basedon such analysis, method inlining expands themethod definitions
in Figure 14.1 at their call sites, substituting the appropriate parameter
values. As shown in Figure 14.2, the resulting program avoids the over-
head of function calls. Moreover, the code is now specially tailored for its
arguments, whose row and column sizes are N . Program optimization
can then eliminate the tests at Markers 1 and 2 .
Perhaps it can be shown that a language-mandated operation is not
necessary. For example, Java TM insists on subscript checks for array
references and type-checks for narrowing casts . Such checks are unnec-
essary if an optimizing compiler can determine the outcome of the result
at compile-time. When code is generated for Figure 14.2, induction vari-
able analysis can show that i , j ,and k all stay within the declared range
of matrices A , B ,and C . Thus, subscript tests can be eliminated for those
arrays.
Even if the outcome is uncertain at compile-time, a test can be eliminated
if its outcome is already computed. Suppose the compiler is required
to check the subscript expressions for the Result matrix at Marker 5 .
Most likely, the code generator would insert a test for each reference of
Result [ i , j ]. An optimization pass could determine that the second test is
redundant.
Modern software-construction practices dictate that large software systems
should be comprised of small, easily written, readily reusable components.
As a result, the size of a compiler's compilation unit —the text directly pre-
sented in one run of the compiler—has has been steadily dwindling. In re-
sponse, optimizing compilers consider the problem of whole-program op-
timization (WPO), which requires analyzing the interaction of a program's
compilation units. Method inlining (shown in Figure 14.2) is one example of
 
Search WWH ::




Custom Search