Skip to content

Commit 8d773e9

Browse files
committed
Avoid polymorphic dispatch over JNI
When linked statically on GraalVM, JNI symbols declared in the overloaded form cannot be resolved. Luckily, all of `Native`'s callsites are in `Pointer` or itself, and all `native` methods of `Native` are non-public. This PR adjusts the JNA C API to avoid using overloaded `read`, `write`, or `getDirectByteBuffer`. Callsites are amended in `Pointer` accordingly. Signed-off-by: Sam Gammon <[email protected]> Signed-off-by: Dario Valdespino <[email protected]>
1 parent 85fac39 commit 8d773e9

File tree

4 files changed

+58
-58
lines changed

4 files changed

+58
-58
lines changed

common.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<property name="jni.revision" value="2"/>
2828
<property name="jni.build" value="0"/> <!--${build.number}-->
2929
<property name="jni.version" value="${jni.major}.${jni.minor}.${jni.revision}"/>
30-
<property name="jni.md5" value="eea709d4f4531903eb04ab51ff3840ce"/>
30+
<property name="jni.md5" value="2758dad3ef270c95b39b70ca30de3941"/>
3131
<property name="spec.title" value="Java Native Access (JNA)"/>
3232
<property name="spec.vendor" value="${vendor}"/>
3333
<property name="spec.version" value="${jna.major}"/>

native/dispatch.c

+29-29
Original file line numberDiff line numberDiff line change
@@ -2334,10 +2334,10 @@ Java_com_sun_jna_Native_findSymbol(JNIEnv *env, jclass UNUSED(cls),
23342334

23352335
/*
23362336
* Class: com_sun_jna_Native
2337-
* Method: write
2337+
* Method: writeBytes
23382338
* Signature: (Lcom/sun/jna/Pointer;JJ[BII)V
23392339
*/
2340-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3BII
2340+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_writeBytes
23412341
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jbyteArray arr, jint off, jint n)
23422342
{
23432343
PSTART();
@@ -2347,21 +2347,21 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3
23472347

23482348
/*
23492349
* Class: com_sun_jna_Native
2350-
* Method: write
2350+
* Method: writeChars
23512351
* Signature: (Lcom/sun/jna/Pointer;JJ[CII)V
23522352
*/
2353-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3CII
2353+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_writeChars
23542354
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jcharArray arr, jint off, jint n)
23552355
{
23562356
getChars(env, (wchar_t*)L2A(addr + offset), arr, off, n);
23572357
}
23582358

23592359
/*
23602360
* Class: com_sun_jna_Native
2361-
* Method: write
2361+
* Method: writeDoubles
23622362
* Signature: (Lcom/sun/jna/Pointer;JJ[DII)V
23632363
*/
2364-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3DII
2364+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_writeDoubles
23652365
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jdoubleArray arr, jint off, jint n)
23662366
{
23672367
PSTART();
@@ -2371,10 +2371,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3
23712371

23722372
/*
23732373
* Class: com_sun_jna_Native
2374-
* Method: write
2374+
* Method: writeFloats
23752375
* Signature: (Lcom/sun/jna/Pointer;JJ[FII)V
23762376
*/
2377-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3FII
2377+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_writeFloats
23782378
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jfloatArray arr, jint off, jint n)
23792379
{
23802380
PSTART();
@@ -2384,10 +2384,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3
23842384

23852385
/*
23862386
* Class: com_sun_jna_Native
2387-
* Method: write
2387+
* Method: writeInts
23882388
* Signature: (Lcom/sun/jna/Pointer;JJ[III)V
23892389
*/
2390-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3III
2390+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_writeInts
23912391
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jintArray arr, jint off, jint n)
23922392
{
23932393
PSTART();
@@ -2397,10 +2397,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3
23972397

23982398
/*
23992399
* Class: com_sun_jna_Native
2400-
* Method: write
2400+
* Method: writeLongs
24012401
* Signature: (Lcom/sun/jna/Pointer;JJ[JII)V
24022402
*/
2403-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3JII
2403+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_writeLongs
24042404
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlongArray arr, jint off, jint n)
24052405
{
24062406
PSTART();
@@ -2410,10 +2410,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3
24102410

24112411
/*
24122412
* Class: com_sun_jna_Native
2413-
* Method: write
2413+
* Method: writeShorts
24142414
* Signature: (Lcom/sun/jna/Pointer;JJ[SII)V
24152415
*/
2416-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3SII
2416+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_writeShorts
24172417
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jshortArray arr, jint off, jint n)
24182418
{
24192419
PSTART();
@@ -2445,10 +2445,10 @@ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native_indexOf
24452445

24462446
/*
24472447
* Class: com_sun_jna_Native
2448-
* Method: read
2448+
* Method: readBytes
24492449
* Signature: (Lcom/sun/jna/Pointer;JJ[BII)V
24502450
*/
2451-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3BII
2451+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_readBytes
24522452
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jbyteArray arr, jint off, jint n)
24532453
{
24542454
PSTART();
@@ -2458,21 +2458,21 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3B
24582458

24592459
/*
24602460
* Class: com_sun_jna_Native
2461-
* Method: read
2461+
* Method: readChars
24622462
* Signature: (Lcom/sun/jna/Pointer;JJ[CII)V
24632463
*/
2464-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3CII
2464+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_readChars
24652465
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jcharArray arr, jint off, jint n)
24662466
{
24672467
setChars(env, (wchar_t*)L2A(addr + offset), arr, off, n);
24682468
}
24692469

