< prev index next >
src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp
Print this page
rev 53367 : 8248851: CMS: Missing memory fences between free chunk check and klass read
Reviewed-by: aph, kbarrett, dholmes
Contributed-by: wangshuai94@huawei.com
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -1176,10 +1176,14 @@
if (FreeChunk::indicatesFreeChunk(p)) {
assert(res != 0, "Block size should not be 0");
return res;
}
} else {
+ // The barrier is required to prevent reordering of the free chunk check
+ // and the klass read.
+ OrderAccess::loadload();
+
// Ensure klass read before size.
Klass* k = oop(p)->klass_or_null_acquire();
if (k != NULL) {
assert(k->is_klass(), "Should really be klass oop.");
oop o = (oop)p;
@@ -1226,10 +1230,14 @@
assert(res != 0, "Block size should not be 0");
assert(loops == 0, "Should be 0");
return res;
}
} else {
+ // The barrier is required to prevent reordering of the free chunk check
+ // and the klass read.
+ OrderAccess::loadload();
+
// Ensure klass read before size.
Klass* k = oop(p)->klass_or_null_acquire();
if (k != NULL) {
assert(k->is_klass(), "Should really be klass oop.");
oop o = (oop)p;
@@ -1269,10 +1277,15 @@
// promotion.)
bool CompactibleFreeListSpace::block_is_obj(const HeapWord* p) const {
FreeChunk* fc = (FreeChunk*)p;
assert(is_in_reserved(p), "Should be in space");
if (FreeChunk::indicatesFreeChunk(p)) return false;
+
+ // The barrier is required to prevent reordering of the free chunk check
+ // and the klass read.
+ OrderAccess::loadload();
+
Klass* k = oop(p)->klass_or_null_acquire();
if (k != NULL) {
// Ignore mark word because it may have been used to
// chain together promoted objects (the last one
// would have a null value).
< prev index next >