blob: 6a4f5ef773aa511a18a17bddf19078b1f2668312 [file] [log] [blame]
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001/*
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
17public class Transaction {
18 static class EmptyStatic {
19 }
20
Mathieu Chartierbb816d62016-09-07 10:17:46 -070021 static class ResolveString {
22 static String s = "ResolvedString";
23 }
24
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010025 static class StaticFieldClass {
26 public static int intField;
27 static {
28 intField = 5;
29 }
30 }
31
Sebastien Hertz1c80bec2015-02-03 11:58:06 +010032 static class FinalizableAbortClass {
33 public static AbortHelperClass finalizableObject;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010034 static {
Sebastien Hertz1c80bec2015-02-03 11:58:06 +010035 finalizableObject = new AbortHelperClass();
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010036 }
37 }
38
Sebastien Hertz1c80bec2015-02-03 11:58:06 +010039 static class NativeCallAbortClass {
40 static {
41 AbortHelperClass.nativeMethod();
42 }
43 }
44
45 static class SynchronizedNativeCallAbortClass {
46 static {
47 synchronized (SynchronizedNativeCallAbortClass.class) {
48 AbortHelperClass.nativeMethod();
49 }
50 }
51 }
52
53 static class CatchNativeCallAbortClass {
54 static {
55 try {
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 {
67 AbortHelperClass.nativeMethod();
68 } catch (Throwable e) {
69 // ignore exception.
70 }
71
72 // Call another native method.
73 AbortHelperClass.nativeMethod2();
74 }
75 }
76
Vladimir Marko0685b982021-03-25 11:59:22 +000077 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
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100102 // Helper class to abort transaction: finalizable class with natve methods.
103 static class AbortHelperClass {
104 public void finalize() throws Throwable {
105 super.finalize();
106 }
107 public static native void nativeMethod();
108 public static native void nativeMethod2();
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100109 }
110}