24702470
/*
24712471
* Class: com_sun_jna_Native
2472-
* Method: read
2472+
* Method: readDoubles
24732473
* Signature: (Lcom/sun/jna/Pointer;JJ[DII)V
24742474
*/
2475-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3DII
2475+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_readDoubles
24762476
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jdoubleArray arr, jint off, jint n)
24772477
{
24782478
PSTART();
@@ -2482,10 +2482,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3D
24822482

24832483
/*
24842484
* Class: com_sun_jna_Native
2485-
* Method: read
2485+
* Method: readFloats
24862486
* Signature: (Lcom/sun/jna/Pointer;JJ[FII)V
24872487
*/
2488-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3FII
2488+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_readFloats
24892489
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jfloatArray arr, jint off, jint n)
24902490
{
24912491
PSTART();
@@ -2495,10 +2495,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3F
24952495

24962496
/*
24972497
* Class: com_sun_jna_Native
2498-
* Method: read
2498+
* Method: readInts
24992499
* Signature: (Lcom/sun/jna/Pointer;JJ[III)V
25002500
*/
2501-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3III
2501+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_readInts
25022502
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jintArray arr, jint off, jint n)
25032503
{
25042504
PSTART();
@@ -2508,10 +2508,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3I
25082508

25092509
/*
25102510
* Class: com_sun_jna_Native
2511-
* Method: read
2511+
* Method: readLongs
25122512
* Signature: (Lcom/sun/jna/Pointer;JJ[JII)V
25132513
*/
2514-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3JII
2514+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_readLongs
25152515
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlongArray arr, jint off, jint n)
25162516
{
25172517
PSTART();
@@ -2521,10 +2521,10 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3J
25212521

25222522
/*
25232523
* Class: com_sun_jna_Native
2524-
* Method: read
2524+
* Method: readShorts
25252525
* Signature: (Lcom/sun/jna/Pointer;JJ[SII)V
25262526
*/
2527-
JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3SII
2527+
JNIEXPORT void JNICALL Java_com_sun_jna_Native_readShorts
25282528
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jshortArray arr, jint off, jint n)
25292529
{
25302530
PSTART();
@@ -2576,7 +2576,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native__1getPointer
25762576
* Method: getDirectByteBuffer
25772577
* Signature: (Lcom/sun/jna/Pointer;JJJ)Ljava/nio/ByteBuffer;
25782578
*/
2579-
JNIEXPORT jobject JNICALL Java_com_sun_jna_Native_getDirectByteBuffer__Lcom_sun_jna_Pointer_2JJJ
2579+
JNIEXPORT jobject JNICALL Java_com_sun_jna_Native_getDirectByteBuffer
25802580
(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlong length)
25812581
{
25822582
#ifdef NO_NIO_BUFFERS

src/com/sun/jna/Native.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -2229,33 +2229,33 @@ static long open(String name) {
22292229
*/
22302230
static native long indexOf(Pointer pointer, long baseaddr, long offset, byte value);
22312231

2232-
static native void read(Pointer pointer, long baseaddr, long offset, byte[] buf, int index, int length);
2232+
static native void readBytes(Pointer pointer, long baseaddr, long offset, byte[] buf, int index, int length);
22332233

2234-
static native void read(Pointer pointer, long baseaddr, long offset, short[] buf, int index, int length);
2234+
static native void readShorts(Pointer pointer, long baseaddr, long offset, short[] buf, int index, int length);
22352235

2236-
static native void read(Pointer pointer, long baseaddr, long offset, char[] buf, int index, int length);
2236+
static native void readChars(Pointer pointer, long baseaddr, long offset, char[] buf, int index, int length);
22372237

2238-
static native void read(Pointer pointer, long baseaddr, long offset, int[] buf, int index, int length);
2238+
static native void readInts(Pointer pointer, long baseaddr, long offset, int[] buf, int index, int length);
22392239

2240-
static native void read(Pointer pointer, long baseaddr, long offset, long[] buf, int index, int length);
2240+
static native void readLongs(Pointer pointer, long baseaddr, long offset, long[] buf, int index, int length);
22412241

2242-
static native void read(Pointer pointer, long baseaddr, long offset, float[] buf, int index, int length);
2242+
static native void readFloats(Pointer pointer, long baseaddr, long offset, float[] buf, int index, int length);
22432243

2244-
static native void read(Pointer pointer, long baseaddr, long offset, double[] buf, int index, int length);
2244+
static native void readDoubles(Pointer pointer, long baseaddr, long offset, double[] buf, int index, int length);
22452245

2246-
static native void write(Pointer pointer, long baseaddr, long offset, byte[] buf, int index, int length);
2246+
static native void writeBytes(Pointer pointer, long baseaddr, long offset, byte[] buf, int index, int length);
22472247

2248-
static native void write(Pointer pointer, long baseaddr, long offset, short[] buf, int index, int length);
2248+
static native void writeShorts(Pointer pointer, long baseaddr, long offset, short[] buf, int index, int length);
22492249

2250-
static native void write(Pointer pointer, long baseaddr, long offset, char[] buf, int index, int length);
2250+
static native void writeChars(Pointer pointer, long baseaddr, long offset, char[] buf, int index, int length);
22512251

2252-
static native void write(Pointer pointer, long baseaddr, long offset, int[] buf, int index, int length);
2252+
static native void writeInts(Pointer pointer, long baseaddr, long offset, int[] buf, int index, int length);
22532253

2254-
static native void write(Pointer pointer, long baseaddr, long offset, long[] buf, int index, int length);
2254+
static native void writeLongs(Pointer pointer, long baseaddr, long offset, long[] buf, int index, int length);
22552255

2256-
static native void write(Pointer pointer, long baseaddr, long offset, float[] buf, int index, int length);
2256+
static native void writeFloats(Pointer pointer, long baseaddr, long offset, float[] buf, int index, int length);
22572257

2258-
static native void write(Pointer pointer, long baseaddr, long offset, double[] buf, int index, int length);
2258+
static native void writeDoubles(Pointer pointer, long baseaddr, long offset, double[] buf, int index, int length);
22592259

22602260
static native byte getByte(Pointer pointer, long baseaddr, long offset);
22612261

src/com/sun/jna/Pointer.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public long indexOf(long offset, byte value) {
137137
* @param length number of elements from native pointer that must be copied
138138
*/
139139
public void read(long offset, byte[] buf, int index, int length) {
140-
Native.read(this, this.peer, offset, buf, index, length);
140+
Native.readBytes(this, this.peer, offset, buf, index, length);
141141
}
142142

143143
/**
@@ -150,7 +150,7 @@ public void read(long offset, byte[] buf, int index, int length) {
150150
* @param length number of elements from native pointer that must be copied
151151
*/
152152
public void read(long offset, short[] buf, int index, int length) {
153-
Native.read(this, this.peer, offset, buf, index, length);
153+
Native.readShorts(this, this.peer, offset, buf, index, length);
154154
}
155155

156156
/**
@@ -163,7 +163,7 @@ public void read(long offset, short[] buf, int index, int length) {
163163
* @param length number of elements from native pointer that must be copied
164164
*/
165165
public void read(long offset, char[] buf, int index, int length) {
166-
Native.read(this, this.peer, offset, buf, index, length);
166+
Native.readChars(this, this.peer, offset, buf, index, length);
167167
}
168168

169169
/**
@@ -176,7 +176,7 @@ public void read(long offset, char[] buf, int index, int length) {
176176
* @param length number of elements from native pointer that must be copied
177177
*/
178178
public void read(long offset, int[] buf, int index, int length) {
179-
Native.read(this, this.peer, offset, buf, index, length);
179+
Native.readInts(this, this.peer, offset, buf, index, length);
180180
}
181181

182182
/**
@@ -189,7 +189,7 @@ public void read(long offset, int[] buf, int index, int length) {
189189
* @param length number of elements from native pointer that must be copied
190190
*/
191191
public void read(long offset, long[] buf, int index, int length) {
192-
Native.read(this, this.peer, offset, buf, index, length);
192+
Native.readLongs(this, this.peer, offset, buf, index, length);
193193
}
194194

195195
/**
@@ -202,7 +202,7 @@ public void read(long offset, long[] buf, int index, int length) {
202202
* @param length number of elements from native pointer that must be copied
203203
*/
204204
public void read(long offset, float[] buf, int index, int length) {
205-
Native.read(this, this.peer, offset, buf, index, length);
205+
Native.readFloats(this, this.peer, offset, buf, index, length);
206206
}
207207

208208
/**
@@ -215,7 +215,7 @@ public void read(long offset, float[] buf, int index, int length) {
215215
* @param length number of elements from native pointer that must be copied
216216
*/
217217
public void read(long offset, double[] buf, int index, int length) {
218-
Native.read(this, this.peer, offset, buf, index, length);
218+
Native.readDoubles(this, this.peer, offset, buf, index, length);
219219
}
220220

221221
/**
@@ -254,7 +254,7 @@ public void read(long offset, Pointer[] buf, int index, int length) {
254254
* copied
255255
*/
256256
public void write(long offset, byte[] buf, int index, int length) {
257-
Native.write(this, this.peer, offset, buf, index, length);
257+
Native.writeBytes(this, this.peer, offset, buf, index, length);
258258
}
259259

260260
/**
@@ -268,7 +268,7 @@ public void write(long offset, byte[] buf, int index, int length) {
268268
* copied
269269
*/
270270
public void write(long offset, short[] buf, int index, int length) {
271-
Native.write(this, this.peer, offset, buf, index, length);
271+
Native.writeShorts(this, this.peer, offset, buf, index, length);
272272
}
273273

274274
/**
@@ -282,7 +282,7 @@ public void write(long offset, short[] buf, int index, int length) {
282282
* copied
283283
*/
284284
public void write(long offset, char[] buf, int index, int length) {
285-
Native.write(this, this.peer, offset, buf, index, length);
285+
Native.writeChars(this, this.peer, offset, buf, index, length);
286286
}
287287

288288
/**
@@ -296,7 +296,7 @@ public void write(long offset, char[] buf, int index, int length) {
296296
* copied
297297
*/
298298
public void write(long offset, int[] buf, int index, int length) {
299-
Native.write(this, this.peer, offset, buf, index, length);
299+
Native.writeInts(this, this.peer, offset, buf, index, length);
300300
}
301301

302302
/**
@@ -310,7 +310,7 @@ public void write(long offset, int[] buf, int index, int length) {
310310
* copied
311311
*/
312312
public void write(long offset, long[] buf, int index, int length) {
313-
Native.write(this, this.peer, offset, buf, index, length);
313+
Native.writeLongs(this, this.peer, offset, buf, index, length);
314314
}
315315

316316
/**
@@ -324,7 +324,7 @@ public void write(long offset, long[] buf, int index, int length) {
324324
* copied
325325
*/
326326
public void write(long offset, float[] buf, int index, int length) {
327-
Native.write(this, this.peer, offset, buf, index, length);
327+
Native.writeFloats(this, this.peer, offset, buf, index, length);
328328
}
329329

330330
/**
@@ -338,7 +338,7 @@ public void write(long offset, float[] buf, int index, int length) {
338338
* copied
339339
*/
340340
public void write(long offset, double[] buf, int index, int length) {
341-
Native.write(this, this.peer, offset, buf, index, length);
341+
Native.writeDoubles(this, this.peer, offset, buf, index, length);
342342
}
343343

344344
/** Write the given array of Pointer to native memory.

0 commit comments

Comments
 (0)