1 /* 2 * Copyright (C) 2014 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 public class Transaction { 18 static class EmptyStatic { 19 } 20 21 static class ResolveString { 22 static String s = "ResolvedString"; 23 } 24 25 static class StaticFieldClass { 26 public static int intField; 27 static { 28 intField = 5; 29 } 30 } 31 32 static class FinalizableAbortClass { 33 public static AbortHelperClass finalizableObject; 34 static { 35 finalizableObject = new AbortHelperClass(); 36 } 37 } 38 39 static class NativeCallAbortClass { 40 static { AbortHelperClass.nativeMethod()41 AbortHelperClass.nativeMethod(); 42 } 43 } 44 45 static class SynchronizedNativeCallAbortClass { 46 static { 47 synchronized (SynchronizedNativeCallAbortClass.class) { AbortHelperClass.nativeMethod()48 AbortHelperClass.nativeMethod(); 49 } 50 } 51 } 52 53 static class CatchNativeCallAbortClass { 54 static { 55 try { AbortHelperClass.nativeMethod()56 AbortHelperClass.nativeMethod(); 57 } catch (Throwable e) { 58 // ignore exception. 59 } 60 } 61 } 62 63 static class MultipleNativeCallAbortClass { 64 static { 65 // Call native method but catch the transaction exception. 66 try { AbortHelperClass.nativeMethod()67 AbortHelperClass.nativeMethod(); 68 } catch (Throwable e) { 69 // ignore exception. 70 } 71 72 // Call another native method. AbortHelperClass.nativeMethod2()73 AbortHelperClass.nativeMethod2(); 74 } 75 } 76 77 static class CatchClassForNameAbortClass { 78 static { 79 try { 80 Class.forName("non.existent.TestClass"); 81 } catch (Throwable e) { 82 // ignore exception. 83 } 84 } 85 } 86 87 static class CatchClassForNameAbortClassTwice { 88 static { 89 try { 90 Class.forName("non.existent.TestClass"); 91 } catch (Throwable e) { 92 // ignore exception. 93 } 94 try { 95 Class.forName("non.existent.TestClass"); 96 } catch (Throwable e) { 97 // ignore exception. 98 } 99 } 100 } 101 102 // Helper class to abort transaction: finalizable class with natve methods. 103 static class AbortHelperClass { finalize()104 public void finalize() throws Throwable { 105 super.finalize(); 106 } nativeMethod()107 public static native void nativeMethod(); nativeMethod2()108 public static native void nativeMethod2(); 109 } 110 } 111