blob: d1c8f340a59866b0b527d053c9b51fa2539b481a [file] [log] [blame]
Alan Leunged36ba52017-05-12 17:31:13 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14package lockedregioncodeinjection;
15
16public class TestTarget {
17 public static int boostCount = 0;
18 public static int unboostCount = 0;
19 public static int invokeCount = 0;
Colin Crosscebc3822017-08-03 15:58:45 -070020 public static boolean nextUnboostThrows = false;
Alan Leunged36ba52017-05-12 17:31:13 -070021
22 public static void boost() {
23 boostCount++;
24 }
25
26 public static void unboost() {
Colin Crosscebc3822017-08-03 15:58:45 -070027 if (nextUnboostThrows) {
28 nextUnboostThrows = false;
29 throw new RuntimeException();
30 }
Alan Leunged36ba52017-05-12 17:31:13 -070031 unboostCount++;
32 }
33
34 public static void invoke() {
35 invokeCount++;
36 }
37
38 public static void resetCount() {
39 boostCount = 0;
40 unboostCount = 0;
41 invokeCount = 0;
42 }
43
44 public synchronized void synchronizedCall() {
45 invoke();
46 }
47
48 public synchronized int synchronizedCallReturnInt() {
49 invoke();
50 return 0;
51 }
52
53 public synchronized Object synchronizedCallReturnObject() {
54 invoke();
55 return this;
56 }
Colin Crosscebc3822017-08-03 15:58:45 -070057
58 public void synchronizedThrowsOnUnboost() {
59 nextUnboostThrows = true;
60 synchronized(this) {
61 invoke();
62 }
63 }
Alan Leunged36ba52017-05-12 17:31:13 -070064}