-
Notifications
You must be signed in to change notification settings - Fork 180
Fix Mahjong's FieldPointsToGraph by handling non-functional MockObj in PTA Result #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #162 +/- ##
============================================
+ Coverage 72.85% 75.18% +2.32%
- Complexity 4435 4580 +145
============================================
Files 480 480
Lines 15927 15927
Branches 2185 2179 -6
============================================
+ Hits 11603 11974 +371
+ Misses 3467 3080 -387
- Partials 857 873 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The perceived 'inconsistency' is actually a minor optimization. If a field has never been loaded, there's no need to consider it during object merging; hence, we omitted it from the FPG. Regarding zero-length arrays, as they are non-functional, their indices should not reference any objects. Is it necessary for Mahjong to perform a check on this? |
Just force-updated a test in 5d2fa24 in this PR to reproduce the bug regarding zero-length arrays, a corresponding stacktrace for this bug can be found here. Yes, zero-length arrays are non-functional objects and their indices do not point to any objects, so the Tai-e/src/main/java/pascal/taie/analysis/pta/core/solver/DefaultSolver.java Lines 452 to 455 in 21118b5
When FieldPointsToGraph iterates through pointers concurrently, without checking whether the base object is functional, PointerAnalysisResultImpl will invoke csManager.getArrayIndex() to create pointers for zero-length arrays:Tai-e/src/main/java/pascal/taie/analysis/pta/PointerAnalysisResultImpl.java Lines 273 to 278 in 21118b5
This is explains the |
Incorrect PFG edgeFor an array load statement Tai-e/src/main/java/pascal/taie/analysis/pta/toolkit/mahjong/FieldPointsToGraph.java Lines 57 to 65 in 21118b5
This is in fact incorrect, since This will actually add more edges than needed to the PFG. Consider the following example: Object[] x = new Object[1]; // o1
Object[] y = new Object[2]; // o2
x[0] = new Object[]; // o3
y[0] = new Object[]; // o4
Object[] z; z = x; z = y;
return z[0]; // ?? For array access OptimizationAs for the optimization, a field (or array index) that is never loaded can still affect the final analysis result through reflection or native APIs (consider the handling of argument passing for Here I compare 2-object sensitive pointer analysis guided by the current mahjong (denoted as Mahjong) and my fix (denoted as Mahjong-Fix) using some of the benchmark programs from https://github.com/pascal-lab/java-benchmarks, and the four precision metrics from mahjong's paper.
|
Great and detailed explanation! Your fix on PFG edge building is well-executed. Regarding the Tai-e/src/main/java/pascal/taie/analysis/pta/PointerAnalysisResultImpl.java Lines 200 to 215 in 21118b5
Tai-e/src/main/java/pascal/taie/analysis/pta/PointerAnalysisResultImpl.java Lines 218 to 231 in 21118b5
Tai-e/src/main/java/pascal/taie/analysis/pta/PointerAnalysisResultImpl.java Lines 264 to 279 in 21118b5
Tai-e/src/main/java/pascal/taie/analysis/pta/PointerAnalysisResultImpl.java Lines 282 to 295 in 21118b5
|
…and object fields in `PointerAnalysisResultImpl`
I have fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Inconsistency
The current implementation of Mahjong is inconsistent with its paper. According to [1], if the field
f
of an objectoi
may point to another objectoj
, then there is an edge fromoi
tooj
with labelf
added to the FieldPointsToGraph. However, currently Mahjong builds edges only for those fields that are loaded in the analyzed program.MockObjs
ConcurrentModificationException may be thrown when building the FieldPointsToGraph.
In #140 an optimization targeting zero length arrays is introduced by allocating non-functional MockObjs for 0 sized arrays, whose array indices should never point to any objects. Currently FieldPointsToGraph does not check for this situation.
[1] T. Tan, Y. Li, and J. Xue, “Efficient and precise points-to analysis: modeling the heap by merging equivalent automata,” in Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation, in PLDI 2017. New York, NY, USA: Association for Computing Machinery, 2017, pp. 278–291. doi: 10.1145/3062341.3062360.