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

Many quantities are held as signed that should be unsigned

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: hs23, 18
    • Fix Version/s: 18
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
      gc
    • Resolved In Build:
      b21
    • CPU:
      generic
    • OS:
      generic

      Description

      Many quantities are kept as signed quantities that should be unsigned.
      Consider oopDesc::size() which returns an int. Since the size can never
      be negative, we could extend the range of the result. In fact, we should
      make these quantities size_t, so that on LP64 machines they expand with
      the address space. What's the size of long[Integer.MAX_VALUE]? Much
      bigger than will fit in a int!

      There are probably hundreds of these.

      There are places where we've started the conversion, and at the transitions
      from signed to unsigned there are sometimes asserts that the quantities are
      >= 0 -- since otherwise they won't convert well to unsigned. We can clean
      up all those asserts when we have uniformly converted to unsigned.

      Paul Hohensee points out that

        // Returns the actual oop size of the object
        inline int oopDesc::size();

      actually returns the size in HeapWords, not in oops. Actually it uses
      wordSize, not HeapWordSize.

      I just noticed

          inline intx byte_size(void* from, void* to) {
            return (address)to - (address)from;
          }

      which only works as well as it does because it casts the arguments
      to u_char*, and I guess sizeof(u_char) is 1, so the signed divide
      by the size of the elements computes the right representation, if
      not the right type. But then the return type is intx, rather than
      uintx (or size_t), so we lose (except for the representation) if
      the answer is more than intx.MAX_VALUE.

      Also, VirtualSpace::committed_size() and friends say they return
      size_t's but they also only compute the right representation because
      they use naked pointer subtraction.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              stefank Stefan Karlsson
              Reporter:
              pbk Peter Kessler
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: