@Override
  public byte[] toBytes() {
    PdxReaderImpl ur = getUnmodifiableReader();
    if (ur.getPdxType().getHasDeletedField()) {
      PdxWriterImpl writer = convertToTypeWithNoDeletedFields(ur);
      return writer.toByteArray();
    } else {
      byte[] result = new byte[PdxWriterImpl.HEADER_SIZE + ur.basicSize()];
      ByteBuffer bb = ByteBuffer.wrap(result);
      bb.put(DSCODE.PDX.toByte());
      bb.putInt(ur.basicSize());
      bb.putInt(ur.getPdxType().getTypeId());
      ur.basicSendTo(bb);
      return result;
    }
  }
Computes the hash code once and stores it. This is added to address the issue of identity value
getting changed for each hash code call (as new objects instances are created in each call for
the same object). The value 0 means the hash code is not yet computed (this avoids using extra
variable for this), if the computation returns 0, it will be set to 1. This doesn't break the
equality rule, where hash code can be same for non-equal objects.
geode-core/src/main/java/org/apache/geode/pdx/internal/PdxInstanceImpl.java