
Comp ositional Pointer and Escap e Analysis for Multithreaded Java Programs Martin Rinard John Whaley Lab oratory for Computer Science IBM Tokyo Research Lab oratory Massachusetts Institute of Technology Network Computing Platform Cambridge, MA 02139 1623-14 Shimotsuruma Yamato-shi, Kanagawa-ken 242-8502 Japan [email protected] [email protected] For example, an ob ject escap es if it is reachable from an un- Abstract analyzed thread running in parallel with the current thread This pap er presents a new combined p ointer and escap e or returned to an unanalyzed region of the program. analysis algorithm for Java programs with unstructured mul- Combining p oints-to and escap e information in the same tithreading. The algorithm is based on the abstraction of analysis enables the algorithm to represent all p otential in- paral lel interaction graphs, whichcharacterize the p oints-to teractions b etween the analyzed and unanalyzed regions of and escap e relationships b etween ob jects and the ordering the program. The algorithm represents these interactions, relationships between actions p erformed by multiple par- in part, by distinguishing b etween two kinds of edges: in- allel threads. To our knowledge, this algorithm is the rst side edges, which represent references created within the cur- interpro cedural, ow-sensitive p ointer analysis algorithm ca- rently analyzed region, and outside edges, which represent pable of extracting the p oints-to relationships generated by references created outside this region. Each outside edge the interactions between unstructured parallel threads. It represents a p otential interaction in which the analyzed re- is also the rst algorithm capable of analyzing interactions gion reads a reference created in an unanalyzed region. Each between threads to extract precise escap e information even inside edge from escap ed no de represents a p otential inter- for ob jects accessible to multiple threads. action in which the analyzed region creates a reference that Wehave implemented our analysis in the IBM Jalap eno ~ an unanalyzed region may read. dynamic compiler for Java and used the analysis results Representing p otential interactions with inside and out- to eliminate redundant synchronization. For our b ench- side edges leads to an analysis that is comp ositional in two mark programs, the thread interaction analysis signi cantly senses: improves the e ectiveness of the synchronization elimina- Metho d Comp ositionality: The algorithm analyzes tion algorithm as compared with previously published tech- each metho d once to derive a single parameterized niques, which do not analyze these interactions. analysis result that records all p otential interactions of 1 the metho d with its callers. At each call site, the al- 1 Intro duction gorithm matches outside edges from the callee against inside edges from the caller to compute the e ect of This pap er presents a new, combined p ointer and escap e the callee on the p oints-to and escap e information of analysis algorithm for multithreaded programs. To our knowl- the caller. edge, this algorithm is the rst interpro cedural, ow-sensitive p ointer analysis algorithm for programs with the unstruc- Thread Comp ositionality: The algorithm analyzes tured form of multithreading present in Java and similar each thread once to derive an analysis result that records languages. It is also the rst algorithm capable of analyz- all of the p otential interactions of the thread with other ing interactions between threads to extract precise escap e parallel threads. The analysis can then combine analy- information even for ob jects accessible to multiple threads. sis results from multiple parallel threads by matching each outside edge from each thread against all cor- resp onding inside edges from parallel threads. The 1.1 Analysis Overview result is a single parallel interaction graph that com- The analysis is based on an abstraction we call paral lel in- pletely characterizes the p oints-to and escap e informa- teraction graphs. The no des in this graph represent ob jects; tion generated by the combined parallel execution of the edges between no des represent references between ob- the threads. Unlike previously published algorithms, jects. For each no de, the analysis also records information which use an iterative xed-p oint algorithm to com- that characterizes how it escap es the current analysis region. pute the interactions [37 , 16 ], the algorithm presented in this pap er can compute the interactions between two parallel threads with a single pass over the paral- lel interaction graphs from the threads. Finally, the combination of p oints-to and escap e infor- mation in the same analysis leads to an algorithm that is 1 Recursive metho ds require an iterative algorithm that may ana- lyze metho ds multiple times to reach a xed p oint. 2 Example designed to analyze arbitrary regions of complete or incom- plete programs, with the analysis result b ecoming more pre- In this section we present an example that illustrates how cise as more of the program is analyzed. Atevery stage in the analysis works. Figure 1 presents the Java co de for the the analysis, the current parallel interaction graph provides example. The sum metho d in the Sum class computes the complete information ab out the p oints-to relationships for sum of the numb ers from 0 to n, storing the result into a ob jects that do not escap e the currently analyzed region destination accumulator a. It computes this sum by creating of the program. The algorithm can therefore obtain useful aworker thread to compute the sum of the even numb ers analysis information without analyzing the entire program. while it computes the sum of the o dd numb ers. When they nish, b oth threads add their contribution into the destina- 1.2 Analysis Uses tion accumulator. The sum metho d rst constructs a work Parallel interaction graphs also record the actions that each vector v of Integers for the worker thread to sum up, then thread p erforms and contain ordering information for these initializes the worker ob ject to p oint to the work vector and actions relative to the actions p erformed by other threads. the destination accumulator. It starts the worker thread Optimization and analysis algorithms can use this informa- running by invoking its start metho d, which invokes the tion to determine that actions from di erent threads can run metho d in a new thread running in parallel with the never execute concurrently and are therefore indep endent. current thread. This mechanism of initializing a thread ob- Our compiler uses this ordering information to improve the ject to p oint to its conceptual parameters is the standard precision of the thread interaction analysis. It also uses this way for Java programs to provide threads with the informa- information to implement a synchronization elimination op- tion they need to initiate their computation. timization | if all lo ck acquire and release actions on a given ob ject are indep endent, they have no e ect on the class Accumulator { computation and can b e removed. int value = 0; The analysis also provides information that is generally synchronized void addint v { useful to compilers and program analysis to ols for multi- value += v; threaded programs. Potential applications of our analysis } include: sophisticated software engineering to ols such as } static race detectors and program slicers [28 , 36]; memory class Sum { system optimizations such as prefetching and moving com- public static void sumint n, Accumulator a { putation to remote data; automatic batching of long latency 1: Vector v = new Vector; le system op erations; memory bank disambiguation in com- for int i = 0; i < n; i += 2 { pilers for distributed memory machines [8 ]; memory mo dule v.addElementnew Integeri; splitting in compilers that generate hardware directly from } high-level languages [6 ]; lo ck coarsening [33 , 22 ]; synchro- 2: Worker t = new Worker; nization elimination and stack allo cation[41 , 10 , 12 , 15 ]; and t.initv,a; to provide information required to apply traditional com- t.start; piler optimizations such as constant propagation, common int s = 0; sub expression elimination, register allo cation, co de motion for int i = 1; i < n; i+= 2 { and induction variable elimination to multithreaded pro- s = s + i; grams. } a.adds; 1.3 Contributions } } This pap er makes the following contributions: class Worker extends Thread { Analysis Algorithm: It presents a new combined Vector work; p ointer and escap e analysis algorithm for multithreaded Accumulator dest; programs. The algorithm is comp ositional at b oth the void initVector v, Accumulator a { metho d and thread levels and is designed to deliver work = v; useful information without analyzing the entire pro- dest = a; gram. } public void run { Analysis Uses: It shows how to use the action order- 3: Enumeration e = work.elements; ing information present in parallel interaction graphs int s = 0; to p erform a synchronization elimination optimization. while e.hasMoreElements { Integer i = Integer e.nextElement; Exp erimental Results: It presents exp erimental re- s = s + i.intValue; sults from a prototyp e implementation of the algo- } rithms. These results show that the algorithm can 4: dest.adds; eliminate a signi cantnumb er of synchronization op- } erations. } The remainder of the pap er is organized as follows. Sec- tion 2 presents an example that illustrates how the analy- sis works. Sections 3 through 11 present the analysis algo- Figure 1: Sum Example rithms. Section 14 presents exp erimental results, Section 15 presents related work, and we conclude in Section 16. We contrast the unstructured form of multithreading in this example with the structured, fork-join form of multi- Figure 2: Callee-Caller Interaction Between init and sum Figure 3: Parallel Thread Interaction Between run and sum Figure 4: Result of Parallel Thread Interaction In addition to the p oints-to information, the parallel in- threading found in, for example, the Cilk programming lan- teraction graph also records the synchronization actions that guage [11 ].
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages23 Page
-
File Size-