• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright (C) 2021 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17TEMPLATE = """
18public class Main {
19  public static void main(String[] args) {
20    Main m = new Main();
21    System.out.println(m.foo(-1, -1));
22    System.out.println(m.foo(-1, +1));
23    System.out.println(m.foo(+1, -1));
24    System.out.println(m.foo(+1, +1));
25    System.out.println(m.value);
26  }
27  public int foo(int a, int b) {
28    if ( a >= 0 ) {
29      if ( b < 0 ) {
30        BODY
31        return 2;
32      }
33      return 1;
34    }
35    return 0;
36  }
37  Object lock = new Object();
38  int value = 0;
39}
40"""
41
42with open("src/Main.java", "wt") as dst:
43  body = " ".join(["synchronized(lock) { value++; }"] * 512)
44  dst.write(TEMPLATE.strip().replace("BODY", body))
45