103ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe/* 203ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * Copyright (C) 2010 The Android Open Source Project 303ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * 403ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * Licensed under the Apache License, Version 2.0 (the "License"); 503ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * you may not use this file except in compliance with the License. 603ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * You may obtain a copy of the License at 703ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * 803ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * http://www.apache.org/licenses/LICENSE-2.0 903ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * 1003ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * Unless required by applicable law or agreed to in writing, software 1103ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * distributed under the License is distributed on an "AS IS" BASIS, 1203ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1303ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * See the License for the specific language governing permissions and 1403ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * limitations under the License. 1503ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe */ 1603ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe 1703ec930faded5bbfa096533ce60b6893847922dbAndreas Gampeimport java.lang.reflect.InvocationTargetException; 1803ec930faded5bbfa096533ce60b6893847922dbAndreas Gampeimport java.lang.reflect.Method; 1903ec930faded5bbfa096533ce60b6893847922dbAndreas Gampeimport java.lang.reflect.Modifier; 2003ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe 2103ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe/* 2203ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * Test case for conditionally using one of two synchronized objects. 2303ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * 2403ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * This code cannot be verified at the moment, as the join point merges a register with two 2503ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * different lock options. Do not put it into Main to avoid the whole class being run in the 2603ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * interpreter. 2703ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe */ 2803ec930faded5bbfa096533ce60b6893847922dbAndreas Gampepublic class TwoPath { 2903ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe 3003ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe /** 3103ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe * Conditionally uses one of the synchronized objects. 3203ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe */ 3303ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe public static void twoPath(Object obj1, Object obj2, int x) { 342758318d7d868bfdf04312b92f244c1f93fbff14Andreas Gampe Main.assertIsManaged(); 352758318d7d868bfdf04312b92f244c1f93fbff14Andreas Gampe 3603ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe Object localObj; 3703ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe 3803ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe synchronized (obj1) { 3903ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe synchronized(obj2) { 4003ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe if (x == 0) { 4103ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe localObj = obj2; 4203ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe } else { 4303ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe localObj = obj1; 4403ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe } 4503ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe } 4603ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe } 4703ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe 4803ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe doNothing(localObj); 4903ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe } 5003ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe 5103ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe private static void doNothing(Object o) { 5203ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe } 5303ec930faded5bbfa096533ce60b6893847922dbAndreas Gampe} 54