java-native-access / java-native-access/jna

Warnings reported with -Xcheck:jni when using Memory class

Open
#1,262 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
8.9k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

To reproduce, run the following snippet with -Xcheck:jni VM argument (I'm running with OpenJDK 11.0.8):

import com.sun.jna.Memory;

public class Test {

	public static void main(String[] args) {
		Memory m = new Memory(1024L);
		System.out.println(m);
	}

}

Observe output:

Warning: SIGINT handler expected:libjvm.so+0xc14f00  found:0x0000000000000001
Running in non-interactive shell, SIGINT handler is replaced by shell
Signal Handlers:
SIGSEGV: [libjvm.so+0xc14d00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGBUS: [libjvm.so+0xc14d00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGFPE: [libjvm.so+0xc14d00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGPIPE: [libjvm.so+0xc14d00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGXFSZ: [libjvm.so+0xc14d00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGILL: [libjvm.so+0xc14d00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGUSR2: [libjvm.so+0xc14b80], sa_mask[0]=00100000000000000000000000000000, sa_flags=SA_RESTART|SA_SIGINFO
SIGHUP: [libjvm.so+0xc14f00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGINT: SIG_IGN, sa_mask[0]=00000000000000000000000000000000, sa_flags=none
SIGTERM: [libjvm.so+0xc14f00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGQUIT: [libjvm.so+0xc14f00], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
WARNING: JNI local refs: 33, exceeds capacity: 32
	at java.lang.ClassLoader$NativeLibrary.load0(java.base@11.0.8/Native Method)
	at java.lang.ClassLoader$NativeLibrary.load(java.base@11.0.8/ClassLoader.java:2442)
	at java.lang.ClassLoader$NativeLibrary.loadLibrary(java.base@11.0.8/ClassLoader.java:2498)
	- locked <0x00000000ff401e20> (a java.util.HashSet)
	at java.lang.ClassLoader.loadLibrary0(java.base@11.0.8/ClassLoader.java:2694)
	at java.lang.ClassLoader.loadLibrary(java.base@11.0.8/ClassLoader.java:2627)
	at java.lang.Runtime.load0(java.base@11.0.8/Runtime.java:768)
	at java.lang.System.load(java.base@11.0.8/System.java:1837)
	at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1018)
	at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:988)
	at com.sun.jna.Native.<clinit>(Native.java:195)
	at com.sun.jna.Memory.malloc(Memory.java:722)
	at com.sun.jna.Memory.<init>(Memory.java:114)
	at test.Test.main(Test.java:9)
WARNING in native method: JNI call made without checking exceptions when required to from CallStaticObjectMethod
	at java.lang.ClassLoader$NativeLibrary.load0(java.base@11.0.8/Native Method)
	at java.lang.ClassLoader$NativeLibrary.load(java.base@11.0.8/ClassLoader.java:2442)
	at java.lang.ClassLoader$NativeLibrary.loadLibrary(java.base@11.0.8/ClassLoader.java:2498)
	- locked <0x00000000ff401e20> (a java.util.HashSet)
	at java.lang.ClassLoader.loadLibrary0(java.base@11.0.8/ClassLoader.java:2694)
	at java.lang.ClassLoader.loadLibrary(java.base@11.0.8/ClassLoader.java:2627)
	at java.lang.Runtime.load0(java.base@11.0.8/Runtime.java:768)
	at java.lang.System.load(java.base@11.0.8/System.java:1837)
	at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1018)
	at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:988)
	at com.sun.jna.Native.<clinit>(Native.java:195)
	at com.sun.jna.Memory.malloc(Memory.java:722)
	at com.sun.jna.Memory.<init>(Memory.java:114)
	at test.Test.main(Test.java:9)
allocated@0x7ffff0510730 (1024 bytes)

Seen with jna-5.6.0.jar (latest I could find from maven: https://mvnrepository.com/artifact/net.java.dev.jna/jna).

Background:

We observe those warnings in our Eclipse based product (when checking for JNI problems with -Xcheck:jni), coming from SVN plug-ins:

WARNING in native method: JNI call made without checking exceptions when required to from CallStaticObjectMethod
	at java.lang.ClassLoader$NativeLibrary.load0(java.base@11.0.8/Native Method)
	at java.lang.ClassLoader$NativeLibrary.load(java.base@11.0.8/ClassLoader.java:2442)
	at java.lang.ClassLoader$NativeLibrary.loadLibrary(java.base@11.0.8/ClassLoader.java:2498)
	- locked <0x00000005007d6730> (a java.util.HashSet)
	at java.lang.ClassLoader.loadLibrary0(java.base@11.0.8/ClassLoader.java:2694)
	at java.lang.ClassLoader.loadLibrary(java.base@11.0.8/ClassLoader.java:2627)
	at java.lang.Runtime.load0(java.base@11.0.8/Runtime.java:768)
	at java.lang.System.load(java.base@11.0.8/System.java:1837)
	at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:761)
	at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:736)
	at com.sun.jna.Native.<clinit>(Native.java:131)
	at com.sun.jna.Pointer.<clinit>(Pointer.java:41)
	at org.tmatesoft.svn.core.internal.util.jna.SVNLinuxUtil.<clinit>(SVNLinuxUtil.java:33)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the supplied Java snippet, OpenJDK 11.0.8, JNA 5.6.0, and -Xcheck:jni. Start by tracing Native.loadNativeDispatchLibraryFromClasspath and Memory.malloc in Native.java and Memory.java; done means determining whether the reported JNI warnings can be eliminated and covering the result with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.