JDK-8221119 : PlainDatagramSocketImpl.c: createBoolean need not create new instances.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8,11,17
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2019-03-19
  • Updated: 2022-05-30
Related Reports
Relates :  
Description
At http://hg.openjdk.java.net/jdk/jdk/file/ddfb658c8ce3/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c#l105, `createBoolean(JNIEnv * env, int b)` creates a new `Boolean` each time it is called, though it can only return `Boolean.FALSE` or `Boolean.TRUE`.  

Rather than allocating (and requiring the collection of) a new instance from each call, it could call `Boolean.valueOf(b != 0)`.

The same might be true for the corresponding `createInteger` function, though I do not know the range of the `int`s that might be wrapped.  But that choice should be left to `Integer.valueOf(int)`.

The same inefficiencies exist over in http://hg.openjdk.java.net/jdk/jdk/file/ddfb658c8ce3/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c#l94.  And it might exist elsewhere.