MAHJONG is implemented as a standalone tool for building heap abstraction
to significantly improve the efficiency of points-to analysis while achieving
almost the same precision for an important class of type-dependent clients,
e.g., call graph construction. 

To demonstrate the usefulness of MAHJONG to points-to analysis, we have integrated
MAHJONG with DOOP (version r160113), a state-of-the-art context-sensitive
points-to analysis framework for Java.

This tutorial introduces how to install and use MAHJONG together with DOOP.


----------------
| Requirements |
----------------

To use MAHJONG, you need to get JDK 1.8 (or later) and Python 2.x installed on your system.


-------------------------
| Building instructions |
-------------------------

We have provided a pre-compiled jar of MAHJONG, i.e., mahjong.jar
in the unpack directory. To build MAHJONG by yourself, you just need to
switch to the unpack directory and run script:

$ ./compile.sh


-------------------------------------------------
| Instructions of Integrating MAHJONG with DOOP |
-------------------------------------------------

1. Download DOOP (r160113) from http://doop.program-analysis.org/download.html.

2. Unzip DOOP, then set environment variable DOOP_HOME to the directory where you unpack DOOP by:
   $ export DOOP_HOME=unpack_directory/doop-r160113-bin/

3. Put doop-mahjong.patch in $DOOP_HOME and then apply it to DOOP by:
   $ cd $DOOP_HOME
   $ patch -p1 < doop-mahjong.patch

4. Put mahjong.jar in $DOOP_HOME.

Now, MAHJONG has been integrated with DOOP.

In addition, to run DOOP, users should follow the instructions in $DOOP_HOME/README
to setup the applications and library (to be analyzed) and configure the corresponding paths.


----------
| Usages |
----------

After integration, you can run the points-to analyses provided by DOOP
with the heap abstraction constructed by MAHJONG. To enable MAHJONG, you
just need to use this option (and the usages of DOOP remain the same):

-mahjong

For example, let us analyze luindex benchmark of DaCapo using the 3-object-sensitive
points-to analysis with the heap abstraction constructed by MAHJONG:

$ ./run -jre1.6 -mahjong 3-object-sensitive+2-heap jars/dacapo/luindex.jar

Then MAHJONG is run and will automatically construct the heap abstraction (by testing
the equivalence of automata to merge the type-consistent objects), which will be used
by later precise points-to analysis.

To save user's time, MAHJONG will cache its heap abstractions for the programs that
have been analyzed. If it is the first time to run MAHJONG for a program,
MAHJONG will construct heap abstraction for it and cache the heap abstraction.
Otherwise, the cached heap abstraction will be directly used without running MAHJONG again.


MAHJONG may affect the reflection resolution of DOOP by merging some string constants,
thus we suggest you to use the reflection analysis results generated by TamiFlex.
We have provided the option for DOOP (after integrated with MAHJONG) to do this:

-refl-log <reflection-log>

For example, let us analyze luindex again. This time, we let DOOP use the reflection analysis
results created by TamiFlex (suppose they are in the file "$DOOP_HOME/refl.log"):

$ ./run -jre1.6 -mahjong -refl-log refl.log 3-object-sensitive+2-heap jars/dacapo/luindex.jar


-----------------------------------------------
| Reproducibility of the Results in Our Paper |
-----------------------------------------------

Generally, using this release version to analyze the programs in our paper
("Efficient and Precise Points-to Analysis: Modeling the Heap by Merging Equivalent Automata",
PLDI'17) will generate the client results with smaller numbers than those in the paper.
This is due to some dynamically loaded classes missed by DOOP.

DOOP builds closed-world without considering dynamic class loading, so some classes
that are dynamically loaded during runtime will be missed by DOOP during analysis.
In the evaluation of our paper, to build a more sound closed-world, we manually adds these
classes (discovered by TamiFlex but missed by DOOP) to DOOP’s closed-world.
But we do not do this in the release version. As a result, DOOP in the evaluation of the paper
reaches more code and genetates client results with larger numbers than this release version.

To reproduce the results in our paper, please download the artifact from MAHJONG website.


-----------
| Licence |
-----------

GPL v3


Please feel free to contact the authors if you have any concerns.
