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.apache.axis2.context.AbstractContext.java

/**
 * Debug for for property key and value.
 * @param key//from w  w  w . j a va2 s  . co  m
 * @param value
 */
private void debugPropertySet(String key, Object value) {
    if (DEBUG_ENABLED) {
        String className = (value == null) ? "null" : value.getClass().getName();
        String classloader = "null";
        if (value != null) {
            ClassLoader cl = Utils.getObjectClassLoader(value);
            if (cl != null) {
                classloader = cl.toString();
            }
        }
        String valueText = (value instanceof String) ? value.toString() : null;
        String identity = getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(this));

        log.debug("==================");
        log.debug(" Property set on object " + identity);
        log.debug("  Key =" + key);
        if (valueText != null) {
            log.debug("  Value =" + valueText);
        }
        log.debug("  Value Class = " + className);
        log.debug("  Value Classloader = " + classloader);
        if (this.DEBUG_CALLSTACK_ON_SET) {
            log.debug("Call Stack = " + JavaUtils.callStackToString());
        }
        log.debug("==================");
    }
}

From source file:WeakIdentityMap.java

public V remove(Object key) {
    if (key == null) {
        key = KeyFactory.NULL;/*from   w ww.  ja v  a2  s  .com*/
    }

    Entry<K, V>[] tab = this.table;
    int hash = System.identityHashCode(key);
    int index = (hash & 0x7fffffff) % tab.length;

    for (Entry<K, V> e = tab[index], prev = null; e != null; e = e.next) {
        Object entryKey = e.get();

        if (entryKey == null) {
            // Clean up after a cleared Reference.
            this.modCount++;
            if (prev != null) {
                prev.next = e.next;
            } else {
                tab[index] = e.next;
            }
            this.count--;
        } else if (e.hash == hash && key == entryKey) {
            this.modCount++;
            if (prev != null) {
                prev.next = e.next;
            } else {
                tab[index] = e.next;
            }
            this.count--;

            V oldValue = e.value;
            e.value = null;
            return oldValue;
        } else {
            prev = e;
        }
    }

    return null;
}

From source file:org.openvpms.tools.data.loader.LoadState.java

/**
 * Removes a deferred updater from the cache, and propagates the removal
 * to the parent, if present./*from w w w  . java 2 s  .  c o m*/
 *
 * @param updater the updater to remove
 */
private void removeDeferredCache(DeferredUpdater updater) {
    deferredCache.remove(System.identityHashCode(updater));
    if (parent != null) {
        parent.removeDeferredCache(updater);
    }
}

From source file:IdentityHashMap.java

/**
 * Removes the mapping for this key from this map if present.
 *
 * @param key key whose mapping is to be removed from the map.
 * @return previous value associated with specified key, or <tt>null</tt>
 *         if there was no mapping for key.  A <tt>null</tt> return can
 *         also indicate that the map previously associated <tt>null</tt>
 *         with the specified key.// w ww. ja v  a  2 s.c om
 */
public Object remove(Object key) {
    Entry tab[] = table;

    if (key != null) {
        // int hash = key.hashCode();
        int hash = System.identityHashCode(key);
        int index = (hash & 0x7FFFFFFF) % tab.length;

        for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) {
            // if ((e.hash == hash) && key.equals(e.key)) {
            if ((e.hash == hash) && (key == e.key)) {
                modCount++;
                if (prev != null)
                    prev.next = e.next;
                else
                    tab[index] = e.next;

                count--;
                Object oldValue = e.value;
                e.value = null;
                return oldValue;
            }
        }
    } else {
        for (Entry e = tab[0], prev = null; e != null; prev = e, e = e.next) {
            if (e.key == null) {
                modCount++;
                if (prev != null)
                    prev.next = e.next;
                else
                    tab[0] = e.next;

                count--;
                Object oldValue = e.value;
                e.value = null;
                return oldValue;
            }
        }
    }

    return null;
}

From source file:org.mule.transport.AbstractMessageReceiver.java

@Override
public String toString() {
    final StringBuffer sb = new StringBuffer(80);
    sb.append(ClassUtils.getSimpleName(this.getClass()));
    sb.append("{this=").append(Integer.toHexString(System.identityHashCode(this)));
    sb.append(", receiverKey=").append(receiverKey);
    sb.append(", endpoint=").append(endpoint.getEndpointURI());
    sb.append('}');
    return sb.toString();
}

From source file:org.compass.core.lucene.engine.transaction.async.AsyncTransactionProcessorFactory.java

