Example usage for java.lang System identityHashCode

List of usage examples for java.lang System identityHashCode

Introduction

In this page you can find the example usage for java.lang System identityHashCode.

Prototype

@HotSpotIntrinsicCandidate
public static native int identityHashCode(Object x);

Source Link

Document

Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode().

Usage

From source file:com.metaparadigm.jsonrpc.BeanSerializer.java

public Object marshall(SerializerState state, Object o) throws MarshallException {
    BeanSerializerState beanState;//from ww w  .  j a  va2s  . com
    try {
        beanState = (BeanSerializerState) state.get(BeanSerializerState.class);
    } catch (Exception e) {
        throw new MarshallException("bean serializer internal error");
    }
    Integer identity = new Integer(System.identityHashCode(o));
    if (beanState.beanSet.contains(identity))
        throw new MarshallException("circular reference");
    beanState.beanSet.add(identity);

    BeanData bd = null;
    try {
        bd = getBeanData(o.getClass());
    } catch (IntrospectionException e) {
        throw new MarshallException(o.getClass().getName() + " is not a bean");
    }

    JSONObject val = new JSONObject();
    if (ser.getMarshallClassHints())
        try {
            val.put("javaClass", o.getClass().getName());
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    Iterator i = bd.readableProps.entrySet().iterator();
    Object args[] = new Object[0];
    Object result = null;
    while (i.hasNext()) {
        Map.Entry ent = (Map.Entry) i.next();
        String prop = (String) ent.getKey();
        Method getMethod = (Method) ent.getValue();
        if (ser.isDebug())
            log.fine("invoking " + getMethod.getName() + "()");
        try {
            result = getMethod.invoke(o, args);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException)
                e = ((InvocationTargetException) e).getTargetException();
            throw new MarshallException("bean " + o.getClass().getName() + " can't invoke "
                    + getMethod.getName() + ": " + e.getMessage());
        }
        try {
            if (result != null || ser.getMarshallNullAttributes())
                val.put(prop, ser.marshall(state, result));
        } catch (MarshallException e) {
            throw new MarshallException("bean " + o.getClass().getName() + " " + e.getMessage());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    beanState.beanSet.remove(identity);
    return val;
}

From source file:IdentityMap.java

/**
 * {@inheritDoc}/*from   w w w .  j ava2 s. c o m*/
 * @see java.util.Map#remove(java.lang.Object)
 */
public Object remove(final Object key) {
    int hash = System.identityHashCode(key);
    int index = hash % _capacity;
    if (index < 0) {
        index = -index;
    }

    Entry entry = _buckets[index];
    Entry prev = null;
    while (entry != null) {
        if (entry.getKey() == key) {
            // Found the entry.
            if (prev == null) {
                // First element in bucket matches.
                _buckets[index] = entry.getNext();
            } else {
                // Remove the entry from the chain.
                prev.setNext(entry.getNext());
            }
            _entries--;
            return entry.getValue();
        }
        prev = entry;
        entry = entry.getNext();
    }
    return null;
}

From source file:org.agiso.core.lang.util.ObjectUtils.java

/**
 * Generuje reprezentacj acuchow pola. Sprawdza, czy nie bya ona ju wczeniej
 * wyznaczana. Jeli tak, tworzy wersj skrcon reprezentacji takiego pola.
 * /*from w w w .j a  va2s.c  om*/
 * @param object
 */
private static void toStringField(Object object) {
    StringBuffer buffer = (StringBuffer) ThreadUtils.getAttribute(TOSTRING_TCBUFF);

    if (object == null) {
        buffer.append(TOSTRING_EMPTY);
    } else {
        Class<?> clazz = object.getClass();
        if (clazz.isPrimitive()) {
            buffer.append(object.toString());
        } else {
            @SuppressWarnings("unchecked")
            Set<String> converted = (Set<String>) ThreadUtils.getAttribute(TOSTRING_TCATTR);
            String hexHash = Integer.toHexString(System.identityHashCode(object));
            if (converted.contains(clazz.getCanonicalName() + "@" + hexHash)) {
                buffer.append(clazz.getSimpleName()).append('@').append(hexHash).append(TOSTRING_REPEATE);
            } else {
                buffer.append(object.toString());
            }
        }
    }
}

From source file:org.betaconceptframework.astroboa.cache.DefinitionCacheManager.java

private void printPropertyDefinitions(Map<String, CmsPropertyDefinition> cmsPropertyDefinitions, int depth,
        StringBuilder sb) {/*from www .ja v a 2 s .c  o m*/

    String tabs = generateTabs(depth);

    if (MapUtils.isNotEmpty(cmsPropertyDefinitions)) {
        for (CmsPropertyDefinition def : cmsPropertyDefinitions.values()) {

            sb.append(tabs).append(def.getName()).append(", instance ").append(System.identityHashCode(def));

            if (def instanceof ContentObjectTypeDefinition) {
                printPropertyDefinitions(((ContentObjectTypeDefinition) def).getPropertyDefinitions(),
                        depth + 1, sb);
            } else if (def instanceof ComplexCmsPropertyDefinition) {
                if (def.getName().equals(def.getParentDefinition().getName())) {
                    //Child definition is the same. Detected a recursion
                    sb.append(tabs).append("\t Detecting recursion ");
                } else {
                    printPropertyDefinitions(
                            ((ComplexCmsPropertyDefinition) def).getChildCmsPropertyDefinitions(), depth + 1,
                            sb);
                }
            }
        }
    }

}

From source file:org.diorite.scheduler.TaskBuilder.java

/**
 * Finish and register task with given delay. <br>
 * If task is of single type, this delay will be added to task delay. <br>
 * If it is repeated type, then first run of task will be delayed by this time. <br>
 * This delay works like task delay, if task dealy is real-time, then it is also real-time.
 *
 * @param startDelay delay to first run.
 *
 * @return finished and registered diorite task.
 *//*w  w  w .  j a  v  a  2s.  c  o  m*/
public DioriteTask start(final long startDelay) {
    if (this.type == TaskType.SINGLE) {
        this.delay += startDelay;
        return Diorite.getScheduler().runTask(this, 0);
    }
    if (this.name == null) {
        this.name = this.runnable.getClass().getName() + "@" + System.identityHashCode(this.runnable);
    }
    return Diorite.getScheduler().runTask(this, startDelay);
}

From source file:org.nuclos.common2.LangUtils.java

/**
 * gets an int value that uniquely identifies the given object inside this JVM (or isolate).
 * @see System#identityHashCode//from   www . j a v  a  2  s .  c om
 * @param o
 * @return an int value containing the object id of <code>o</code>.
 */
public static int getJavaObjectId(Object o) {
    return System.identityHashCode(o);
}

From source file:brooklyn.util.internal.ssh.sshj.SshjTool.java

protected SshjTool(Builder<?, ?> builder) {
    super(builder);

    sshTries = builder.sshTries;//  w w  w .ja  v  a 2 s  .  co  m
    sshTriesTimeout = builder.sshTriesTimeout;
    backoffLimitedRetryHandler = new BackoffLimitedRetryHandler(sshTries, builder.sshRetryDelay);

    sshClientConnection = SshjClientConnection.builder().hostAndPort(HostAndPort.fromParts(host, port))
            .username(user).password(password).privateKeyPassphrase(privateKeyPassphrase)
            .privateKeyData(privateKeyData).privateKeyFile(privateKeyFile)
            .strictHostKeyChecking(strictHostKeyChecking).connectTimeout(builder.connectTimeout)
            .sessionTimeout(builder.sessionTimeout).build();

    if (LOG.isTraceEnabled())
        LOG.trace("Created SshTool {} ({})", this, System.identityHashCode(this));
}

From source file:com.cloud.utils.db.Transaction.java

public static Connection getStandaloneUsageConnection() {
    try {//from w  w  w .  ja va2  s. c o m
        Connection conn = s_usageDS.getConnection();
        if (s_connLogger.isTraceEnabled()) {
            s_connLogger.trace(
                    "Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn));
        }
        return conn;
    } catch (SQLException e) {
        s_logger.warn("Unexpected exception: ", e);
        return null;
    }
}

From source file:org.envirocar.app.application.service.DeviceInRangeService.java

@Override
public IBinder onBind(Intent intent) {
    logger.info("onBind " + getClass().getName() + "; Hash: " + System.identityHashCode(this));
    return new LocalBinder();
}

From source file:org.guzz.web.context.spring.TransactionManagerUtils.java

/**
 * Stringify the given Session for debug logging.
 * Returns output equivalent to <code>Object.toString()</code>:
 * the fully qualified class name + "@" + the identity hash code.
 * <p>The sole reason why this is necessary is because Guzz3's
 * <code>Session.toString()</code> implementation is broken (and won't be fixed):
 * it logs the toString representation of all persistent objects in the Session,
 * which might lead to ConcurrentModificationExceptions if the persistent objects
 * in turn refer to the Session (for example, for lazy loading).
 * @param session the Guzz WriteTranSession to stringify
 * @return the String representation of the given Session
 *///from  w ww. j a  v a  2  s.  co m
public static String toString(WriteTranSession session) {
    return session.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(session));
}