27.03.2014 Views

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

To validate the proposed approach, we conduct an experimental<br />

study on a popular open source software JHotDraw. We<br />

compare the result with that reported by some other researches,<br />

and find that our identification of Adapter pattern instances is<br />

more precise, and identification result of State and Strategy<br />

pattern instances is m uch more precise than that of existing<br />

researches. For identification of Observer pattern instances, our<br />

approach has relatively high precision. Our approach can identify<br />

instances that cannot be i dentified by other methods, and<br />

report more detailed information of the pattern instances, but it<br />

cannot identify Observer instances that hasn't data dependence<br />

relations between Subject and Observer.<br />

The rest of this paper is organized as follows: Section II introduces<br />

the implementation of dependence analysis in our tool<br />

JDP-Detector; Section III and IV introduce approaches to identifying<br />

adapting method and Notify method of observer pattern<br />

respectively; Section V compares results of our experimentation<br />

with that of other researches; Section VI concludes the<br />

paper.<br />

II. DEPENDENCE ANALYSIS AND ITS IMPLEMENTATION<br />

We use two kinds of dependence relations in our approach:<br />

control dependence and data dependence. Control dependence<br />

relations are computed using the approach in [15]. Data dependence<br />

relations are computed directly from define-use relations<br />

[3]. The dependence relations is expressed by program<br />

dependence graph (PDG). The Inter-procedural dependence is<br />

expressed by system dependence graph (SDG), an extension of<br />

PDG [14].<br />

Construction of SDG is base d on information of method<br />

call. We use points-to analysis to determine the callee of polymorphic<br />

method call. As a pattern normally involves only several<br />

classes, we adapt Soot and implement a local points-to<br />

analysis that can start from entry of any method [4].<br />

We develop a to ol named JDP-Detector based on Soot to<br />

identify pattern instances in Java system. JDP-Detector<br />

takes .class files as input, and transforms them into Jimple intermediate<br />

representation [4]. Analysis is made on the Jimple<br />

codes. JDP-Detector firstly identify pattern instance candidates<br />

using structure information, and then make dependence analysis<br />

on these candidates to get more precise result.<br />

III.<br />

IDENTIFICATION OF ADAPTING METHOD<br />

A. Dependency Characteristics of Adapting Method<br />

In Adapter pattern, class Adapter inherits from Target.<br />

Method of Adaptee has fulfilled the function required by Target,<br />

but has not the required interface, so the only work the<br />

adapting method of Adapter needs to do is to call the method of<br />

Adaptee and adapt the Adptee's interface to that of the Target.<br />

So, strictly speaking, an adapting method m 1 consists of<br />

three parts: (1) a call to method m 2 ; (2) statements (if available)<br />

before the call, whose only duty is to prepare parameters for m 2 ;<br />

(3) statements (if available) after the call, whose only duty is to<br />

transform the output of m 2 to output of m 1 .<br />

Based on the observation, we identify the adapting method<br />

according to the following conditions: (1) m 1 calls m 2 ; (2) the<br />

call statement depends on all the statements (when available)<br />

before the call and part or all of m 1 's parameters; (3) the output<br />

of m 1 depends on the call statement and all the statements<br />

(when available) after the call; (4) the input and output of m 2<br />

forms cut-set of m 1 's data dependence graph. Condition 4<br />

means that the dataflow paths cannot bypass the call statement.<br />

B. Case Study<br />

Fig. 1 illustrates the structure of an Adapter instance identified<br />

by JDP-Detector in JHotDraw 5.1. In the instance,<br />

startConnector is the Adapter interface and connectorAt is the<br />

Adaptee interface. Fig. 2 shows the PDG of startConnector, in<br />

which the yellow node represents a call to connectorAt, the<br />

green nodes represent the parameters of startConnector and the<br />

statements before the call to connectorAt, the red node represents<br />

the output of startConnector. As what can be seen from<br />

Fig. 2, the PDG of startConnector matches the dependence<br />

relation characteristic of adapting method.<br />

Figure 1. An Object Adapter Instance in JHotDraw 5.1<br />

Figure 2. The Dependence Graph of startConnector<br />

IV.<br />

IDENTIFICATION OF NOTIFY METHOD<br />

A. Dependence Relation of Notify Method<br />

The intent of Observer pattern is to "define a one-to-many<br />

dependency between objects so that when one object changes<br />

state, all its dependents are notified and updated automatically"<br />

[1] . When Subject changes its state, its Notify method invokes<br />

Update methods of all the Observers.<br />

In some cases, the Subject only informs the Observers that<br />

an event happens. As a classical implementation, the Subject<br />

creates an event object, and sends it to Observer as a parameter<br />

of Update. In some other cases, the Observer needs to update<br />

values of its own fields to keep consistent with that of the Subject.<br />

290

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!