8231410: Shenandoah: clone barrier should use base pointer

Reviewed-by: rkennke
This commit is contained in:
Aleksey Shipilev 2019-09-25 12:21:10 +02:00
parent 37465fba75
commit c49aa4ffa5
4 changed files with 258 additions and 14 deletions

View File

@ -461,11 +461,12 @@ const TypeFunc* ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type() {
}
const TypeFunc* ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type() {
const Type **fields = TypeTuple::fields(3);
fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // src
fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // dst
fields[TypeFunc::Parms+2] = TypeInt::INT; // length
const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
const Type **fields = TypeTuple::fields(4);
fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // src oop
fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // src
fields[TypeFunc::Parms+2] = TypeRawPtr::NOTNULL; // dst
fields[TypeFunc::Parms+3] = TypeInt::INT; // length
const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
// create result type (range)
fields = TypeTuple::fields(0);
@ -807,13 +808,16 @@ void ShenandoahBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCo
Node* dest_offset = ac->in(ArrayCopyNode::DestPos);
Node* length = ac->in(ArrayCopyNode::Length);
assert (src_offset == NULL && dest_offset == NULL, "for clone offsets should be null");
assert (src->is_AddP(), "for clone the src should be the interior ptr");
assert (dest->is_AddP(), "for clone the dst should be the interior ptr");
if (ShenandoahCloneBarrier && clone_needs_barrier(src, phase->igvn())) {
Node* call = phase->make_leaf_call(ctrl, mem,
ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type(),
CAST_FROM_FN_PTR(address, ShenandoahRuntime::shenandoah_clone_barrier),
"shenandoah_clone",
TypeRawPtr::BOTTOM,
src, dest, length);
src->in(AddPNode::Base), src, dest, length);
call = phase->transform_later(call);
phase->igvn().replace_node(ac, call);
} else {

View File

@ -28,6 +28,7 @@
#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
#include "runtime/interfaceSupport.inline.hpp"
#include "oops/oop.inline.hpp"
#include "utilities/copy.hpp"
void ShenandoahRuntime::write_ref_array_pre_oop_entry(oop* src, oop* dst, size_t length) {
ShenandoahBarrierSet *bs = ShenandoahBarrierSet::barrier_set();
@ -75,13 +76,13 @@ JRT_END
// Shenandoah clone barrier: makes sure that references point to to-space
// in cloned objects.
JRT_LEAF(void, ShenandoahRuntime::shenandoah_clone_barrier(oopDesc* s, oopDesc* d, size_t length))
oop src = oop(s);
oop dst = oop(d);
shenandoah_assert_correct(NULL, src);
shenandoah_assert_correct(NULL, dst);
ShenandoahBarrierSet::barrier_set()->clone_barrier(src);
RawAccessBarrier<IS_NOT_NULL>::clone(src, dst, length);
JRT_LEAF(void, ShenandoahRuntime::shenandoah_clone_barrier(oopDesc* src, void* src_ptr, void* dst_ptr, size_t length))
oop s = oop(src);
shenandoah_assert_correct(NULL, s);
ShenandoahBarrierSet::barrier_set()->clone_barrier(s);
Copy::conjoint_jlongs_atomic(reinterpret_cast<jlong*>(src_ptr),
reinterpret_cast<jlong*>(dst_ptr),
length);
JRT_END
JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_native(oopDesc * src))

View File

@ -44,7 +44,7 @@ public:
static oopDesc* load_reference_barrier_native(oopDesc* src);
static void shenandoah_clone_barrier(oopDesc* s, oopDesc* d, size_t length);
static void shenandoah_clone_barrier(oopDesc* src, void* src_ptr, void* dst_ptr, size_t length);
};
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHRUNTIME_HPP

View File

@ -0,0 +1,239 @@
/*
* Copyright (c) 2019, Red Hat, Inc. 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test TestClone
* @summary Test clone barriers work correctly
* @key gc
* @requires vm.gc.Shenandoah & !vm.graal.enabled
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -Xint
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:-TieredCompilation
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:TieredStopAtLevel=1
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:TieredStopAtLevel=4
* TestClone
*/
/*
* @test TestClone
* @summary Test clone barriers work correctly
* @key gc
* @requires vm.gc.Shenandoah & !vm.graal.enabled
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -Xint
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -XX:-TieredCompilation
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -XX:TieredStopAtLevel=1
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -XX:TieredStopAtLevel=4
* TestClone
*/
/*
* @test TestClone
* @summary Test clone barriers work correctly
* @key gc
* @requires vm.gc.Shenandoah & !vm.graal.enabled
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -Xint
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -XX:-TieredCompilation
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -XX:TieredStopAtLevel=1
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -XX:TieredStopAtLevel=4
* TestClone
*/
/*
* @test TestClone
* @summary Test clone barriers work correctly
* @key gc
* @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -Xint
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:-TieredCompilation
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:TieredStopAtLevel=1
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:TieredStopAtLevel=4
* TestClone
*/
/*
* @test TestClone
* @summary Test clone barriers work correctly
* @key gc
* @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -Xint
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -XX:-TieredCompilation
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -XX:TieredStopAtLevel=1
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC
* -XX:+ShenandoahVerify
* -XX:TieredStopAtLevel=4
* TestClone
*/
/*
* @test TestClone
* @summary Test clone barriers work correctly
* @key gc
* @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
*
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -Xint
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -XX:-TieredCompilation
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -XX:TieredStopAtLevel=1
* TestClone
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
* -XX:-UseCompressedOops
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
* -XX:TieredStopAtLevel=4
* TestClone
*/
public class TestClone {
public static void main(String[] args) throws Exception {
for (int i = 0; i < 10000; i++) {
Object[] src = new Object[i];
for (int c = 0; c < src.length; c++) {
src[c] = new Object();
}
testWith(src);
}
}
static void testWith(Object[] src) {
Object[] dst = src.clone();
int srcLen = src.length;
int dstLen = dst.length;
if (srcLen != dstLen) {
throw new IllegalStateException("Lengths do not match: " + srcLen + " vs " + dstLen);
}
for (int c = 0; c < src.length; c++) {
Object s = src[c];
Object d = dst[c];
if (s != d) {
throw new IllegalStateException("Elements do not match at " + c + ": " + s + " vs " + d);
}
}
}
}