A System Dependence Net Generator for Ada ... - Semantic Scholar

5 downloads 0 Views 385KB Size Report
A System Dependence Net Generator for Ada Programs. Yusuke Nonaka. Department of Computer Science and Communication Engineering.
A System Dependence Net Generator for Ada Programs Yusuke Nonaka Department of Computer Science and Communication Engineering Kyushu University 6-10-1 Hakozaki, Fukuoka 812-8581, Japan [email protected] Katsuhiko Hatano

Yoshinari Nomura

Jingde Cheng

[email protected]

[email protected]

[email protected]

Kazuo Ushijima [email protected]

Abstract An explicit representation of various dependence relationship in a program has many application in software engineering. System Dependence Net is a model to represent program dependences in a concurrent program which consists of multiple procedures. This paper presents how to generate System Dependence Net for Ada 95 programs automatically.

1. Introduction The concept of program dependences is important for developing and maintaining software systems. Program dependences are dependence relationships holding between statements in a program that implicitly exist. In a sequential program, there are two types of primary program dependences, i. e., control dependence and data dependence. The Program Dependences Graph[7] was proposed to represent control dependences and data dependences in a sequential program by the form of a digraph. System Dependence Graph(SDG for short)[8] is a representation model for sequential programs which can represent data dependences, control dependences, and interprocedural relations such as parameter inputs, parameter outputs, and relations between call sites and entrances of subprograms. A concurrent program has multiple threads of control ow and multiple threads of data ow, and these control ows and data ows are not independent be-

cause of the existence of interprocess synchronization among multiple control ows and interprocess communication among multiple data ows in the program. Moreover, a process in a concurrent program may nondeterministically select a communication partner among a number of processes ready for communication with the process. In concurrent programs, there are other three types of primary program dependences, they are intrinsically di erent from data dependences and control dependences in sequential programs. They are synchronization dependences, communication dependences, and selection dependences. Process Dependence Net(PDN for short)[2] is a representation model for concurrent programs, which is an arc-classi ed digraph to explicitly represent various primary program dependences in concurrent programs as well as sequential programs. Task Dependence Net(TDN for short)[4, 10] is the Ada version of PDN. System Dependence Net(SDN for short)[16] is a representation model extended from each of PDN and SDG. It can represent dependences and interprocedural relations which exist in a concurrent program with multiple procedures. In general, since Ada 95[1, 9] programs are concurrent programs including multiple procedures, if we could analyze program dependences and interprocedural relations in Ada 95 programs and represent them with SDNs, it would be very helpful for development and maintenance of the software systems by using many applications of the net, such as program slicing[15], testing, debugging, metrics for measuring software complexity. This paper presents the SDN based on the tasking model of Ada 95, and a tool to generate SDNs

 YK YKVVJ #FC6GZVA+1   RT RTQQEGFW FWTTG 'ZCORNG KU   RCE CEMMCIG +PVA+1 KU PGY  #FC6GZVA+1+PVGIGTA+1 +PVGIGT    RTQV QVGGEVGF 28 KU  HWPE PEVVKQP 4GCF TGVWTP +PVGIGT  RTQE QEGGFWTG #FF :  KP +PVGIGT   RTKX KXCCVG  8  +PVGIGT    GPF 28   VCU CUMM /QPKVQT KU  GPVT[ 3WKV  GPF /QPKVQT   RTQ TQVVGEVGF DQF[ 28 KU  HWPE PEVVKQP 4GCF TGVWTP +PVGIGT KU  DGIK IKPP  TGVWTP 8  GPF 4GCF   RTQEGF GFWWTG #FF :  KP +PVGIGT KU  DGIK IKPP  8  8 :  GPF #FF  GPF 28

            

