forked from ReadyTalk/avian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjnienv.cpp
3809 lines (2924 loc) · 102 KB
/
jnienv.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2008-2015, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
#include "avian/jnienv.h"
#include "avian/machine.h"
#include "avian/util.h"
#include "avian/processor.h"
#include "avian/constants.h"
#include <avian/util/runtime-array.h>
using namespace vm;
namespace {
namespace local {
jint JNICALL AttachCurrentThread(Machine* m, Thread** t, void*)
{
*t = static_cast<Thread*>(m->localThread->get());
if (*t == 0) {
*t = attachThread(m, false);
}
return 0;
}
jint JNICALL AttachCurrentThreadAsDaemon(Machine* m, Thread** t, void*)
{
*t = static_cast<Thread*>(m->localThread->get());
if (*t == 0) {
*t = attachThread(m, true);
}
return 0;
}
jint JNICALL DetachCurrentThread(Machine* m)
{
Thread* t = static_cast<Thread*>(m->localThread->get());
if (t) {
// todo: detaching the root thread seems to cause stability
// problems which I haven't yet had a chance to investigate
// thoroughly. Meanwhile, we just ignore requests to detach it,
// which leaks a bit of memory but should be harmless otherwise.
if (m->rootThread != t) {
m->localThread->set(0);
ACQUIRE_RAW(t, t->m->stateLock);
enter(t, Thread::ActiveState);
t->javaThread->peer() = 0;
enter(t, Thread::ZombieState);
t->state = Thread::JoinedState;
}
return 0;
} else {
return -1;
}
}
uint64_t destroyJavaVM(Thread* t, uintptr_t*)
{
// wait for other non-daemon threads to exit
{
ACQUIRE(t, t->m->stateLock);
while (t->m->liveCount - t->m->daemonCount > 1) {
t->m->stateLock->wait(t->systemThread, 0);
}
}
{
ENTER(t, Thread::ActiveState);
t->m->classpath->shutDown(t);
}
// wait again in case the Classpath::shutDown process started new
// threads:
{
ACQUIRE(t, t->m->stateLock);
while (t->m->liveCount - t->m->daemonCount > 1) {
t->m->stateLock->wait(t->systemThread, 0);
}
enter(t, Thread::ExclusiveState);
}
shutDown(t);
return 1;
}
jint JNICALL DestroyJavaVM(Machine* m)
{
Thread* t;
AttachCurrentThread(m, &t, 0);
if (runRaw(t, destroyJavaVM, 0)) {
t->exit();
return 0;
} else {
return -1;
}
}
jint JNICALL GetEnv(Machine* m, Thread** t, jint version)
{
*t = static_cast<Thread*>(m->localThread->get());
if (*t) {
if (version <= JNI_VERSION_1_6) {
return AVIAN_JNI_OK;
} else {
return AVIAN_JNI_EVERSION;
}
} else {
return AVIAN_JNI_EDETACHED;
}
}
jint JNICALL GetVersion(Thread* t)
{
ENTER(t, Thread::ActiveState);
return JNI_VERSION_1_6;
}
jsize JNICALL GetStringLength(Thread* t, jstring s)
{
ENTER(t, Thread::ActiveState);
return (*s)->length(t);
}
const jchar* JNICALL GetStringChars(Thread* t, jstring s, jboolean* isCopy)
{
ENTER(t, Thread::ActiveState);
jchar* chars = static_cast<jchar*>(
t->m->heap->allocate(((*s)->length(t) + 1) * sizeof(jchar)));
stringChars(t, *s, chars);
if (isCopy)
*isCopy = true;
return chars;
}
void JNICALL ReleaseStringChars(Thread* t, jstring s, const jchar* chars)
{
ENTER(t, Thread::ActiveState);
t->m->heap->free(chars, ((*s)->length(t) + 1) * sizeof(jchar));
}
void JNICALL
GetStringRegion(Thread* t, jstring s, jsize start, jsize length, jchar* dst)
{
ENTER(t, Thread::ActiveState);
stringChars(t, *s, start, length, dst);
}
const jchar* JNICALL GetStringCritical(Thread* t, jstring s, jboolean* isCopy)
{
if (t->criticalLevel == 0) {
enter(t, Thread::ActiveState);
}
++t->criticalLevel;
if (isCopy) {
*isCopy = true;
}
object data = (*s)->data();
if (objectClass(t, data) == type(t, GcByteArray::Type)) {
return GetStringChars(t, s, isCopy);
} else {
return &cast<GcCharArray>(t, data)->body()[(*s)->offset(t)];
}
}
void JNICALL ReleaseStringCritical(Thread* t, jstring s, const jchar* chars)
{
if (objectClass(t, (*s)->data()) == type(t, GcByteArray::Type)) {
ReleaseStringChars(t, s, chars);
}
if ((--t->criticalLevel) == 0) {
enter(t, Thread::IdleState);
}
}
jsize JNICALL GetStringUTFLength(Thread* t, jstring s)
{
ENTER(t, Thread::ActiveState);
return stringUTFLength(t, *s);
}
const char* JNICALL GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
{
ENTER(t, Thread::ActiveState);
int length = stringUTFLength(t, *s);
char* chars = static_cast<char*>(t->m->heap->allocate(length + 1));
stringUTFChars(t, *s, chars, length);
if (isCopy)
*isCopy = true;
return chars;
}
void JNICALL ReleaseStringUTFChars(Thread* t, jstring s, const char* chars)
{
ENTER(t, Thread::ActiveState);
t->m->heap->free(chars, stringUTFLength(t, *s) + 1);
}
void JNICALL GetStringUTFRegion(Thread* t,
jstring s,
jsize start,
jsize length,
char* dst)
{
ENTER(t, Thread::ActiveState);
stringUTFChars(
t, *s, start, length, dst, stringUTFLength(t, *s, start, length));
}
jsize JNICALL GetArrayLength(Thread* t, jarray array)
{
ENTER(t, Thread::ActiveState);
return fieldAtOffset<uintptr_t>(*array, BytesPerWord);
}
uint64_t newString(Thread* t, uintptr_t* arguments)
{
const jchar* chars = reinterpret_cast<const jchar*>(arguments[0]);
jsize size = arguments[1];
GcCharArray* a = makeCharArray(t, size);
if (size) {
memcpy(a->body().begin(), chars, size * sizeof(jchar));
}
return reinterpret_cast<uint64_t>(
makeLocalReference(t, t->m->classpath->makeString(t, a, 0, size)));
}
jstring JNICALL NewString(Thread* t, const jchar* chars, jsize size)
{
if (chars == 0)
return 0;
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(chars), static_cast<uintptr_t>(size)};
return reinterpret_cast<jstring>(run(t, newString, arguments));
}
uint64_t newStringUTF(Thread* t, uintptr_t* arguments)
{
const char* chars = reinterpret_cast<const char*>(arguments[0]);
object array = parseUtf8(t, chars, strlen(chars));
return reinterpret_cast<uint64_t>(makeLocalReference(
t,
t->m->classpath->makeString(
t, array, 0, fieldAtOffset<uintptr_t>(array, BytesPerWord) - 1)));
}
jstring JNICALL NewStringUTF(Thread* t, const char* chars)
{
if (chars == 0)
return 0;
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(chars)};
return reinterpret_cast<jstring>(run(t, newStringUTF, arguments));
}
void replace(int a, int b, const char* in, int8_t* out)
{
while (*in) {
*out = (*in == a ? b : *in);
++in;
++out;
}
*out = 0;
}
uint64_t defineClass(Thread* t, uintptr_t* arguments)
{
jobject loader = reinterpret_cast<jobject>(arguments[0]);
const uint8_t* buffer = reinterpret_cast<const uint8_t*>(arguments[1]);
jsize length = arguments[2];
return reinterpret_cast<uint64_t>(makeLocalReference(
t,
getJClass(
t,
cast<GcClass>(t,
defineClass(t,
loader ? cast<GcClassLoader>(t, *loader)
: roots(t)->bootLoader(),
buffer,
length)))));
}
jclass JNICALL DefineClass(Thread* t,
const char*,
jobject loader,
const jbyte* buffer,
jsize length)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(loader),
reinterpret_cast<uintptr_t>(buffer),
static_cast<uintptr_t>(length)};
return reinterpret_cast<jclass>(run(t, defineClass, arguments));
}
uint64_t findClass(Thread* t, uintptr_t* arguments)
{
const char* name = reinterpret_cast<const char*>(arguments[0]);
GcByteArray* n = makeByteArray(t, strlen(name) + 1);
replace('.', '/', name, n->body().begin());
GcMethod* caller = getCaller(t, 0);
GcClass* c
= resolveClass(t,
caller ? t->m->classpath->libraryClassLoader(t, caller)
: roots(t)->appLoader(),
n);
if (t->m->classpath->mayInitClasses()) {
PROTECT(t, c);
initClass(t, c);
}
return reinterpret_cast<uint64_t>(makeLocalReference(t, getJClass(t, c)));
}
jclass JNICALL FindClass(Thread* t, const char* name)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(name)};
return reinterpret_cast<jclass>(run(t, findClass, arguments));
}
uint64_t throwNew(Thread* t, uintptr_t* arguments)
{
jclass c = reinterpret_cast<jclass>(arguments[0]);
const char* message = reinterpret_cast<const char*>(arguments[1]);
GcString* m = 0;
PROTECT(t, m);
if (message) {
m = makeString(t, "%s", message);
}
object trace = makeTrace(t);
PROTECT(t, trace);
t->exception = cast<GcThrowable>(t, make(t, (*c)->vmClass()));
t->exception->setMessage(t, m);
t->exception->setTrace(t, trace);
return 1;
}
jint JNICALL ThrowNew(Thread* t, jclass c, const char* message)
{
if (t->exception) {
return -1;
}
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(c), reinterpret_cast<uintptr_t>(message)};
return run(t, throwNew, arguments) ? 0 : -1;
}
jint JNICALL Throw(Thread* t, jthrowable throwable)
{
if (t->exception) {
return -1;
}
ENTER(t, Thread::ActiveState);
t->exception = *throwable;
return 0;
}
jobject JNICALL NewLocalRef(Thread* t, jobject o)
{
ENTER(t, Thread::ActiveState);
return makeLocalReference(t, *o);
}
void JNICALL DeleteLocalRef(Thread* t, jobject r)
{
ENTER(t, Thread::ActiveState);
disposeLocalReference(t, r);
}
jboolean JNICALL ExceptionCheck(Thread* t)
{
return t->exception != 0;
}
uint64_t getObjectClass(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
return reinterpret_cast<uint64_t>(
makeLocalReference(t, getJClass(t, objectClass(t, *o))));
}
jclass JNICALL GetObjectClass(Thread* t, jobject o)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o)};
return reinterpret_cast<jclass>(run(t, getObjectClass, arguments));
}
uint64_t getSuperclass(Thread* t, uintptr_t* arguments)
{
GcClass* class_ = (*reinterpret_cast<jclass>(arguments[0]))->vmClass();
if (class_->flags() & ACC_INTERFACE) {
return 0;
} else {
GcClass* super = class_->super();
return super ? reinterpret_cast<uint64_t>(
makeLocalReference(t, getJClass(t, super)))
: 0;
}
}
jclass JNICALL GetSuperclass(Thread* t, jclass c)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(c)};
return reinterpret_cast<jclass>(run(t, getSuperclass, arguments));
}
uint64_t isInstanceOf(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jclass c = reinterpret_cast<jclass>(arguments[1]);
return instanceOf(t, (*c)->vmClass(), *o);
}
jboolean JNICALL IsInstanceOf(Thread* t, jobject o, jclass c)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), reinterpret_cast<uintptr_t>(c)};
return run(t, isInstanceOf, arguments);
}
uint64_t isAssignableFrom(Thread* t, uintptr_t* arguments)
{
jclass b = reinterpret_cast<jclass>(arguments[0]);
jclass a = reinterpret_cast<jclass>(arguments[1]);
return isAssignableFrom(t, (*a)->vmClass(), (*b)->vmClass());
}
jboolean JNICALL IsAssignableFrom(Thread* t, jclass b, jclass a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(b), reinterpret_cast<uintptr_t>(a)};
return run(t, isAssignableFrom, arguments);
}
GcMethod* findMethod(Thread* t, jclass c, const char* name, const char* spec)
{
GcByteArray* n = makeByteArray(t, "%s", name);
PROTECT(t, n);
GcByteArray* s = makeByteArray(t, "%s", spec);
return vm::findMethod(t, (*c)->vmClass(), n, s);
}
jint methodID(Thread* t, GcMethod* method)
{
int id = method->nativeID();
loadMemoryBarrier();
if (id == 0) {
PROTECT(t, method);
ACQUIRE(t, t->m->referenceLock);
if (method->nativeID() == 0) {
GcVector* v = vectorAppend(t, roots(t)->jNIMethodTable(), method);
// sequence point, for gc (don't recombine statements)
roots(t)->setJNIMethodTable(t, v);
storeStoreMemoryBarrier();
method->nativeID() = roots(t)->jNIMethodTable()->size();
}
}
return method->nativeID();
}
uint64_t getMethodID(Thread* t, uintptr_t* arguments)
{
jclass c = reinterpret_cast<jclass>(arguments[0]);
const char* name = reinterpret_cast<const char*>(arguments[1]);
const char* spec = reinterpret_cast<const char*>(arguments[2]);
GcMethod* method = findMethod(t, c, name, spec);
assertT(t, (method->flags() & ACC_STATIC) == 0);
return methodID(t, method);
}
jmethodID JNICALL
GetMethodID(Thread* t, jclass c, const char* name, const char* spec)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(c),
reinterpret_cast<uintptr_t>(name),
reinterpret_cast<uintptr_t>(spec)};
return run(t, getMethodID, arguments);
}
uint64_t getStaticMethodID(Thread* t, uintptr_t* arguments)
{
jclass c = reinterpret_cast<jclass>(arguments[0]);
const char* name = reinterpret_cast<const char*>(arguments[1]);
const char* spec = reinterpret_cast<const char*>(arguments[2]);
GcMethod* method = findMethod(t, c, name, spec);
assertT(t, method->flags() & ACC_STATIC);
return methodID(t, method);
}
jmethodID JNICALL
GetStaticMethodID(Thread* t, jclass c, const char* name, const char* spec)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(c),
reinterpret_cast<uintptr_t>(name),
reinterpret_cast<uintptr_t>(spec)};
return run(t, getStaticMethodID, arguments);
}
GcMethod* getMethod(Thread* t, jmethodID m)
{
assertT(t, m);
GcMethod* method
= cast<GcMethod>(t, roots(t)->jNIMethodTable()->body()[m - 1]);
assertT(t, (method->flags() & ACC_STATIC) == 0);
return method;
}
uint64_t newObjectV(Thread* t, uintptr_t* arguments)
{
jclass c = reinterpret_cast<jclass>(arguments[0]);
jmethodID m = arguments[1];
va_list* a = reinterpret_cast<va_list*>(arguments[2]);
object o = make(t, (*c)->vmClass());
PROTECT(t, o);
t->m->processor->invokeList(t, getMethod(t, m), o, true, *a);
return reinterpret_cast<uint64_t>(makeLocalReference(t, o));
}
jobject JNICALL NewObjectV(Thread* t, jclass c, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(c),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return reinterpret_cast<jobject>(run(t, newObjectV, arguments));
}
jobject JNICALL NewObject(Thread* t, jclass c, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jobject r = NewObjectV(t, c, m, a);
va_end(a);
return r;
}
uint64_t newObjectA(Thread* t, uintptr_t* arguments)
{
jclass c = reinterpret_cast<jclass>(arguments[0]);
jmethodID m = arguments[1];
const jvalue* a = reinterpret_cast<const jvalue*>(arguments[2]);
object o = make(t, (*c)->vmClass());
PROTECT(t, o);
t->m->processor->invokeArray(t, getMethod(t, m), o, a);
return reinterpret_cast<uint64_t>(makeLocalReference(t, o));
}
jobject JNICALL NewObjectA(Thread* t, jclass c, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(c), m, reinterpret_cast<uintptr_t>(a)};
return reinterpret_cast<jobject>(run(t, newObjectA, arguments));
}
uint64_t callObjectMethodV(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jmethodID m = arguments[1];
va_list* a = reinterpret_cast<va_list*>(arguments[2]);
return reinterpret_cast<uint64_t>(makeLocalReference(
t, t->m->processor->invokeList(t, getMethod(t, m), *o, true, *a)));
}
jobject JNICALL CallObjectMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return reinterpret_cast<jobject>(run(t, callObjectMethodV, arguments));
}
jobject JNICALL CallObjectMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jobject r = CallObjectMethodV(t, o, m, a);
va_end(a);
return r;
}
uint64_t callObjectMethodA(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jmethodID m = arguments[1];
const jvalue* a = reinterpret_cast<const jvalue*>(arguments[2]);
return reinterpret_cast<uint64_t>(makeLocalReference(
t, t->m->processor->invokeArray(t, getMethod(t, m), *o, a)));
}
jobject JNICALL
CallObjectMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return reinterpret_cast<jobject>(run(t, callObjectMethodA, arguments));
}
uint64_t callIntMethodV(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jmethodID m = arguments[1];
va_list* a = reinterpret_cast<va_list*>(arguments[2]);
return cast<GcInt>(
t, t->m->processor->invokeList(t, getMethod(t, m), *o, true, *a))
->value();
}
jboolean JNICALL
CallBooleanMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return run(t, callIntMethodV, arguments) != 0;
}
jboolean JNICALL CallBooleanMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jboolean r = CallBooleanMethodV(t, o, m, a);
va_end(a);
return r;
}
uint64_t callIntMethodA(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jmethodID m = arguments[1];
const jvalue* a = reinterpret_cast<const jvalue*>(arguments[2]);
return cast<GcInt>(t, t->m->processor->invokeArray(t, getMethod(t, m), *o, a))
->value();
}
jboolean JNICALL
CallBooleanMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return run(t, callIntMethodA, arguments) != 0;
}
jbyte JNICALL CallByteMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return run(t, callIntMethodV, arguments);
}
jbyte JNICALL CallByteMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jbyte r = CallByteMethodV(t, o, m, a);
va_end(a);
return r;
}
jbyte JNICALL
CallByteMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return run(t, callIntMethodA, arguments);
}
jchar JNICALL CallCharMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return run(t, callIntMethodV, arguments);
}
jchar JNICALL CallCharMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jchar r = CallCharMethodV(t, o, m, a);
va_end(a);
return r;
}
jchar JNICALL
CallCharMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return run(t, callIntMethodA, arguments);
}
jshort JNICALL CallShortMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return run(t, callIntMethodV, arguments);
}
jshort JNICALL CallShortMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jshort r = CallShortMethodV(t, o, m, a);
va_end(a);
return r;
}
jshort JNICALL
CallShortMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return run(t, callIntMethodA, arguments);
}
jint JNICALL CallIntMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return run(t, callIntMethodV, arguments);
}
jint JNICALL CallIntMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jint r = CallIntMethodV(t, o, m, a);
va_end(a);
return r;
}
jint JNICALL CallIntMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return run(t, callIntMethodA, arguments);
}
uint64_t callLongMethodV(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jmethodID m = arguments[1];
va_list* a = reinterpret_cast<va_list*>(arguments[2]);
return cast<GcLong>(
t, t->m->processor->invokeList(t, getMethod(t, m), *o, true, *a))
->value();
}
jlong JNICALL CallLongMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return run(t, callLongMethodV, arguments);
}
jlong JNICALL CallLongMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jlong r = CallLongMethodV(t, o, m, a);
va_end(a);
return r;
}
uint64_t callLongMethodA(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jmethodID m = arguments[1];
const jvalue* a = reinterpret_cast<const jvalue*>(arguments[2]);
return cast<GcLong>(t,
t->m->processor->invokeArray(t, getMethod(t, m), *o, a))
->value();
}
jlong JNICALL
CallLongMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return run(t, callLongMethodA, arguments);
}
jfloat JNICALL CallFloatMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return bitsToFloat(run(t, callIntMethodV, arguments));
}
jfloat JNICALL CallFloatMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jfloat r = CallFloatMethodV(t, o, m, a);
va_end(a);
return r;
}
jfloat JNICALL
CallFloatMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return bitsToFloat(run(t, callIntMethodA, arguments));
}
jdouble JNICALL CallDoubleMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
return bitsToDouble(run(t, callLongMethodV, arguments));
}
jdouble JNICALL CallDoubleMethod(Thread* t, jobject o, jmethodID m, ...)
{
va_list a;
va_start(a, m);
jdouble r = CallDoubleMethodV(t, o, m, a);
va_end(a);
return r;
}
jdouble JNICALL
CallDoubleMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
{
uintptr_t arguments[]
= {reinterpret_cast<uintptr_t>(o), m, reinterpret_cast<uintptr_t>(a)};
return bitsToDouble(run(t, callLongMethodA, arguments));
}
uint64_t callVoidMethodV(Thread* t, uintptr_t* arguments)
{
jobject o = reinterpret_cast<jobject>(arguments[0]);
jmethodID m = arguments[1];
va_list* a = reinterpret_cast<va_list*>(arguments[2]);
t->m->processor->invokeList(t, getMethod(t, m), *o, true, *a);
return 0;
}
void JNICALL CallVoidMethodV(Thread* t, jobject o, jmethodID m, va_list a)
{
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(o),
m,
reinterpret_cast<uintptr_t>(VA_LIST(a))};
run(t, callVoidMethodV, arguments);