|
1 | | -# latte: Lightweight Aliasing Tracking for Java |
| 1 | +# Latte: Lightweight Aliasing Tracking for Java |
2 | 2 |
|
3 | | -Small project following the paper https://arxiv.org/pdf/2309.05637.pdf |
| 3 | +Latte is a lightweight static analysis tool for tracking aliasing in Java programs. This tool allows you to annotate your programs with permissions where aliases are tracked to prevent bugs related to unexpected object references and side effects. |
| 4 | + |
| 5 | +For more details, check our [research paper](https://arxiv.org/pdf/2309.05637). |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +Latte enables developers to identify and track aliasing relationships in their Java code using a permission-based type system. The tool statically verifies aliasing properties to help prevent common concurrency and memory management bugs. |
| 10 | + |
| 11 | +## Latte Annotations System |
| 12 | + |
| 13 | +Latte uses annotations to specify the permissions of fields and parameters to track their uniqueness properties and the aliases that are created throughout the program: |
| 14 | + |
| 15 | +- For parameters: |
| 16 | + - `@Free` - For parameters that are globally unique. When a caller passes an argument to a `@Free` parameter, they cannot observe that value again. |
| 17 | + - `@Borrowed` - For parameters that are unique in the callee's scope but may be stored elsewhere on the heap or stack. |
| 18 | +- For fields: |
| 19 | + - `@Unique` - For fields that cannot be aliased with other fields. |
| 20 | +- For both: |
| 21 | + - `@Shared` - For parameters or fields that can be shared, so they have no uniqueness guarantees. |
| 22 | + |
| 23 | +Local variables are not annotated and start with a default annotation that allows them to take the assignment's permissions. |
| 24 | + |
| 25 | +## Project Structure |
| 26 | + |
| 27 | +``` |
| 28 | +latte-umbrella/ |
| 29 | +├── src/ |
| 30 | +│ └── main/ |
| 31 | +│ └── java/ |
| 32 | +│ ├── latte/ |
| 33 | +│ │ └── latte_umbrella/ |
| 34 | +│ │ └── App.java # Main application entry point |
| 35 | +│ └── examples/ # Test examples for the analysis |
| 36 | +│ └── test/ |
| 37 | +│ └── java/ |
| 38 | +│ ├── AppTest.java # Creating JUnit tests |
| 39 | +│ └── examples/ # Java classes to be used in the JUnit tests |
| 40 | +
|
| 41 | +``` |
| 42 | + |
| 43 | +## Getting Started |
| 44 | + |
| 45 | +### Prerequisites |
| 46 | + |
| 47 | +- Java 11 or higher |
| 48 | +- Maven |
| 49 | + |
| 50 | +### Prerequisites |
| 51 | + |
| 52 | +- Java 11 or higher |
| 53 | +- Maven |
| 54 | + |
| 55 | +### Installation |
| 56 | + |
| 57 | +Clone the repository and build with Maven: |
| 58 | + |
| 59 | +```bash |
| 60 | +git clone https://github.com/your-username/latte.git |
| 61 | +cd latte |
| 62 | +mvn clean install |
| 63 | +``` |
| 64 | + |
| 65 | +To use Latte in your Java projects, you need to: |
| 66 | +1. Add the latte.jar to your project dependencies |
| 67 | +2. Import the specifications in your files (e.g., `import specification.Free`) |
| 68 | + |
| 69 | + |
| 70 | +### Usage |
| 71 | + |
| 72 | +Run the tool against your Java code by executing the main application: |
| 73 | + |
| 74 | +```bash |
| 75 | +java -cp target/latte-umbrella-1.0.0.jar latte.latte_umbrella.App [options] <file-to-analyze> |
| 76 | +``` |
| 77 | + |
| 78 | +## Running Examples |
| 79 | + |
| 80 | +The project includes example files to test the analysis capabilities: |
| 81 | + |
| 82 | +```bash |
| 83 | +# Run the analysis on a specific example |
| 84 | +java -cp target/latte-umbrella-1.0.0.jar latte.latte_umbrella.App src/main/java/examples/Example1.java |
| 85 | +``` |
| 86 | + |
| 87 | +## Example |
| 88 | + |
| 89 | +Here is an example of Java classes using the Latte annotations: |
| 90 | + |
| 91 | +```java |
| 92 | +class Node { |
| 93 | + @Unique Object value; // Field value is Unique |
| 94 | + @Unique Node next; // Field next is Unique |
| 95 | + |
| 96 | + |
| 97 | + public Node (@Free Object value, @Free Node next) { |
| 98 | + // We can assign @Free objects to Unique fields given that they have no aliases |
| 99 | + this.value = value; |
| 100 | + this.next = next; |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +public class MyStack { |
| 105 | + |
| 106 | + @Unique Node root; // Field root is Unique |
| 107 | + |
| 108 | + public MyStack(@Free Node root) { |
| 109 | + this.root = root; // Since root is @Free we can assign it to root:@Unique |
| 110 | + } |
| 111 | + |
| 112 | + void push(@Free Object value) { |
| 113 | + Node r; // Local variables start with a default annotation that allows |
| 114 | + Node n; // them to take the assignment's permissions |
| 115 | + |
| 116 | + r = this.root; // r is an alias to this.root with permission @Unique |
| 117 | + this.root = null; // Nullify this.root so there is only one pointer to the |
| 118 | + // value of the root, no other aliases |
| 119 | + n = new Node(value, r); // Create new root with values that have no aliases. The constructors |
| 120 | + // always return an new object that is @Free |
| 121 | + this.root = n; // Replace root with a new value that is @Free and so can be assigned |
| 122 | + // to an @Unique field |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +## Testing |
| 128 | + |
| 129 | +Tests can be run using Maven: |
| 130 | + |
| 131 | +```bash |
| 132 | +mvn test |
| 133 | +``` |
| 134 | + |
| 135 | +You can also test the tool directly on the example files: |
| 136 | + |
| 137 | +```bash |
| 138 | +java -cp target/latte-umbrella-1.0.0.jar latte.latte_umbrella.App src/main/java/examples/MyStack.java |
| 139 | +``` |
| 140 | + |
| 141 | +## Contributing |
| 142 | + |
| 143 | +We welcome contributions to Latte! Here's how to get started: |
| 144 | + |
| 145 | +### Development Workflow |
| 146 | + |
| 147 | +1. **Create a new branch for your feature:** |
| 148 | + ```bash |
| 149 | + git checkout -b feature/your-feature-name |
| 150 | + ``` |
| 151 | + |
| 152 | +2. **Make your changes and commit them:** |
| 153 | + ```bash |
| 154 | + git add . |
| 155 | + git commit -m "Description of your changes" |
| 156 | + ``` |
| 157 | + |
| 158 | +3. **Set the upstream branch and push your changes:** |
| 159 | + ```bash |
| 160 | + git push --set-upstream origin feature/your-feature-name |
| 161 | + ``` |
| 162 | + |
| 163 | +4. **Create a Pull Request:** |
| 164 | + - Go to the repository on GitHub |
| 165 | + - Click on "Pull Requests" > "New Pull Request" |
| 166 | + - Select your branch |
| 167 | + - Fill in the PR template with details about your changes |
| 168 | + - Request a review from a team member |
| 169 | + |
| 170 | +5. **Address review feedback** and update your PR as needed |
| 171 | + |
| 172 | +### Code Standards |
| 173 | + |
| 174 | +- Follow Java code conventions |
| 175 | +- Write unit tests for new functionality |
| 176 | +- Update documentation for any changes |
| 177 | + |
| 178 | +## Known Limitations |
| 179 | + |
| 180 | +The tool is still under active development, and some features are limited: |
| 181 | + |
| 182 | +- Does not support if statements without else branches |
| 183 | +- Limited verification of aliases related to while loops |
| 184 | +- Limited support for complex collections and generics |
| 185 | + |
| 186 | +## Future Work |
| 187 | + |
| 188 | +We are continuously improving Latte to support more complex Java patterns and enhance the aliasing tracking capabilities. |
| 189 | + |
| 190 | +## Contributing Issues |
| 191 | + |
| 192 | +If you encounter any problems while using Latte, please add an Issue to the repository with: |
| 193 | +- A description of the problem |
| 194 | +- Code sample that demonstrates the issue |
| 195 | +- Expected vs. actual behavior |
| 196 | + |
| 197 | +## License |
| 198 | + |
| 199 | +[Your license here] |
| 200 | + |
| 201 | +## Contact |
| 202 | + |
| 203 | +[Your contact information here] |
0 commit comments