VCU CUMM DDQQF[ /QPKVQT KU 8  +PVGIGT   (KPKUJ  $QQNGCP  (CNUG DGI GIKKP YJKNG PQV (KPKUJ NQQR UGNGEV CE CEEEGRV 3WKV (KPKUJ  6TWG QT FGN GNCC[  8  284GCF #FC6GZVA+12WVA.KPG /QPKVQT 28 U XCNWG §  +PVGIGT +OCIG 8  GPF UUGN GNGGEV GPF NQQR GPF /QPKVQT

     8CNWG  +PVGIGT     DG DGIIKP  NQQ QQRR  +PVA+1)GV 8CNWG   GZKV YYJJGP 8CNWG    28#FF 8CNWG   GPF NNQQQR  /QPKVQT3WKV  GP GPFF 'ZCORNG

Figure 1. An example Ada 95 program. VHTXHQWLDO FRQWURO DUF



SDUDOOHO H[HFXWLRQ DUF





'  ^9`



'  ^)LQLVK`



'  ^9DOXH`







V\QFKURQL]DWLRQ FKDQQHO

D



$LQ D ^9DOXH`

5 

)LQ  ^;`

^([DPSOH39`

8  ^)LQLVK`



QRQGHWHUPLQLVWLF VHOHFWLRQ DUF FDOO DUF

'  ^9`

5  ^([DPSOH` 6  ^([DPSOH`







5 



^([DPSOH39`

'  ^9DOXH`

  

'  ^9` 8 

 8  ^9`

^([DPSOH 395HDG`

 

5  ^([DPSOH



8  ^9DOXH`



8  ^9`

0RQLWRU4XLW`

5HW 



^([DPSOH

 6 









395HDG`

6  ^([DPSOH39`



8  ^9 ;` '  ^9`

 

6  ^([DPSOH39`

^([DPSOH 0RQLWRU 4XLW(1'` ' 



6  ^([DPSOH0RQLWRU4XLW`

^)LQLVK`



5  ^([DPSOH0RQLWRU4XLW(1'`

Figure 2. The DUN of the example Ada program given in Figure 1. for Ada 95 programs. Since the facilities of programming languages representing concurrency in concurrent programs have various forms by the kinds of their pro-

 RTQVGEVGF %QWPVGT KU RTQEGFWTG #FF :  KP +PVGIGT  HWPEVKQP 4GHGT TGVWTP +PVGIGT RTKXCVG  8CNWG  +PVGIGT   GPF %QWPVGT



3DUHQW EORFN

 '  ^9DOXH`

     

RTQVGEVGF DDQQF[ %QWPVGT KU RTQEGFWTG #FF :  KP +PVGIGT KU DGIKP 8CNWG  8CNWG : GPF #FF HWPEVKQP 4GHGT TGVWTP +PVGIGT KU DGIKP TGVWTP 8CNWG GPF 4GHGT GPF %QWPVGT



)LQ  ^;` 5  ^6DPSOH&RXQWHU`



5  ^6DPSOH&RXQWHU`

'  ^9DOXH`

 

8  ^ 9DOXH` 3  ^5HIHU`

8  ^9DOXH`

 

6  ^6DPSOH&RXQWHU`

6  ^6DPSOH&RXQWHU`

Figure 3. Representation of a protected object gramming languages, the de nition of synchronization dependences, communication dependences and selection dependences in this paper depends on the tasking model of Ada 95. However, the concept of the SDN is intrinsically independent on programming languages used to write concurrent systems.

2. De nition-Use Nets for Concurrent Ada 95 Programs with Multiple Procedures In order to identify, de ne, and analyze various program dependences and interprocedural relations in an Ada program formally, we have to construct a formal representation of multiple threads of control ow in Ada programs. But lack of space prevents us from presenting the formal representation, so we give only some informal explanations. A Nondeterministic Parallel Control-Flow Net (CFN for short) is a model to represent multiple threads of control ow in concurrent programs[3]. We extend the model to represent interprocedural control

ow in concurrent Ada 95 programs. A CFN of a concurrent program is an arc-classi ed digraph where a vertex represents either a simple statement, a deterministic control transition statement with

some control predicate, a nondeterministic selective statement, a statement to call subprograms, or a virtual statement introduced for representing the start point or termination point of a subprogram. A CFN has four types of arcs, called sequential control arcs, nondeterministic selection arcs, parallel execution arcs, and call arcs. The CFN which represents an Ada program includes a number of subnets in the form of CFN, each of which represents a subprogram. Each subnet includes a start vertex and a termination vertex. The CFN does not represent control ows from a subprogram calling statement to the subprogram entrance, and from a statement of a termination of a subprogram to the next statement of the subprogram calling statement. Instead of these ows, the CFN represents relations between a subprogram calling statement and the subprogram entrance. A Nondeterministic Parallel De nition-Use Net(DUN for short) of a concurrent program is an extension of the CFN of the program such that its vertices are labeled with information about de nitions or uses of the values of variables, interprocess synchronization and communication, formal parameters of the subprograms, and results of the functions, and its call arcs are labeled with information about actual parameters of the subprogram call. For a vertex of representing subprogram calls, each

FRQWURO GHSHQGHQFH DUF GDWD GHSHQGHQFH DUF



V\QFKURQL]DWLRQ GHSHQGHQFH DUF FRPPXQLFDWLRQ GHSHQGHQFH DUF





SDUDPHWHULQRXW 



FDOO  UHWXUQHGYDOXH UHODWLRQ DUF

































 









VHOHFWLRQ GHSHQGHQFH DUF













©

©

Figure 4. The SDN of the example Ada program given in Figure 1. relation between a subprogram calling statement or expression and the call site in each call is represented as a call arc and the call-labeling-function. For a start vertex of a subprogram, formal parameters which have the mode in or the mode in out are represented by formal-in-labeling-function from the start vertex, and formal parameters which have the mode out or the mode in out are represented by formal-out-labeling-function. An example Ada 95 program and its DUN are given in Figure 1 and Figure 2 respectively. By the DUN, new concurrent facilities of Ada 95 are able to be represented. For example, Figure 3 shows an example of a protected object. Protected variables are represented as the same as general global variables, and protected operations are represented like subprograms. However, to represent the synchronization of mutual exclusion, the protection acquired by receive-labeling function from the start vertex and the protection acquired by send-labeling function from the termination vertex in a protected object is the same protection. Because the execution of the termination point in a protected operation makes the execution of the start point in the other (or the same) protected operation start when we take a view of statement by statement.

In order to make the formal de nition simple, we de ned the extended DUN. Since some of subprogram calling statements contain multiple data ows in a statement, each actual or formal parameter must have a corresponding vertex. So actual-in vertices, actual-out vertices, formalin vertices and formal-out vertices are needed, and to represent which vertex of any parameter corresponds to which vertex representing a subprogram calling statement, the actual-in-function, actual-outfunction, formal-in-function and formal-out-function are de ned by actual-in-labeling-function, actualout-labeling-function, formal-in-labeling-function and formal-out-labeling-function, respectively. However, we cannot represent some special case when two function calls having the same symbol appear in an actual parameter, though if all functions including pre-de ned functions and functions in other compilation units could be represented by the DUN precisely, such case would not occur.

3. Primary Program Dependences in Concurrent Programs and Interprocedural Relations Based on the DUN of an Ada program, we can de ne and analyze various primary program dependences and interprocedural relations in the program. Since each informal de nition of the following description can be represented by the formal de nition on the DUN, each relation between any two vertices can be detected automatically, and it can be done in nite time. Informally, statement u is said to be directly strongly control-dependent on deterministic control transition statement v with a control predicate if v has at least two successors v and v such that if the branch from v to v is executed then u must be executed, while if the branch from v to v is executed then u may not be executed. Statement u is said to be directly weakly controldependent on deterministic control transition statement v with some control predicate if v has two successors v and v such that if the branch from v to v is executed then u is necessarily executed within a xed number of steps, while if the branch from v to v is executed then u may not be executed or the execution of u may be delayed inde nitely. Statement u is said to be directly weakly controldependent on the start statement v of the subprogram including u if v is executed then u is necessarily executed. Parameter u is said to be directly weakly controldependent on a statement v including subprogram calling statement if u is included by v . Statement or parameter u is said to be directly datadependent on statement v if the value of a variable assigned at v has some direct in uence on the value of a variable used at u. Statement u is said to be directly selectiondependent on nondeterministic selection statement v if v has some successors such that if the branch from v to one of the successors is executed then u must be executed, while if another branch is executed then u may not be executed. Statement u is said to be directly synchronizationdependent on statement v if the start and/or end of execution of v directly determines whether or not the execution of u starts and/or ends. Statement or parameter u is said to be directly communication-dependent on statement v if the value of the variable assigned at v has some direct in uence on the value of a variable used at u by an intertask communication or a shared variable. Statement u is said to be call-related with statement 0

00

0

v if u is the start statement of the subprogram which is called by v. Formal parameter u is said to be parameter-inrelated with actual parameter v if u has the mode in or in out and v corresponds to u. Actual parameter u is said to be parameter-outrelated with formal parameter v if v has the mode out or in out and u corresponds to v . Parameter or statement u is said to be returnedvalue-related with a return statement v if the value of a variable assigned at u has direct in uence on the returned value of the statement v .

4. System Dependence Nets of Concurrent Ada 95 Programs

00

0

00

0

00

If we represent all ve types of primary program dependences and four types of interprocedural relations in an Ada program within an arc-classi ed digraph such that each type of arc represents a type of primary program dependences and interprocedural relations, then we can obtain an explicit dependence-based representation of the program, which is the System Dependence Net for the Ada program. The System Dependence Net (SDN for short) of a concurrent Ada program is an arc-classi ed digraph (V ; C on; Dat; S el; S yn; C om; C al; P in; P out; Ret; S um), where V 2 (V \ VAin \ VAout \ VFin \ VFout ), the vertex set of the extended DUN of the program, C on is the set of control dependence arcs such that any (u; v ) 2 C on if and only if u is directly weakly control-dependent on v , Dat is the set of data dependence arcs such that any (u; v ) 2 Dat if and only if u is directly data-dependent on v , S el is the set of selection dependence arcs such that any (u; v ) 2 S el if and only if u is directly selection-dependent on v , S yn is the set of synchronization dependence arcs such that any (u; v ) 2 S yn if and only if u is directly synchronizationdependent on v , C om is the set of communication dependence arcs such that any (u; v ) 2 C om if and only if u is directly communication-dependent on v , C al is the set of call relation arcs such that any (u; v ) 2 C al if and only if u is call-related on v , P in is the set of parameter-in relation arcs such that any (u; v ) 2 P in if and only if u is parameter-in-related on v , P out is the set of parameter-out relation arcs such that any (u; v ) 2 P out if and only if u is parameter-out-related on v , Ret is the set of returned-value relation arcs such that any (u; v) 2 Ret if and only if u is returned-valuerelated on v , and S um is the set of summary arcs such that any (u; v ) 2 S um. Summary arcs represent the transitive ow of dependence across procedure calls. 0

0

Figure 4 shows the SDN of the example Ada program given in Figure 1. For example, the variable named as V is declared at line 12, which is a private variable in the protected object P V . Both the function Read and the procedure Add are protected operations of P V , the value of V used at line 22 can be the value de ned at line 27, by the other task or the task itself. So the statement at line 22 is communicationdependent on the statement at line 27.

5. A De nition-Use Net Generator for Ada 95 Programs To generate the DUN of an Ada program, lexical analysis and syntactical analysis of the target program must be done. Also, what have to be done are control

ow analysis of the program, identi cation of places where each variable is de ned or used and each synchronization is occurred, and identi cation of each concurrent fork/join point. The Ada Semantic Interface Speci cation(ASIS) is an interface between an Ada environment and any tool requiring information from it. Our DUN generator gets above information from target programs with ASIS[5, 6]. There are many advantages to use ASIS for the tool instead of lexical and syntactical analyzing target programs by itself. First, we can develop the tool with less trouble to cope with large-scale syntax and semantics of Ada 95. Second, the tool can gain much anities with Ada compilers whose interfaces of ASIS have already been implemented. Third, resources of the computer can be made good use of since the tool need not analyze the target one lexically, syntactically and also a little semantically by itself. The function of our DUN generator is to generate DUN from a compilation unit in the Ada environment, since a compilation unit is a unit of software development, and from the viewpoint of visibility control, it is not useful for various applications to represent program dependences among each statement in multiple compilation units explicitly. However, some model is needed, which can represent dependences among each compilation unit and cooperate with the model representing program dependences. But if two compilation units make a pair of a speci cation and its body, the target is composed by both of their units. Figure 5 shows the relation among DUN Generator, Ada compiler and ASIS. The generation of DUN has the following process. 1. initialize ASIS 2. open a context

$GD VRXUFH FRGH $GD FRPSLOHU $GD (QYLURQPHQW ¶¶¶

$6,6 ,QWHUIDFH

&RPSLODWLRQ &RPSLODWLRQ 8QLW 8QLW

'81 *HQHUDWRU '81

/LQNHU ([HFXWDEOH ILOH

6'1 *HQHUDWRU 6'1

Figure 5. The DUN Generator and ASIS. 3. get the name of the target unit from the user, and get a compilation unit (or a pair of a speci cation and a body as the case may be) of the name from the Ada environment 4. process elements contained in each compilation unit and generate DUN 5. process the whole DUN still more 6. nalize ASIS 7. dump the DUN to the text le To process elements, the tool uses the ASIS.Iterator.Traverse Element query basically, and individual structural queries where each relation between elements is signi cant to generate the DUN. Semantic queries contained in ASIS have been also e ective. To enable slicing programs with access types accurately, each symbol for a variable contains the normalized form, the type of the variable, which also shows whether it is an access type or not. The details for the algorithm of analysis of the data ow in a program with pointers can be found in [11], and it is applicable to access types of Ada. We tried to generate the DUN by the tool from an Ada 95 program having enough scale for practical use. As a subject program, we chose \Complete parallel code for LTE spectral line synthesis in rotating and (non)radially pulsating stars"[14]. It has 29 compilation units and we converted it into one unit which has about 8200 lines. A DUN had been generated from the unit, which had 2126 vertices and 2423 arcs. The generation took 2 minutes 7 seconds,

where the execution environment was Sun Ultra1 (Ultra SPARC 200MHz, main memory 128MB), Solaris 2.6, gnat 3.11p[13], ASIS-for-GNAT 3.11p[12].

6. A System Dependence Net Generator for Ada 95 Programs The SDN of the target program can be generated from its DUN. A SDN Generator can be implemented in a language-independent way. As the rst step of the generation, our SDN Generator computes control dependences and data dependences in the target DUN. As the second step, it computes selection dependences, synchronization dependences and communication dependences, which are related with concurrency, in the target. In these two steps, we could use some technique used in the generation of TDNs[10]. As the next step, the tool computes call relation arcs, parameter-in relation arcs and parameter-out relation arcs in the target. Actual-in vertices are generated from the actual-in-labeling-function in the target DUN, actual-out vertices are from actual-outlabeling-function. Formal-in vertices are from formalin-labeling-function and formal-out vertices are from formal-out-labeling-function. From result-labelingfunction, call arcs, and above 4 functions, call relation arcs, parameter-in relation arcs and parameter-out relation arcs are generated. Finally, summary arcs are computed. An input of our SDN Generator is a text le which represents DUN, and the tool puts computed dependence arcs and interprocedural relation arcs together and generates the SDN, and outputs it as a text le.

Since the SDN for concurrent programs is an extension of the System Dependence Graph in [8], we can use the two-pass slicing algorithm to compute slices of a concurrent program based on the SDN. The twopass slicing algorithm can be brie y described as follows based on the SDN. The details for the algorithm can be found in [8]. The following algorithm is for backward-slicing, as an example. In the rst phase, the algorithm traverses forward along all arcs except parameter-out relation arcs, and marks those vertices reached in the SDN. In the second phase, the algorithm traverses forward to all vertices marked during the rst phase along all arcs except call relation arcs and parameter-in relation arcs, and marks reached vertices in the SDN. The slice is union of the vertices of the SDN marked during the rst and second phases.

7. A Static Slicer as an Application of System Dependence Nets The most direct application of SDN is slicing concurrent programs[15]. Using SDN as a representation of concurrent programs, we can extend the notion of slicing to concurrent programs and propose a graphtheoretical approach to slicing the programs. A static backward-slicing criterion of a concurrent program is an ordered pair (s; V ) where s is a statement in the program and V is a set of variables used at s. The static backward-slice S BS (s; V ) of a concurrent program with respect to a given static backward-slicing criterion (s; V ) is the set of all statements in the program that possibly a ect the start or end of execution of s and/or a ect the values of variables in V .

Figure 6. An output of a slice by the slicer.

We implemented a static slicer based on the SDN and above algorithm, for an example of applications of the SDN. When we specify a source le of a program as an input of the slicer, it reads a text le of the SDN corresponding to the program, which have been given beforehand, by the DUN Generator and the SDN Generator. We can specify a slicing criterion in the program by the mouse pointer. Figure 6 shows an example of the execution of the slicer.

8. Concluding Remarks We have de ned the DUN and the SDN as two representations for concurrent Ada 95 programs and presented implementations of a DUN generator and a SDN generator for Ada 95 programs. Moreover, as an example of many applications of the SDN, we presented an implementation of a static slicer for Ada 95 programs based on the SDN. However, the applicable range of the SDN and its generator presented in this paper is within a compilation unit contained Ada environment. As a future work, we will try to identify various dependence relationships holding between components in a large-scale software system with Ada 95, and construct a new representation adequate to various large-scale software systems. There is an complicated problem, which is to cover all syntax and semantics of Ada 95 for the DUN generator. For example, composite types are still dicult to handle well.

References [1] J. Barnes. Programming in Ada 95. AddisonWesley, 1995. [2] J. Cheng. Process Depence Net of Distributed Programs and Its Applications in Development of Distributed Systems. Proc. IEEE-CS 17th Annual International Computer Software & Applications Conference: 231{240, 1993.

[3] J. Cheng. Nondeterministic Parallel Control-Flow / De nition-Use Nets and Their Applications. in G. R. Joubert, D. Trystram, F. J. Prters, and D. J. Evans (Eds.), \Parallel Computing: Trends and Applications," Elsevier Science Publishers B. V. (North-Holland): 589{592, June 1994. [4] J. Cheng. Task Dependence Nets for Concurrent Systems with Ada 95 and Its Application.

Proc. 1997 ACM TRI-Ada International Conference: 67{78, 1997.

[5] C. Colket. et al. Architecture of ASIS: A tool to Support Code Analysis of Complex Systems. ACM Ada Letters, Volume XVII, No. 1: 35{40, 1997. [6] C. D. Cooper. ASIS-Based Code Analysis Automation. ACM Ada Letters, Volume XVII, No. 6: 65{69, 1997. [7] J. Ferrante, K. J. Ottenstein, J. D. Warren. The Program Dependence Graph and Its Use in Optimization. ACM Transactions on Programming

Languages and Systems, Vol. 9, No. 3: 319{349,

1987.

[8] S. Horwitz, T. Reps. Interprocedural Slicing Using Dependence Graphs. ACM Transaction on Programming Language and System, Vol. 12, No. 1: 26{60, 1990. [9] International Organization for Standardization. Information Technology - Programming Language - Ada. ISO/IEC 8652:1995(E), 1995. [10] Y. Kasahara, J. Cheng, K. Ushijima. Task Dependence Net of Concurrent Ada Programs and Its Automatic Generation. Transactions of IEICE, Vol. J79-D-I, No. 11: 925{935, 1996. (in Japanese) [11] Y. Nomura, J. Cheng, K. Ushijima. Slicing Programs with Pointers. Proceedings of the Interna-

tional Symposium on Future Software Technology '96, Xian, China: 131{138, October, 1996.

[12] S. Rybin, A. Strohmeier, E. Zue . ASIS for GNAT: Goals, Problems, and Implementation Strategy. ACM Ada Letters, Volume XVI, No. 2: 39{49, 1996. [13] E. Schonberg, B. Banner. The GNAT Project: A GNU-Ada 9X Compiler. Ada Europe News, No. 20: 10{19, 1995. [14] M. J. Stift. Astrophysical software engineering in Ada. Irish Astron. Journal, No. 23: 46{48, 1996. [15] M. Weiser. Program Slicing. IEEE-CS Transactions on Software Engineering, Vol. SE-10, No. 4: 352{357, 1984. [16] J. Zhao, J. Cheng, K. Ushijima. System Dependence Net: An Interprocedural Program Dependence Representation for occam2 Programs. in S. Noguchi and M. Ota (Eds.), \Correct Models of Parallel Computing," IOS Press: 87{96, 1996.

Suggest Documents