CN105183655B - Android application program data contention detection based on predictability analysis - Google Patents
Android application program data contention detection based on predictability analysis Download PDFInfo
- Publication number
- CN105183655B CN105183655B CN201510626507.2A CN201510626507A CN105183655B CN 105183655 B CN105183655 B CN 105183655B CN 201510626507 A CN201510626507 A CN 201510626507A CN 105183655 B CN105183655 B CN 105183655B
- Authority
- CN
- China
- Prior art keywords
- activity
- thread
- android
- data contention
- variable
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The inventive method is based on Android Development Framework and its multithreading model, pitching pile Android application program and the single perform track of dynamic operation extraction, predictive analysis method is reused to analyze perform track, construct the generation order relation (Happens Before) between its activity and predict the multiple perform tracks of generation, variable relaxation is combined on this basis and path relaxation enters row constraint coding to all activities in perform track, is finally put into constraint solver and is solved to complete the detection of data contention.The present invention can effectively reduce the rate of false alarm of data contention, favorable expandability, efficiency high, only need to collect single running orbit, greatly reduce cost of labor.
Description
Technical field
The invention belongs to field of computer technology, especially software technology field.The invention provides one kind to use prediction
Property analysis method detection Android application program in data contention problem, for Software Quality Assurance.
Background technology
In cybertimes, cell phone is easy to carry, and application program (Mobile App) has obtained wide variety of user thereon
Favor.Due to numerous Google applications of the opening and seamless combination of Android so that manufacturer can release rich at low cost
Rich multiple product colorful, with their own characteristics.The market share shared by Android rises to from the 79.6% of the second quarter in 2013
The 84.7% of the second quarter in 2014.But due to the opening and freedom of Android platform, Android application program has species numerous
The characteristics of more, isomery autonomy, and develop threshold it is low, it is Open Source Code prevailing so that application program in software quality it is congenital not
Foot, how to ensure that the quality of Android application is a huge problem for developer.
Android application program is event driven, and Android system has unique threading mechanism, callback method and entered more
The characteristics such as mouth.Android system provides 4 big components for developer:
(1) it is movable, Activity, the interface that can be interacted therewith is provided the user, each user mutual
Interface is all to have a main Activity in an Activity and whole application program, i.e., when initial user starts
The interface entered;
(2) service, Service, perform the task of long-play on backstage, other components can be opened and bound
One Service;
(3) content provider, Content Providers, there is provided a kind of data storage management in Android system
Mechanism, other components can necessary data access in Content Providers be used for and user-to-user information friendship
Stream;
(4) broadcast, Broadcast, for monitoring some activities caused by Android system, for example receive information, receive
Phone etc., App can receive sort of activity by Broadcast Receiver, and can make respective handling by it.
Android system is by calling the life cycle methodology of a series of component come the operation of management assembly.Create one newly
Component, it is necessary to inherit the component class that an Android system provides.In subclass, it is also necessary to realize what some were fixed
Callback method, for when component carries out State Transferring can management assembly well operation.
There is the callback method of following several life cycles in Activity:
1.onCreate():Create;
2.onStart():Call and start immediately after onCreate () callback method;
3.onResume():Status user can interact with interface;
4.onPause:Suspend current component;
5.onStop():Stop and discharge some resources;
6.onDestory():Destroy component;
7.onRestart():Restart component.
Service is then following callback method:
Start Service:OnCreate (), onStartCommand (), onDestroy ();
Bind Service:OnCreate (), onBind (), onUnBind (), onDestroy ().
Under default situations, all component of an application operates in identical processor and identical thread in Android system
Above.Can certainly be by setting the Android of component:Process attributes carry out specified run processor.Transported in component
In the trade, it is contemplated that the efficiency of operation, developer perform different tasks commonly using different threads, to improve application
Performance.Since application startup, system can maintain a main thread, through the whole life cycle of application, for allocation activities,
Administration interface, processing respective logic operation.Developer can create extra asynchronous thread concurrently to carry out relevant work simultaneously,
Referred to as worker thread, including:Directly inherit Thread classes or realize Runnable interfaces;Open or binding one is extra
Service performs task on backstage;A worker thread, which is opened, using AsyncTask performs asynchronous task.
Due to the multi-thread mechanism and its distinctive callback method of Android system, developer, which is easy to write out, to cause to flow
Such as deadlock in journey be present, perform the code of the problems such as unreachable activity, data contention, wherein data contention phenomenon is the most general
Time.Data contention refers to:In multithread programs, two access operated to identical shared variable of different threads are without spy
Fixed order, and wherein at least one is the situation of write operation.Once data contention occurs, then application program may be caused to run quickly
Burst, situations such as data are inconsistent, bring serious harm.
Traditional concurrent program field compares in-depth study to data contention, and conventional method has based on occurred sequence
With the detection method based on lock collection.In Android application program data contention context of detection, existing method is confined to occurred sequence.This hair
It is bright will provide it is a kind of it is new, the data contention problem in Android application program is detected based on the method for predictability analysis, to carry
The precision and efficiency of high detection.
The content of the invention
The problem to be solved in the present invention is:Android application program running environment is simulated, formulates Android Parallel Semantics rule, and
Using it is new, the data contention of Android application program detected based on the detection technique of predictability analysis, to ensure its quality.
The technical scheme is that:Android application program data contention detection based on predictability analysis, it is characterized in that
Based on Android Development Framework and its multithreading model, pitching pile Android application program and the single perform track of dynamic operation extraction, then
Perform track is analyzed using predictive analysis method, constructs the generation order relation (Happens-Before) between its activity
And the multiple perform tracks of generation are predicted, on this basis with reference to variable relaxation and path relaxation to all activities in perform track
Enter row constraint coding, be finally put into constraint solver and solved, to complete the detection of data contention.
Invention specifically includes following steps:
1) according to Android Development Framework and its multithreading model, pitching pile point and the activity to be recorded, pitching pile Android are designed
Application source program, and Dynamic Execution obtains single perform track.
2) it is regular according to the Parallel Semantics of Android application program, construct the Happens-Before set of relations of perform track.
3) analyze perform track Happens-Before set of relations, using the rationally change activity of predictive analysis method it
Between scheduling, to generate multiple perform tracks.
4) all activities in perform track are entered with row constraint coding, and combine variable relaxation and path relaxation to reduce wrong report
Rate.
5) constraints is solved by constraint solver, completes the detection of data contention.
In step 1), Android Development Framework is analyzed, with reference to its distinctive multithreading model, pitching pile original Android application program,
Dynamic operation is to obtain Android application perform track.
Wherein, perform track T=<e1, e2..., en>It is an active flow, for source program Source APK, we recognize
Different operations has been carried out for each sentence in it, has been called activity.We record wherein to it is concurrent it is related, may
Cause the activity of data contention, including:The initialization of thread, open the threading operations such as a thread;The read-write behaviour of shared variable
Make;The application release operation of lock collection;The mandate related to task, the operation such as start, end task.
In step 2), the Parallel Semantics based on Android are regular, the Happens-Before set of relations between tectonic activity.Android
Parallel Semantics rule include regular (Intra-Thread Happens-Before), cross-thread rule (Inter- in thread
Thread Happens-Before), callback method it is regular (CallBack Happens-Before).
Rule includes in thread:Sequence (Order-Intra) in thread, authorized appropriation (PowerPost- in thread
Intra), distribution starts (PostBegin-Intra), task atomicity (TaskAtomic-Intra), activity transmission in thread
(Trans-Intra)。
Cross-thread rule includes:Cross-thread authorized appropriation (PowerPost-Inter), cross-thread distribution start
(PostBegin-Inter), cross-thread activity transitivity (Trans-Inter), Fork, Join, lock are regular (Lock).
Callback method rule includes:Activity readjustment (activity callback), service readjustment (service
callback)。
Happens-Before set of relations=<E, R>, wherein E is the activity in perform track<e1, e2..., en>, R=<
ej< ek| j, k ∈ [1, n] ∧ j ≠ k>, ej< ekExpression activity is to (ej, ek) meet Android Parallel Semantics and movable ejPrior to work
Dynamic ekOccur.
In step 3), the scheduling between reasonable change activity is analyzed to generate multiple perform tracks using predictive.
Perform track T=<e1, e2..., en>Be activity once scheduling, due to multithreading perform uncertainty, every time
The activity scheduling of execution is different.In single perform track, some activities must comply with specific priority order relation, but some
Scheduling mode can be changed between read-write activity, i.e.,:On constant Android Parallel Semantics rule-based approach is met, variable active is operated
Rearrange, to obtain new activity scheduling, so as to generate multiple perform tracks from the prediction of single perform track, it is possible thereby to visit
Survey wider solution space.
In step 4), application variables relaxation and path relaxation, to obtain the expression of some constraintss.
In traditional predictive method, it is desirable to which the reading value of same variable is necessarily equal to the last to variable write-in
Value, because this constraint is present, impliedly to reading " activity after same thread " and to write " activity before same thread "
Constraint is applied with, but actually such constraints is excessively strict, can cause failing to report for result.We are relaxed to this change
The constraint of read-write is measured, referred to as variable relaxes.
In the once execution of program, if running into branch's situation, a wherein branch can only be performed.Traditional predictability
Analysis method requires to perform as former state, can not cover the defects of being hidden in other branches.We pass through to control statement branch bar
Part value is negated to enforce other branches, referred to as path relaxation.
After completing aforesaid operations, multiple predictive perform tracks are obtained, accordingly generate some constraintss, following institute
Show.
Variable bound (Value Constraints):Row constraint is entered to the specific assignment of variable;
Control constraints (Control Constraints):Row constraint is entered to the control condition of branch statement;
Sequence constraints (Order Constraints):Row constraint is entered to Android Parallel Semantics;
Data contention constrains (Race Constraints):Row constraint is entered to the activity that data contention may occur;
Cross-thread activity scheduling constrains (Inter-thread Act Constraints):By rearranging same variable
Between read-write alignment constraints, a variety of scheduling modes can be obtained, so as to predict the multiple perform tracks of generation.
In step 5), institute's Constrained is put into constraint solver and solved, so as to complete the detection of data contention.Its
In, constraint solver uses the Z3 solvers of Microsoft, if solution, then shows data be present in tested Android application program
Race problem.
The present invention has advantages below by using above technical scheme:
1. scalability is good:The present invention is based on predictive analysis method, the advantages of remaining dynamic analysing method, for big
For sizable application program, autgmentability is strong.
2. do not report by mistake:Because perform track is obtained by actual motion, and is the single execution based on reality
Track is predicted analysis, thus can avoid reporting by mistake.
3. accuracy rate is high:Present invention uses optimisation techniques such as variable relaxation and path relaxations, reduce and fail to report, improve
The precision of testing result.
Brief description of the drawings
Fig. 1 is the flow chart of the present invention.
Fig. 2 is tested Android application program MusicPlayer partial source symbols.
Fig. 3 is MusicPlayer part running orbit.
Embodiment
The inventive method is primarily based on Android Development Framework and its multithreading model, pitching pile Android application program and dynamic fortune
Row extracts single perform track, reuses predictive analysis method and perform track is analyzed, construct the generation between its activity
Order relation (Happens-Before) simultaneously predicts the multiple perform tracks of generation, on this basis with reference to variable relaxation and path relaxation
All activities in perform track are entered with row constraint coding, is finally put into constraint solver and is solved, so as to complete data
The detection of competition.
The flow of the present invention is as shown in figure 1, specifically include following five steps.
The first step:Android Development Framework is analyzed, with reference to its distinctive multithreading model, pitching pile original Android application program, is moved
State operation obtains Android perform track, perform track T=<e1, e2..., en>It is an active flow, for source program Source
APK, it is believed that each sentence in it has carried out different operations, is called activity.We record wherein with concurrently
Activity that is related, may result in data contention, including:The initialization of thread, open the threading operations such as a thread;It is shared to become
The read-write operation of amount;The application release operation of lock collection;The mandate related to task, the operation such as start, end task.
According to every activity particular situation in program, we summarize our correlated activations to be recorded, and in source
Identify and record one by one in program.
Define 1:The basic activity of record
1).threadinit(t):Current thread initializes;
2).threadexit(t):Current thread is finished;
3) .fork (t, s, t '):New t ' threads are created in t threads, s is the type of thread;
4) .join (t, s, t '):Thread is finished, returning result;
5).wait(t):Wait current thread obstruction;
6) .notify (t) or notify All (t):Notice wait () thread can continue executing with;
7) .beginTask (t, p):Task p is performed in thread t;
8) .endTask (t, p):Terminate execution task p in thread t;
9) .touchEvent (t, e):Thread t response events, including following event:launch:Initiate app;home:
Home keys use;click:Click on;Rotate:Rotation;sliding:Slide;back:Retract, each movable triggering can
Cause the change of Android component lifecycle;
10) .acq (t, 1):Process t application locks I;
11) .reI (t, I):Process t release locks I;
12) .read (t, m):Process t carries out internal memory reading to m;
13) .write (t, m, value):Process t carries out internal memory write-in to m;
14) .post (t, p, t '):Transmit execution task p and give thread t ';
15) .hasRunPower (t, p):Task p has the right to perform.
Second step:Parallel Semantics based on Android are regular, the Happens-Before set of relations between tectonic activity.
Define 2:Happens-Before relations
Happens-Before is initially a kind of partial order for being used for describing program activity introduced by Lesile Lamport
Relation.If A HB B in program, then B is with regard to that can see A operation (no matter whether A and B is same thread).
Here we regard the execution of multithreading as movable E track, and activity here refers to that JMM is acted, namely
Java memory models act (Java Memory Model Action).According to the multithreading model for defining 2 and Android, Wo Menke
To obtain definition 3, Android Parallel Semantics rule.
Define 3:The Parallel Semantics rule of Android
(1) cross-thread Happens-Before relations (intra-thread)
I. sequence relation (Order-Intra) in thread:If movable ei, eiBelong to same thread t, and ejControl
Dependent on ei, then have ei< intra ej;
Ii. authorized appropriation (PowerPost-Intra) in thread:If movable eiPossess perform some task authority i.e.
ei=hasRunPower (t, p), movable ejDistribute the task (ej=Post (t, p, _)), and ei, ejBelong to same thread, then
ei< intra ej;
Iii. distribution starts (PostBegin-Intra) in thread:The distribution of one task is sent out before the task starts
It is raw, even ei=Post (t, p, t), ej=beginTask (t, p) and ei, ejBelong to same thread, then ei< intra ei;
Task atomicity (TaskAtomic-Intra):If before a task starts from another task, the task
Also can terminate before another task starts, i.e.,:If ek=beginTask (t, p1), ei=endTask (t, p1), ej=
BeginTask (t, p2), ek< ej, then ei< intra ej;
Iv. transitive relation (Trans-Intra) in thread:If ei, ekMeet Happens-Before relations in thread,
And ek, ejMeet Happens-Before relations in thread, then ei, ejMeet Happens-Before relations in thread.
(2) cross-thread Happens-Before relations (inter-thread)
I. cross-thread authorized appropriation (PowerPost-Inter):If movable eiPossess the authority for performing some task, i.e. ei
=hasRunPower (t, p), movable ejDistribute the task (ej=Post (t,p, _)), and ei, ejSame thread is not belonging to, then
ei< inter ej;
Ii. cross-thread distribution starts (PostBegin-Intra):The distribution of one task is sent out before the task starts
It is raw, i.e., if ei=Post (t, p, t), ej=beginTask (t, p) and ei, ejSame thread is not belonging to, then ei< inter
ej;
Iii. cross-thread transitive relation Trans-Intra:If ei, ekMeet cross-thread Happens-Before relations, and
ek, ejMeet cross-thread Happens-Before relations, then ei, ejMeet cross-thread Happens-Before relations;
iv.Fork:If movable ei, ejSame thread is not belonging to, and has ei=fork (t, t '), ej=threadinit
(t '), then:ei< inter ej;
v.Join:If movable ei, ejSame thread is not belonging to, and has ei=threadexit (t '), ej=join (t,
T '), then:ei< inter ej;
Vi. (Lock) is locked:If movable ei, eiIt is not belonging to same thread and ei=release (t, 1) ej=acquire
(t ', 1), then:ei< inter ej。
(3) life cycle callback Happens-Before relations (callback method)
Activity:
I.onCreate () < cb onStart () < cb onResume ();
Ii.onResume () < cb onPause () [< cb onStop ()];
Iii.onStop () < cb onDestory ();
Iv.onStop () < cb onRestart () < cb onStart ();
V.onPause () < cb onResume ();
Vi.onStop () < cb onCreate ().
Service
I.onCreate () < cb onStartCommand () < cb onDestory ();
Ii.onCreate () < cb onBind () < cb onUnbind () < cb onDestory ().
According to define 1 and define 3, we analyze perform track and construct its interior activity must be fulfilled for it is unmodifiable
Happens-Before set of relations < E, R >.
Define 4:<E, R>Relation
The Happens-Before relations between Android activity are characterized, wherein E is the activity in perform track<e1, e2..., en
>, R=<ej< ek| j, k ∈ [1, n] ∧ j ≠ k>, ej< ekExpression activity is to (ej, ek) meet Android Parallel Semantics and activity
ejPrior to movable ekOccur.
3rd step:Multiple perform tracks are generated using the scheduling between the rationally change activity of predictive analysis method.
Perform track T=<e1, e2..., en>Be activity once scheduling, due to multithreading perform uncertainty, every time
The activity scheduling of execution is different.In single perform track, some activities must comply with specific priority order relation, but some
Scheduling mode can be changed between read-write activity, i.e.,:On constant Android Parallel Semantics rule-based approach is met, variable active is operated
Rearrange, to obtain new activity scheduling, so as to generate multiple perform tracks from the prediction of single perform track, it is possible thereby to visit
Survey wider solution space.
For example, to a variable v, thread 1 has first carried out read operation to it, then has carried out write operation (being designated as W1, R1);Line
Journey 2 has equally also carried out read operation and write operation (being designated as W2, R2) to it.In once performing, we may be to thread 1 and 2
Between interaction only obtain a kind of scheduling mode and (be designated as scheduling 1:W1, W2, R1, R2).Between being interacted yet with multithreading not
Certainty, it is also possible to scheduling 2 be present:W1, W2, R2, R1;Scheduling 3:W1, R1, W2, R2;Dispatch 4.... etc..
Predictive analysis method, constant Android Parallel Semantics rule is namely based on, is once performing obtained scheduling 1
On the basis of, rationally change interaction sequences between variable activity, to predict the multiple perform tracks of generation.
4th step:, should according to the Parallel Semantics rule (defining 3) and Happens-Before set of relations (defining 4) of Android
All activities in perform track are entered with row constraint with variable relaxation and path relaxation to encode.
In traditional predictive method, it is desirable to which the reading value of same variable is necessarily write equal to the last time to the variable
The value entered, because this constraint is present, impliedly to reading " activity after same thread " and writing the " work before same thread
It is dynamic " constraint is applied with, but actually such constraints is excessively strict, can cause failing to report for result.Variable relaxation relaxes
This kind of constraint variable operant activity, accuracy is improved.
Use Oj, OjDeputy activity ei, ejAppearance order, taken with symbolic execution technique to replace the possibility of program internal variable
Value.To a kind of scheduling R1, W1, R2, the W2 of a variable, if using traditional predictive method, W1, R2 will meet cross-thread
Happens-Before relations, and according to Happens-Before rules in thread:(R1, W1), (R2, W2) and transitivity rule
Then, R1 can be obtained, Happens-Before relations between W2 activities be present.But due between multithreading interaction under truth
Uncertainty, may have data contention between R1, W2, original method, which will result in, to be failed to report.In the present invention, Wo Mentong
Variable relaxation is crossed to improve the accuracy of detection, specific implementation is ensured by various constraintss.
In the once execution of program, if running into branch's situation, a wherein branch can only be performed.Traditional predictability
Analysis method requires to perform as former state, can not cover the defects of being hidden in other branches.We pass through to control statement branch bar
Part value is negated to enforce other branches, referred to as path relaxation.It is different because Android application program is event driven program
Event can cause the execution of different callback methods, in order to detect Android application source program in all directions, we have also carried out road
Footpath relaxes.
After completing above-mentioned variable relaxation and path relaxation, multiple predictive perform tracks can be obtained, corresponding constraint
Condition represents as follows.
Variable bound (Value Constraints):Such as:Some variable in a program is represented, its
Middle line number 1 represents position, and the variable name in subscript y representation programs, W represents write operation, then the constraint representation:The first of program
OK, y variables are clearly entered as 3.Variable bound is for variable in logging program by the operant activity of clear and definite assignment.
Control constraints (Control Constraints):Such as:Some variable in program is represented, its
Middle line number 1 represents position, and subscript x represents variable name, and R represents read operation, then the constraint representation:In the first row of program, read
The value of the x variables taken is greater than 3.Control constraints constrain the trend of program, illustrate to need the control followed during program operation
Condition.
Sequence constraints (Order Constraints):Activity in Android multithread programs orbution it is a kind of about
Beam.For example, 2 movable ej, ejThe priority order relation R in 4 is being defined if meeting, is using Oi< OjTo represent.
Data contention constrains (Race Constraints):The form of expression is Oi=Oj, wherein movable i, j are belonging respectively to 2
Different threads, and (at least one write operation) is operated to same variable, two movable sequence constraints are equal, just
Represent that they can concurrently be performed, meet the definition of data contention.
Cross-thread interaction constraint (Inter-thread Constraints):Such as: The different dispatch situation of representation program activity,Represent second
Row is equal to the value write in the first row to the variable, and corresponding movable O to the value that variable x is read1Prior to movable O2Occur,
It is multiple it is such constrain between use or action link.Cross-thread interaction constraint be variable active in program is dispatched it is a kind of about
Beam.
5th step:Institute's Constrained is put into constraint solver to be solved, so as to complete the detection of data contention.
The process that constraint solver solves feasible perform track is:Constraints all in perform track is encoded
Substitute into afterwards in constraint solver, obtain solution space, solution space is to meet all feasible perform tracks of constraints.Compile
Code process is that conditional expression is converted into the recognizable form of solver, and the conditional expression form that different solvers need is omited
There is difference.
The present invention uses Z3 solvers.Z3 solvers are a Statistical Model Theories developed by Microsoft Research
(Satisfiability Modulo Theories) solver, logarithm value type can be used for, Boolean type expression formula enters row constraint
Solve.
Specific implementation explanation is done with reference to a real case MusicPlayer, not only limit of the invention is applied to should
Example.
MusicPlayer is an Android application program, and its function is down-load music and to play music from website.
Fig. 2 illustrates its code snippet, including two classes:DwFileAct classes and FileDwTask classes.DwFileAct is inherited
Activity, it is an Activity component, there is provided the interface with user mutual, wherein onPlayClick methods make user
Play buttons play music can be clicked on.FileDwTask inherits AsyncTask classes, and AsyncTask provides a kind of execution
The framework of asynchronous task, FileDwTask is set to perform the task of long-time down-load music on backstage.
The detailed process that data contention detection is carried out to the application program is as follows:
1. Android Development Framework is analyzed, with reference to its distinctive multithreading model, pitching pile original Android application program, dynamic operation
Obtain Android perform track.
The activity to be recorded has:Threadinit (t), threadexit (t), fork (t, s, t '), join (t, s,
T '), wait (t), notify (t) or notifyAll (t), beginTask (t, p), endTask (t, p), touchEvent (t,
E), acq (t, I), reI (t, I), read (t, m), write (t, m, value), post (t, p, t '), hasRuPower (t, p),
Being described in detail can be referring to definition 1.
Fig. 3 presents MusicPlayer perform track fragment, there is 3 threads in figure, and thread t0 represents system
ActivityManagerService, for managing the component of Android application program;Thread t1 is main thread main, i.e. source code
In DwFileAct;Thread t2 represents the worker thread for performing asynchronous task, i.e., the FileDwTask classes in source code.Holding
In row track, main thread initializes first, and activity afterwards performs LAUNCH_ACTIVITY authorities, after thread t0 notice,
LAUNCH_ACTIVITY tasks are performed, object is then initialized, has carried out write operation, are then opened by fork operations
Asynchronous thread performs inter-related task;Asynchronous thread have read DwFileAct-obj in processing task, then notify main thread to hold
Row onPostExecute tasks;Main thread performs onPostExecute tasks after being connected to post;During this period, due to performing
LAUNCH_ACTIVITY, main thread have had the authority for performing onDestroy tasks, all may be used at subsequent any moment
OnDestroy tasks can be performed.
2. the Happens-Before set of relations between tectonic activity.
The Parallel Semantics rule of Android is as follows:
1) Happens-Before rules in thread
Sequence rules (Order-Intra) in thread, authorized appropriation regular (PowerPost-Intra), thread in thread
Interior distribution starts rule (PostBegin-Intra), task atomicity regular (TaskAtomic-Intra), interior transmit of thread is closed
System is regular (Trans-Intra).
2) cross-thread Happens-Before rules
Cross-thread authority distribution rule (PowerPost-Inter), cross-thread distribution start rule (PostBegin-
Inter), cross-thread delivery rules (Trans-Inter), Fork, Join, lock are regular (Lock).
3) life cycle callback Happens-Before rules
Active rule (Activity)
Service regulation (Service)
Detailed description can be referring to definition 3.MusicPlayer Happens-Before relations are constructed, summary record is such as
Under (directly use line number deputy activity).
i.Order-Intra:
The < 8 of 1 <, 2 <, 4 <, 5 <, 6 < 7
The < 12 of 9 <, 10 < 11
The < 16 of 13 <, 14 < 15
The < 20 of 18 < 19
ii.PowerPost-Inter
2 < 3;7 < 17
iii.PostBegin-Inter
3 < 4;11 < 13;17 < 18
iv.Fork
6 < 9
v.Activity callback
4 < 18
vi.TaskAtomic-Intra
8 < 18
3. the Happens-Before set of relations of perform track is analyzed, using between predictive method rationally change activity
Dispatch to generate multiple perform tracks.Such as Fig. 3, herein it may be seen that the 5th row, the 10th row, the 14th row, the 19th row are to becoming
Amount has carried out obtaining operation, is respectivelyApplication variables relax, and rearrange these activities, and generation is new
Scheduling mode, centre be attached with OR operation.Therefore cross-thread interaction constraint is as follows:
4. application variables relax and path relaxation enters row constraint coding to all activities in Fig. 3 perform tracks
Value Constraints:
Order Constraints:See the 2nd step.
Inter Thread Constraints:See the 3rd step.
ControlConstraints:It is empty.
Race Constraints:5=10,5=14,10=19,14=19,5=19.Due to shared variable
The active set that DwFileAct-obj carries out write operation is { 5,19 }, carries out read operation collection and is combined into { 10,14 }, competing according to data
The definition striven, we can obtain 5, and there may be the movable right of data contention:<5,10>、<5,14>、<10,19>、<14,19
>、<5,19>.
5. solving constraint coding by constraint solver, the detection of data contention is completed.
Institute's Constrained of 4th step is put into z3 solvers and solved, is constrained in 14=19 and 10=19 data contentions
Under, we obtain feasible solution, and other data contentions are constrained in solution space without feasible solution.
Analysis:
1. due to<5,6>、<6,9>、<9,10>For Happens-Before relations, it can be seen from transitivity<5,10>Also belong to
In Happens-Before relations, so<5,10>Data contention will not be caused.
2. due to<5,10>、<10,11<、<11,13>、<13,14>For Happens-Before relations, it is known that<5,14>Category
In Happens-Before relations, so<5,14>Data contention will not be caused.
3. due to<5,7>、<7,17>、<17,18>、<18,19>For Happens-Before relations, it is known that<5,19>Belong to
Happens-Before relations, so<5,19>Data contention will not be caused.
As fully visible, the inventive method obtains multiple perform tracks simultaneously by single perform track using predictability analysis
Analyzed, efficiency high.Application variables relaxation simultaneously and path relaxation carry out coding bound to execution route activity, reduce mistake
Report rate.The data contention mistake that can be efficiently accurately detected so as to the inventive method in Android application program.
Claims (7)
1. the Android application program data contention detection based on predictability analysis, it is characterized in that being based on Android Development Framework and Qi Duo
Threading model, pitching pile Android application program and dynamic operation extract single perform track, reuse predictive analysis to performing rail
Mark is analyzed, and is constructed the generation order relation (Happens-Before) between its activity and is predicted the multiple perform tracks of generation,
Variable relaxation is combined on the basis of this and path relaxation enters row constraint coding to all activities in perform track, is finally put into constraint
Solved in solver to complete the detection of data contention;So-called variable relaxation, it is:Predictive analysis method usually requires that
The reading value of same variable is necessarily equal to the last value for writing the variable, loosens the constraint to this variable read-write so that
The reading value of same variable needs not be equal to the last value for writing the variable;So-called path relaxation, it is:Predictability analysis
Method usually requires that branch's execution according to record, can not cover and not record the defects of being hidden in branch, by controlling language
Sentence branch condition value negates does not record branch to enforce.
2. the Android application program data contention detection according to claim 1 based on predictability analysis, it is characterized in that bag
Include following steps:
1) according to Android Development Framework and its multithreading model, pitching pile point and the activity to be recorded, pitching pile Android application are designed
Source program, and Dynamic Execution obtains single perform track;
2) it is regular according to the Parallel Semantics of Android application program, construct the Happens-Before set of relations of perform track;
3) the Happens-Before set of relations of perform track is analyzed, using between the rationally change activity of predictive analysis method
Scheduling, to generate multiple perform tracks;
4) all activities in perform track are entered with row constraint coding, and combine variable relaxation and path relaxation to reduce rate of false alarm;
5) constraints is solved by constraint solver, completes the detection of data contention.
3. the Android application program data contention detection according to claim 2 based on predictability analysis, it is characterized in that step
It is rapid 1) in, analyze Android Development Framework, with reference to its distinctive multithreading model, pitching pile original Android application program, dynamic operation with
Obtain Android application perform track;
Wherein, perform track T=<e1, e2..., en>It is an active flow, for source program Source APK, it is believed that in it
Each sentence has carried out different operations, is called activity;Record wherein to concurrent work related, that data contention can be caused
It is dynamic, including:The initialization of thread, open a thread;The read-write operation of shared variable;The application release operation of lock collection;With appointing
Be engaged in related Authorized operation, start to operate and the operation that ends task.
4. the Android application program data contention detection according to claim 2 based on predictability analysis, it is characterized in that step
It is rapid 2) in, Parallel Semantics based on Android rule, the Happens-Before set of relations between tectonic activity;The Parallel Semantics of Android
Rule includes regular (Intra-Thread Happens-Before), cross-thread rule (Inter-Thread in thread
Happens-Before), callback method is regular (CallBack Happens-Before);
Rule includes in thread:Sequence (Order-Intra) in thread, authorized appropriation (PowerPost-Intra), line in thread
Distribution starts (PostBegin-Intra), task atomicity (TaskAtomic-Intra), activity transmission (Trans- in journey
Intra);
Cross-thread rule includes:Cross-thread authorized appropriation (PowerPost-Inter), cross-thread distribution start (PostBegin-
Inter), cross-thread activity transitivity (Trans-Inter), Fork, Join, lock are regular (Lock);
Callback method rule includes:Activity readjustment (activity callback), service readjustment (service callback);
Happens-Before set of relations=<E, R>, wherein E is the activity in perform track<e1, e2..., en>, R=<ej<
ek| j, k ∈ [1, n] ∧ j ≠ k>, ej< ekExpression activity is to (ej, ek) meet Android Parallel Semantics and movable ejPrior to movable ek
Occur.
5. the Android application program data contention detection according to claim 2 based on predictability analysis, it is characterized in that step
It is rapid 3) in, generate multiple perform tracks using the scheduling between the rationally change activity of predictive analysis method;
Perform track T=<e1, e2..., en>It is the once scheduling of activity, due to the uncertainty that multithreading performs, holds every time
Capable activity scheduling is different;In single perform track, some activities must comply with specific priority order relation, but some are read
Scheduling mode can be changed between activity by writing, i.e.,:On constant Android Parallel Semantics rule-based approach is met, weight is operated to variable active
New arrangement, to obtain new activity scheduling, so as to generate multiple perform tracks from the prediction of single perform track, it is possible thereby to detect
Wider solution space.
6. the Android application program data contention detection according to claim 2 based on predictability analysis, it is characterized in that step
It is rapid 4) in, application variables relaxation and path relaxation, to obtain the expression of some constraintss;
After completing aforesaid operations, multiple predictive perform tracks are obtained, accordingly generate some constraintss, it is as follows:
Variable bound (Value Constraints):Row constraint is entered to the specific assignment of variable;
Control constraints (Control Constraints):Row constraint is entered to the control condition of branch statement;
Sequence constraints (Order Constraints):Row constraint is entered to Android Parallel Semantics;
Data contention constrains (Race Constraints):Row constraint is entered to the activity that data contention may occur;
Cross-thread activity scheduling constrains (Inter-thread Act Constraints):By rearranging between same variable
Read-write alignment constraints, a variety of scheduling modes can be obtained, so as to predict the multiple perform tracks of generation.
7. the Android application program data contention detection according to claim 2 based on predictability analysis, it is characterized in that step
It is rapid 5) in, institute's Constrained is put into constraint solver and solved, so as to complete the detection of data contention;Wherein, constraint is asked
The Z3 solvers that device uses Microsoft are solved, if solution, then show data contention be present in tested Android application program.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510626507.2A CN105183655B (en) | 2015-09-25 | 2015-09-25 | Android application program data contention detection based on predictability analysis |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510626507.2A CN105183655B (en) | 2015-09-25 | 2015-09-25 | Android application program data contention detection based on predictability analysis |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105183655A CN105183655A (en) | 2015-12-23 |
CN105183655B true CN105183655B (en) | 2017-12-12 |
Family
ID=54905747
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201510626507.2A Active CN105183655B (en) | 2015-09-25 | 2015-09-25 | Android application program data contention detection based on predictability analysis |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105183655B (en) |
Families Citing this family (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106294169B (en) * | 2016-08-17 | 2018-08-03 | 华中科技大学 | A kind of data contention detection and playback method based on semiology analysis virtual machine |
CN106529304B (en) * | 2016-10-27 | 2019-06-14 | 南京大学 | A kind of Android applies concurrent leakage location |
CN106802866B (en) * | 2017-01-23 | 2019-12-10 | 浙江大学 | method for restoring execution path of Android program |
CN109885489B (en) * | 2019-01-31 | 2020-07-21 | 清华大学 | Data race detection method and device in driver |
CN110851353B (en) * | 2019-10-22 | 2023-03-31 | 天津大学 | Concurrent program defect positioning method based on Delta debug and constraint solution |
CN111431737B (en) * | 2020-03-02 | 2022-07-12 | 苏州市职业大学 | Predictive method for detecting data competition in software defined network |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104077226A (en) * | 2014-07-07 | 2014-10-01 | 西安交通大学 | Multithreaded program output uniqueness detection and evidence generation method based on program constraint building |
CN104077144A (en) * | 2014-07-07 | 2014-10-01 | 西安交通大学 | Data race detection and evidence generation method based on multithreaded program constraint building |
CN104572445A (en) * | 2014-12-17 | 2015-04-29 | 南京大学 | Method for detecting BPEL (business process execution language) process data competition in Web service combination |
-
2015
- 2015-09-25 CN CN201510626507.2A patent/CN105183655B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104077226A (en) * | 2014-07-07 | 2014-10-01 | 西安交通大学 | Multithreaded program output uniqueness detection and evidence generation method based on program constraint building |
CN104077144A (en) * | 2014-07-07 | 2014-10-01 | 西安交通大学 | Data race detection and evidence generation method based on multithreaded program constraint building |
CN104572445A (en) * | 2014-12-17 | 2015-04-29 | 南京大学 | Method for detecting BPEL (business process execution language) process data competition in Web service combination |
Also Published As
Publication number | Publication date |
---|---|
CN105183655A (en) | 2015-12-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105183655B (en) | Android application program data contention detection based on predictability analysis | |
Wang et al. | Coverage guided systematic concurrency testing | |
Pavlogiannis | Fast, sound, and effectively complete dynamic race prediction | |
US9792161B2 (en) | Maximizing concurrency bug detection in multithreaded software programs | |
Farzan et al. | Predicting null-pointer dereferences in concurrent programs | |
Kalhauge et al. | Sound deadlock prediction | |
Huang et al. | GPredict: Generic predictive concurrency analysis | |
CN105308578B (en) | The diagnosis of state transformation | |
Hong et al. | A survey of race bug detection techniques for multithreaded programmes | |
CN109635568B (en) | Concurrent vulnerability detection method based on combination of static analysis and fuzzy test | |
EP2713277B1 (en) | Latent defect identification | |
Fiedor et al. | Advances in noise‐based testing of concurrent software | |
Theelen et al. | Model checking of scenario-aware dataflow with CADP | |
Bell | Detecting, isolating, and enforcing dependencies among and within test cases | |
Ghica et al. | Compositional model extraction for higher-order concurrent programs | |
Carvalho et al. | On the implementation of dynamic software product lines: An exploratory study | |
Zhang et al. | Run-time systems failure prediction via proactive monitoring | |
Daian et al. | Runtime verification at work: A tutorial | |
Ehlers | Self-adaptive performance monitoring for component-based software systems | |
Madapudi et al. | Change requests artifacts to assess impact on structural design of SDLC phases | |
Bradbury et al. | Defining a catalog of programming anti-patterns for concurrent java | |
Beckman | A survey of methods for preventing race conditions | |
Calzolai et al. | Simulation and analysis of distributed systems in Klaim | |
Wang et al. | Tracking runtime concurrent dependences in Java threads using thread control profiling | |
Chang et al. | Transformation from activity diagrams with time properties to Timed Coloured Petri Nets |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |