Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk18u Public archive

Commit

Permalink
8282194: C1: Missing side effects of dynamic constant linkage
Browse files Browse the repository at this point in the history
Backport-of: 9332071784b7150512f7e27b07c290a356d43c2e
  • Loading branch information
TobiHartmann committed Apr 6, 2022
1 parent 8f3c889 commit 7ebdcf5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/hotspot/share/c1/c1_GraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,8 @@ void GraphBuilder::load_constant() {
}
Value x;
if (patch_state != NULL) {
x = new Constant(t, patch_state);
bool kills_memory = stream()->is_dynamic_constant(); // arbitrary memory effects from running BSM during linkage
x = new Constant(t, patch_state, kills_memory);
} else {
x = new Constant(t);
}
Expand Down
9 changes: 6 additions & 3 deletions src/hotspot/share/c1/c1_Instruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class Instruction: public CompilationResourceObj {
NeedsRangeCheckFlag,
InWorkListFlag,
DeoptimizeOnException,
KillsMemoryFlag,
InstructionLastFlag
};

Expand Down Expand Up @@ -719,13 +720,13 @@ LEAF(Constant, Instruction)
assert(type->is_constant(), "must be a constant");
}

Constant(ValueType* type, ValueStack* state_before):
Constant(ValueType* type, ValueStack* state_before, bool kills_memory = false):
Instruction(type, state_before, /*type_is_constant*/ true)
{
assert(state_before != NULL, "only used for constants which need patching");
assert(type->is_constant(), "must be a constant");
// since it's patching it needs to be pinned
pin();
set_flag(KillsMemoryFlag, kills_memory);
pin(); // since it's patching it needs to be pinned
}

// generic
Expand All @@ -737,6 +738,8 @@ LEAF(Constant, Instruction)

virtual ciType* exact_type() const;

bool kills_memory() const { return check_flag(KillsMemoryFlag); }

enum CompareResult { not_comparable = -1, cond_false, cond_true };

virtual CompareResult compare(Instruction::Condition condition, Value right) const;
Expand Down
7 changes: 6 additions & 1 deletion src/hotspot/share/c1/c1_ValueMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ class ValueNumberingVisitor: public InstructionVisitor {

void do_Phi (Phi* x) { /* nothing to do */ }
void do_Local (Local* x) { /* nothing to do */ }
void do_Constant (Constant* x) { /* nothing to do */ }
void do_Constant (Constant* x) {
if (x->kills_memory()) {
assert(x->can_trap(), "already linked");
kill_memory();
}
}
void do_LoadField (LoadField* x) {
if (x->is_init_point() || // getstatic is an initialization point so treat it as a wide kill
x->field()->is_volatile()) { // the JMM requires this
Expand Down
8 changes: 8 additions & 0 deletions src/hotspot/share/ci/ciStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ constantTag ciBytecodeStream::get_constant_pool_tag(int index) const {
return _method->get_Method()->constants()->constant_tag_at(index);
}

// ------------------------------------------------------------------
// ciBytecodeStream::get_raw_pool_tag
//
constantTag ciBytecodeStream::get_raw_pool_tag(int index) const {
VM_ENTRY_MARK;
return _method->get_Method()->constants()->tag_at(index);
}

// ------------------------------------------------------------------
// ciBytecodeStream::get_basic_type_for_constant_at
//
Expand Down
13 changes: 13 additions & 0 deletions src/hotspot/share/ci/ciStreams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,25 @@ class ciBytecodeStream : StackObj {
constantTag get_constant_pool_tag(int index) const;
BasicType get_basic_type_for_constant_at(int index) const;

constantTag get_raw_pool_tag(int index) const;

// True if the klass-using bytecode points to an unresolved klass
bool is_unresolved_klass() const {
constantTag tag = get_constant_pool_tag(get_klass_index());
return tag.is_unresolved_klass();
}

bool is_dynamic_constant() const {
assert(cur_bc() == Bytecodes::_ldc ||
cur_bc() == Bytecodes::_ldc_w ||
cur_bc() == Bytecodes::_ldc2_w, "not supported: %s", Bytecodes::name(cur_bc()));

int index = get_constant_pool_index();
constantTag tag = get_raw_pool_tag(index);
return tag.is_dynamic_constant() ||
tag.is_dynamic_constant_in_error();
}

bool is_in_error() const {
assert(cur_bc() == Bytecodes::_ldc ||
cur_bc() == Bytecodes::_ldc_w ||
Expand Down

1 comment on commit 7ebdcf5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.