private void process(TransactionJobs jobs) throws InterruptedException {
    Set<String> subIndexes = new HashSet<String>();
    List<TransactionJob>[] concurrentJobsToProcess = new List[concurrencyLevel];
    for (int i = 0; i < concurrentJobsToProcess.length; i++) {
        concurrentJobsToProcess[i] = new ArrayList<TransactionJob>();
    }/*  w ww  .  j ava  2s. com*/

    // build the concurrent job list of lists
    addConcurrentJobsToProcess(concurrentJobsToProcess, subIndexes, jobs);
    // spin a bit to get more possible jobs, if enabled (batchJobSize is set to higher value than 0)
    for (int i = 0; i < batchJobsSize; i++) {
        jobs = jobsToProcess.poll(batchJobTimeout, TimeUnit.MILLISECONDS);
        if (jobs == null) {
            break;
        }
        if (logger.isTraceEnabled()) {
            logger.trace("Batching additional Jobs [" + System.identityHashCode(jobs) + "]");
        }
        addConcurrentJobsToProcess(concurrentJobsToProcess, subIndexes, jobs);
    }
    // now spin non blocking
    List<TransactionJobs> nonBlockingDrainToList = new ArrayList<TransactionJobs>();
    if (jobsToProcess.drainTo(nonBlockingDrainToList, nonBlockingBatchSize) > 0) {
        for (TransactionJobs transactionJobs : nonBlockingDrainToList) {
            if (logger.isTraceEnabled()) {
                logger.trace("Batching additional Jobs [" + System.identityHashCode(transactionJobs) + "]");
            }
            addConcurrentJobsToProcess(concurrentJobsToProcess, subIndexes, transactionJobs);
        }
    }

    boolean failure = false;

    Map<String, IndexWriter> writers = new HashMap<String, IndexWriter>();
    // open index writers
    for (String subIndex : subIndexes) {
        try {
            IndexWriter writer = indexManager.getIndexWritersManager().openIndexWriter(settings, subIndex);
            indexManager.getIndexWritersManager().trackOpenIndexWriter(subIndex, writer);
            writers.put(subIndex, writer);
        } catch (Exception e) {
            logger.warn("Failed to open index writer for sub index [" + subIndex + "]", e);
            failure = true;
            break;
        }
    }
    if (failure) {
        closeWriters(writers);
        return;
    }

    // process all the jobs by multiple threads
    ArrayList<Callable<Object>> processCallables = new ArrayList<Callable<Object>>();
    for (List<TransactionJob> list : concurrentJobsToProcess) {
        if (list.isEmpty()) {
            // no need to create a thread for empty list
            continue;
        }
        processCallables.add(new TransactionalCallable(indexManager.getTransactionContext(),
                new TransactionJobProcessor(list, writers)));
    }
    try {
        indexManager.getExecutorManager().invokeAllWithLimitBailOnException(processCallables, 1);
    } catch (Exception e) {
        logger.warn("Failed to index", e);
        failure = true;
    }
    if (failure) {
        rollbackWriters(writers);
        return;
    }

    // prepare for commit
    ArrayList<Callable<Object>> prepareCallables = new ArrayList<Callable<Object>>();
    for (Map.Entry<String, IndexWriter> entry : writers.entrySet()) {
        prepareCallables.add(new TransactionalCallable(indexManager.getTransactionContext(),
                new PrepareCommitCallable(entry.getKey(), entry.getValue())));
    }
    try {
        indexManager.getExecutorManager().invokeAllWithLimitBailOnException(prepareCallables, 1);
    } catch (Exception e) {
        logger.warn("Faield to prepare commit", e);
        failure = true;
    }
    if (failure) {
        rollbackWriters(writers);
        return;
    }

    // commit
    ArrayList<Callable<Object>> commitCallables = new ArrayList<Callable<Object>>();
    for (Map.Entry<String, IndexWriter> entry : writers.entrySet()) {
        commitCallables.add(new TransactionalCallable(indexManager.getTransactionContext(),
                new CommitCallable(indexManager, entry.getKey(), entry.getValue(), isClearCacheOnCommit())));
    }
    try {
        indexManager.getExecutorManager().invokeAllWithLimitBailOnException(commitCallables, 1);
    } catch (Exception e) {
        logger.warn("Failed to commit", e);
    }
}

From source file:com.tasktop.c2c.server.web.proxy.ajp.AjpProtocol.java

private void debug(String string, Socket connection) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("connection " + System.identityHashCode(connection) + ": " + string);
    }//from  w w  w  .  j  a  v a 2  s .c o m
}

From source file:com.ayuget.redface.ui.fragment.PostsFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Log.d(LOG_TAG, String.format("@%d -> Fragment(currentPage=%d) Saving '%d' posts / scrollPosition = '%d'",
            System.identityHashCode(this), currentPage, displayedPosts.size(), currentScrollPosition));

    outState.putParcelableArrayList(ARG_POST_LIST, displayedPosts);
    outState.putInt(ARG_SAVED_SCROLL_POSITION, currentScrollPosition);
}

From source file:de.tsystems.mms.apm.performancesignature.ui.PerfSigProjectAction.java

private String addTimeStampToLog(final String message) {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
    return sdf.format(new Date()) + ": " + this.getClass().getSimpleName() + "@"
            + Integer.toHexString(System.identityHashCode(this)) + ", threadId:"
            + Thread.currentThread().getId() + " " + message;
}

From source file:org.mule.module.launcher.application.DefaultMuleApplication.java

@Override
public String toString() {
    return String.format("%s[%s]@%s", getClass().getName(), descriptor.getAppName(),
            Integer.toHexString(System.identityHashCode(this)));
}