Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 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 | |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 21 | static class ResolveString { |
| 22 | static String s = "ResolvedString"; |
| 23 | } |
| 24 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 25 | static class StaticFieldClass { |
| 26 | public static int intField; |
| 27 | static { |
| 28 | intField = 5; |
| 29 | } |
| 30 | } |
| 31 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 32 | static class FinalizableAbortClass { |
| 33 | public static AbortHelperClass finalizableObject; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 34 | static { |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 35 | finalizableObject = new AbortHelperClass(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 39 | 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 | |
| 77 | // Helper class to abort transaction: finalizable class with natve methods. |
| 78 | static class AbortHelperClass { |
| 79 | public void finalize() throws Throwable { |
| 80 | super.finalize(); |
| 81 | } |
| 82 | public static native void nativeMethod(); |
| 83 | public static native void nativeMethod2(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 84 | } |
| 85 | } |