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

HashMap arrays should be lazily allocated

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs

      According to JDK-8003585, we can strength-reduce the array range check in HashMap.getEntry to a simple check whether table.length is zero or not.

      A side effect of this is that an explicit zero check in this place has no additional cost, since it is done implicitly. Therefore code to lazily create tables has little or no downside, if the "lazy" state is a zero-length table.

      This is better than using a null pointer as a sentinel for an unallocated table, because it does not force the compiler to deal with the null case.

      (The compiler prefers to use "implicit" null checks, which are a side effect of taking a SEGV trap when loading through an address that is assumed to be non-null.)

            Unassigned Unassigned
            jrose John Rose
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: