intptr_t ObjectSynchronizer::FastHashCode (Thread * Self, oop obj) {
if (UseBiasedLocking) {
// NOTE: many places throughout the JVM do not expect a safepoint
// to be taken here, in particular most operations on perm gen
// objects. However, we only ever bias Java instances and all of
// the call sites of identity_hash that might revoke biases have
// been checked to make sure they can handle a safepoint. The
// added check of the bias pattern is to avoid useless calls to
// thread-local storage.
if (obj->mark()->has_bias_pattern()) {
// Box and unbox the raw reference just in case we cause a STW safepoint.
Handle hobj (Self, obj) ;
// Relaxing assertion for bug 6320749.
assert (Universe::verify_in_progress() ||
!SafepointSynchronize::is_at_safepoint(),
"biases should not be seen by VM thread here");
BiasedLocking::revoke_and_rebias(hobj, false, JavaThread::current());
obj = hobj() ;
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
}
// hashCode() is a heap mutator ...
// Relaxing assertion for bug 6320749.
assert (Universe::verify_in_progress() ||
!SafepointSynchronize::is_at_safepoint(), "invariant") ;
assert (Universe::verify_in_progress() ||
Self->is_Java_thread() , "invariant") ;
assert (Universe::verify_in_progress() ||
((JavaThread *)Self)->thread_state() != _thread_blocked, "invariant") ;
ObjectMonitor* monitor = NULL;
markOop temp, test;
intptr_t hash;
markOop mark = ReadStableMark (obj);
// object should remain ineligible for biased locking
assert (!mark->has_bias_pattern(), "invariant") ;
if (mark->is_neutral()) {
hash = mark->hash(); // this is a normal header
if (hash) { // if it has hash, just return it
return hash;
}
hash = get_next_hash(Self, obj); // allocate a new hash code
temp = mark->copy_set_hash(hash); // merge the hash code into header
// use (machine word version) atomic operation to install the hash
test = (markOop) Atomic::cmpxchg_ptr(temp, obj->mark_addr(), mark);
if (test == mark) {
return hash;
}
// If atomic operation failed, we must inflate the header
// into heavy weight monitor. We could add more code here
// for fast path, but it does not worth the complexity.
} else if (mark->has_monitor()) {
monitor = mark->monitor();
temp = monitor->header();
assert (temp->is_neutral(), "invariant") ;
hash = temp->hash();
if (hash) {
return hash;
}
// Skip to the following code to reduce code size
} else if (Self->is_lock_owned((address)mark->locker())) {
temp = mark->displaced_mark_helper(); // this is a lightweight monitor owned
assert (temp->is_neutral(), "invariant") ;
hash = temp->hash(); // by current thread, check if the displaced
if (hash) { // header contains hash code
return hash;
}
// WARNING:
// The displaced header is strictly immutable.
// It can NOT be changed in ANY cases. So we have
// to inflate the header into heavyweight monitor
// even the current thread owns the lock. The reason
// is the BasicLock (stack slot) will be asynchronously
// read by other threads during the inflate() function.
// Any change to stack may not propagate to other threads
// correctly.
}
// Inflate the monitor to set hash code
monitor = ObjectSynchronizer::inflate(Self, obj);
// Load displaced header and check it has hash code
mark = monitor->header();
assert (mark->is_neutral(), "invariant") ;
hash = mark->hash();
if (hash == 0) {
hash = get_next_hash(Self, obj);
temp = mark->copy_set_hash(hash); // merge hash code into header
assert (temp->is_neutral(), "invariant") ;
test = (markOop) Atomic::cmpxchg_ptr(temp, monitor, mark);
if (test != mark) {
// The only update to the header in the monitor (outside GC)
// is install the hash code. If someone add new usage of
// displaced header, please update this code
hash = test->hash();
assert (test->is_neutral(), "invariant") ;
assert (hash != 0, "Trivial unexpected object/monitor header usage.");
}
}
// We finally get the hash
return hash;
}
分享到:
相关推荐
retry.zip,用于异步重试scala futures的简单原语库,因为您不应该放弃,至少在第一次尝试时不应该放弃。
hashcode-2021练习跑步使用npm start <input file path> <output>
HashCode-21-实践圆 迄今为止最好的成绩:) A –示例-> 74分 B –一点点-> 13,750点 C –许多成分-> 706,619,049点 D –很多披萨-> 7,345,043点 E –多支球队-> 10,369,792点 总分-> 724,347,708分
Google Hashcode 2015 - 资格认证任务 ##概要 用于优化数据中心布局的快速而肮脏的 CLI 实用程序。 有关完整说明,请参阅task/文件夹。 ##团队
Google Hashcode 2021分数计算器计算Google Hashcode 2021资格回合得分。 对于我们提交的内容,其结果与Google相同。 它也为示例文件提供了相同的结果。 注意:对于不正确的提交文件,它可能不够可靠。 注意:不提供...
Google HashCode PlayGround 通过该项目,您可以评估过去版本的Google HashCode的提交文件。 这项工作正在进行中,到目前为止,我已经完全实现了以下评分系统: 2018年资格赛2017年决赛2017年资格赛2016年决赛2016年...
Google Hash Code 2018:实时模拟介绍比赛的一些背景: 我们为您提供了城市中的预先预订的游乐设施清单以及无人驾驶汽车车队。 比赛的目的是将游乐设施分配给车辆,以便骑手按时到达目的地。更好地了解动画的指南...
我们的Google Hashcode工作区
Google Hashcode 2021解决方案我们针对Google Hashcode 2021交通信号的解决方案。 全球排名前15%,加拿大排名第19 :Canada: 。 (击败UofT的所有人:P)
谷歌哈希码-2021 Google哈希码2021
该存储库旨在用作编写Google Hashcode解决方案的框架。它针对所选参数提供了解决方案的自动优化。 什么是Google Hashcode? Google Hashcode是一项竞赛,其中向一个团队提供问题陈述和6个数据集,并且他们必须为每...
项目标题在这里有关您的项目的信息在这里
Google哈希码2021SushiMaroto团队: :sushi: 姓名Github 克里斯托弗·艾克罗伊德(Christopher Aykroyd) 加布里埃尔·奥利维拉(Gabriel Oliveira) 伊恩·杜莱巴(Ian Duleba) 拉斐尔·费乔
##在(R)流和(C)列中的矩阵,左上角,(0,0)至(N-1,N-1)
Object类的hashCode的用法 马克-to-win java视频哈希码
Google-HashCode-2020(资格赛) 哈希代码是Google举办的面向全球学生和专业人士的团队编程竞赛。 您选择您的团队和编程语言,我们选择一个工程问题供您解决。 今年的比赛以在线资格赛拉开帷幕,在线资格赛使您的...
HashCode教程 这是什么 这是一个代码库,用于测试解决优化问题的一些常规思路以及所需的样板代码。 结果 a_example:2(手动) b_lovely_landscapes:212679(图表DFS) c_memorable_moments:1533(在线贪婪) d...
哈希码2k21 回购我们团队的HashCode 2k21解决方案
Google Hashcode 2021 2021年的哈希码以Google地图为主题,问题是交通灯调度问题,该问题涉及最大化通过城市交通网络的汽车数量。 结果 在9000多个参与者中,我们的团队在整个澳大利亚排名第三,在全球排名中排名前...
Object类的hashCode的用法1---马克-to-win java视频哈希码