Fri, 17 Jul 2020 07:03:30 +0800
8248851: CMS: Missing memory fences between free chunk check and klass read
Reviewed-by: aph, kbarrett, dholmes
Contributed-by: wangshuai94@huawei.com
src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Thu Aug 13 06:55:26 2020 +0100 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Fri Jul 17 07:03:30 2020 +0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -994,6 +994,10 @@ 1.11 return res; 1.12 } 1.13 } else { 1.14 + // The barrier is required to prevent reordering of the free chunk check 1.15 + // and the klass read. 1.16 + OrderAccess::loadload(); 1.17 + 1.18 // must read from what 'p' points to in each loop. 1.19 Klass* k = ((volatile oopDesc*)p)->klass_or_null(); 1.20 if (k != NULL) { 1.21 @@ -1049,6 +1053,10 @@ 1.22 return res; 1.23 } 1.24 } else { 1.25 + // The barrier is required to prevent reordering of the free chunk check 1.26 + // and the klass read. 1.27 + OrderAccess::loadload(); 1.28 + 1.29 // must read from what 'p' points to in each loop. 1.30 Klass* k = ((volatile oopDesc*)p)->klass_or_null(); 1.31 // We trust the size of any object that has a non-NULL 1.32 @@ -1111,6 +1119,11 @@ 1.33 // assert(CollectedHeap::use_parallel_gc_threads() || _bt.block_start(p) == p, 1.34 // "Should be a block boundary"); 1.35 if (FreeChunk::indicatesFreeChunk(p)) return false; 1.36 + 1.37 + // The barrier is required to prevent reordering of the free chunk check 1.38 + // and the klass read. 1.39 + OrderAccess::loadload(); 1.40 + 1.41 Klass* k = oop(p)->klass_or_null(); 1.42 if (k != NULL) { 1.43 // Ignore mark word because it may have been used to