-
Notifications
You must be signed in to change notification settings - Fork 573
/
Generator.java
4644 lines (4521 loc) · 255 KB
/
Generator.java
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) 2011-2022 Samuel Audet
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
* the Free Software Foundation (subject to the "Classpath" exception),
* either version 2, or any later version (collectively, the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/
* http://www.gnu.org/software/classpath/license.html
*
* or as provided in the LICENSE.txt file that accompanied this code.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bytedeco.javacpp.tools;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.ShortBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.bytedeco.javacpp.BoolPointer;
import org.bytedeco.javacpp.BooleanPointer;
import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.CLongPointer;
import org.bytedeco.javacpp.CharPointer;
import org.bytedeco.javacpp.ClassProperties;
import org.bytedeco.javacpp.DoublePointer;
import org.bytedeco.javacpp.FloatPointer;
import org.bytedeco.javacpp.FunctionPointer;
import org.bytedeco.javacpp.IntPointer;
import org.bytedeco.javacpp.LoadEnabled;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.LongPointer;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.PointerPointer;
import org.bytedeco.javacpp.ShortPointer;
import org.bytedeco.javacpp.SizeTPointer;
import org.bytedeco.javacpp.annotation.Adapter;
import org.bytedeco.javacpp.annotation.Allocator;
import org.bytedeco.javacpp.annotation.ArrayAllocator;
import org.bytedeco.javacpp.annotation.ByPtr;
import org.bytedeco.javacpp.annotation.ByPtrPtr;
import org.bytedeco.javacpp.annotation.ByPtrRef;
import org.bytedeco.javacpp.annotation.ByRef;
import org.bytedeco.javacpp.annotation.ByVal;
import org.bytedeco.javacpp.annotation.Cast;
import org.bytedeco.javacpp.annotation.Const;
import org.bytedeco.javacpp.annotation.Convention;
import org.bytedeco.javacpp.annotation.CriticalRegion;
import org.bytedeco.javacpp.annotation.Function;
import org.bytedeco.javacpp.annotation.Index;
import org.bytedeco.javacpp.annotation.MemberGetter;
import org.bytedeco.javacpp.annotation.MemberSetter;
import org.bytedeco.javacpp.annotation.Name;
import org.bytedeco.javacpp.annotation.Namespace;
import org.bytedeco.javacpp.annotation.AsUtf16;
import org.bytedeco.javacpp.annotation.NoDeallocator;
import org.bytedeco.javacpp.annotation.NoException;
import org.bytedeco.javacpp.annotation.NoOffset;
import org.bytedeco.javacpp.annotation.Opaque;
import org.bytedeco.javacpp.annotation.Platform;
import org.bytedeco.javacpp.annotation.Raw;
import org.bytedeco.javacpp.annotation.ValueGetter;
import org.bytedeco.javacpp.annotation.ValueSetter;
import org.bytedeco.javacpp.annotation.Virtual;
/**
* The Generator is where all the C++ source code that we need gets generated.
* It has not been designed in any meaningful way since the requirements were
* not well understood. It is basically a prototype and is really quite a mess.
* Now that we understand better what we need, it could use some refactoring.
* <p>
* When attempting to understand what the Generator does, try to run experiments
* and inspect the generated code: It is quite readable.
* <p>
* Moreover, although Generator is the one ultimately doing something with the
* various annotations it relies on, it was easier to describe the behavior its
* meant to have with them as part of the documentation of the annotations, so
* we can refer to them to understand more about how Generator should work:
*
* @see Adapter
* @see Allocator
* @see ArrayAllocator
* @see ByPtr
* @see ByPtrPtr
* @see ByPtrRef
* @see ByRef
* @see ByVal
* @see Cast
* @see Const
* @see Convention
* @see CriticalRegion
* @see Function
* @see Index
* @see MemberGetter
* @see MemberSetter
* @see Name
* @see Namespace
* @see NoDeallocator
* @see NoException
* @see NoOffset
* @see Opaque
* @see Platform
* @see Raw
* @see ValueGetter
* @see ValueSetter
*
* @author Samuel Audet
*/
public class Generator {
public Generator(Logger logger, Properties properties) {
this(logger, properties, null);
}
public Generator(Logger logger, Properties properties, String encoding) {
this.logger = logger;
this.properties = properties;
this.encoding = encoding;
}
static enum BooleanEnum { BOOLEAN; boolean value; }
static enum ByteEnum { BYTE; byte value; }
static enum ShortEnum { SHORT; short value; }
static enum IntEnum { INT; int value; }
static enum LongEnum { LONG; long value; }
static final String JNI_VERSION = "JNI_VERSION_1_6";
static final List<Class> baseClasses = Arrays.asList(new Class[] {
Loader.class,
Loader.Helper.class,
Pointer.class,
//FunctionPointer.class,
BytePointer.class,
ShortPointer.class,
IntPointer.class,
LongPointer.class,
FloatPointer.class,
DoublePointer.class,
CharPointer.class,
BooleanPointer.class,
PointerPointer.class,
BoolPointer.class,
CLongPointer.class,
SizeTPointer.class });
final Logger logger;
final Properties properties;
final String encoding;
PrintWriter out, out2, jniConfigOut, reflectConfigOut;
Map<String,String> callbacks;
IndexedSet<Class> functions, deallocators, arrayDeallocators, jclasses;
Map<Class,Set<String>> members, virtualFunctions, virtualMembers;
Map<Method,MethodInformation> annotationCache;
boolean mayThrowExceptions, usesAdapters, passesStrings, accessesEnums;
public boolean generate(String sourceFilename, String jniConfigFilename, String reflectConfigFilename, String headerFilename,
String loadSuffix, String baseLoadSuffix, String classPath, Class<?> ... classes) throws IOException {
try {
// first pass using a null writer to fill up the IndexedSet objects
out = new PrintWriter(new Writer() {
@Override public void write(char[] cbuf, int off, int len) { }
@Override public void flush() { }
@Override public void close() { }
});
out2 = jniConfigOut = reflectConfigOut= null;
callbacks = new LinkedHashMap<String,String>();
functions = new IndexedSet<Class>();
deallocators = new IndexedSet<Class>();
arrayDeallocators = new IndexedSet<Class>();
jclasses = new IndexedSet<Class>();
members = new LinkedHashMap<Class,Set<String>>();
virtualFunctions = new LinkedHashMap<Class,Set<String>>();
virtualMembers = new LinkedHashMap<Class,Set<String>>();
annotationCache = new LinkedHashMap<Method,MethodInformation>();
mayThrowExceptions = false;
usesAdapters = false;
passesStrings = false;
if (baseLoadSuffix == null || baseLoadSuffix.isEmpty()) {
for (Class<?> cls : baseClasses) {
jclasses.index(cls);
}
}
if (classes(true, true, true, true, loadSuffix, baseLoadSuffix, classPath, classes)) {
// second pass with a real writer
File sourceFile = new File(sourceFilename);
File sourceDir = sourceFile.getParentFile();
if (sourceDir != null) {
sourceDir.mkdirs();
}
out = encoding != null ? new PrintWriter(sourceFile, encoding) : new PrintWriter(sourceFile);
if (headerFilename != null) {
logger.info("Generating " + headerFilename);
File headerFile = new File(headerFilename);
File headerDir = headerFile.getParentFile();
if (headerDir != null) {
headerDir.mkdirs();
}
out2 = encoding != null ? new PrintWriter(headerFile, encoding) : new PrintWriter(headerFile);
}
if (jniConfigFilename != null) {
logger.info("Generating " + jniConfigFilename);
File jniConfigFile = new File(jniConfigFilename);
File jniConfigDir = jniConfigFile.getParentFile();
if (jniConfigDir != null) {
jniConfigDir.mkdirs();
}
jniConfigOut = encoding != null ? new PrintWriter(jniConfigFile, encoding) : new PrintWriter(jniConfigFile);
}
if (reflectConfigFilename != null) {
logger.info("Generating " + reflectConfigFilename);
File reflectConfigFile = new File(reflectConfigFilename);
File reflectConfigDir = reflectConfigFile.getParentFile();
if (reflectConfigDir != null) {
reflectConfigDir.mkdirs();
}
reflectConfigOut = encoding != null ? new PrintWriter(reflectConfigFile, encoding) : new PrintWriter(reflectConfigFile);
}
return classes(mayThrowExceptions, usesAdapters, passesStrings, accessesEnums, loadSuffix, baseLoadSuffix, classPath, classes);
} else {
return false;
}
} finally {
if (out != null) {
out.close();
}
if (out2 != null) {
out2.close();
}
if (jniConfigOut != null) {
jniConfigOut.close();
}
if (reflectConfigOut != null) {
reflectConfigOut.close();
}
}
}
boolean classes(boolean handleExceptions, boolean defineAdapters, boolean convertStrings, boolean declareEnums,
String loadSuffix, String baseLoadSuffix, String classPath, Class<?> ... classes) {
String version = Generator.class.getPackage().getImplementationVersion();
if (version == null) {
version = "unknown";
}
String warning = "// Generated by JavaCPP version " + version + ": DO NOT EDIT THIS FILE";
out.println(warning);
out.println();
if (out2 != null) {
out2.println(warning);
out2.println();
}
ClassProperties clsProperties = Loader.loadProperties(classes, properties, true);
for (String s : clsProperties.get("platform.pragma")) {
out.println("#pragma " + s);
}
for (String s : clsProperties.get("platform.define")) {
out.println("#define " + s);
}
out.println();
out.println("#ifdef _WIN32");
out.println(" #define _JAVASOFT_JNI_MD_H_");
out.println();
out.println(" #define JNIEXPORT __declspec(dllexport)");
out.println(" #define JNIIMPORT __declspec(dllimport)");
out.println(" #define JNICALL __stdcall");
out.println();
out.println(" typedef int jint;");
out.println(" typedef long long jlong;");
out.println(" typedef signed char jbyte;");
out.println("#elif defined(__GNUC__) && !defined(__ANDROID__)");
out.println(" #define _JAVASOFT_JNI_MD_H_");
out.println();
out.println(" #define JNIEXPORT __attribute__((visibility(\"default\")))");
out.println(" #define JNIIMPORT");
out.println(" #define JNICALL");
out.println();
out.println(" typedef int jint;");
out.println(" typedef long long jlong;");
out.println(" typedef signed char jbyte;");
out.println("#endif");
out.println();
out.println("#include <jni.h>");
if (out2 != null) {
out2.println("#include <jni.h>");
}
out.println();
out.println("#ifdef __ANDROID__");
out.println(" #include <android/log.h>");
out.println("#elif defined(__APPLE__) && defined(__OBJC__)");
out.println(" #include <TargetConditionals.h>");
out.println(" #include <Foundation/Foundation.h>");
out.println("#elif defined(__APPLE__)");
out.println(" #include <TargetConditionals.h>");
out.println("#endif");
out.println();
out.println("#ifdef __linux__");
out.println(" #include <malloc.h>");
out.println(" #include <sys/types.h>");
out.println(" #include <sys/stat.h>");
out.println(" #include <sys/syscall.h>");
out.println(" #include <sys/sysinfo.h>");
out.println(" #include <fcntl.h>");
out.println(" #include <unistd.h>");
out.println(" #include <dlfcn.h>");
out.println(" #include <link.h>");
out.println(" #include <pthread.h>");
out.println("#elif defined(__APPLE__)");
out.println(" #include <sys/types.h>");
out.println(" #include <sys/sysctl.h>");
out.println(" #include <mach/mach_init.h>");
out.println(" #include <mach/mach_host.h>");
out.println(" #include <mach/task.h>");
out.println(" #include <unistd.h>");
out.println(" #include <dlfcn.h>");
out.println(" #include <mach-o/dyld.h>");
out.println(" #include <pthread.h>");
out.println("#elif defined(_WIN32) && !defined(NO_WINDOWS_H)");
out.println(" #define NOMINMAX");
out.println(" #include <windows.h>");
out.println(" #include <psapi.h>");
out.println("#elif defined(_WIN32)");
out.println(" extern \"C\" unsigned long __stdcall GetCurrentThreadId();");
out.println("#endif");
out.println();
out.println("#if defined(__ANDROID__) || TARGET_OS_IPHONE");
out.println(" #define NewWeakGlobalRef(obj) NewGlobalRef(obj)");
out.println(" #define DeleteWeakGlobalRef(obj) DeleteGlobalRef(obj)");
out.println("#endif");
out.println();
out.println("#include <limits.h>");
out.println("#include <stddef.h>");
out.println("#ifndef _WIN32");
out.println(" #include <stdint.h>");
out.println("#endif");
out.println("#include <stdio.h>");
out.println("#include <stdlib.h>");
out.println("#include <string.h>");
out.println("#include <exception>");
out.println("#include <memory>");
out.println("#include <new>");
if (baseLoadSuffix == null || baseLoadSuffix.isEmpty()) {
out.println();
out.println("#if defined(NATIVE_ALLOCATOR) && defined(NATIVE_DEALLOCATOR)");
out.println(" void* operator new(std::size_t size, const std::nothrow_t&) throw() {");
out.println(" return NATIVE_ALLOCATOR(size);");
out.println(" }");
out.println(" void* operator new[](std::size_t size, const std::nothrow_t&) throw() {");
out.println(" return NATIVE_ALLOCATOR(size);");
out.println(" }");
out.println(" void* operator new(std::size_t size) throw(std::bad_alloc) {");
out.println(" return NATIVE_ALLOCATOR(size);");
out.println(" }");
out.println(" void* operator new[](std::size_t size) throw(std::bad_alloc) {");
out.println(" return NATIVE_ALLOCATOR(size);");
out.println(" }");
out.println(" void operator delete(void* ptr) throw() {");
out.println(" NATIVE_DEALLOCATOR(ptr);");
out.println(" }");
out.println(" void operator delete[](void* ptr) throw() {");
out.println(" NATIVE_DEALLOCATOR(ptr);");
out.println(" }");
out.println("#endif");
}
out.println();
out.println("#define jlong_to_ptr(a) ((void*)(uintptr_t)(a))");
out.println("#define ptr_to_jlong(a) ((jlong)(uintptr_t)(a))");
out.println();
out.println("#if defined(_MSC_VER)");
out.println(" #define JavaCPP_noinline __declspec(noinline)");
out.println(" #define JavaCPP_hidden /* hidden by default */");
out.println("#elif defined(__GNUC__)");
out.println(" #define JavaCPP_noinline __attribute__((noinline)) __attribute__ ((unused))");
out.println(" #define JavaCPP_hidden __attribute__((visibility(\"hidden\"))) __attribute__ ((unused))");
out.println("#else");
out.println(" #define JavaCPP_noinline");
out.println(" #define JavaCPP_hidden");
out.println("#endif");
out.println("#if __cplusplus >= 201103L || _MSC_VER >= 1900");
out.println(" #define JavaCPP_override override");
out.println("#else");
out.println(" #define JavaCPP_override");
out.println("#endif");
out.println();
if (loadSuffix == null) {
loadSuffix = "";
String p = clsProperties.getProperty("platform.library.static", "false").toLowerCase();
if (p.equals("true") || p.equals("t") || p.equals("")) {
loadSuffix = "_" + clsProperties.getProperty("platform.library");
}
}
if (classes != null) {
List exclude = clsProperties.get("platform.exclude");
List[] include = { clsProperties.get("platform.cinclude"),
clsProperties.get("platform.include") };
for (int i = 0; i < include.length; i++) {
if (include[i] != null && include[i].size() > 0) {
if (i == 0) {
out.println("extern \"C\" {");
if (out2 != null) {
out2.println("#ifdef __cplusplus");
out2.println("extern \"C\" {");
out2.println("#endif");
}
}
for (String s : (List<String>)include[i]) {
if (exclude.contains(s)) {
continue;
}
String line = "#include ";
if (!s.startsWith("<") && !s.startsWith("\"")) {
line += '"';
}
line += s;
if (!s.endsWith(">") && !s.endsWith("\"")) {
line += '"';
}
out.println(line);
if (out2 != null) {
out2.println(line);
}
}
if (i == 0) {
out.println("}");
if (out2 != null) {
out2.println("#ifdef __cplusplus");
out2.println("}");
out2.println("#endif");
}
}
out.println();
}
}
}
out.println("static JavaVM* JavaCPP_vm = NULL;");
out.println("static bool JavaCPP_haveAllocObject = false;");
out.println("static bool JavaCPP_haveNonvirtual = false;");
out.println("static const char* JavaCPP_classNames[" + jclasses.size() + "] = {");
Iterator<Class> classIterator = jclasses.iterator();
int maxMemberSize = 0;
while (classIterator.hasNext()) {
Class c = classIterator.next();
out.print(" \"" + c.getName().replace('.','/') + "\"");
if (classIterator.hasNext()) {
out.println(",");
}
Set<String> m = members.get(c);
if (m != null && m.size() > maxMemberSize) {
maxMemberSize = m.size();
}
}
out.println(" };");
out.println("static jclass JavaCPP_classes[" + jclasses.size() + "] = { NULL };");
out.println("static jfieldID JavaCPP_addressFID = NULL;");
out.println("static jfieldID JavaCPP_positionFID = NULL;");
out.println("static jfieldID JavaCPP_limitFID = NULL;");
out.println("static jfieldID JavaCPP_capacityFID = NULL;");
out.println("static jfieldID JavaCPP_deallocatorFID = NULL;");
out.println("static jfieldID JavaCPP_ownerAddressFID = NULL;");
if (declareEnums) {
out.println("static jfieldID JavaCPP_booleanValueFID = NULL;");
out.println("static jfieldID JavaCPP_byteValueFID = NULL;");
out.println("static jfieldID JavaCPP_shortValueFID = NULL;");
out.println("static jfieldID JavaCPP_intValueFID = NULL;");
out.println("static jfieldID JavaCPP_longValueFID = NULL;");
}
out.println("static jmethodID JavaCPP_initMID = NULL;");
out.println("static jmethodID JavaCPP_arrayMID = NULL;");
out.println("static jmethodID JavaCPP_arrayOffsetMID = NULL;");
out.println("static jfieldID JavaCPP_bufferPositionFID = NULL;");
out.println("static jfieldID JavaCPP_bufferLimitFID = NULL;");
out.println("static jfieldID JavaCPP_bufferCapacityFID = NULL;");
out.println("static jmethodID JavaCPP_stringMID = NULL;");
out.println("static jmethodID JavaCPP_getBytesMID = NULL;");
out.println("static jmethodID JavaCPP_toStringMID = NULL;");
out.println("#ifdef STRING_BYTES_CHARSET");
out.println("#ifdef MODIFIED_UTF8_STRING");
out.println("#pragma message (\"warning: STRING_BYTES_CHARSET and MODIFIED_UTF8_STRING are mutually exclusive.\")");
out.println("#endif");
out.println("static jobject JavaCPP_stringBytesCharset = NULL;");
out.println("static jmethodID JavaCPP_stringWithCharsetMID = NULL;");
out.println("static jmethodID JavaCPP_getBytesWithCharsetMID = NULL;");
out.println("#endif");
out.println();
out.println("static inline void JavaCPP_log(const char* fmt, ...) {");
out.println(" va_list ap;");
out.println(" va_start(ap, fmt);");
out.println("#ifdef __ANDROID__");
out.println(" __android_log_vprint(ANDROID_LOG_ERROR, \"javacpp\", fmt, ap);");
out.println("#elif defined(__APPLE__) && defined(__OBJC__)");
out.println(" NSLogv([NSString stringWithUTF8String:fmt], ap);");
out.println("#else");
out.println(" vfprintf(stderr, fmt, ap);");
out.println(" fprintf(stderr, \"\\n\");");
out.println(" fflush(stderr);");
out.println("#endif");
out.println(" va_end(ap);");
out.println("}");
out.println();
out.println("#if !defined(NO_JNI_DETACH_THREAD) && defined(_WIN32)");
out.println("#if __cplusplus >= 201103L || _MSC_VER >= 1900");
out.println(" static thread_local");
out.println("#else");
out.println(" static __declspec(thread)");
out.println("#endif");
out.println(" struct JavaCPP_thread_local {");
out.println(" JNIEnv* env = NULL;");
out.println(" ~JavaCPP_thread_local() {");
out.println(" if (env && JavaCPP_vm) {");
out.println(" JavaCPP_vm->DetachCurrentThread();");
out.println(" }");
out.println(" }");
out.println(" } JavaCPP_thread_local; ");
out.println("#elif !defined(NO_JNI_DETACH_THREAD) && (defined(__linux__) || defined(__APPLE__))");
out.println(" static pthread_key_t JavaCPP_current_env;");
out.println(" static JavaCPP_noinline void JavaCPP_detach_env(void *data) {");
out.println(" if (JavaCPP_vm) {");
out.println(" JavaCPP_vm->DetachCurrentThread();");
out.println(" }");
out.println(" }");
out.println(" static JavaCPP_noinline void JavaCPP_create_pthread_key(void) {");
out.println(" pthread_key_create(&JavaCPP_current_env, JavaCPP_detach_env);");
out.println(" }");
out.println("#endif");
out.println();
if (baseLoadSuffix == null || baseLoadSuffix.isEmpty()) {
out.println("static inline jboolean JavaCPP_trimMemory() {");
out.println("#if defined(__linux__) && !defined(__ANDROID__)");
out.println(" return (jboolean)malloc_trim(0);");
out.println("#else");
out.println(" return 0;");
out.println("#endif");
out.println("}");
out.println();
out.println("static inline jlong JavaCPP_physicalBytes(jlong maxSize = 0) {");
out.println(" jlong size = 0;");
out.println("#ifdef __linux__");
out.println(" static int fd = open(\"/proc/self/statm\", O_RDONLY, 0);");
out.println(" if (fd >= 0) {");
out.println(" char line[256];");
out.println(" char* s;");
out.println(" int n;");
out.println(" if ((n = pread(fd, line, sizeof(line), 0)) > 0 && (s = (char*)memchr(line, ' ', n)) != NULL) {");
out.println(" size = (jlong)atoll(s + 1);");
out.println(" if ((s = (char*)memchr(s + 1, ' ', n)) != NULL) {");
out.println(" size -= (jlong)atoll(s + 1);");
out.println(" }");
out.println(" }");
out.println(" size *= (jlong)getpagesize();");
out.println(" // no close(fd);");
out.println(" }");
out.println("#elif defined(__APPLE__)");
out.println(" task_vm_info_data_t info;");
out.println(" mach_msg_type_number_t count = TASK_VM_INFO_COUNT;");
out.println(" if (task_info(current_task(), TASK_VM_INFO, (task_info_t)&info, &count) == KERN_SUCCESS) {");
out.println(" size = (jlong)info.internal;");
out.println(" }");
out.println("#elif defined(_WIN32)");
out.println(" PROCESS_MEMORY_COUNTERS counters;");
out.println(" if (GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters))) {");
out.println(" jlong size2 = (jlong)counters.WorkingSetSize;");
out.println(" if (size2 <= maxSize) return size2;");
out.println(" }");
out.println(" DWORD length = sizeof(PSAPI_WORKING_SET_INFORMATION);");
out.println(" PSAPI_WORKING_SET_INFORMATION *info = (PSAPI_WORKING_SET_INFORMATION*)malloc(length);");
out.println(" BOOL success = QueryWorkingSet(GetCurrentProcess(), info, length);");
out.println(" while (!success && GetLastError() == ERROR_BAD_LENGTH) {");
out.println(" length = sizeof(PSAPI_WORKING_SET_INFORMATION) + info->NumberOfEntries * sizeof(PSAPI_WORKING_SET_BLOCK);");
out.println(" info = (PSAPI_WORKING_SET_INFORMATION*)realloc(info, length);");
out.println(" success = QueryWorkingSet(GetCurrentProcess(), info, length);");
out.println(" }");
out.println(" if (success && info != NULL) {");
out.println(" for (DWORD i = 0; i < info->NumberOfEntries; i++) {");
out.println(" size += !info->WorkingSetInfo[i].Shared;");
out.println(" }");
out.println(" }");
out.println(" SYSTEM_INFO sysinfo;");
out.println(" GetSystemInfo(&sysinfo);");
out.println(" size *= (jlong)sysinfo.dwPageSize;");
out.println(" free(info);");
out.println("#endif");
out.println(" return size;");
out.println("}");
out.println();
out.println("static inline jlong JavaCPP_totalPhysicalBytes() {");
out.println(" jlong size = 0;");
out.println("#ifdef __linux__");
out.println(" struct sysinfo info;");
out.println(" if (sysinfo(&info) == 0) {");
out.println(" size = (jlong)info.totalram * info.mem_unit;");
out.println(" }");
out.println("#elif defined(__APPLE__)");
out.println(" size_t length = sizeof(size);");
out.println(" sysctlbyname(\"hw.memsize\", &size, &length, NULL, 0);");
out.println("#elif defined(_WIN32)");
out.println(" MEMORYSTATUSEX status;");
out.println(" status.dwLength = sizeof(status);");
out.println(" if (GlobalMemoryStatusEx(&status)) {");
out.println(" size = status.ullTotalPhys;");
out.println(" }");
out.println("#endif");
out.println(" return size;");
out.println("}");
out.println();
out.println("static inline jlong JavaCPP_availablePhysicalBytes() {");
out.println(" jlong size = 0;");
out.println("#ifdef __linux__");
out.println(" int fd = open(\"/proc/meminfo\", O_RDONLY, 0);");
out.println(" if (fd >= 0) {");
out.println(" char temp[4096];");
out.println(" char *s;");
out.println(" int n;");
out.println(" if ((n = read(fd, temp, sizeof(temp))) > 0 && (s = (char*)memmem(temp, n, \"MemAvailable:\", 13)) != NULL) {");
out.println(" size = (jlong)(atoll(s + 13) * 1024);");
out.println(" }");
out.println(" close(fd);");
out.println(" }");
out.println(" if (size == 0) {");
out.println(" struct sysinfo info;");
out.println(" if (sysinfo(&info) == 0) {");
out.println(" size = (jlong)info.freeram * info.mem_unit;");
out.println(" }");
out.println(" }");
out.println("#elif defined(__APPLE__)");
out.println(" vm_statistics_data_t info;");
out.println(" mach_msg_type_number_t count = HOST_VM_INFO_COUNT;");
out.println(" if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&info, &count) == KERN_SUCCESS) {");
out.println(" size = (jlong)info.free_count * getpagesize();");
out.println(" }");
out.println("#elif defined(_WIN32)");
out.println(" MEMORYSTATUSEX status;");
out.println(" status.dwLength = sizeof(status);");
out.println(" if (GlobalMemoryStatusEx(&status)) {");
out.println(" size = status.ullAvailPhys;");
out.println(" }");
out.println("#endif");
out.println(" return size;");
out.println("}");
out.println();
out.println("static inline jlong JavaCPP_getDirectBufferAddress(JNIEnv *env, jclass cls, jobject obj) {");
out.println(" return (jlong)env->GetDirectBufferAddress(obj);");
out.println("}");
out.println();
out.println("static inline jint JavaCPP_totalProcessors() {");
out.println(" jint total = 0;");
out.println("#ifdef __linux__");
out.println(" total = sysconf(_SC_NPROCESSORS_CONF);");
out.println("#elif defined(__APPLE__)");
out.println(" size_t length = sizeof(total);");
out.println(" sysctlbyname(\"hw.logicalcpu_max\", &total, &length, NULL, 0);");
out.println("#elif defined(_WIN32)");
out.println(" SYSTEM_INFO info;");
out.println(" GetSystemInfo(&info);");
out.println(" total = info.dwNumberOfProcessors;");
out.println("#endif");
out.println(" return total;");
out.println("}");
out.println();
out.println("static inline jint JavaCPP_totalCores() {");
out.println(" jint total = 0;");
out.println("#ifdef __linux__");
out.println(" const int n = sysconf(_SC_NPROCESSORS_CONF);");
out.println(" int pids[n], cids[n];");
out.println(" for (int i = 0; i < n; i++) {");
out.println(" int fd = 0, pid = 0, cid = 0;");
out.println(" char temp[256];");
out.println(" sprintf(temp, \"/sys/devices/system/cpu/cpu%d/topology/physical_package_id\", i);");
out.println(" if ((fd = open(temp, O_RDONLY, 0)) >= 0) {");
out.println(" if (read(fd, temp, sizeof(temp)) > 0) {");
out.println(" pid = atoi(temp);");
out.println(" }");
out.println(" close(fd);");
out.println(" }");
out.println(" sprintf(temp, \"/sys/devices/system/cpu/cpu%d/topology/core_id\", i);");
out.println(" if ((fd = open(temp, O_RDONLY, 0)) >= 0) {");
out.println(" if (read(fd, temp, sizeof(temp)) > 0) {");
out.println(" cid = atoi(temp);");
out.println(" }");
out.println(" close(fd);");
out.println(" }");
out.println(" bool found = false;");
out.println(" for (int j = 0; j < total; j++) {");
out.println(" if (pids[j] == pid && cids[j] == cid) {");
out.println(" found = true;");
out.println(" break;");
out.println(" }");
out.println(" }");
out.println(" if (!found) {");
out.println(" pids[total] = pid;");
out.println(" cids[total] = cid;");
out.println(" total++;");
out.println(" }");
out.println(" }");
out.println("#elif defined(__APPLE__)");
out.println(" size_t length = sizeof(total);");
out.println(" sysctlbyname(\"hw.physicalcpu_max\", &total, &length, NULL, 0);");
out.println("#elif defined(_WIN32)");
out.println(" SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info = NULL;");
out.println(" DWORD length = 0;");
out.println(" BOOL success = GetLogicalProcessorInformation(info, &length);");
out.println(" while (!success && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {");
out.println(" info = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION*)realloc(info, length);");
out.println(" success = GetLogicalProcessorInformation(info, &length);");
out.println(" }");
out.println(" if (success && info != NULL) {");
out.println(" length /= sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);");
out.println(" for (DWORD i = 0; i < length; i++) {");
out.println(" if (info[i].Relationship == RelationProcessorCore) {");
out.println(" total++;");
out.println(" }");
out.println(" }");
out.println(" }");
out.println(" free(info);");
out.println("#endif");
out.println(" return total;");
out.println("}");
out.println();
out.println("static inline jint JavaCPP_totalChips() {");
out.println(" jint total = 0;");
out.println("#ifdef __linux__");
out.println(" const int n = sysconf(_SC_NPROCESSORS_CONF);");
out.println(" int pids[n];");
out.println(" for (int i = 0; i < n; i++) {");
out.println(" int fd = 0, pid = 0;");
out.println(" char temp[256];");
out.println(" sprintf(temp, \"/sys/devices/system/cpu/cpu%d/topology/physical_package_id\", i);");
out.println(" if ((fd = open(temp, O_RDONLY, 0)) >= 0) {");
out.println(" if (read(fd, temp, sizeof(temp)) > 0) {");
out.println(" pid = atoi(temp);");
out.println(" }");
out.println(" close(fd);");
out.println(" }");
out.println(" bool found = false;");
out.println(" for (int j = 0; j < total; j++) {");
out.println(" if (pids[j] == pid) {");
out.println(" found = true;");
out.println(" break;");
out.println(" }");
out.println(" }");
out.println(" if (!found) {");
out.println(" pids[total] = pid;");
out.println(" total++;");
out.println(" }");
out.println(" }");
out.println("#elif defined(__APPLE__)");
out.println(" size_t length = sizeof(total);");
out.println(" sysctlbyname(\"hw.packages\", &total, &length, NULL, 0);");
out.println("#elif defined(_WIN32)");
out.println(" SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info = NULL;");
out.println(" DWORD length = 0;");
out.println(" BOOL success = GetLogicalProcessorInformation(info, &length);");
out.println(" while (!success && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {");
out.println(" info = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION*)realloc(info, length);");
out.println(" success = GetLogicalProcessorInformation(info, &length);");
out.println(" }");
out.println(" if (success && info != NULL) {");
out.println(" length /= sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);");
out.println(" for (DWORD i = 0; i < length; i++) {");
out.println(" if (info[i].Relationship == RelationProcessorPackage) {");
out.println(" total++;");
out.println(" }");
out.println(" }");
out.println(" }");
out.println(" free(info);");
out.println("#endif");
out.println(" return total;");
out.println("}");
out.println();
out.println("#if defined(__linux__) && !(defined(__ANDROID__) && defined(__arm__))");
out.println("static int JavaCPP_dlcallback(dl_phdr_info *info, size_t size, void *data) {");
out.println(" void *handle = dlopen(info->dlpi_name, RTLD_LAZY);");
out.println(" if (handle != NULL) {");
out.println(" void *address = dlsym(handle, ((char**)data)[0]);");
out.println(" dlclose(handle);");
out.println(" if (address != NULL) {");
out.println(" ((void**)data)[1] = address;");
out.println(" return 1;");
out.println(" }");
out.println(" }");
out.println(" return 0;");
out.println("}");
out.println("#endif");
out.println();
out.println("static JavaCPP_noinline jclass JavaCPP_getClass(JNIEnv* env, int i);");
out.println("static inline void JavaCPP_loadGlobal(JNIEnv* env, jclass cls, const char* filename) {");
out.println("#ifdef _WIN32");
out.println(" HMODULE handle = LoadLibrary(filename);");
out.println(" if (handle == NULL) {");
out.println(" char temp[256];");
out.println(" sprintf(temp, \"LoadLibrary() failed with 0x%lx\", GetLastError());");
out.println(" env->ThrowNew(JavaCPP_getClass(env, " + jclasses.index(UnsatisfiedLinkError.class) + "), temp);");
out.println(" }");
out.println("#else");
out.println(" void *handle = dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);");
out.println(" if (handle == NULL) {");
out.println(" env->ThrowNew(JavaCPP_getClass(env, " + jclasses.index(UnsatisfiedLinkError.class) + "), dlerror());");
out.println(" }");
out.println("#endif");
out.println("}");
out.println();
out.println("static inline void* JavaCPP_addressof(const char* name) {");
out.println(" void *address = NULL;");
out.println("#ifdef __linux__");
out.println(" address = dlsym(RTLD_DEFAULT, name);");
out.println("#if !(defined(__ANDROID__) && defined(__arm__))");
out.println(" if (address == NULL) {");
out.println(" void *data[] = { (char*)name, NULL };");
out.println(" dl_iterate_phdr(JavaCPP_dlcallback, data);");
out.println(" address = data[1];");
out.println(" }");
out.println("#endif");
out.println("#elif defined(__APPLE__)");
out.println(" address = dlsym(RTLD_DEFAULT, name);");
out.println(" if (address == NULL) {");
out.println(" for (uint32_t i = 0; i < _dyld_image_count(); i++) {");
out.println(" const char *libname = _dyld_get_image_name(i);");
out.println(" if (libname != NULL) {");
out.println(" void *handle = dlopen(libname, RTLD_LAZY);");
out.println(" if (handle != NULL) {");
out.println(" address = dlsym(handle, name);");
out.println(" dlclose(handle);");
out.println(" if (address != NULL) {");
out.println(" break;");
out.println(" }");
out.println(" }");
out.println(" }");
out.println(" }");
out.println(" }");
out.println("#elif defined(_WIN32)");
out.println(" HANDLE process = GetCurrentProcess();");
out.println(" HMODULE *modules = NULL;");
out.println(" DWORD length = 0, needed = 0;");
out.println(" BOOL success = EnumProcessModules(process, modules, length, &needed);");
out.println(" while (success && needed > length) {");
out.println(" modules = (HMODULE*)realloc(modules, length = needed);");
out.println(" success = EnumProcessModules(process, modules, length, &needed);");
out.println(" }");
out.println(" if (success && modules != NULL) {");
out.println(" length = needed / sizeof(HMODULE);");
out.println(" for (DWORD i = 0; i < length; i++) {");
out.println(" address = (void*)GetProcAddress(modules[i], name);");
out.println(" if (address != NULL) {");
out.println(" break;");
out.println(" }");
out.println(" }");
out.println(" }");
out.println(" free(modules);");
out.println("#endif");
out.println(" return address;");
out.println("}");
out.println();
out.println("static inline JavaVM* JavaCPP_getJavaVM() {");
out.println(" return JavaCPP_vm;");
out.println("}");
out.println();
out.println("static inline jobject JavaCPP_newGlobalRef(JNIEnv *env, jclass cls, jobject obj) {");
out.println(" return env->NewGlobalRef(obj);");
out.println("}");
out.println();
out.println("static inline jobject JavaCPP_accessGlobalRef(JNIEnv *env, jclass cls, jobject globalRef) {");
out.println(" return globalRef;");
out.println("}");
out.println();
out.println("static inline void JavaCPP_deleteGlobalRef(JNIEnv *env, jclass cls, jobject globalRef) {");
out.println(" env->DeleteGlobalRef(globalRef);");
out.println("}");
out.println();
}
out.println("static JavaCPP_noinline jclass JavaCPP_getClass(JNIEnv* env, int i) {");
out.println(" if (JavaCPP_classes[i] == NULL && env->PushLocalFrame(1) == 0) {");
out.println(" jclass cls = env->FindClass(JavaCPP_classNames[i]);");
out.println(" if (cls == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error loading class %s.\", JavaCPP_classNames[i]);");
out.println(" return NULL;");
out.println(" }");
out.println(" JavaCPP_classes[i] = (jclass)env->NewWeakGlobalRef(cls);");
out.println(" if (JavaCPP_classes[i] == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error creating global reference of class %s.\", JavaCPP_classNames[i]);");
out.println(" return NULL;");
out.println(" }");
out.println(" env->PopLocalFrame(NULL);");
out.println(" }");
out.println(" return JavaCPP_classes[i];");
out.println("}");
out.println();
out.println("static JavaCPP_noinline jfieldID JavaCPP_getFieldID(JNIEnv* env, int i, const char* name, const char* sig) {");
out.println(" jclass cls = JavaCPP_getClass(env, i);");
out.println(" if (cls == NULL) {");
out.println(" return NULL;");
out.println(" }");
out.println(" jfieldID fid = env->GetFieldID(cls, name, sig);");
out.println(" if (fid == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error getting field ID of %s/%s\", JavaCPP_classNames[i], name);");
out.println(" return NULL;");
out.println(" }");
out.println(" return fid;");
out.println("}");
out.println();
if (declareEnums) {
out.println("static JavaCPP_noinline jfieldID JavaCPP_getFieldID(JNIEnv* env, const char* clsName, const char* name, const char* sig) {");
out.println(" jclass cls = env->FindClass(clsName);");
out.println(" if (cls == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error loading class %s.\", clsName);");
out.println(" return NULL;");
out.println(" }");
out.println(" jfieldID fid = env->GetFieldID(cls, name, sig);");
out.println(" if (fid == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error getting field ID of %s/%s\", clsName, name);");
out.println(" return NULL;");
out.println(" }");
out.println(" return fid;");
out.println("}");
out.println();
}
out.println("static JavaCPP_noinline jmethodID JavaCPP_getMethodID(JNIEnv* env, int i, const char* name, const char* sig) {");
out.println(" jclass cls = JavaCPP_getClass(env, i);");
out.println(" if (cls == NULL) {");
out.println(" return NULL;");
out.println(" }");
out.println(" jmethodID mid = env->GetMethodID(cls, name, sig);");
out.println(" if (mid == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error getting method ID of %s/%s\", JavaCPP_classNames[i], name);");
out.println(" return NULL;");
out.println(" }");
out.println(" return mid;");
out.println("}");
out.println();
out.println("static JavaCPP_noinline jmethodID JavaCPP_getStaticMethodID(JNIEnv* env, int i, const char* name, const char* sig) {");
out.println(" jclass cls = JavaCPP_getClass(env, i);");
out.println(" if (cls == NULL) {");
out.println(" return NULL;");
out.println(" }");
out.println(" jmethodID mid = env->GetStaticMethodID(cls, name, sig);");
out.println(" if (mid == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error getting static method ID of %s/%s\", JavaCPP_classNames[i], name);");
out.println(" return NULL;");
out.println(" }");
out.println(" return mid;");
out.println("}");
out.println();
out.println("static JavaCPP_noinline jobject JavaCPP_createPointer(JNIEnv* env, int i, jclass cls = NULL) {");
out.println(" if (cls == NULL && (cls = JavaCPP_getClass(env, i)) == NULL) {");
out.println(" return NULL;");
out.println(" }");
out.println(" if (JavaCPP_haveAllocObject) {");
out.println(" return env->AllocObject(cls);");
out.println(" } else {");
out.println(" jmethodID mid = env->GetMethodID(cls, \"<init>\", \"(Lorg/bytedeco/javacpp/Pointer;)V\");");
out.println(" if (mid == NULL || env->ExceptionCheck()) {");
out.println(" JavaCPP_log(\"Error getting Pointer constructor of %s, while VM does not support AllocObject()\", JavaCPP_classNames[i]);");
out.println(" return NULL;");
out.println(" }");
out.println(" return env->NewObject(cls, mid, NULL);");
out.println(" }");
out.println("}");
out.println();
out.println("static JavaCPP_noinline void JavaCPP_initPointer(JNIEnv* env, jobject obj, const void* ptr, jlong size, void* owner, void (*deallocator)(void*)) {");
out.println(" if (owner != NULL && deallocator != NULL) {");
out.println(" jvalue args[4];");
out.println(" args[0].j = ptr_to_jlong(ptr);");
out.println(" args[1].j = size;");
out.println(" args[2].j = ptr_to_jlong(owner);");
out.println(" args[3].j = ptr_to_jlong(deallocator);");
out.println(" if (JavaCPP_haveNonvirtual) {");
out.println(" env->CallNonvirtualVoidMethodA(obj, JavaCPP_getClass(env, "
+ jclasses.index(Pointer.class) + "), JavaCPP_initMID, args);");
out.println(" } else {");
out.println(" env->CallVoidMethodA(obj, JavaCPP_initMID, args);");
out.println(" }");
out.println(" } else {");
out.println(" env->SetLongField(obj, JavaCPP_addressFID, ptr_to_jlong(ptr));");
out.println(" env->SetLongField(obj, JavaCPP_limitFID, (jlong)size);");