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.ReferenceSerializer.java

public Object marshall(SerializerState state, Object o) throws MarshallException {
    Class clazz = o.getClass();//from  w ww . jav a 2  s  .  c  om
    Integer identity = new Integer(System.identityHashCode(o));
    if (bridge.isReference(clazz)) {
        if (ser.isDebug())
            log.fine("marshalling reference to object " + identity + " of class " + clazz.getName());
        synchronized (bridge.referenceMap) {
            bridge.referenceMap.put(identity, o);
        }
        JSONObject jso = new JSONObject();
        try {
            jso.put("JSONRPCType", "Reference");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            jso.put("javaClass", clazz.getName());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            jso.put("objectID", identity);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return jso;
    } else if (bridge.isCallableReference(clazz)) {
        if (ser.isDebug())
            log.fine("marshalling callable reference to object " + identity + " of class " + clazz.getName());
        bridge.registerObject(identity, o);
        JSONObject jso = new JSONObject();
        try {
            jso.put("JSONRPCType", "CallableReference");
        } catch (JSONException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }
        try {
            jso.put("javaClass", clazz.getName());
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            jso.put("objectID", identity);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return jso;
    }
    return null;
}

From source file:com.github.dozermapper.core.util.MappingUtils.java

public static String getMappedParentFieldKey(Object destObj, FieldMap destFieldMap) {
    StringBuilder buf = new StringBuilder(100); // TODO Use IdentityHashMap instead of String concatenation
    buf.append(System.identityHashCode(destObj));
    buf.append(destFieldMap.getDestFieldName());
    if (destFieldMap.getDestFieldKey() != null) {
        buf.append("[").append(destFieldMap.getDestFieldKey()).append("]");
    }/* w w w  .  j  a va2  s .  co m*/
    return buf.toString();
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReferenceHashmap.java

@SuppressWarnings("unchecked")
@Override/*from w w  w . j av a2 s  .c  o m*/
public V remove(Object key) {

    V value = get(key);
    if (value == null)
        return null;

    int hash = System.identityHashCode(key);

    // remove from keys
    removeFromKeys(keys.get(hash), (K) key);

    // remove from values
    removeFromValues(values.get(hash), (K) key);

    size--;
    return value;
}

From source file:de.ailis.midi4js.Midi4JS.java

/**
 * @see java.applet.Applet#start()/*from  w ww .  j  a va  2  s  .c o m*/
 */
@Override
public void start() {
    System.out.println("Started midi4js applet (Instance #" + System.identityHashCode(this) + ")");
    this.deviceMap = new HashMap<Integer, MidiDevice>();
    this.receiverMap = new HashMap<Integer, Receiver>();
    this.transmitterMap = new HashMap<Integer, Transmitter>();
    execJSMethod("appletStarted");
}

From source file:ch.sourcepond.io.checksum.impl.PathUpdateStrategyTest.java

/**
 * //  w  w  w  .j  a va 2s. c om
 */
@Test(timeout = 2000)
public void verifyUpdateDigestGCRun() throws Exception {
    strategy = newStrategy(SHA256, realFile);
    final long objectIdentityBeforeGC = System.identityHashCode(strategy.getTempBuffer());

    // Call to update will set the hard-reference tempBuffer to null. This
    // is necessary, otherwise the weak-reference will not be cleared.
    strategy.update(0, MILLISECONDS);

    // After running the garbage collector the weak-references should have
    // been cleared.
    System.gc();
    assertNotEquals(objectIdentityBeforeGC, System.identityHashCode(strategy.getTempBuffer()));
}

From source file:org.agatom.springatom.data.hades.model.NAbstractPersistable.java

@Override
public int hashCode() {
    if (hash == null) {
        final Long id = this.getId();
        hash = id == null ? System.identityHashCode(this) : id.hashCode();
    }/*from   w w w  .  j a  v  a 2 s. c o m*/
    return hash.hashCode();
}

From source file:org.silverpeas.core.process.io.file.TestAbstractFileHandler.java

@Before
public void beforeTest() throws Exception {
    BASE_PATH_TEST = FileBasePath.UPLOAD_PATH;
    sessionRootPath = new File(ResourceLocator.getGeneralSettingBundle().getString("tempPath"));
    realRootPath = new File(BASE_PATH_TEST.getPath());
    otherFile = new File(new File(BASE_PATH_TEST.getPath()).getParentFile(), "other");

    componentInstanceId = "component" + String.valueOf(System.identityHashCode(this)).substring(0, 2);
    currentSession = createSessionTest();
    fileHandler = new FileHandlerTest(currentSession);
    realPath = getFile(realRootPath, componentInstanceId);
    realPath.mkdirs();/*from ww  w  . j  av a2s.  c o m*/
    sessionPath = getFile(sessionRootPath, currentSession.getId(), BASE_PATH_TEST.getHandledNodeName(),
            componentInstanceId);
    sessionPath.mkdirs();
    touch(otherFile);
}

From source file:com.adaptris.core.runtime.AdapterBuilder.java

public AdapterBuilder(AdapterRegistry owner, Properties cfg) throws MalformedObjectNameException {
    this();/*from   ww  w  .java2s  . c o  m*/
    parent = owner;
    this.config = new BootstrapProperties(cfg);
    runtimeVCS = loadVCS();
    boolean enableValidation = config.isEnabled(Constants.CFG_KEY_VALIDATE_CONFIG);
    if (enableValidation) {
        validatorFactory = Validation.buildDefaultValidatorFactory();
    }
    myObjectName = ObjectName
            .getInstance(JMX_OBJECT_PREFIX + Integer.toHexString(System.identityHashCode(cfg)));
}

From source file:org.jabsorb.ng.serializer.impl.ReferenceSerializer.java

@Override
public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException {

    final Class<?> clazz = o.getClass();
    final Integer identity = new Integer(System.identityHashCode(o));
    if (bridge.isReference(clazz)) {
        if (log.isDebugEnabled()) {
            log.debug("marshall",
                    "marshalling reference to object " + identity + " of class " + clazz.getName());
        }/*from  w  w w. j  a  v  a  2s  .co  m*/
        bridge.addReference(o);
        final JSONObject jso = new JSONObject();
        try {
            jso.put("JSONRPCType", "Reference");
            jso.put("javaClass", clazz.getName());
            jso.put("objectID", identity);
        } catch (final JSONException e) {
            throw new MarshallException(e.getMessage(), e);
        }
        return jso;
    } else if (bridge.isCallableReference(clazz)) {
        if (log.isDebugEnabled()) {
            log.debug("marshall",
                    "marshalling callable reference to object " + identity + " of class " + clazz.getName());
        }
        bridge.registerObject(identity, o);
        bridge.addReference(o);

        final JSONObject jso = new JSONObject();
        try {
            jso.put("JSONRPCType", "CallableReference");
            jso.put("javaClass", clazz.getName());
            jso.put("objectID", identity);
        } catch (final JSONException e) {
            throw new MarshallException(e.getMessage(), e);
        }

        return jso;
    }
    return null;
}

From source file:org.apache.kylin.common.KylinConfig.java

public static KylinConfig getInstanceFromEnv() {
    synchronized (KylinConfig.class) {
        KylinConfig config = THREAD_ENV_INSTANCE.get();
        if (config != null) {
            return config;
        }//from   w  w  w  .  j  a  v  a2  s  .  com

        if (SYS_ENV_INSTANCE == null) {
            try {
                config = new KylinConfig();
                config.reloadKylinConfig(getKylinProperties());

                logger.info("Initialized a new KylinConfig from getInstanceFromEnv : "
                        + System.identityHashCode(config));
                SYS_ENV_INSTANCE = config;
            } catch (IllegalArgumentException e) {
                throw new IllegalStateException("Failed to find KylinConfig ", e);
            }
        }
        return SYS_ENV_INSTANCE;
    }
}