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:org.agiso.core.lang.util.ObjectUtils.java

/**
 * Metoda generujca reprezentacj acuchow obiektu. Przeglda wszystkie
 * pola obiektu i pobiera ich reprezentacj acuchow. Na tej podstawie
 * generuje acuch wynikowy./*from w  ww  .jav a 2s. co  m*/
 * 
 * @param clazz
 * @param object
 */
private static void toStringObject(Class<?> clazz, Object object) {
    StringBuffer buffer = (StringBuffer) ThreadUtils.getAttribute(TOSTRING_TCBUFF);

    String hexHash = Integer.toHexString(System.identityHashCode(object));
    if (0 == buffer.length()) {
        buffer.append(clazz.getSimpleName()).append('@').append(hexHash).append(TOSTRING_PREFIX);
    }

    @SuppressWarnings("unchecked")
    Set<String> converted = (Set<String>) ThreadUtils.getAttribute(TOSTRING_TCATTR);
    converted.add(object.getClass().getCanonicalName() + "@" + hexHash);

    // Rekurencyjne przegldanie wszystkich klas nadrzdnych:
    Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        toStringObject(superClass, object);
    }

    String hyphen = "";
    if (TOSTRING_PREFIX.charAt(0) != buffer.charAt(buffer.length() - 1)) {
        hyphen = TOSTRING_HYPHEN;
    }

    for (Field field : clazz.getDeclaredFields()) {
        try {
            field.setAccessible(true);
            if (field.isAnnotationPresent(InToString.class)) {
                InToString inToString = field.getAnnotation(InToString.class);
                if (!inToString.ignore()) {
                    String name = inToString.name();
                    buffer.append(hyphen).append((name.length() > 0) ? name : field.getName())
                            .append(TOSTRING_COLON);
                    toStringField(field.get(object));
                    hyphen = TOSTRING_HYPHEN;
                }
            } else if ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0) {
                buffer.append(hyphen).append(field.getName()).append(TOSTRING_COLON);
                toStringField(field.get(object));
                hyphen = TOSTRING_HYPHEN;
            }
        } catch (Exception e) {
            // TODO: Zaimplementowa logowanie wyjtku
            e.printStackTrace();
        }
    }
}

From source file:org.apache.openjpa.enhance.PCDataGenerator.java

/**
 * Creates a unique name for the given type's pcdata implementation.
 *//* w  w  w.  ja  v  a  2s  .  c o  m*/
protected String getUniqueName(Class<?> type) {
    return type.getName() + "$" + System.identityHashCode(type) + POSTFIX;
}

From source file:org.impalaframework.classloader.BaseURLClassLoader.java

private void debug(String message) {
    logger.debug(this.getClass().getSimpleName() + "[" + System.identityHashCode(this) + "]: " + message);
}

From source file:fr.univnantes.lina.UIMAProfiler.java

private String getClassTaskId(Object o, String taskName) {
    return System.identityHashCode(o) + ":" + taskName;
}

From source file:com.jaspersoft.jasperserver.war.util.LRUSessionObjectAccessor.java

protected String createName(Object object) {
    return System.identityHashCode(object) + "_" + System.currentTimeMillis() + "_"
            + idCounter.getAndIncrement();
}

From source file:org.myrian.persistence.oql.Generator.java

void hash(ObjectMap map) {
    appendHash("m");
    appendHash(Integer.toString(System.identityHashCode(map.getRoot())));
    terminal();//from   ww  w  .  j  a va 2s  . c om
    appendHash(Integer.toString(System.identityHashCode(map)));
    terminal();
}

From source file:IdentityIntMap.java

/**
 * Deletes the entry.  Returns true if successful.
 *///from w  w  w  .  ja  va2s . c  om
public int remove(Object key) {
    int mask = _mask;
    int hash = System.identityHashCode(key) % mask & mask;

    while (true) {
        Object mapKey = _keys[hash];

        if (mapKey == null)
            return NULL;
        else if (mapKey == key) {
            _keys[hash] = DELETED;

            _size--;

            return _values[hash];
        }

        hash = (hash + 1) % mask;
    }
}

From source file:org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor.java

@Override
public void run() {
    long startTimeMs = 0;
    Thread.currentThread().setName("CacheReplicationMonitor(" + System.identityHashCode(this) + ")");
    LOG.info("Starting CacheReplicationMonitor with interval " + intervalMs + " milliseconds");
    try {//from  w w w. j  a va2  s.  c o  m
        long curTimeMs = Time.monotonicNow();
        while (true) {
            lock.lock();
            try {
                while (true) {
                    if (shutdown) {
                        LOG.info("Shutting down CacheReplicationMonitor");
                        return;
                    }
                    if (needsRescan) {
                        LOG.info("Rescanning because of pending operations");
                        break;
                    }
                    long delta = (startTimeMs + intervalMs) - curTimeMs;
                    if (delta <= 0) {
                        LOG.info("Rescanning after " + (curTimeMs - startTimeMs) + " milliseconds");
                        break;
                    }
                    doRescan.await(delta, TimeUnit.MILLISECONDS);
                    curTimeMs = Time.monotonicNow();
                }
                isScanning = true;
                needsRescan = false;
            } finally {
                lock.unlock();
            }
            startTimeMs = curTimeMs;
            mark = !mark;
            rescan();
            curTimeMs = Time.monotonicNow();
            // Update synchronization-related variables.
            lock.lock();
            try {
                isScanning = false;
                scanCount++;
                scanFinished.signalAll();
            } finally {
                lock.unlock();
            }
            LOG.info("Scanned " + scannedDirectives + " directive(s) and " + scannedBlocks + " block(s) in "
                    + (curTimeMs - startTimeMs) + " " + "millisecond(s).");
        }
    } catch (InterruptedException e) {
        LOG.info("Shutting down CacheReplicationMonitor.");
        return;
    } catch (Throwable t) {
        LOG.fatal("Thread exiting", t);
        terminate(1, t);
    }
}

From source file:edu.wisc.my.portlets.bookmarks.domain.Folder.java

/**
 * @see java.lang.Object#hashCode()//  w w  w. java  2  s  .  co  m
 */
public int hashCode() {
    final Set<Integer> visited = hashCodeVisitedFolder.getSet();
    final int identityHash = System.identityHashCode(this);
    try {
        if (!visited.add(identityHash)) {
            visited.clear();
            throw new IllegalStateException("A loop exists in the Folder tree.");
        }

        return new HashCodeBuilder(-409984457, 961354191).appendSuper(super.hashCode()).append(this.children)
                .append(this.minimized).toHashCode();
    } finally {
        visited.remove(identityHash);
    }
}

From source file:org.cloudfoundry.identity.uaa.login.saml.ZoneAwareMetadataManager.java

protected String getThreadNameAndId() {
    return Thread.currentThread().getName() + "-" + System.identityHashCode(Thread.currentThread());
}