code: private Object getMemory(String label, Object array, Class<?> arrayClass,
              boolean mayAllocate, int sizeNeeded)
      {
          int len = Array.getLength(array);
  
          /* we have at least enough memory and must not allocate */
          if (sizeNeeded == len) {
              return array;
          }
          if (!mayAllocate) {
              /* we must not allocate */
              if (sizeNeeded <= len) {
                  return array;
              }
              throw new OutOfMemoryError("Failed to allocate memory for "
                                         + label);
          }
          /* we may try to grow or shrink */
          /* FOOD FOR THOUGHT: when shrinking it should be possible to avoid
             the allocation altogether and rely on this.length */
          try {
              return Array.newInstance(arrayClass, sizeNeeded);
          } catch (Exception e) {
              throw new OutOfMemoryError("Failed to allocate memory for "
                                         + label);
          }
      }
docs: /*
  We are allowed to allocate memory if object==null or
  mayAllocate==true for each array that we need.
  
  Assume sizeNeeded>0.
  If object != null, then assume size > 0.