Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | import dalvik.annotation.optimization.FastNative; |
| 18 | import dalvik.annotation.optimization.CriticalNative; |
| 19 | |
| 20 | public class Main { |
| 21 | |
| 22 | public static void main(String[] args) throws Exception { |
| 23 | System.loadLibrary(args[0]); |
| 24 | |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 25 | // To avoid going through resolution trampoline, make test classes visibly initialized. |
| 26 | new Test(); |
| 27 | new TestFast(); |
| 28 | new TestCritical(); |
| 29 | new TestMissing(); |
| 30 | new TestMissingFast(); |
| 31 | new TestMissingCritical(); |
| 32 | makeVisiblyInitialized(); // Make sure they are visibly initialized. |
| 33 | |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 34 | test(); |
Vladimir Marko | 08d0984 | 2019-12-02 12:38:49 +0000 | [diff] [blame] | 35 | testFast(); |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 36 | testCritical(); |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 37 | testMissing(); |
Vladimir Marko | 08d0984 | 2019-12-02 12:38:49 +0000 | [diff] [blame] | 38 | testMissingFast(); |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 39 | testMissingCritical(); |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void test() { |
| 43 | System.out.println("test"); |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 44 | assertEquals(42, Test.nativeMethodVoid()); |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 45 | assertEquals(42, Test.nativeMethod(42)); |
| 46 | assertEquals(42, Test.nativeMethodWithManyParameters( |
| 47 | 11, 12L, 13.0f, 14.0d, |
| 48 | 21, 22L, 23.0f, 24.0d, |
| 49 | 31, 32L, 33.0f, 34.0d, |
| 50 | 41, 42L, 43.0f, 44.0d, |
| 51 | 51, 52L, 53.0f, 54.0d, |
| 52 | 61, 62L, 63.0f, 64.0d, |
| 53 | 71, 72L, 73.0f, 74.0d, |
| 54 | 81, 82L, 83.0f, 84.0d)); |
| 55 | } |
| 56 | |
| 57 | static void testFast() { |
| 58 | System.out.println("testFast"); |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 59 | assertEquals(42, TestFast.nativeMethodVoid()); |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 60 | assertEquals(42, TestFast.nativeMethod(42)); |
| 61 | assertEquals(42, TestFast.nativeMethodWithManyParameters( |
| 62 | 11, 12L, 13.0f, 14.0d, |
| 63 | 21, 22L, 23.0f, 24.0d, |
| 64 | 31, 32L, 33.0f, 34.0d, |
| 65 | 41, 42L, 43.0f, 44.0d, |
| 66 | 51, 52L, 53.0f, 54.0d, |
| 67 | 61, 62L, 63.0f, 64.0d, |
| 68 | 71, 72L, 73.0f, 74.0d, |
| 69 | 81, 82L, 83.0f, 84.0d)); |
| 70 | } |
| 71 | |
| 72 | static void testCritical() { |
| 73 | System.out.println("testCritical"); |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 74 | assertEquals(42, TestCritical.nativeMethodVoid()); |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 75 | assertEquals(42, TestCritical.nativeMethod(42)); |
| 76 | assertEquals(42, TestCritical.nativeMethodWithManyParameters( |
| 77 | 11, 12L, 13.0f, 14.0d, |
| 78 | 21, 22L, 23.0f, 24.0d, |
| 79 | 31, 32L, 33.0f, 34.0d, |
| 80 | 41, 42L, 43.0f, 44.0d, |
| 81 | 51, 52L, 53.0f, 54.0d, |
| 82 | 61, 62L, 63.0f, 64.0d, |
| 83 | 71, 72L, 73.0f, 74.0d, |
| 84 | 81, 82L, 83.0f, 84.0d)); |
| 85 | } |
| 86 | |
| 87 | static void testMissing() { |
| 88 | System.out.println("testMissing"); |
| 89 | |
| 90 | try { |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 91 | TestMissing.nativeMethodVoid(); |
| 92 | throw new Error("UNREACHABLE"); |
| 93 | } catch (LinkageError expected) {} |
| 94 | |
| 95 | try { |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 96 | TestMissing.nativeMethod(42); |
| 97 | throw new Error("UNREACHABLE"); |
| 98 | } catch (LinkageError expected) {} |
| 99 | |
| 100 | try { |
| 101 | TestMissing.nativeMethodWithManyParameters( |
| 102 | 11, 12L, 13.0f, 14.0d, |
| 103 | 21, 22L, 23.0f, 24.0d, |
| 104 | 31, 32L, 33.0f, 34.0d, |
| 105 | 41, 42L, 43.0f, 44.0d, |
| 106 | 51, 52L, 53.0f, 54.0d, |
| 107 | 61, 62L, 63.0f, 64.0d, |
| 108 | 71, 72L, 73.0f, 74.0d, |
| 109 | 81, 82L, 83.0f, 84.0d); |
| 110 | throw new Error("UNREACHABLE"); |
| 111 | } catch (LinkageError expected) {} |
| 112 | } |
| 113 | |
| 114 | static void testMissingFast() { |
| 115 | System.out.println("testMissingFast"); |
| 116 | |
| 117 | try { |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 118 | TestMissingFast.nativeMethodVoid(); |
| 119 | throw new Error("UNREACHABLE"); |
| 120 | } catch (LinkageError expected) {} |
| 121 | |
| 122 | try { |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 123 | TestMissingFast.nativeMethod(42); |
| 124 | throw new Error("UNREACHABLE"); |
| 125 | } catch (LinkageError expected) {} |
| 126 | |
| 127 | try { |
| 128 | TestMissingFast.nativeMethodWithManyParameters( |
| 129 | 11, 12L, 13.0f, 14.0d, |
| 130 | 21, 22L, 23.0f, 24.0d, |
| 131 | 31, 32L, 33.0f, 34.0d, |
| 132 | 41, 42L, 43.0f, 44.0d, |
| 133 | 51, 52L, 53.0f, 54.0d, |
| 134 | 61, 62L, 63.0f, 64.0d, |
| 135 | 71, 72L, 73.0f, 74.0d, |
| 136 | 81, 82L, 83.0f, 84.0d); |
| 137 | throw new Error("UNREACHABLE"); |
| 138 | } catch (LinkageError expected) {} |
| 139 | } |
| 140 | |
| 141 | static void testMissingCritical() { |
| 142 | System.out.println("testMissingCritical"); |
| 143 | |
| 144 | try { |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 145 | TestMissingCritical.nativeMethodVoid(); |
| 146 | throw new Error("UNREACHABLE"); |
| 147 | } catch (LinkageError expected) {} |
| 148 | |
| 149 | try { |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 150 | TestMissingCritical.nativeMethod(42); |
| 151 | throw new Error("UNREACHABLE"); |
| 152 | } catch (LinkageError expected) {} |
| 153 | |
| 154 | try { |
| 155 | TestMissingCritical.nativeMethodWithManyParameters( |
| 156 | 11, 12L, 13.0f, 14.0d, |
| 157 | 21, 22L, 23.0f, 24.0d, |
| 158 | 31, 32L, 33.0f, 34.0d, |
| 159 | 41, 42L, 43.0f, 44.0d, |
| 160 | 51, 52L, 53.0f, 54.0d, |
| 161 | 61, 62L, 63.0f, 64.0d, |
| 162 | 71, 72L, 73.0f, 74.0d, |
| 163 | 81, 82L, 83.0f, 84.0d); |
| 164 | throw new Error("UNREACHABLE"); |
| 165 | } catch (LinkageError expected) {} |
| 166 | } |
| 167 | |
| 168 | static void assertEquals(int expected, int actual) { |
| 169 | if (expected != actual) { |
| 170 | throw new AssertionError("Expected " + expected + " got " + actual); |
| 171 | } |
| 172 | } |
| 173 | |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 174 | public static native void makeVisiblyInitialized(); |
| 175 | } |
| 176 | |
| 177 | class Test { |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 178 | public static native int nativeMethodVoid(); |
| 179 | |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 180 | public static native int nativeMethod(int i); |
| 181 | |
| 182 | public static native int nativeMethodWithManyParameters( |
| 183 | int i1, long l1, float f1, double d1, |
| 184 | int i2, long l2, float f2, double d2, |
| 185 | int i3, long l3, float f3, double d3, |
| 186 | int i4, long l4, float f4, double d4, |
| 187 | int i5, long l5, float f5, double d5, |
| 188 | int i6, long l6, float f6, double d6, |
| 189 | int i7, long l7, float f7, double d7, |
| 190 | int i8, long l8, float f8, double d8); |
| 191 | } |
| 192 | |
| 193 | class TestFast { |
| 194 | @FastNative |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 195 | public static native int nativeMethodVoid(); |
| 196 | |
| 197 | @FastNative |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 198 | public static native int nativeMethod(int i); |
| 199 | |
| 200 | @FastNative |
| 201 | public static native int nativeMethodWithManyParameters( |
| 202 | int i1, long l1, float f1, double d1, |
| 203 | int i2, long l2, float f2, double d2, |
| 204 | int i3, long l3, float f3, double d3, |
| 205 | int i4, long l4, float f4, double d4, |
| 206 | int i5, long l5, float f5, double d5, |
| 207 | int i6, long l6, float f6, double d6, |
| 208 | int i7, long l7, float f7, double d7, |
| 209 | int i8, long l8, float f8, double d8); |
| 210 | } |
| 211 | |
| 212 | class TestCritical { |
| 213 | @CriticalNative |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 214 | public static native int nativeMethodVoid(); |
| 215 | |
| 216 | @CriticalNative |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 217 | public static native int nativeMethod(int i); |
| 218 | |
| 219 | @CriticalNative |
| 220 | public static native int nativeMethodWithManyParameters( |
| 221 | int i1, long l1, float f1, double d1, |
| 222 | int i2, long l2, float f2, double d2, |
| 223 | int i3, long l3, float f3, double d3, |
| 224 | int i4, long l4, float f4, double d4, |
| 225 | int i5, long l5, float f5, double d5, |
| 226 | int i6, long l6, float f6, double d6, |
| 227 | int i7, long l7, float f7, double d7, |
| 228 | int i8, long l8, float f8, double d8); |
| 229 | } |
| 230 | |
| 231 | class TestMissing { |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 232 | public static native int nativeMethodVoid(); |
| 233 | |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 234 | public static native int nativeMethod(int i); |
| 235 | |
| 236 | public static native int nativeMethodWithManyParameters( |
| 237 | int i1, long l1, float f1, double d1, |
| 238 | int i2, long l2, float f2, double d2, |
| 239 | int i3, long l3, float f3, double d3, |
| 240 | int i4, long l4, float f4, double d4, |
| 241 | int i5, long l5, float f5, double d5, |
| 242 | int i6, long l6, float f6, double d6, |
| 243 | int i7, long l7, float f7, double d7, |
| 244 | int i8, long l8, float f8, double d8); |
| 245 | } |
| 246 | |
| 247 | class TestMissingFast { |
| 248 | @FastNative |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 249 | public static native int nativeMethodVoid(); |
| 250 | |
| 251 | @FastNative |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 252 | public static native int nativeMethod(int i); |
| 253 | |
| 254 | @FastNative |
| 255 | public static native int nativeMethodWithManyParameters( |
| 256 | int i1, long l1, float f1, double d1, |
| 257 | int i2, long l2, float f2, double d2, |
| 258 | int i3, long l3, float f3, double d3, |
| 259 | int i4, long l4, float f4, double d4, |
| 260 | int i5, long l5, float f5, double d5, |
| 261 | int i6, long l6, float f6, double d6, |
| 262 | int i7, long l7, float f7, double d7, |
| 263 | int i8, long l8, float f8, double d8); |
| 264 | } |
| 265 | |
| 266 | class TestMissingCritical { |
| 267 | @CriticalNative |
Vladimir Marko | fa458ac | 2020-02-12 14:08:07 +0000 | [diff] [blame] | 268 | public static native int nativeMethodVoid(); |
| 269 | |
| 270 | @CriticalNative |
Vladimir Marko | 7dac864 | 2019-11-06 17:09:30 +0000 | [diff] [blame] | 271 | public static native int nativeMethod(int i); |
| 272 | |
| 273 | @CriticalNative |
| 274 | public static native int nativeMethodWithManyParameters( |
| 275 | int i1, long l1, float f1, double d1, |
| 276 | int i2, long l2, float f2, double d2, |
| 277 | int i3, long l3, float f3, double d3, |
| 278 | int i4, long l4, float f4, double d4, |
| 279 | int i5, long l5, float f5, double d5, |
| 280 | int i6, long l6, float f6, double d6, |
| 281 | int i7, long l7, float f7, double d7, |
| 282 | int i8, long l8, float f8, double d8); |
| 283 | } |