public static void clearObjectArray(Object[] objects, int start, int size) {
    if (size < COPY_THRESHOLD) {
      Arrays.fill(objects, start, start + size, null);
    } else {
      if (size < NIL_ARRAY_SIZE) {
        System.arraycopy(NIL_ARRAY, 0, objects, start, size);
      } else {
        while (size > NIL_ARRAY_SIZE) {
          System.arraycopy(NIL_ARRAY, 0, objects, start, NIL_ARRAY_SIZE);
          size -= NIL_ARRAY_SIZE;
          start += NIL_ARRAY_SIZE;
        }
        System.arraycopy(NIL_ARRAY, 0, objects, start, size);
      }
    }
  }
@Test
  public void testClearObjectArray() {
    int[] numObjs = new int[] {100, 500, 1000, 5000, 10000, 100000, 1000000};
    for (int numObj : numObjs) {
      Object[] array = new Object[numObj];
      Object o = new Object();
      for (int i = 0; i < numObj; i++) {
        array[i] = o;
      }
      ObjectArray.clearObjectArray(array, 0, array.length);
      for (int i = 0; i < array.length; i++) {
        Object value = array[i];
        if (value != null) {
          throw new IllegalStateException(String.format("numObj: %d, index: %d", numObj, i));
        }
      }
      for (int i = 0; i < numObj; i++) {
        array[i] = o;
      }
      ObjectArray.clearObjectArray(array, 1, array.length - 1);
      for (int i = 1; i < array.length; i++) {
        Object value = array[i];
        if (value != null) {
          throw new IllegalStateException(String.format("numObj: %d, index: %d", numObj, i));
        }
      }
    }
  }