Skip to content

Commit aa251e0

Browse files
committed
8231499: Shenandoah: compiler/arraycopy/TestDefaultMethodArrayCloneDeoptC2 fails
Reviewed-by: shade, roland
1 parent 56bc797 commit aa251e0

File tree

5 files changed

+61
-17
lines changed

5 files changed

+61
-17
lines changed

src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "opto/movenode.hpp"
3939
#include "opto/narrowptrnode.hpp"
4040
#include "opto/rootnode.hpp"
41+
#include "opto/runtime.hpp"
4142

4243
ShenandoahBarrierSetC2* ShenandoahBarrierSetC2::bsc2() {
4344
return reinterpret_cast<ShenandoahBarrierSetC2*>(BarrierSet::barrier_set()->barrier_set_c2());
@@ -461,12 +462,9 @@ const TypeFunc* ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type() {
461462
}
462463

463464
const TypeFunc* ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type() {
464-
const Type **fields = TypeTuple::fields(4);
465-
fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // src oop
466-
fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // src
467-
fields[TypeFunc::Parms+2] = TypeRawPtr::NOTNULL; // dst
468-
fields[TypeFunc::Parms+3] = TypeInt::INT; // length
469-
const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
465+
const Type **fields = TypeTuple::fields(1);
466+
fields[TypeFunc::Parms+0] = TypeOopPtr::NOTNULL; // src oop
467+
const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
470468

471469
// create result type (range)
472470
fields = TypeTuple::fields(0);
@@ -797,8 +795,6 @@ bool ShenandoahBarrierSetC2::clone_needs_barrier(Node* src, PhaseGVN& gvn) {
797795
return false;
798796
}
799797

800-
#define XTOP LP64_ONLY(COMMA phase->top())
801-
802798
void ShenandoahBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const {
803799
Node* ctrl = ac->in(TypeFunc::Control);
804800
Node* mem = ac->in(TypeFunc::Memory);
@@ -812,13 +808,62 @@ void ShenandoahBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCo
812808
assert (dest->is_AddP(), "for clone the dst should be the interior ptr");
813809

814810
if (ShenandoahCloneBarrier && clone_needs_barrier(src, phase->igvn())) {
815-
Node* call = phase->make_leaf_call(ctrl, mem,
811+
// Check if heap is has forwarded objects. If it does, we need to call into the special
812+
// routine that would fix up source references before we can continue.
813+
814+
enum { _heap_stable = 1, _heap_unstable, PATH_LIMIT };
815+
Node* region = new RegionNode(PATH_LIMIT);
816+
Node* mem_phi = new PhiNode(region, Type::MEMORY, TypeRawPtr::BOTTOM);
817+
818+
Node* thread = phase->transform_later(new ThreadLocalNode());
819+
Node* offset = phase->igvn().MakeConX(in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
820+
Node* gc_state_addr = phase->transform_later(new AddPNode(phase->C->top(), thread, offset));
821+
822+
uint gc_state_idx = Compile::AliasIdxRaw;
823+
const TypePtr* gc_state_adr_type = NULL; // debug-mode-only argument
824+
debug_only(gc_state_adr_type = phase->C->get_adr_type(gc_state_idx));
825+
826+
Node* gc_state = phase->transform_later(new LoadBNode(ctrl, mem, gc_state_addr, gc_state_adr_type, TypeInt::BYTE, MemNode::unordered));
827+
Node* stable_and = phase->transform_later(new AndINode(gc_state, phase->igvn().intcon(ShenandoahHeap::HAS_FORWARDED)));
828+
Node* stable_cmp = phase->transform_later(new CmpINode(stable_and, phase->igvn().zerocon(T_INT)));
829+
Node* stable_test = phase->transform_later(new BoolNode(stable_cmp, BoolTest::ne));
830+
831+
IfNode* stable_iff = phase->transform_later(new IfNode(ctrl, stable_test, PROB_UNLIKELY(0.999), COUNT_UNKNOWN))->as_If();
832+
Node* stable_ctrl = phase->transform_later(new IfFalseNode(stable_iff));
833+
Node* unstable_ctrl = phase->transform_later(new IfTrueNode(stable_iff));
834+
835+
// Heap is stable, no need to do anything additional
836+
region->init_req(_heap_stable, stable_ctrl);
837+
mem_phi->init_req(_heap_stable, mem);
838+
839+
// Heap is unstable, call into clone barrier stub
840+
Node* call = phase->make_leaf_call(unstable_ctrl, mem,
816841
ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type(),
817842
CAST_FROM_FN_PTR(address, ShenandoahRuntime::shenandoah_clone_barrier),
818843
"shenandoah_clone",
819844
TypeRawPtr::BOTTOM,
820-
src->in(AddPNode::Base), src, dest, length);
845+
src->in(AddPNode::Base));
821846
call = phase->transform_later(call);
847+
848+
ctrl = phase->transform_later(new ProjNode(call, TypeFunc::Control));
849+
mem = phase->transform_later(new ProjNode(call, TypeFunc::Memory));
850+
region->init_req(_heap_unstable, ctrl);
851+
mem_phi->init_req(_heap_unstable, mem);
852+
853+
// Wire up the actual arraycopy stub now
854+
ctrl = phase->transform_later(region);
855+
mem = phase->transform_later(mem_phi);
856+
857+
const char* name = "arraycopy";
858+
call = phase->make_leaf_call(ctrl, mem,
859+
OptoRuntime::fast_arraycopy_Type(),
860+
phase->basictype2arraycopy(T_LONG, NULL, NULL, true, name, true),
861+
name, TypeRawPtr::BOTTOM,
862+
src, dest, length
863+
LP64_ONLY(COMMA phase->top()));
864+
call = phase->transform_later(call);
865+
866+
// Hook up the whole thing into the graph
822867
phase->igvn().replace_node(ac, call);
823868
} else {
824869
BarrierSetC2::clone_at_expansion(phase, ac);

src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ oop ShenandoahBarrierSet::oop_load_from_native_barrier(oop obj) {
286286
}
287287

288288
void ShenandoahBarrierSet::clone_barrier_runtime(oop src) {
289-
clone_barrier(src);
289+
if (_heap->has_forwarded_objects()) {
290+
clone_barrier(src);
291+
}
290292
}
291293

src/hotspot/share/gc/shenandoah/shenandoahBarrierSetClone.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ShenandoahUpdateRefsForOopClosure: public BasicOopIterateClosure {
7373

7474
void ShenandoahBarrierSet::clone_barrier(oop obj) {
7575
assert(ShenandoahCloneBarrier, "only get here with clone barriers enabled");
76-
if (!_heap->has_forwarded_objects()) return;
76+
assert(_heap->has_forwarded_objects(), "only when heap is unstable");
7777

7878
// This is called for cloning an object (see jvm.cpp) after the clone
7979
// has been made. We are not interested in any 'previous value' because

src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,10 @@ JRT_END
7676

7777
// Shenandoah clone barrier: makes sure that references point to to-space
7878
// in cloned objects.
79-
JRT_LEAF(void, ShenandoahRuntime::shenandoah_clone_barrier(oopDesc* src, void* src_ptr, void* dst_ptr, size_t length))
79+
JRT_LEAF(void, ShenandoahRuntime::shenandoah_clone_barrier(oopDesc* src))
8080
oop s = oop(src);
8181
shenandoah_assert_correct(NULL, s);
8282
ShenandoahBarrierSet::barrier_set()->clone_barrier(s);
83-
Copy::conjoint_jlongs_atomic(reinterpret_cast<jlong*>(src_ptr),
84-
reinterpret_cast<jlong*>(dst_ptr),
85-
length);
8683
JRT_END
8784

8885
JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_native(oopDesc * src))

src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ShenandoahRuntime : public AllStatic {
4444

4545
static oopDesc* load_reference_barrier_native(oopDesc* src);
4646

47-
static void shenandoah_clone_barrier(oopDesc* src, void* src_ptr, void* dst_ptr, size_t length);
47+
static void shenandoah_clone_barrier(oopDesc* src);
4848
};
4949

5050
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHRUNTIME_HPP

0 commit comments

Comments
 (0)