PlainDatagramSocketImpl.c: createBoolean need not create new instances.

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 8, 11, 17
    • Component/s: 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.

            Assignee:
            Daniel Fuchs
            Reporter:
            Peter Kessler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: