# HG changeset patch # User shade # Date 1569406870 -7200 # Wed Sep 25 12:21:10 2019 +0200 # Node ID 3a3577abeb9045ef143f37e0a50a22d3a7b92f22 # Parent 69289957896337aa20ff581df9f60efd7536b178 [backport] 8231410: Shenandoah: clone barrier should use base pointer Reviewed-by: rkennke diff -r 692899578963 -r 3a3577abeb90 src/share/vm/gc_implementation/shenandoah/shenandoahRuntime.cpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahRuntime.cpp Wed Sep 18 20:56:19 2019 +0200 +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahRuntime.cpp Wed Sep 25 12:21:10 2019 +0200 @@ -71,10 +71,8 @@ // 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); +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); JRT_END diff -r 692899578963 -r 3a3577abeb90 src/share/vm/gc_implementation/shenandoah/shenandoahRuntime.hpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahRuntime.hpp Wed Sep 18 20:56:19 2019 +0200 +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahRuntime.hpp Wed Sep 25 12:21:10 2019 +0200 @@ -42,7 +42,7 @@ static oopDesc* load_reference_barrier_JRT(oopDesc* src); static oopDesc* load_reference_barrier_interpreter(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_VM_GC_SHENANDOAH_SHENANDOAHRUNTIME_HPP diff -r 692899578963 -r 3a3577abeb90 src/share/vm/opto/library_call.cpp --- a/src/share/vm/opto/library_call.cpp Wed Sep 18 20:56:19 2019 +0200 +++ b/src/share/vm/opto/library_call.cpp Wed Sep 25 12:21:10 2019 +0200 @@ -4552,12 +4552,15 @@ #ifdef INCLUDE_ALL_GCS if (UseShenandoahGC && ShenandoahCloneBarrier) { + 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"); + // Make sure that references in the cloned object are updated for Shenandoah. make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::shenandoah_clone_barrier_Type(), CAST_FROM_FN_PTR(address, ShenandoahRuntime::shenandoah_clone_barrier), "shenandoah_clone_barrier", TypePtr::BOTTOM, - src, dest, countx); + src->in(AddPNode::Base), src, dest, countx); } #endif diff -r 692899578963 -r 3a3577abeb90 src/share/vm/opto/runtime.cpp --- a/src/share/vm/opto/runtime.cpp Wed Sep 18 20:56:19 2019 +0200 +++ b/src/share/vm/opto/runtime.cpp Wed Sep 25 12:21:10 2019 +0200 @@ -583,11 +583,12 @@ } const TypeFunc *OptoRuntime::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); diff -r 692899578963 -r 3a3577abeb90 test/hotspot/jtreg/gc/shenandoah/compiler/TestClone.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/gc/shenandoah/compiler/TestClone.java Wed Sep 25 12:21:10 2019 +0200 @@ -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); + } + } + } +}