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

Many quantities are held as signed that should be unsigned



    • gc
    • b21
    • generic
    • generic


      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.


        Issue Links



              stefank Stefan Karlsson
              pbk Peter Kessler
              0 Vote for this issue
              7 Start watching this issue