-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathJNICalls.c
More file actions
1759 lines (1539 loc) · 39.7 KB
/
JNICalls.c
File metadata and controls
1759 lines (1539 loc) · 39.7 KB
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) 2004-2021 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Tada AB
* Chapman Flack
*
* @author Thomas Hallgren
*/
#include <string.h> /* for _MSC_VER *_min_messages hack */
#include "pljava/JNICalls.h"
#include "pljava/Backend.h"
#include "pljava/Invocation.h"
#include "pljava/Exception.h"
#include "pljava/type/ErrorData.h"
#include "pljava/type/String.h"
/**
* \addtogroup JNI
* @{
*/
JNIEnv* jniEnv;
jint (JNICALL *pljava_createvm)(JavaVM **, void **, void *);
void* mainThreadId; /* declared in pljava.h */
static JNIEnv* primordialJNIEnv;
static jobject s_threadLock;
static bool s_refuseOtherThreads = false;
static bool s_doMonitorOps = true;
static jclass s_Thread_class;
static jmethodID s_Thread_currentThread;
static jfieldID s_Thread_contextLoader;
static jobject s_threadObject;
void pljava_JNI_setThreadPolicy(bool refuseOtherThreads, bool doMonitorOps)
{
s_refuseOtherThreads = refuseOtherThreads;
s_doMonitorOps = doMonitorOps;
}
/*
* This file contains very specialized methods for updating the context
* class loader of a thread, because this is where they can be implemented
* without the overhead of several calls to wrappers defined here.
*
* More lightweight implementations of those can be chosen if the selected
* thread policy precludes native access from any but the primordial thread.
*/
JNI_ContextLoaderUpdater *JNI_loaderUpdater;
JNI_ContextLoaderRestorer *JNI_loaderRestorer;
static JNI_ContextLoaderUpdater _noopUpdater;
static JNI_ContextLoaderRestorer _noopRestorer;
static JNI_ContextLoaderUpdater _lightUpdater;
static JNI_ContextLoaderRestorer _lightRestorer;
static JNI_ContextLoaderUpdater _heavyUpdater;
static JNI_ContextLoaderRestorer _heavyRestorer;
void pljava_JNI_threadInitialize(bool manageLoader)
{
if ( ! manageLoader )
{
JNI_loaderUpdater = _noopUpdater;
JNI_loaderRestorer = _noopRestorer;
return;
}
s_Thread_class = JNI_newGlobalRef(PgObject_getJavaClass(
"java/lang/Thread"));
s_Thread_currentThread = PgObject_getStaticJavaMethod(
s_Thread_class,
"currentThread",
"()"
"Ljava/lang/Thread;");
s_Thread_contextLoader = JNI_getFieldIDOrNull(s_Thread_class,
"contextClassLoader", "Ljava/lang/ClassLoader;");
if ( NULL == s_Thread_contextLoader )
{
ereport(WARNING, (
errmsg("unable to manage thread context classloaders in this JVM")
));
JNI_loaderUpdater = _noopUpdater;
JNI_loaderRestorer = _noopRestorer;
}
else if ( s_refuseOtherThreads || ! s_doMonitorOps )
{
s_threadObject =
JNI_newGlobalRef(
JNI_callStaticObjectMethod(
s_Thread_class, s_Thread_currentThread));
JNI_loaderUpdater = _lightUpdater;
JNI_loaderRestorer = _lightRestorer;
}
else
{
JNI_loaderUpdater = _heavyUpdater;
JNI_loaderRestorer = _heavyRestorer;
}
}
/*
* BEGIN_JAVA and END_JAVA are used in JNI wrappers that are not expected to
* invoke Java methods; all they do is play the game with the scope of the JNI
* env value that was devised to fail fast if the intended pattern for PL/Java's
* JNI usage isn't followed.
*
* BEGIN_CALL and END_CALL add to that the releasing of the "THREADLOCK"
* monitor when calling into Java, and reacquiring it on return, that support
* the java_thread_pg_entry=allow mode of operation, and also checking for
* exceptions and turning them into PostgreSQL ereports.
*
* The _MONITOR_HELD flavors of those skip the monitor operations but still do
* the exception checks. They are used in a select few *Locked flavors of
* method call wrappers used where only known and lightweight Java methods will
* be invoked and not arbitrary methods of user code.
*/
#define BEGIN_JAVA { JNIEnv* env = jniEnv; jniEnv = 0;
#define END_JAVA jniEnv = env; }
#define BEGIN_CALL \
BEGIN_JAVA \
if(s_doMonitorOps && ((*env)->MonitorExit(env, s_threadLock) < 0)) \
elog(ERROR, "Java exit monitor failure");
#define END_CALL endCall(env); }
#define BEGIN_CALL_MONITOR_HELD \
BEGIN_JAVA
#define END_CALL_MONITOR_HELD endCallMonitorHeld(env); }
static void elogExceptionMessage(JNIEnv* env, jthrowable exh, int logLevel)
{
StringInfoData buf;
int sqlState = ERRCODE_INTERNAL_ERROR;
JNIEnv* saveEnv = jniEnv;
jclass exhClass = (*env)->GetObjectClass(env, exh);
jstring jtmp =
(jstring)(*env)->CallObjectMethod(env, exhClass, Class_getName);
/* ExceptionOccurred check is found below ... */
initStringInfo(&buf);
jniEnv = env; /* Used by the String operations */
if ( 0 == (*env)->ExceptionOccurred(env) ) /* ... here */
String_appendJavaString(&buf, jtmp);
else
{
(*env)->ExceptionClear(env);
appendStringInfoString(&buf, "<unknown Java class>");
}
(*env)->DeleteLocalRef(env, exhClass);
(*env)->DeleteLocalRef(env, jtmp);
jtmp = (jstring)(*env)->CallObjectMethod(env, exh, Throwable_getMessage);
if ( 0 != (*env)->ExceptionOccurred(env) )
{
(*env)->ExceptionClear(env);
jtmp = 0;
}
if(jtmp != 0)
{
appendStringInfoString(&buf, ": ");
String_appendJavaString(&buf, jtmp);
(*env)->DeleteLocalRef(env, jtmp);
}
if((*env)->IsInstanceOf(env, exh, SQLException_class))
{
jtmp = (*env)->CallObjectMethod(env, exh, SQLException_getSQLState);
if ( 0 != (*env)->ExceptionOccurred(env) )
{
(*env)->ExceptionClear(env);
jtmp = 0;
}
if(jtmp != 0)
{
char* s = String_createNTS(jtmp);
(*env)->DeleteLocalRef(env, jtmp);
if(strlen(s) >= 5)
sqlState = MAKE_SQLSTATE(s[0], s[1], s[2], s[3], s[4]);
pfree(s);
}
}
jniEnv = saveEnv;
ereport(logLevel, (errcode(sqlState), errmsg("%s", buf.data)));
}
static void printStacktrace(JNIEnv* env, jobject exh)
{
#ifndef _MSC_VER
if(DEBUG1 >= log_min_messages || DEBUG1 >= client_min_messages)
#else
/* This is gross, but only happens as often as an exception escapes Java
* code to be rethrown. There is some renewed interest on pgsql-hackers to
* find a good answer for the MSVC PGDLLIMPORT nonsense, and all of this
* handling of exceptions and logging could stand some rework anyway.
*/
if ( 0 == strncmp("debug", PG_GETCONFIGOPTION("log_min_messages"), 5)
|| 0 == strncmp("debug", PG_GETCONFIGOPTION("client_min_messages"), 5) )
#endif
{
int currLevel = Backend_setJavaLogLevel(DEBUG1);
(*env)->CallVoidMethod(env, exh, Throwable_printStackTrace);
(*env)->ExceptionOccurred(env); /* sop for JNI exception-check check */
Backend_setJavaLogLevel(currLevel);
}
}
static void endCall(JNIEnv* env)
{
jobject exh = (*env)->ExceptionOccurred(env);
if(exh != 0)
(*env)->ExceptionClear(env);
if(s_doMonitorOps && ((*env)->MonitorEnter(env, s_threadLock) < 0))
elog(ERROR, "Java enter monitor failure");
jniEnv = env;
if(exh != 0)
{
printStacktrace(env, exh);
if((*env)->IsInstanceOf(env, exh, ServerException_class))
{
/* Rethrow the server error.
*/
jobject jed = (*env)->CallObjectMethod(env, exh, ServerException_getErrorData);
if ( 0 != (*env)->ExceptionOccurred(env) )
{
(*env)->ExceptionClear(env);
jed = 0;
}
if(jed != 0)
ReThrowError(pljava_ErrorData_getErrorData(jed));
}
/* There's no return from this call.
*/
elogExceptionMessage(env, exh, ERROR);
}
}
static void endCallMonitorHeld(JNIEnv* env)
{
jobject exh = (*env)->ExceptionOccurred(env);
if(exh != 0)
(*env)->ExceptionClear(env);
jniEnv = env;
if(exh != 0)
{
printStacktrace(env, exh);
if((*env)->IsInstanceOf(env, exh, ServerException_class))
{
/* Rethrow the server error.
*/
jobject jed = (*env)->CallObjectMethod(env, exh, ServerException_getErrorData);
if ( 0 != (*env)->ExceptionOccurred(env) )
{
(*env)->ExceptionClear(env);
jed = 0;
}
if(jed != 0)
ReThrowError(pljava_ErrorData_getErrorData(jed));
}
/* There's no return from this call.
*/
elogExceptionMessage(env, exh, ERROR);
}
}
bool beginNativeNoErrCheck(JNIEnv* env)
{
if ( s_refuseOtherThreads && env != primordialJNIEnv )
{
env = JNI_setEnv(env);
Exception_throw(ERRCODE_INTERNAL_ERROR,
"Attempt by non-initial thread to enter PostgreSQL from Java");
JNI_setEnv(env);
return false;
}
if((env = JNI_setEnv(env)) != 0)
{
/* The backend is *not* awaiting the return of a call to the JVM
* so there's no way the JVM can be allowed to call out at this
* point.
*/
Exception_throw(ERRCODE_INTERNAL_ERROR,
"An attempt was made to call a PostgreSQL backend function while main thread was not in the JVM");
JNI_setEnv(env);
return false;
}
return true;
}
bool beginNative(JNIEnv* env)
{
if (!currentInvocation)
{
env = JNI_setEnv(env);
Exception_throw(ERRCODE_INTERNAL_ERROR, "An attempt was made to call a PostgreSQL backend function in a transaction callback. At the end of a transaction you may not access the database any longer.");
JNI_setEnv(env);
return false;
}
if(currentInvocation->errorOccurred)
{
/* An elog with level higher than ERROR was issued. The transaction
* state is unknown. There's no way the JVM is allowed to enter the
* backend at this point.
*/
env = JNI_setEnv(env);
Exception_throw(ERRCODE_INTERNAL_ERROR,
"An attempt was made to call a PostgreSQL backend function after an elog(ERROR) had been issued");
JNI_setEnv(env);
return false;
}
return beginNativeNoErrCheck(env);
}
jboolean JNI_callBooleanMethod(jobject object, jmethodID methodID, ...)
{
jboolean result;
va_list args;
va_start(args, methodID);
result = JNI_callBooleanMethodV(object, methodID, args);
va_end(args);
return result;
}
jboolean JNI_callBooleanMethodV(jobject object, jmethodID methodID, va_list args)
{
jboolean result;
BEGIN_CALL
result = (*env)->CallBooleanMethodV(env, object, methodID, args);
END_CALL
return result;
}
jbyte JNI_callByteMethod(jobject object, jmethodID methodID, ...)
{
jbyte result;
va_list args;
va_start(args, methodID);
result = JNI_callByteMethodV(object, methodID, args);
va_end(args);
return result;
}
jbyte JNI_callByteMethodV(jobject object, jmethodID methodID, va_list args)
{
jbyte result;
BEGIN_CALL
result = (*env)->CallByteMethodV(env, object, methodID, args);
END_CALL
return result;
}
jdouble JNI_callDoubleMethod(jobject object, jmethodID methodID, ...)
{
jdouble result;
va_list args;
va_start(args, methodID);
result = JNI_callDoubleMethodV(object, methodID, args);
va_end(args);
return result;
}
jdouble JNI_callDoubleMethodV(jobject object, jmethodID methodID, va_list args)
{
jdouble result;
BEGIN_CALL
result = (*env)->CallDoubleMethodV(env, object, methodID, args);
END_CALL
return result;
}
jfloat JNI_callFloatMethod(jobject object, jmethodID methodID, ...)
{
jfloat result;
va_list args;
va_start(args, methodID);
result = JNI_callFloatMethodV(object, methodID, args);
va_end(args);
return result;
}
jfloat JNI_callFloatMethodV(jobject object, jmethodID methodID, va_list args)
{
jfloat result;
BEGIN_CALL
result = (*env)->CallFloatMethodV(env, object, methodID, args);
END_CALL
return result;
}
jint JNI_callIntMethod(jobject object, jmethodID methodID, ...)
{
jint result;
va_list args;
va_start(args, methodID);
result = JNI_callIntMethodV(object, methodID, args);
va_end(args);
return result;
}
jint JNI_callIntMethodV(jobject object, jmethodID methodID, va_list args)
{
jint result;
BEGIN_CALL
result = (*env)->CallIntMethodV(env, object, methodID, args);
END_CALL
return result;
}
jint JNI_callIntMethodLocked(jobject object, jmethodID methodID, ...)
{
jint result;
va_list args;
va_start(args, methodID);
result = JNI_callIntMethodLockedV(object, methodID, args);
va_end(args);
return result;
}
jint JNI_callIntMethodLockedV(jobject object, jmethodID methodID, va_list args)
{
jint result;
BEGIN_CALL_MONITOR_HELD
result = (*env)->CallIntMethodV(env, object, methodID, args);
END_CALL_MONITOR_HELD
return result;
}
jlong JNI_callLongMethod(jobject object, jmethodID methodID, ...)
{
jlong result;
va_list args;
va_start(args, methodID);
result = JNI_callLongMethodV(object, methodID, args);
va_end(args);
return result;
}
jlong JNI_callLongMethodV(jobject object, jmethodID methodID, va_list args)
{
jlong result;
BEGIN_CALL
result = (*env)->CallLongMethodV(env, object, methodID, args);
END_CALL
return result;
}
jlong JNI_callLongMethodLocked(jobject object, jmethodID methodID, ...)
{
jlong result;
va_list args;
va_start(args, methodID);
result = JNI_callLongMethodLockedV(object, methodID, args);
va_end(args);
return result;
}
jlong JNI_callLongMethodLockedV(jobject object, jmethodID methodID, va_list args)
{
jlong result;
BEGIN_CALL_MONITOR_HELD
result = (*env)->CallLongMethodV(env, object, methodID, args);
END_CALL_MONITOR_HELD
return result;
}
jshort JNI_callShortMethod(jobject object, jmethodID methodID, ...)
{
jshort result;
va_list args;
va_start(args, methodID);
result = JNI_callShortMethodV(object, methodID, args);
va_end(args);
return result;
}
jshort JNI_callShortMethodV(jobject object, jmethodID methodID, va_list args)
{
jshort result;
BEGIN_CALL
result = (*env)->CallShortMethodV(env, object, methodID, args);
END_CALL
return result;
}
jobject JNI_callObjectMethod(jobject object, jmethodID methodID, ...)
{
jobject result;
va_list args;
va_start(args, methodID);
result = JNI_callObjectMethodV(object, methodID, args);
va_end(args);
return result;
}
jobject JNI_callObjectMethodV(jobject object, jmethodID methodID, va_list args)
{
jobject result;
BEGIN_CALL
result = (*env)->CallObjectMethodV(env, object, methodID, args);
END_CALL
return result;
}
jobject JNI_callObjectMethodLocked(jobject object, jmethodID methodID, ...)
{
jobject result;
va_list args;
va_start(args, methodID);
result = JNI_callObjectMethodLockedV(object, methodID, args);
va_end(args);
return result;
}
jobject JNI_callObjectMethodLockedV(jobject object, jmethodID methodID, va_list args)
{
jobject result;
BEGIN_CALL_MONITOR_HELD
result = (*env)->CallObjectMethodV(env, object, methodID, args);
END_CALL_MONITOR_HELD
return result;
}
jboolean JNI_callStaticBooleanMethod(jclass clazz, jmethodID methodID, ...)
{
jboolean result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticBooleanMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jboolean JNI_callStaticBooleanMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jboolean result;
BEGIN_CALL
result = (*env)->CallStaticBooleanMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
jboolean JNI_callStaticBooleanMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jboolean result;
BEGIN_CALL
result = (*env)->CallStaticBooleanMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jbyte JNI_callStaticByteMethod(jclass clazz, jmethodID methodID, ...)
{
jbyte result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticByteMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jbyte JNI_callStaticByteMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jbyte result;
BEGIN_CALL
result = (*env)->CallStaticByteMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
jbyte JNI_callStaticByteMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jbyte result;
BEGIN_CALL
result = (*env)->CallStaticByteMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jshort JNI_callStaticShortMethod(jclass clazz, jmethodID methodID, ...)
{
jshort result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticShortMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jshort JNI_callStaticShortMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jshort result;
BEGIN_CALL
result = (*env)->CallStaticShortMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jchar JNI_callStaticCharMethod(jclass clazz, jmethodID methodID, ...)
{
jchar result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticCharMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jchar JNI_callStaticCharMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jchar result;
BEGIN_CALL
result = (*env)->CallStaticCharMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jdouble JNI_callStaticDoubleMethod(jclass clazz, jmethodID methodID, ...)
{
jdouble result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticDoubleMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jdouble JNI_callStaticDoubleMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jdouble result;
BEGIN_CALL
result = (*env)->CallStaticDoubleMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
jdouble JNI_callStaticDoubleMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jdouble result;
BEGIN_CALL
result = (*env)->CallStaticDoubleMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jfloat JNI_callStaticFloatMethod(jclass clazz, jmethodID methodID, ...)
{
jfloat result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticFloatMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jfloat JNI_callStaticFloatMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jfloat result;
BEGIN_CALL
result = (*env)->CallStaticFloatMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
jfloat JNI_callStaticFloatMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jfloat result;
BEGIN_CALL
result = (*env)->CallStaticFloatMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jint JNI_callStaticIntMethod(jclass clazz, jmethodID methodID, ...)
{
jint result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticIntMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jint JNI_callStaticIntMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jint result;
BEGIN_CALL
result = (*env)->CallStaticIntMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
jint JNI_callStaticIntMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jint result;
BEGIN_CALL
result = (*env)->CallStaticIntMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jlong JNI_callStaticLongMethod(jclass clazz, jmethodID methodID, ...)
{
jlong result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticLongMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jlong JNI_callStaticLongMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jlong result;
BEGIN_CALL
result = (*env)->CallStaticLongMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
jlong JNI_callStaticLongMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jlong result;
BEGIN_CALL
result = (*env)->CallStaticLongMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jobject JNI_callStaticObjectMethod(jclass clazz, jmethodID methodID, ...)
{
jobject result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticObjectMethodV(clazz, methodID, args);
va_end(args);
return result;
}
jobject JNI_callStaticObjectMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jobject result;
BEGIN_CALL
result = (*env)->CallStaticObjectMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
jobject JNI_callStaticObjectMethodV(jclass clazz, jmethodID methodID, va_list args)
{
jobject result;
BEGIN_CALL
result = (*env)->CallStaticObjectMethodV(env, clazz, methodID, args);
END_CALL
return result;
}
jobject JNI_callStaticObjectMethodLocked(jclass clazz, jmethodID methodID, ...)
{
jobject result;
va_list args;
va_start(args, methodID);
result = JNI_callStaticObjectMethodLockedV(clazz, methodID, args);
va_end(args);
return result;
}
jobject JNI_callStaticObjectMethodLockedV(jclass clazz, jmethodID methodID, va_list args)
{
jobject result;
BEGIN_CALL_MONITOR_HELD
result = (*env)->CallStaticObjectMethodV(env, clazz, methodID, args);
END_CALL_MONITOR_HELD
return result;
}
jshort JNI_callStaticShortMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
jshort result;
BEGIN_CALL
result = (*env)->CallStaticShortMethodA(env, clazz, methodID, args);
END_CALL
return result;
}
void JNI_callStaticVoidMethod(jclass clazz, jmethodID methodID, ...)
{
va_list args;
va_start(args, methodID);
JNI_callStaticVoidMethodV(clazz, methodID, args);
va_end(args);
}
void JNI_callStaticVoidMethodA(jclass clazz, jmethodID methodID, jvalue* args)
{
BEGIN_CALL
(*env)->CallStaticVoidMethodA(env, clazz, methodID, args);
END_CALL
}
void JNI_callStaticVoidMethodV(jclass clazz, jmethodID methodID, va_list args)
{
BEGIN_CALL
(*env)->CallStaticVoidMethodV(env, clazz, methodID, args);
END_CALL
}
void JNI_callStaticVoidMethodLocked(jclass clazz, jmethodID methodID, ...)
{
va_list args;
va_start(args, methodID);
JNI_callStaticVoidMethodLockedV(clazz, methodID, args);
va_end(args);
}
void JNI_callStaticVoidMethodLockedV(jclass clazz, jmethodID methodID, va_list args)
{
BEGIN_CALL_MONITOR_HELD
(*env)->CallStaticVoidMethodV(env, clazz, methodID, args);
END_CALL_MONITOR_HELD
}
void JNI_callVoidMethod(jobject object, jmethodID methodID, ...)
{
va_list args;
va_start(args, methodID);
JNI_callVoidMethodV(object, methodID, args);
va_end(args);
}
void JNI_callVoidMethodV(jobject object, jmethodID methodID, va_list args)
{
BEGIN_CALL
(*env)->CallVoidMethodV(env, object, methodID, args);
END_CALL
}
void JNI_callVoidMethodLocked(jobject object, jmethodID methodID, ...)
{
va_list args;
va_start(args, methodID);
JNI_callVoidMethodLockedV(object, methodID, args);
va_end(args);
}
void JNI_callVoidMethodLockedV(jobject object, jmethodID methodID, va_list args)
{
BEGIN_CALL_MONITOR_HELD
(*env)->CallVoidMethodV(env, object, methodID, args);
END_CALL_MONITOR_HELD
}
jint JNI_createVM(JavaVM** javaVM, JavaVMInitArgs* vmArgs)
{
JNIEnv* env = 0;
jint jstat = pljava_createvm(javaVM, (void **)&env, vmArgs);
if(jstat == JNI_OK)
{
jniEnv = env;
primordialJNIEnv = env;
mainThreadId = env;
}
return jstat;
}
void JNI_deleteGlobalRef(jobject object)
{
BEGIN_JAVA
(*env)->DeleteGlobalRef(env, object);
END_JAVA
}
void JNI_deleteLocalRef(jobject object)
{
BEGIN_JAVA
(*env)->DeleteLocalRef(env, object);
END_JAVA
}
void JNI_deleteWeakGlobalRef(jweak object)
{
BEGIN_JAVA
(*env)->DeleteWeakGlobalRef(env, object);
END_JAVA
}
jint JNI_destroyVM(JavaVM *vm)
{
jint result;
BEGIN_JAVA
result = (*vm)->DestroyJavaVM(vm);
END_JAVA
jniEnv = 0;
s_threadLock = 0;
return result;
}
jboolean JNI_exceptionCheck(void)
{
jboolean result;
BEGIN_JAVA
result = (*env)->ExceptionCheck(env);
END_JAVA
return result;
}
void JNI_exceptionClear(void)
{
BEGIN_JAVA
(*env)->ExceptionClear(env);
END_JAVA
}
void JNI_exceptionDescribe(void)
{
/* The ExceptionDescribe will print on stderr. Not a good idea
* since the exception itself might have been caused by an unwriteable
* stdout/stderr (happens when running as a windows service
*
* (*env)->ExceptionDescribe(env);
*/
jthrowable exh;
BEGIN_JAVA
exh = (*env)->ExceptionOccurred(env);
if(exh != 0)
{
(*env)->ExceptionClear(env);
printStacktrace(env, exh);
elogExceptionMessage(env, exh, WARNING);
}
END_JAVA
}
jthrowable JNI_exceptionOccurred(void)
{
jthrowable result;
BEGIN_JAVA
result = (*env)->ExceptionOccurred(env);
END_JAVA
return result;
}
jclass JNI_findClass(const char* className)
{
jclass result;
BEGIN_JAVA
result = (*env)->FindClass(env, className);
END_JAVA
return result;
}
jsize JNI_getArrayLength(jarray array)
{
jsize result;
BEGIN_JAVA
result = (*env)->GetArrayLength(env, array);
END_JAVA
return result;
}
jbyte* JNI_getByteArrayElements(jbyteArray array, jboolean* isCopy)
{
jbyte* result;
BEGIN_JAVA
result = (*env)->GetByteArrayElements(env, array, isCopy);
END_JAVA
return result;
}
void JNI_getByteArrayRegion(jbyteArray array, jsize start, jsize len, jbyte* buf)