1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import java.lang.reflect.InvocationTargetException; 18 import java.lang.reflect.Method; 19 import java.lang.reflect.Modifier; 20 21 /* 22 * Test case for conditionally using one of two synchronized objects. 23 * 24 * This code cannot be verified at the moment, as the join point merges a register with two 25 * different lock options. Do not put it into Main to avoid the whole class being run in the 26 * interpreter. 27 */ 28 public class TwoPath { 29 30 /** 31 * Conditionally uses one of the synchronized objects. 32 */ twoPath(Object obj1, Object obj2, int x)33 public static void twoPath(Object obj1, Object obj2, int x) { 34 Main.assertIsManaged(); 35 36 Object localObj; 37 38 synchronized (obj1) { 39 synchronized(obj2) { 40 if (x == 0) { 41 localObj = obj2; 42 } else { 43 localObj = obj1; 44 } 45 } 46 } 47 48 doNothing(localObj); 49 } 50 doNothing(Object o)51 private static void doNothing(Object o) { 52 } 53 } 54