| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 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; |
| 20 |
public static boolean nextUnboostThrows = false; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public static Object mLock = null; |
| 25 |
public static int boostCountLocked = 0; |
| 26 |
public static int unboostCountLocked = 0; |
| 27 |
|
| 28 |
public static void boost() { |
| 29 |
boostCount++; |
| 30 |
if (mLock != null && Thread.currentThread().holdsLock(mLock)) { |
| 31 |
boostCountLocked++; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public static void unboost() { |
| 36 |
if (nextUnboostThrows) { |
| 37 |
nextUnboostThrows = false; |
| 38 |
throw new RuntimeException(); |
| 39 |
} |
| 40 |
unboostCount++; |
| 41 |
if (mLock != null && Thread.currentThread().holdsLock(mLock)) { |
| 42 |
unboostCountLocked++; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
public static void invoke() { |
| 47 |
invokeCount++; |
| 48 |
} |
| 49 |
|
| 50 |
public static void resetCount() { |
| 51 |
boostCount = 0; |
| 52 |
unboostCount = 0; |
| 53 |
invokeCount = 0; |
| 54 |
} |
| 55 |
|
| 56 |
public synchronized void synchronizedCall() { |
| 57 |
invoke(); |
| 58 |
} |
| 59 |
|
| 60 |
public synchronized int synchronizedCallReturnInt() { |
| 61 |
invoke(); |
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
public synchronized Object synchronizedCallReturnObject() { |
| 66 |
invoke(); |
| 67 |
return this; |
| 68 |
} |
| 69 |
|
| 70 |
public void synchronizedThrowsOnUnboost() { |
| 71 |
nextUnboostThrows = true; |
| 72 |
synchronized(this) { |
| 73 |
invoke(); |
| 74 |
} |
| 75 |
} |
| 76 |
} |