JDK-8261719 : NetworkInterface.getAll() exceeds jni localref capacity when using -Xcheck:jni
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 17
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2021-02-14
  • Updated: 2022-09-21
  • Resolved: 2021-04-12
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
I noticed this when I ran  the test/jdk/sun/tools/jhsdb tests with -Xcheck:jni. In some of the logs you see the warning below.  test/jdk/sun/tools/jhsdb/HeapDumpTest.java is one test where I saw this.

WARNING: JNI local refs: 33, exceeds capacity: 32
	at java.net.NetworkInterface.getAll(java.base@17-internal/Native Method)
	at java.net.NetworkInterface.getNetworkInterfaces(java.base@17-internal/NetworkInterface.java:351)
	at sun.security.provider.SeedGenerator.addNetworkAdapterInfo(java.base@17-internal/SeedGenerator.java:229)
	at sun.security.provider.SeedGenerator$1.run(java.base@17-internal/SeedGenerator.java:179)
	at sun.security.provider.SeedGenerator$1.run(java.base@17-internal/SeedGenerator.java:167)
	at java.security.AccessController.executePrivileged(java.base@17-internal/AccessController.java:753)
	at java.security.AccessController.doPrivileged(java.base@17-internal/AccessController.java:312)
	at sun.security.provider.SeedGenerator.getSystemEntropy(java.base@17-internal/SeedGenerator.java:167)
	at sun.security.provider.AbstractDrbg$SeederHolder.<clinit>(java.base@17-internal/AbstractDrbg.java:551)
	at sun.security.provider.AbstractDrbg.getEntropyInput(java.base@17-internal/AbstractDrbg.java:505)
	at sun.security.provider.AbstractDrbg.getEntropyInput(java.base@17-internal/AbstractDrbg.java:494)
	at sun.security.provider.AbstractDrbg.instantiateIfNecessary(java.base@17-internal/AbstractDrbg.java:696)
	- locked <0x00000000ffc9e380> (a sun.security.provider.HashDrbg)
	at sun.security.provider.AbstractDrbg.engineNextBytes(java.base@17-internal/AbstractDrbg.java:378)
	at sun.security.provider.AbstractDrbg.engineNextBytes(java.base@17-internal/AbstractDrbg.java:334)
	at sun.security.provider.DRBG.engineNextBytes(java.base@17-internal/DRBG.java:234)
	at java.security.SecureRandom.nextBytes(java.base@17-internal/SecureRandom.java:751)
	at java.util.UUID.randomUUID(java.base@17-internal/UUID.java:151)
	at jdk.test.lib.apps.LingeredApp.<init>(LingeredApp.java:111)
	at LingeredAppWithExtendedChars.<init>(LingeredAppWithExtendedChars.java:25)
	at HeapDumpTest.launch(HeapDumpTest.java:63)
	at HeapDumpTest.launch(HeapDumpTest.java:97)
	at HeapDumpTest.testHeapDump(HeapDumpTest.java:118)
	at HeapDumpTest.main(HeapDumpTest.java:131)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@17-internal/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@17-internal/NativeMethodAccessorImpl.java:78)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@17-internal/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@17-internal/Method.java:566)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
	at java.lang.Thread.run(java.base@17-internal/Thread.java:831)
Comments
JDK-8263818 and JDK-8187450 resolve this issue. Closing as duplicate.
12-04-2021

The following code in NetworkInterface.getAll() seems to be the culprit. while (curr != NULL) { jobject netifObj; netifObj = createNetworkInterface(env, curr, -1, NULL); if (netifObj == NULL) { free_netif(ifList); return NULL; } /* put the NetworkInterface into the array */ (*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj); curr = curr->next; } A DeleteLocalRef(netifObj) is needed on each iteration of the loop. The same code exists for both windows and unix versions of the file, but the problem only turned up on windows, so there must be a lot more interfaces to deal with, or at least on the particular host I was using.
15-02-2021