Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8221119

PlainDatagramSocketImpl.c: createBoolean need not create new instances.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 8, 11, 17
    • core-libs

      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.

            chegar Chris Hegarty
            pbk Peter Kessler
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: