Wednesday, September 2, 2020

Object and array inlining

A brief overview of  related work is included below. A static compiler for a variation of C++ was extended earlier to perform automatic object inlining.  Its algorithm clones the code of methods that accesses optimized objects. That approach is different from the above mentioned in that all objects of a class are inlined when it meets a criterion. Also, that algorithm moves the object headers and pointers to inlined objects which reduces the object size. It can also convert an array of references to an array of object values. The approach described here is from the paper on Automatic Array Inlining in Java Virtual Machines by Wimmer et al and this approach can inline dynamic arrays while the earlier one does not.

Another example is from object inlining in the CoSy compiler construction framework, a static compiler for Java where the replacement of child objects with new one can be detected. The approach described in this document requires that the objects not be references by anything else other than the parent object.

Object inlining also has also shown four different classes of inlinable fields. The related work mentioned above also provide their benchmarks. But array fields are not evaluated.  In fact, this approach has differentiated itself in its treatment of arrays with constant and arrays with variable length. Inlining of array elements is seldom evaluated.

There is a more aggressive approach than object inlining which is called object combining. It optimizes unrelated objects if they have the same lifetime. It also allows the garbage collector to free multiple objects simultaneously. It allows the garbage collector to free multiple objects simultaneously. The elimination of the pointer accesses is performed separately. This reduces the overhead of memory allocation and deallocation and is preferred for mark and sweep garbage collectors. In comparison to this approach, the emphasis has shifted from arrays and instructions to allocations and size.

There are other global optimizations possible for object inlining. One uses a cheap interprocedural analysis for object inlining. For example, arrays are only inlined when the length is known and unchanged during compilation. This was implemented in Swift which is a flavor of Java compiler for Alpha architecture.

Another approach modifies the object copying order of the garbage collector which improves the cache performance but it has little or no effect on field loads. Another approach, known as the online object reordering, optimizes all the fields accessed frequently. Another approach, known as the cache conscious data placement, uses run-time counters but does not distinguish between different fields of the same object.  A pointer-analysis approach has an algorithm that guesses the possible run-time values of pointers but this one is unsuitable for object and array inlining because it works only with the location a variable may point to. But such location information is valuable when it is precise and so there is another approach that collects the points-to-mapping for all instances. This can be useful to flatten multi-dimensional arrays.

Array inlining is not possible without a global data flow analysis because it can only optimize array fields.


No comments:

Post a Comment