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 #include <sstream>
18
19 #include "jni.h"
20
21 #include "arch/context.h"
22 #include "monitor.h"
23 #include "scoped_thread_state_change-inl.h"
24 #include "stack.h"
25 #include "thread-current-inl.h"
26
27 namespace art {
28
VerifyManyParameters(jint i1,jlong l1,jfloat f1,jdouble d1,jint i2,jlong l2,jfloat f2,jdouble d2,jint i3,jlong l3,jfloat f3,jdouble d3,jint i4,jlong l4,jfloat f4,jdouble d4,jint i5,jlong l5,jfloat f5,jdouble d5,jint i6,jlong l6,jfloat f6,jdouble d6,jint i7,jlong l7,jfloat f7,jdouble d7,jint i8,jlong l8,jfloat f8,jdouble d8)29 static inline bool VerifyManyParameters(
30 jint i1, jlong l1, jfloat f1, jdouble d1,
31 jint i2, jlong l2, jfloat f2, jdouble d2,
32 jint i3, jlong l3, jfloat f3, jdouble d3,
33 jint i4, jlong l4, jfloat f4, jdouble d4,
34 jint i5, jlong l5, jfloat f5, jdouble d5,
35 jint i6, jlong l6, jfloat f6, jdouble d6,
36 jint i7, jlong l7, jfloat f7, jdouble d7,
37 jint i8, jlong l8, jfloat f8, jdouble d8) {
38 return
39 (i1 == 11) && (l1 == 12) && (f1 == 13.0) && (d1 == 14.0) &&
40 (i2 == 21) && (l2 == 22) && (f2 == 23.0) && (d2 == 24.0) &&
41 (i3 == 31) && (l3 == 32) && (f3 == 33.0) && (d3 == 34.0) &&
42 (i4 == 41) && (l4 == 42) && (f4 == 43.0) && (d4 == 44.0) &&
43 (i5 == 51) && (l5 == 52) && (f5 == 53.0) && (d5 == 54.0) &&
44 (i6 == 61) && (l6 == 62) && (f6 == 63.0) && (d6 == 64.0) &&
45 (i7 == 71) && (l7 == 72) && (f7 == 73.0) && (d7 == 74.0) &&
46 (i8 == 81) && (l8 == 82) && (f8 == 83.0) && (d8 == 84.0);
47 }
48
Java_Test_nativeMethodVoid(JNIEnv *,jclass)49 extern "C" JNIEXPORT jint JNICALL Java_Test_nativeMethodVoid(JNIEnv*, jclass) {
50 return 42;
51 }
52
Java_Test_nativeMethod(JNIEnv *,jclass,jint i)53 extern "C" JNIEXPORT jint JNICALL Java_Test_nativeMethod(JNIEnv*, jclass, jint i) {
54 return i;
55 }
56
Java_Test_nativeMethodWithManyParameters(JNIEnv *,jclass,jint i1,jlong l1,jfloat f1,jdouble d1,jint i2,jlong l2,jfloat f2,jdouble d2,jint i3,jlong l3,jfloat f3,jdouble d3,jint i4,jlong l4,jfloat f4,jdouble d4,jint i5,jlong l5,jfloat f5,jdouble d5,jint i6,jlong l6,jfloat f6,jdouble d6,jint i7,jlong l7,jfloat f7,jdouble d7,jint i8,jlong l8,jfloat f8,jdouble d8)57 extern "C" JNIEXPORT jint JNICALL Java_Test_nativeMethodWithManyParameters(
58 JNIEnv*, jclass,
59 jint i1, jlong l1, jfloat f1, jdouble d1,
60 jint i2, jlong l2, jfloat f2, jdouble d2,
61 jint i3, jlong l3, jfloat f3, jdouble d3,
62 jint i4, jlong l4, jfloat f4, jdouble d4,
63 jint i5, jlong l5, jfloat f5, jdouble d5,
64 jint i6, jlong l6, jfloat f6, jdouble d6,
65 jint i7, jlong l7, jfloat f7, jdouble d7,
66 jint i8, jlong l8, jfloat f8, jdouble d8) {
67 bool ok = VerifyManyParameters(
68 i1, l1, f1, d1,
69 i2, l2, f2, d2,
70 i3, l3, f3, d3,
71 i4, l4, f4, d4,
72 i5, l5, f5, d5,
73 i6, l6, f6, d6,
74 i7, l7, f7, d7,
75 i8, l8, f8, d8);
76 return ok ? 42 : -1;
77 }
78
Java_TestFast_nativeMethodVoid(JNIEnv *,jclass)79 extern "C" JNIEXPORT jint JNICALL Java_TestFast_nativeMethodVoid(JNIEnv*, jclass) {
80 return 42;
81 }
82
Java_TestFast_nativeMethod(JNIEnv *,jclass,jint i)83 extern "C" JNIEXPORT jint JNICALL Java_TestFast_nativeMethod(JNIEnv*, jclass, jint i) {
84 return i;
85 }
86
Java_TestFast_nativeMethodWithManyParameters(JNIEnv *,jclass,jint i1,jlong l1,jfloat f1,jdouble d1,jint i2,jlong l2,jfloat f2,jdouble d2,jint i3,jlong l3,jfloat f3,jdouble d3,jint i4,jlong l4,jfloat f4,jdouble d4,jint i5,jlong l5,jfloat f5,jdouble d5,jint i6,jlong l6,jfloat f6,jdouble d6,jint i7,jlong l7,jfloat f7,jdouble d7,jint i8,jlong l8,jfloat f8,jdouble d8)87 extern "C" JNIEXPORT jint JNICALL Java_TestFast_nativeMethodWithManyParameters(
88 JNIEnv*, jclass,
89 jint i1, jlong l1, jfloat f1, jdouble d1,
90 jint i2, jlong l2, jfloat f2, jdouble d2,
91 jint i3, jlong l3, jfloat f3, jdouble d3,
92 jint i4, jlong l4, jfloat f4, jdouble d4,
93 jint i5, jlong l5, jfloat f5, jdouble d5,
94 jint i6, jlong l6, jfloat f6, jdouble d6,
95 jint i7, jlong l7, jfloat f7, jdouble d7,
96 jint i8, jlong l8, jfloat f8, jdouble d8) {
97 bool ok = VerifyManyParameters(
98 i1, l1, f1, d1,
99 i2, l2, f2, d2,
100 i3, l3, f3, d3,
101 i4, l4, f4, d4,
102 i5, l5, f5, d5,
103 i6, l6, f6, d6,
104 i7, l7, f7, d7,
105 i8, l8, f8, d8);
106 return ok ? 42 : -1;
107 }
108
Java_TestCritical_nativeMethodVoid()109 extern "C" JNIEXPORT jint JNICALL Java_TestCritical_nativeMethodVoid() {
110 return 42;
111 }
112
Java_TestCritical_nativeMethod(jint i)113 extern "C" JNIEXPORT jint JNICALL Java_TestCritical_nativeMethod(jint i) {
114 return i;
115 }
116
Java_TestCritical_nativeMethodWithManyParameters(jint i1,jlong l1,jfloat f1,jdouble d1,jint i2,jlong l2,jfloat f2,jdouble d2,jint i3,jlong l3,jfloat f3,jdouble d3,jint i4,jlong l4,jfloat f4,jdouble d4,jint i5,jlong l5,jfloat f5,jdouble d5,jint i6,jlong l6,jfloat f6,jdouble d6,jint i7,jlong l7,jfloat f7,jdouble d7,jint i8,jlong l8,jfloat f8,jdouble d8)117 extern "C" JNIEXPORT jint JNICALL Java_TestCritical_nativeMethodWithManyParameters(
118 jint i1, jlong l1, jfloat f1, jdouble d1,
119 jint i2, jlong l2, jfloat f2, jdouble d2,
120 jint i3, jlong l3, jfloat f3, jdouble d3,
121 jint i4, jlong l4, jfloat f4, jdouble d4,
122 jint i5, jlong l5, jfloat f5, jdouble d5,
123 jint i6, jlong l6, jfloat f6, jdouble d6,
124 jint i7, jlong l7, jfloat f7, jdouble d7,
125 jint i8, jlong l8, jfloat f8, jdouble d8) {
126 bool ok = VerifyManyParameters(
127 i1, l1, f1, d1,
128 i2, l2, f2, d2,
129 i3, l3, f3, d3,
130 i4, l4, f4, d4,
131 i5, l5, f5, d5,
132 i6, l6, f6, d6,
133 i7, l7, f7, d7,
134 i8, l8, f8, d8);
135 return ok ? 42 : -1;
136 }
137
Java_CriticalSignatures_nativeILFFFFD(jint i,jlong l,jfloat f1,jfloat f2,jfloat f3,jfloat f4,jdouble d)138 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeILFFFFD(
139 jint i,
140 jlong l,
141 jfloat f1,
142 jfloat f2,
143 jfloat f3,
144 jfloat f4,
145 jdouble d) {
146 if (i != 1) return -1;
147 if (l != INT64_C(0xf00000002)) return -2;
148 if (f1 != 3.0f) return -3;
149 if (f2 != 4.0f) return -4;
150 if (f3 != 5.0f) return -5;
151 if (f4 != 6.0f) return -6;
152 if (d != 7.0) return -7;
153 return 42;
154 }
155
Java_CriticalSignatures_nativeLIFFFFD(jlong l,jint i,jfloat f1,jfloat f2,jfloat f3,jfloat f4,jdouble d)156 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeLIFFFFD(
157 jlong l,
158 jint i,
159 jfloat f1,
160 jfloat f2,
161 jfloat f3,
162 jfloat f4,
163 jdouble d) {
164 if (l != INT64_C(0xf00000007)) return -1;
165 if (i != 6) return -2;
166 if (f1 != 5.0f) return -3;
167 if (f2 != 4.0f) return -4;
168 if (f3 != 3.0f) return -5;
169 if (f4 != 2.0f) return -6;
170 if (d != 1.0) return -7;
171 return 42;
172 }
173
Java_CriticalSignatures_nativeFLIFFFD(jfloat f1,jlong l,jint i,jfloat f2,jfloat f3,jfloat f4,jdouble d)174 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeFLIFFFD(
175 jfloat f1,
176 jlong l,
177 jint i,
178 jfloat f2,
179 jfloat f3,
180 jfloat f4,
181 jdouble d) {
182 if (f1 != 1.0f) return -3;
183 if (l != INT64_C(0xf00000002)) return -1;
184 if (i != 3) return -2;
185 if (f2 != 4.0f) return -4;
186 if (f3 != 5.0f) return -5;
187 if (f4 != 6.0f) return -6;
188 if (d != 7.0) return -7;
189 return 42;
190 }
191
Java_CriticalSignatures_nativeDDIIIIII(jdouble d1,jdouble d2,jint i1,jint i2,jint i3,jint i4,jint i5,jint i6)192 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeDDIIIIII(
193 jdouble d1,
194 jdouble d2,
195 jint i1,
196 jint i2,
197 jint i3,
198 jint i4,
199 jint i5,
200 jint i6) {
201 if (d1 != 8.0) return -1;
202 if (d2 != 7.0) return -2;
203 if (i1 != 6) return -3;
204 if (i2 != 5) return -4;
205 if (i3 != 4) return -5;
206 if (i4 != 3) return -6;
207 if (i5 != 2) return -7;
208 if (i6 != 1) return -8;
209 return 42;
210 }
211
Java_CriticalSignatures_nativeDFFILIII(jdouble d,jfloat f1,jfloat f2,jint i1,jlong l,jint i2,jint i3,jint i4)212 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeDFFILIII(
213 jdouble d,
214 jfloat f1,
215 jfloat f2,
216 jint i1,
217 jlong l,
218 jint i2,
219 jint i3,
220 jint i4) {
221 if (d != 1.0) return -1;
222 if (f1 != 2.0f) return -2;
223 if (f2 != 3.0f) return -3;
224 if (i1 != 4) return -4;
225 if (l != INT64_C(0xf00000005)) return -5;
226 if (i2 != 6) return -6;
227 if (i3 != 7) return -7;
228 if (i4 != 8) return -8;
229 return 42;
230 }
231
Java_CriticalSignatures_nativeDDFILIII(jdouble d1,jdouble d2,jfloat f,jint i1,jlong l,jint i2,jint i3,jint i4)232 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeDDFILIII(
233 jdouble d1,
234 jdouble d2,
235 jfloat f,
236 jint i1,
237 jlong l,
238 jint i2,
239 jint i3,
240 jint i4) {
241 if (d1 != 8.0) return -1;
242 if (d2 != 7.0) return -2;
243 if (f != 6.0f) return -3;
244 if (i1 != 5) return -4;
245 if (l != INT64_C(0xf00000004)) return -5;
246 if (i2 != 3) return -6;
247 if (i3 != 2) return -7;
248 if (i4 != 1) return -8;
249 return 42;
250 }
251
Java_CriticalSignatures_nativeDDIFII(jdouble d1,jdouble d2,jint i1,jfloat f,jint i2,jint i3)252 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeDDIFII(
253 jdouble d1,
254 jdouble d2,
255 jint i1,
256 jfloat f,
257 jint i2,
258 jint i3) {
259 if (d1 != 1.0) return -1;
260 if (d2 != 2.0) return -2;
261 if (i1 != 3) return -3;
262 if (f != 4.0f) return -4;
263 if (i2 != 5) return -5;
264 if (i3 != 6) return -6;
265 return 42;
266 }
267
Java_CriticalSignatures_nativeFullArgs(jlong l0,jint i2,jlong l3,jint i5,jlong l6,jint i8,jlong l9,jint i11,jlong l12,jint i14,jlong l15,jint i17,jlong l18,jint i20,jlong l21,jint i23,jlong l24,jint i26,jlong l27,jint i29,jlong l30,jint i32,jlong l33,jint i35,jlong l36,jint i38,jlong l39,jint i41,jlong l42,jint i44,jlong l45,jint i47,jlong l48,jint i50,jlong l51,jint i53,jlong l54,jint i56,jlong l57,jint i59,jlong l60,jint i62,jlong l63,jint i65,jlong l66,jint i68,jlong l69,jint i71,jlong l72,jint i74,jlong l75,jint i77,jlong l78,jint i80,jlong l81,jint i83,jlong l84,jint i86,jlong l87,jint i89,jlong l90,jint i92,jlong l93,jint i95,jlong l96,jint i98,jlong l99,jint i101,jlong l102,jint i104,jlong l105,jint i107,jlong l108,jint i110,jlong l111,jint i113,jlong l114,jint i116,jlong l117,jint i119,jlong l120,jint i122,jlong l123,jint i125,jlong l126,jint i128,jlong l129,jint i131,jlong l132,jint i134,jlong l135,jint i137,jlong l138,jint i140,jlong l141,jint i143,jlong l144,jint i146,jlong l147,jint i149,jlong l150,jint i152,jlong l153,jint i155,jlong l156,jint i158,jlong l159,jint i161,jlong l162,jint i164,jlong l165,jint i167,jlong l168,jint i170,jlong l171,jint i173,jlong l174,jint i176,jlong l177,jint i179,jlong l180,jint i182,jlong l183,jint i185,jlong l186,jint i188,jlong l189,jint i191,jlong l192,jint i194,jlong l195,jint i197,jlong l198,jint i200,jlong l201,jint i203,jlong l204,jint i206,jlong l207,jint i209,jlong l210,jint i212,jlong l213,jint i215,jlong l216,jint i218,jlong l219,jint i221,jlong l222,jint i224,jlong l225,jint i227,jlong l228,jint i230,jlong l231,jint i233,jlong l234,jint i236,jlong l237,jint i239,jlong l240,jint i242,jlong l243,jint i245,jlong l246,jint i248,jlong l249,jint i251,jlong l252,jint i254)268 extern "C" JNIEXPORT jint JNICALL Java_CriticalSignatures_nativeFullArgs(
269 // Generated by script (then modified to close argument list):
270 // for i in {0..84}; do echo " jlong l$((i*3)),"; echo " jint i$((i*3+2)),"; done
271 jlong l0,
272 jint i2,
273 jlong l3,
274 jint i5,
275 jlong l6,
276 jint i8,
277 jlong l9,
278 jint i11,
279 jlong l12,
280 jint i14,
281 jlong l15,
282 jint i17,
283 jlong l18,
284 jint i20,
285 jlong l21,
286 jint i23,
287 jlong l24,
288 jint i26,
289 jlong l27,
290 jint i29,
291 jlong l30,
292 jint i32,
293 jlong l33,
294 jint i35,
295 jlong l36,
296 jint i38,
297 jlong l39,
298 jint i41,
299 jlong l42,
300 jint i44,
301 jlong l45,
302 jint i47,
303 jlong l48,
304 jint i50,
305 jlong l51,
306 jint i53,
307 jlong l54,
308 jint i56,
309 jlong l57,
310 jint i59,
311 jlong l60,
312 jint i62,
313 jlong l63,
314 jint i65,
315 jlong l66,
316 jint i68,
317 jlong l69,
318 jint i71,
319 jlong l72,
320 jint i74,
321 jlong l75,
322 jint i77,
323 jlong l78,
324 jint i80,
325 jlong l81,
326 jint i83,
327 jlong l84,
328 jint i86,
329 jlong l87,
330 jint i89,
331 jlong l90,
332 jint i92,
333 jlong l93,
334 jint i95,
335 jlong l96,
336 jint i98,
337 jlong l99,
338 jint i101,
339 jlong l102,
340 jint i104,
341 jlong l105,
342 jint i107,
343 jlong l108,
344 jint i110,
345 jlong l111,
346 jint i113,
347 jlong l114,
348 jint i116,
349 jlong l117,
350 jint i119,
351 jlong l120,
352 jint i122,
353 jlong l123,
354 jint i125,
355 jlong l126,
356 jint i128,
357 jlong l129,
358 jint i131,
359 jlong l132,
360 jint i134,
361 jlong l135,
362 jint i137,
363 jlong l138,
364 jint i140,
365 jlong l141,
366 jint i143,
367 jlong l144,
368 jint i146,
369 jlong l147,
370 jint i149,
371 jlong l150,
372 jint i152,
373 jlong l153,
374 jint i155,
375 jlong l156,
376 jint i158,
377 jlong l159,
378 jint i161,
379 jlong l162,
380 jint i164,
381 jlong l165,
382 jint i167,
383 jlong l168,
384 jint i170,
385 jlong l171,
386 jint i173,
387 jlong l174,
388 jint i176,
389 jlong l177,
390 jint i179,
391 jlong l180,
392 jint i182,
393 jlong l183,
394 jint i185,
395 jlong l186,
396 jint i188,
397 jlong l189,
398 jint i191,
399 jlong l192,
400 jint i194,
401 jlong l195,
402 jint i197,
403 jlong l198,
404 jint i200,
405 jlong l201,
406 jint i203,
407 jlong l204,
408 jint i206,
409 jlong l207,
410 jint i209,
411 jlong l210,
412 jint i212,
413 jlong l213,
414 jint i215,
415 jlong l216,
416 jint i218,
417 jlong l219,
418 jint i221,
419 jlong l222,
420 jint i224,
421 jlong l225,
422 jint i227,
423 jlong l228,
424 jint i230,
425 jlong l231,
426 jint i233,
427 jlong l234,
428 jint i236,
429 jlong l237,
430 jint i239,
431 jlong l240,
432 jint i242,
433 jlong l243,
434 jint i245,
435 jlong l246,
436 jint i248,
437 jlong l249,
438 jint i251,
439 jlong l252,
440 jint i254) {
441 jlong l = INT64_C(0xf00000000);
442 // Generated by script (then modified to close argument list):
443 // for i in {0..84}; do \
444 // echo " if (l$((i*3)) != l + $(($i*3))) return -$(($i*3));"; \
445 // echo " if (i$(($i*3+2)) != $(($i*3+2))) return -$(($i*3+2));"; \
446 // done
447 if (l0 != l + 0) return -0;
448 if (i2 != 2) return -2;
449 if (l3 != l + 3) return -3;
450 if (i5 != 5) return -5;
451 if (l6 != l + 6) return -6;
452 if (i8 != 8) return -8;
453 if (l9 != l + 9) return -9;
454 if (i11 != 11) return -11;
455 if (l12 != l + 12) return -12;
456 if (i14 != 14) return -14;
457 if (l15 != l + 15) return -15;
458 if (i17 != 17) return -17;
459 if (l18 != l + 18) return -18;
460 if (i20 != 20) return -20;
461 if (l21 != l + 21) return -21;
462 if (i23 != 23) return -23;
463 if (l24 != l + 24) return -24;
464 if (i26 != 26) return -26;
465 if (l27 != l + 27) return -27;
466 if (i29 != 29) return -29;
467 if (l30 != l + 30) return -30;
468 if (i32 != 32) return -32;
469 if (l33 != l + 33) return -33;
470 if (i35 != 35) return -35;
471 if (l36 != l + 36) return -36;
472 if (i38 != 38) return -38;
473 if (l39 != l + 39) return -39;
474 if (i41 != 41) return -41;
475 if (l42 != l + 42) return -42;
476 if (i44 != 44) return -44;
477 if (l45 != l + 45) return -45;
478 if (i47 != 47) return -47;
479 if (l48 != l + 48) return -48;
480 if (i50 != 50) return -50;
481 if (l51 != l + 51) return -51;
482 if (i53 != 53) return -53;
483 if (l54 != l + 54) return -54;
484 if (i56 != 56) return -56;
485 if (l57 != l + 57) return -57;
486 if (i59 != 59) return -59;
487 if (l60 != l + 60) return -60;
488 if (i62 != 62) return -62;
489 if (l63 != l + 63) return -63;
490 if (i65 != 65) return -65;
491 if (l66 != l + 66) return -66;
492 if (i68 != 68) return -68;
493 if (l69 != l + 69) return -69;
494 if (i71 != 71) return -71;
495 if (l72 != l + 72) return -72;
496 if (i74 != 74) return -74;
497 if (l75 != l + 75) return -75;
498 if (i77 != 77) return -77;
499 if (l78 != l + 78) return -78;
500 if (i80 != 80) return -80;
501 if (l81 != l + 81) return -81;
502 if (i83 != 83) return -83;
503 if (l84 != l + 84) return -84;
504 if (i86 != 86) return -86;
505 if (l87 != l + 87) return -87;
506 if (i89 != 89) return -89;
507 if (l90 != l + 90) return -90;
508 if (i92 != 92) return -92;
509 if (l93 != l + 93) return -93;
510 if (i95 != 95) return -95;
511 if (l96 != l + 96) return -96;
512 if (i98 != 98) return -98;
513 if (l99 != l + 99) return -99;
514 if (i101 != 101) return -101;
515 if (l102 != l + 102) return -102;
516 if (i104 != 104) return -104;
517 if (l105 != l + 105) return -105;
518 if (i107 != 107) return -107;
519 if (l108 != l + 108) return -108;
520 if (i110 != 110) return -110;
521 if (l111 != l + 111) return -111;
522 if (i113 != 113) return -113;
523 if (l114 != l + 114) return -114;
524 if (i116 != 116) return -116;
525 if (l117 != l + 117) return -117;
526 if (i119 != 119) return -119;
527 if (l120 != l + 120) return -120;
528 if (i122 != 122) return -122;
529 if (l123 != l + 123) return -123;
530 if (i125 != 125) return -125;
531 if (l126 != l + 126) return -126;
532 if (i128 != 128) return -128;
533 if (l129 != l + 129) return -129;
534 if (i131 != 131) return -131;
535 if (l132 != l + 132) return -132;
536 if (i134 != 134) return -134;
537 if (l135 != l + 135) return -135;
538 if (i137 != 137) return -137;
539 if (l138 != l + 138) return -138;
540 if (i140 != 140) return -140;
541 if (l141 != l + 141) return -141;
542 if (i143 != 143) return -143;
543 if (l144 != l + 144) return -144;
544 if (i146 != 146) return -146;
545 if (l147 != l + 147) return -147;
546 if (i149 != 149) return -149;
547 if (l150 != l + 150) return -150;
548 if (i152 != 152) return -152;
549 if (l153 != l + 153) return -153;
550 if (i155 != 155) return -155;
551 if (l156 != l + 156) return -156;
552 if (i158 != 158) return -158;
553 if (l159 != l + 159) return -159;
554 if (i161 != 161) return -161;
555 if (l162 != l + 162) return -162;
556 if (i164 != 164) return -164;
557 if (l165 != l + 165) return -165;
558 if (i167 != 167) return -167;
559 if (l168 != l + 168) return -168;
560 if (i170 != 170) return -170;
561 if (l171 != l + 171) return -171;
562 if (i173 != 173) return -173;
563 if (l174 != l + 174) return -174;
564 if (i176 != 176) return -176;
565 if (l177 != l + 177) return -177;
566 if (i179 != 179) return -179;
567 if (l180 != l + 180) return -180;
568 if (i182 != 182) return -182;
569 if (l183 != l + 183) return -183;
570 if (i185 != 185) return -185;
571 if (l186 != l + 186) return -186;
572 if (i188 != 188) return -188;
573 if (l189 != l + 189) return -189;
574 if (i191 != 191) return -191;
575 if (l192 != l + 192) return -192;
576 if (i194 != 194) return -194;
577 if (l195 != l + 195) return -195;
578 if (i197 != 197) return -197;
579 if (l198 != l + 198) return -198;
580 if (i200 != 200) return -200;
581 if (l201 != l + 201) return -201;
582 if (i203 != 203) return -203;
583 if (l204 != l + 204) return -204;
584 if (i206 != 206) return -206;
585 if (l207 != l + 207) return -207;
586 if (i209 != 209) return -209;
587 if (l210 != l + 210) return -210;
588 if (i212 != 212) return -212;
589 if (l213 != l + 213) return -213;
590 if (i215 != 215) return -215;
591 if (l216 != l + 216) return -216;
592 if (i218 != 218) return -218;
593 if (l219 != l + 219) return -219;
594 if (i221 != 221) return -221;
595 if (l222 != l + 222) return -222;
596 if (i224 != 224) return -224;
597 if (l225 != l + 225) return -225;
598 if (i227 != 227) return -227;
599 if (l228 != l + 228) return -228;
600 if (i230 != 230) return -230;
601 if (l231 != l + 231) return -231;
602 if (i233 != 233) return -233;
603 if (l234 != l + 234) return -234;
604 if (i236 != 236) return -236;
605 if (l237 != l + 237) return -237;
606 if (i239 != 239) return -239;
607 if (l240 != l + 240) return -240;
608 if (i242 != 242) return -242;
609 if (l243 != l + 243) return -243;
610 if (i245 != 245) return -245;
611 if (l246 != l + 246) return -246;
612 if (i248 != 248) return -248;
613 if (l249 != l + 249) return -249;
614 if (i251 != 251) return -251;
615 if (l252 != l + 252) return -252;
616 if (i254 != 254) return -254;
617 return 42;
618 }
619
Java_CriticalClinitCheck_nativeMethodVoid()620 extern "C" JNIEXPORT jint JNICALL Java_CriticalClinitCheck_nativeMethodVoid() {
621 return 42;
622 }
623
Java_CriticalClinitCheck_nativeMethod(jint i)624 extern "C" JNIEXPORT jint JNICALL Java_CriticalClinitCheck_nativeMethod(jint i) {
625 return i;
626 }
627
Java_CriticalClinitCheck_nativeMethodWithManyParameters(jint i1,jlong l1,jfloat f1,jdouble d1,jint i2,jlong l2,jfloat f2,jdouble d2,jint i3,jlong l3,jfloat f3,jdouble d3,jint i4,jlong l4,jfloat f4,jdouble d4,jint i5,jlong l5,jfloat f5,jdouble d5,jint i6,jlong l6,jfloat f6,jdouble d6,jint i7,jlong l7,jfloat f7,jdouble d7,jint i8,jlong l8,jfloat f8,jdouble d8)628 extern "C" JNIEXPORT jint JNICALL Java_CriticalClinitCheck_nativeMethodWithManyParameters(
629 jint i1, jlong l1, jfloat f1, jdouble d1,
630 jint i2, jlong l2, jfloat f2, jdouble d2,
631 jint i3, jlong l3, jfloat f3, jdouble d3,
632 jint i4, jlong l4, jfloat f4, jdouble d4,
633 jint i5, jlong l5, jfloat f5, jdouble d5,
634 jint i6, jlong l6, jfloat f6, jdouble d6,
635 jint i7, jlong l7, jfloat f7, jdouble d7,
636 jint i8, jlong l8, jfloat f8, jdouble d8) {
637 bool ok = VerifyManyParameters(
638 i1, l1, f1, d1,
639 i2, l2, f2, d2,
640 i3, l3, f3, d3,
641 i4, l4, f4, d4,
642 i5, l5, f5, d5,
643 i6, l6, f6, d6,
644 i7, l7, f7, d7,
645 i8, l8, f8, d8);
646 return ok ? 42 : -1;
647 }
648
Java_Main_b189235039CallThrough(JNIEnv * env,jobject m)649 extern "C" JNIEXPORT jint JNICALL Java_Main_b189235039CallThrough(JNIEnv* env, jobject m) {
650 jclass main_klass = env->GetObjectClass(m);
651 jmethodID checkLocks = env->GetStaticMethodID(main_klass, "b189235039CheckLocks", "(ILMain;)I");
652 if (checkLocks == nullptr) {
653 return -1;
654 }
655 return env->CallStaticIntMethod(main_klass, checkLocks, 42, m);
656 }
657
Java_Main_b189235039CheckLocks(JNIEnv *,jclass,int arg,jobject lock)658 extern "C" JNIEXPORT jint JNICALL Java_Main_b189235039CheckLocks(JNIEnv*,
659 jclass,
660 int arg,
661 jobject lock) {
662 // Check that we do not crash when visiting locks and that we find the right lock.
663 ScopedObjectAccess soa(Thread::Current());
664 class VisitLocks : public StackVisitor {
665 public:
666 VisitLocks(Thread* thread, Context* context, jobject expected_lock)
667 : StackVisitor(thread, context, StackWalkKind::kIncludeInlinedFrames),
668 expected_lock_(expected_lock) {
669 }
670
671 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
672 ArtMethod* m = GetMethod();
673
674 // Ignore runtime methods.
675 if (m == nullptr || m->IsRuntimeMethod()) {
676 return true;
677 }
678
679 if (m->IsSynchronized()) {
680 // Interesting frame.
681 Monitor::VisitLocks(this, Callback, expected_lock_);
682 return false;
683 }
684
685 return true;
686 }
687
688 private:
689 static void Callback(ObjPtr<mirror::Object> obj, void* expected_lock)
690 REQUIRES_SHARED(Locks::mutator_lock_) {
691 CHECK(obj != nullptr);
692 CHECK(obj == Thread::Current()->DecodeJObject(reinterpret_cast<jobject>(expected_lock)));
693 }
694
695 jobject expected_lock_;
696 };
697 {
698 std::unique_ptr<Context> context(Context::Create());
699 VisitLocks vl(soa.Self(), context.get(), lock);
700 vl.WalkStack();
701 }
702 return arg;
703 }
704
705 } // namespace art
706