A widespread practice to implement a flexible array is to consider the storage area into two parts: the used area, which is already available for read/write operations, and the supply area, which is used in case of enlargement of the array. The main purpose of the supply area is to avoid as much as possible the reallocation of the whole storage area in case of enlargement. As the supply area is not used by the application, the main idea of the paper is to convey the information to the garbage collector, making it possible to avoid completely the marking of the supply area. We also present a simple method to analyze the types of objects, which are stored in an array as well as the possible presence of NULL values within the array. This allows us to better specialize the work of the garbage collector when marking the used area, and also, by transitivity, to improve overall results for type analysis of all expressions of the source code. After introducing several abstract data types, which represent the main arrays concerned by our technique (i.e., zero or variable indexing, circular arrays and hash maps), we measure its impact during the bootstrap of two compilers whose libraries are equipped with these abstract data types. We then measure, on various software products we have not written, the frequency of certain habits of manipulation of arrays, to assess the validity of our approach. Copyright EXPLOITING ARRAY MANIPULATION HABITS 1641 Create(cap) The creation operation to be used in order to prepare a new empty array with a given capacity cap: assert (cap >= 0); capacity = cap; size = 0; storage = malloc(cap); Extend(obj) To extend by one the array on its right, writing obj in the new slot. In case of reallocation (i.e. when the supply area is empty), the capacity is increased twofold:if ( size >= capacity ) { capacity = capacity * 2; storage = realloc(storage, capacity); } storage[size] = obj; size = size + 1;
Read(ind)This function returns the object stored at index ind assuming that the index is correct, that is, a valid index in the used area:Write(ind, obj) Change the value at index ind using obj for the replacement, assuming that the ind is a valid index in the used area: assert ((0 <= ind) && (ind < size)); storage[ind] = obj; order of statements. For instance, using all the reachable assignments in a variable, we compute all the possible types for that variable. The analysis is flow insensitive, that is, the order of reachable assignments does not matter. We consider on the whole the set of reachable assignments.Concerning instance variables, we do not discriminate between the different instances from the same class (Figure 2); the type information is identical for all instances of a given class. For a formal method argument, we use the set of reachable effective arguments, that is, all reachable calls. Classically, to obtain the set of dynamic types of a given method call, we consider all the methods EXPLOITING ARRAY MANIPULATION HABITS 1645 Note that it is not necessary to reset with NULL the cell that...