xref: /aosp_15_r20/art/test/Transaction/Transaction.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker public class Transaction {
18*795d594fSAndroid Build Coastguard Worker     static class EmptyStatic {
19*795d594fSAndroid Build Coastguard Worker     }
20*795d594fSAndroid Build Coastguard Worker 
21*795d594fSAndroid Build Coastguard Worker     static class ResolveString {
22*795d594fSAndroid Build Coastguard Worker       static String s = "ResolvedString";
23*795d594fSAndroid Build Coastguard Worker     }
24*795d594fSAndroid Build Coastguard Worker 
25*795d594fSAndroid Build Coastguard Worker     static class StaticFieldClass {
26*795d594fSAndroid Build Coastguard Worker       public static int intField;
27*795d594fSAndroid Build Coastguard Worker       static {
28*795d594fSAndroid Build Coastguard Worker         intField = 5;
29*795d594fSAndroid Build Coastguard Worker       }
30*795d594fSAndroid Build Coastguard Worker     }
31*795d594fSAndroid Build Coastguard Worker 
32*795d594fSAndroid Build Coastguard Worker     static class FinalizableAbortClass {
33*795d594fSAndroid Build Coastguard Worker       public static AbortHelperClass finalizableObject;
34*795d594fSAndroid Build Coastguard Worker       static {
35*795d594fSAndroid Build Coastguard Worker         finalizableObject = new AbortHelperClass();
36*795d594fSAndroid Build Coastguard Worker       }
37*795d594fSAndroid Build Coastguard Worker     }
38*795d594fSAndroid Build Coastguard Worker 
39*795d594fSAndroid Build Coastguard Worker     static class NativeCallAbortClass {
40*795d594fSAndroid Build Coastguard Worker       static {
AbortHelperClass.nativeMethod()41*795d594fSAndroid Build Coastguard Worker         AbortHelperClass.nativeMethod();
42*795d594fSAndroid Build Coastguard Worker       }
43*795d594fSAndroid Build Coastguard Worker     }
44*795d594fSAndroid Build Coastguard Worker 
45*795d594fSAndroid Build Coastguard Worker     static class SynchronizedNativeCallAbortClass {
46*795d594fSAndroid Build Coastguard Worker       static {
47*795d594fSAndroid Build Coastguard Worker         synchronized (SynchronizedNativeCallAbortClass.class) {
AbortHelperClass.nativeMethod()48*795d594fSAndroid Build Coastguard Worker           AbortHelperClass.nativeMethod();
49*795d594fSAndroid Build Coastguard Worker         }
50*795d594fSAndroid Build Coastguard Worker       }
51*795d594fSAndroid Build Coastguard Worker     }
52*795d594fSAndroid Build Coastguard Worker 
53*795d594fSAndroid Build Coastguard Worker     static class CatchNativeCallAbortClass {
54*795d594fSAndroid Build Coastguard Worker       static {
55*795d594fSAndroid Build Coastguard Worker         try {
AbortHelperClass.nativeMethod()56*795d594fSAndroid Build Coastguard Worker           AbortHelperClass.nativeMethod();
57*795d594fSAndroid Build Coastguard Worker         } catch (Throwable e) {
58*795d594fSAndroid Build Coastguard Worker           // ignore exception.
59*795d594fSAndroid Build Coastguard Worker         }
60*795d594fSAndroid Build Coastguard Worker       }
61*795d594fSAndroid Build Coastguard Worker     }
62*795d594fSAndroid Build Coastguard Worker 
63*795d594fSAndroid Build Coastguard Worker     static class MultipleNativeCallAbortClass {
64*795d594fSAndroid Build Coastguard Worker       static {
65*795d594fSAndroid Build Coastguard Worker         // Call native method but catch the transaction exception.
66*795d594fSAndroid Build Coastguard Worker         try {
AbortHelperClass.nativeMethod()67*795d594fSAndroid Build Coastguard Worker           AbortHelperClass.nativeMethod();
68*795d594fSAndroid Build Coastguard Worker         } catch (Throwable e) {
69*795d594fSAndroid Build Coastguard Worker           // ignore exception.
70*795d594fSAndroid Build Coastguard Worker         }
71*795d594fSAndroid Build Coastguard Worker 
72*795d594fSAndroid Build Coastguard Worker         // Call another native method.
AbortHelperClass.nativeMethod2()73*795d594fSAndroid Build Coastguard Worker         AbortHelperClass.nativeMethod2();
74*795d594fSAndroid Build Coastguard Worker       }
75*795d594fSAndroid Build Coastguard Worker     }
76*795d594fSAndroid Build Coastguard Worker 
77*795d594fSAndroid Build Coastguard Worker     static class CatchClassForNameAbortClass {
78*795d594fSAndroid Build Coastguard Worker       static {
79*795d594fSAndroid Build Coastguard Worker         try {
80*795d594fSAndroid Build Coastguard Worker           Class.forName("non.existent.TestClass");
81*795d594fSAndroid Build Coastguard Worker         } catch (Throwable e) {
82*795d594fSAndroid Build Coastguard Worker           // ignore exception.
83*795d594fSAndroid Build Coastguard Worker         }
84*795d594fSAndroid Build Coastguard Worker       }
85*795d594fSAndroid Build Coastguard Worker     }
86*795d594fSAndroid Build Coastguard Worker 
87*795d594fSAndroid Build Coastguard Worker     static class CatchClassForNameAbortClassTwice {
88*795d594fSAndroid Build Coastguard Worker       static {
89*795d594fSAndroid Build Coastguard Worker         try {
90*795d594fSAndroid Build Coastguard Worker           Class.forName("non.existent.TestClass");
91*795d594fSAndroid Build Coastguard Worker         } catch (Throwable e) {
92*795d594fSAndroid Build Coastguard Worker           // ignore exception.
93*795d594fSAndroid Build Coastguard Worker         }
94*795d594fSAndroid Build Coastguard Worker         try {
95*795d594fSAndroid Build Coastguard Worker           Class.forName("non.existent.TestClass");
96*795d594fSAndroid Build Coastguard Worker         } catch (Throwable e) {
97*795d594fSAndroid Build Coastguard Worker           // ignore exception.
98*795d594fSAndroid Build Coastguard Worker         }
99*795d594fSAndroid Build Coastguard Worker       }
100*795d594fSAndroid Build Coastguard Worker     }
101*795d594fSAndroid Build Coastguard Worker 
102*795d594fSAndroid Build Coastguard Worker     // Helper class to abort transaction: finalizable class with natve methods.
103*795d594fSAndroid Build Coastguard Worker     static class AbortHelperClass {
finalize()104*795d594fSAndroid Build Coastguard Worker       public void finalize() throws Throwable {
105*795d594fSAndroid Build Coastguard Worker         super.finalize();
106*795d594fSAndroid Build Coastguard Worker       }
nativeMethod()107*795d594fSAndroid Build Coastguard Worker       public static native void nativeMethod();
nativeMethod2()108*795d594fSAndroid Build Coastguard Worker       public static native void nativeMethod2();
109*795d594fSAndroid Build Coastguard Worker     }
110*795d594fSAndroid Build Coastguard Worker }
111