Skip to content

Commit bcac42a

Browse files
committed
8349479: C2: when a Type node becomes dead, make CFG path that uses it unreachable
Reviewed-by: chagedorn, vlivanov
1 parent 45b7c74 commit bcac42a

File tree

20 files changed

+246
-14
lines changed

20 files changed

+246
-14
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16297,7 +16297,8 @@ instruct ShouldNotReachHere() %{
1629716297

1629816298
ins_encode %{
1629916299
if (is_reachable()) {
16300-
__ stop(_halt_reason);
16300+
const char* str = __ code_string(_halt_reason);
16301+
__ stop(str);
1630116302
}
1630216303
%}
1630316304

src/hotspot/cpu/arm/arm.ad

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8992,7 +8992,8 @@ instruct ShouldNotReachHere( )
89928992
format %{ "ShouldNotReachHere" %}
89938993
ins_encode %{
89948994
if (is_reachable()) {
8995-
__ stop(_halt_reason);
8995+
const char* str = __ code_string(_halt_reason);
8996+
__ stop(str);
89968997
}
89978998
%}
89988999
ins_pipe(tail_call);

src/hotspot/cpu/ppc/ppc.ad

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14699,7 +14699,8 @@ instruct ShouldNotReachHere() %{
1469914699
format %{ "ShouldNotReachHere" %}
1470014700
ins_encode %{
1470114701
if (is_reachable()) {
14702-
__ stop(_halt_reason);
14702+
const char* str = __ code_string(_halt_reason);
14703+
__ stop(str);
1470314704
}
1470414705
%}
1470514706
ins_pipe(pipe_class_default);

src/hotspot/cpu/riscv/riscv.ad

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10893,7 +10893,8 @@ instruct ShouldNotReachHere() %{
1089310893

1089410894
ins_encode %{
1089510895
if (is_reachable()) {
10896-
__ stop(_halt_reason);
10896+
const char* str = __ code_string(_halt_reason);
10897+
__ stop(str);
1089710898
}
1089810899
%}
1089910900

src/hotspot/cpu/s390/s390.ad

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10080,7 +10080,8 @@ instruct ShouldNotReachHere() %{
1008010080
format %{ "ILLTRAP; ShouldNotReachHere" %}
1008110081
ins_encode %{
1008210082
if (is_reachable()) {
10083-
__ stop(_halt_reason);
10083+
const char* str = __ code_string(_halt_reason);
10084+
__ stop(str);
1008410085
}
1008510086
%}
1008610087
ins_pipe(pipe_class_dummy);

src/hotspot/cpu/x86/x86.ad

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2874,7 +2874,8 @@ instruct ShouldNotReachHere() %{
28742874
format %{ "stop\t# ShouldNotReachHere" %}
28752875
ins_encode %{
28762876
if (is_reachable()) {
2877-
__ stop(_halt_reason);
2877+
const char* str = __ code_string(_halt_reason);
2878+
__ stop(str);
28782879
}
28792880
%}
28802881
ins_pipe(pipe_slow);

src/hotspot/share/nmt/nativeCallStackPrinter.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ void NativeCallStackPrinter::print_stack(const NativeCallStack* stack) const {
4444
if (created) {
4545
stringStream ss(4 * K);
4646
stack->print_frame(&ss, pc);
47-
const size_t len = ss.size();
48-
char* store = NEW_ARENA_ARRAY(&_text_storage, char, len + 1);
49-
memcpy(store, ss.base(), len + 1);
50-
(*cached_frame_text) = store;
47+
(*cached_frame_text) = ss.as_string(&_text_storage);
5148
}
5249
_out->print_raw_cr(*cached_frame_text);
5350
}

src/hotspot/share/opto/c2_globals.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,12 @@
820820
product(bool, UseStoreStoreForCtor, true, DIAGNOSTIC, \
821821
"Use StoreStore barrier instead of Release barrier at the end " \
822822
"of constructors") \
823+
\
824+
develop(bool, KillPathsReachableByDeadTypeNode, true, \
825+
"When a Type node becomes top, make paths where the node is " \
826+
"used dead by replacing them with a Halt node. Turning this off " \
827+
"could corrupt the graph in rare cases and should be used with " \
828+
"care.") \
823829

824830
// end of C2_FLAGS
825831

src/hotspot/share/opto/castnode.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
9696
//------------------------------Ideal------------------------------------------
9797
// Return a node which is more "ideal" than the current node. Strip out
9898
// control copies
99-
Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
100-
return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
99+
Node* ConstraintCastNode::Ideal(PhaseGVN* phase, bool can_reshape) {
100+
if (in(0) != nullptr && remove_dead_region(phase, can_reshape)) {
101+
return this;
102+
}
103+
if (in(1) != nullptr && phase->type(in(1)) != Type::TOP) {
104+
return TypeNode::Ideal(phase, can_reshape);
105+
}
106+
return nullptr;
101107
}
102108

103109
uint ConstraintCastNode::hash() const {

src/hotspot/share/opto/connode.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class ConNode : public TypeNode {
4646
virtual const RegMask &out_RegMask() const { return RegMask::Empty; }
4747
virtual const RegMask &in_RegMask(uint) const { return RegMask::Empty; }
4848

49+
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape) {
50+
return Node::Ideal(phase, can_reshape);
51+
}
52+
4953
// Polymorphic factory method:
5054
static ConNode* make(const Type *t);
5155
};

0 commit comments

Comments
 (0)