Alan Leung | ed36ba5 | 2017-05-12 17:31:13 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 14 | package lockedregioncodeinjection; |
| 15 | |
| 16 | public class TestTarget { |
| 17 | public static int boostCount = 0; |
| 18 | public static int unboostCount = 0; |
| 19 | public static int invokeCount = 0; |
Colin Cross | cebc382 | 2017-08-03 15:58:45 -0700 | [diff] [blame] | 20 | public static boolean nextUnboostThrows = false; |
Alan Leung | ed36ba5 | 2017-05-12 17:31:13 -0700 | [diff] [blame] | 21 | |
| 22 | public static void boost() { |
| 23 | boostCount++; |
| 24 | } |
| 25 | |
| 26 | public static void unboost() { |
Colin Cross | cebc382 | 2017-08-03 15:58:45 -0700 | [diff] [blame] | 27 | if (nextUnboostThrows) { |
| 28 | nextUnboostThrows = false; |
| 29 | throw new RuntimeException(); |
| 30 | } |
Alan Leung | ed36ba5 | 2017-05-12 17:31:13 -0700 | [diff] [blame] | 31 | 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 Cross | cebc382 | 2017-08-03 15:58:45 -0700 | [diff] [blame] | 57 | |
| 58 | public void synchronizedThrowsOnUnboost() { |
| 59 | nextUnboostThrows = true; |
| 60 | synchronized(this) { |
| 61 | invoke(); |
| 62 | } |
| 63 | } |
Alan Leung | ed36ba5 | 2017-05-12 17:31:13 -0700 | [diff] [blame] | 64 | } |