Skip to content

Commit

Permalink
introducing PackagePrivateProcessorPass
Browse files Browse the repository at this point in the history
Summary:
```
/*
 * Before Android 4.1, Dalvik did not honor package-private accessibility
 * restrictions when constructing vtables, see
 * https://developer.android.com/guide/practices/verifying-apps-art#Object_Model_Changes
 *
 * The original design of Redex somewhat reflected this attitude, not giving
 * proper considerations for package-private access rules. In particular, the
 * MethodOverrideGraph, the VirtualScope facitities, the RenameClasses*
 * transformation, but also many other aspects in Redex basically assume that
 * all members are public. For all internal classes, those assumptions are
 * largely "made true" by the aptly named MakePublicPass. However, there are a
 * few semantic problems, such as the following:
 * - By making everything public, the MakePublicPass may truely establish
 *   overriding relationships between methods that, due to original limited
 *   package private access, shouldn't actually be in an overriding
 *   relationship.
 * - By changing the package name of classes to just X, the RenameClasses*
 *   passes may break package-private access.
 *
 * This pass aims at working out those issues by performing certain
 * transformations upfront:
 * - For apparent overrides that are not actually overrides because of
 *   package-private access and different package names, we treat those as new
 *   virtual scope roots, and rename all involved methods uniquely.
 * - Where actual accesses to package private members occur, we make
 *   the members public, effectively making all accesses public accesses, so
 *   that existing Redex' optimizations are free to move around code and rename
 *   packages, and don't have to worry about package-private access rules.
 *
 * There are few limitations to this approach:
 * - New virtual scopes might implement interfaces, in which case renaming the
 *   methods might break the interface. We currently just give up, stopping
 *   Redex. (TODO: We could still handle this in some cases, renaming also
 *   interface methods, and possibly introducing some bridge methods.)
 * - Some public methods might override multiple (formerly package private)
 *   virtual roots. We don't currently support this.
 * - Some methods might be marked as do-not-rename.
 *
 * We don't currently hit any of those limitations.
 *
 * With these transformations, the MakePublicPass should no longer needed for
 * fixing up package private accesses (but it might still be needed to fix up
 * other effects of Redex transformation on visibility)
 */
```

Reviewed By: wsanville

Differential Revision: D55435220

fbshipit-source-id: ef95f09ece87c61fa0ca77a0551002e81e6e8cfc
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed Apr 11, 2024
1 parent 65f6ed1 commit 5ab335a
Show file tree
Hide file tree
Showing 11 changed files with 1,029 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ libopt_la_SOURCES = \
opt/optimize_enums/OptimizeEnums.cpp \
opt/optimize_enums/OptimizeEnumsUnmap.cpp \
opt/original_name/OriginalNamePass.cpp \
opt/package-private-preprocessor/PackagePrivatePreprocessor.cpp \
opt/partial-application/PartialApplication.cpp \
opt/peephole/Peephole.cpp \
opt/peephole/RedundantCheckCastRemover.cpp \
Expand Down
1 change: 1 addition & 0 deletions libredex/Trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class DexType;
TM(PGR) \
TM(PM) \
TM(POST_LOWERING) \
TM(PPP) \
TM(PTA) \
TM(PURITY) \
TM(QUICK) \
Expand Down
Loading

0 comments on commit 5ab335a

Please sign in to comment.