解释concurrentHashmap的put(key,value)方法的下面几行? [英] Explain the below lines of put(key,value) method of concurrentHashmap?

查看:314
本文介绍了解释concurrentHashmap的put(key,value)方法的下面几行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读一个在 ConcurrentHashMap

我无法理解以下行。

 int j = (hash >>> segmentShift) & segmentMask;
        if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
             (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
            s = ensureSegment(j);
        return s.put(key, hash, value, false);

有人请解释。

推荐答案

方法调用:

UNSAFE.getObject(segments, (j << SSHIFT) + SBASE)

等同于正常数组访问 segments [j] / code>,但是可能更快,因为它不需要边界检查。 SBASE 是数组数据在数组中开始的位置。 SSHIFT 是数组索引标度的log <2>,因此 j < SSHIFT 计算数组中索引 j 的原始字节偏移量。

is equivalent to a normal array access segments[j], but is likely faster because it requires no bounds checks. SBASE is the offset to where the array data begins in the segments array. SSHIFT is log2 of the array index scale, so j << SSHIFT calculates the raw byte offset of index j in the array.

这篇关于解释concurrentHashmap的put(key,value)方法的下面几行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