function virtHashCode(obj) {
    if (obj.constructor === String) {
      var hash = 0;
      for (var i = 0; i < obj.length; ++i) {
        hash = (hash * 31 + obj.charCodeAt(i)) & 0xFFFFFFFF;
      }
      return hash;
    } else if (typeof(obj) !== "object") {
      return obj & 0xFFFFFFFF;
    } else if (obj.hashCode instanceof Function) {
      return obj.hashCode();
    } else {
      if (obj.$id === undef) {
        obj.$id = ((Math.floor(Math.random() * 0x10000) - 0x8000) << 16) | Math.floor(Math.random() * 0x10000);
      }
      return obj.$id;
    }
  }
Returns Java hashCode() result for the object. If the object has the "hashCode" function,
it preforms the call of this function. Otherwise it uses/creates the "$id" property,
which is used as the hashCode.

@param {Object} obj          The object.
@returns {int}               The object's hash code.