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