Skip to content

Commit 6cb4219

Browse files
committed
Model klass loading directly from OOP rather than OOP + klass pointer offset
1 parent 9e008ac commit 6cb4219

19 files changed

+104
-60
lines changed

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6508,13 +6508,3 @@ void C2_MacroAssembler::vector_rearrange_int_float(BasicType bt, XMMRegister dst
65086508
vpermps(dst, shuffle, src, vlen_enc);
65096509
}
65106510
}
6511-
6512-
#ifdef _LP64
6513-
void C2_MacroAssembler::load_nklass_compact_c2(Register dst, Address src) {
6514-
// The incoming address is pointing into obj-start + klass_offset_in_bytes. We need to extract
6515-
// obj-start, so that we can load from the object's mark-word instead. Usually the address
6516-
// comes as obj-start in obj and klass_offset_in_bytes in disp.
6517-
movq(dst, src.plus_disp(-oopDesc::klass_offset_in_bytes()));
6518-
shrq(dst, markWord::klass_shift);
6519-
}
6520-
#endif

src/hotspot/cpu/x86/c2_MacroAssembler_x86.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,4 @@
505505
void vgather8b_offset(BasicType elem_bt, XMMRegister dst, Register base, Register idx_base,
506506
Register offset, Register rtmp, int vlen_enc);
507507

508-
void load_nklass_compact_c2(Register dst, Address src);
509-
510508
#endif // CPU_X86_C2_MACROASSEMBLER_X86_HPP

src/hotspot/cpu/x86/x86_64.ad

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,30 +4369,34 @@ instruct loadKlass(rRegP dst, memory mem)
43694369
// Load narrow Klass Pointer
43704370
instruct loadNKlass(rRegN dst, memory mem)
43714371
%{
4372-
predicate(!UseCompactObjectHeaders);
43734372
match(Set dst (LoadNKlass mem));
43744373

43754374
ins_cost(125); // XXX
43764375
format %{ "movl $dst, $mem\t# compressed klass ptr" %}
43774376
ins_encode %{
4378-
__ movl($dst$$Register, $mem$$Address);
4377+
if (UseNewCode) {
4378+
// The incoming address is pointing into obj-start.
4379+
if (UseCompactObjectHeaders) {
4380+
__ movq($dst$$Register, $mem$$Address.plus_disp(oopDesc::mark_offset_in_bytes()));
4381+
__ shrq($dst$$Register, markWord::klass_shift);
4382+
} else {
4383+
__ movl($dst$$Register, $mem$$Address.plus_disp(oopDesc::klass_offset_in_bytes()));
4384+
}
4385+
} else {
4386+
if (UseCompactObjectHeaders) {
4387+
// The incoming address is pointing into obj-start + klass_offset_in_bytes. We need to extract
4388+
// obj-start, so that we can load from the object's mark-word instead. Usually the address
4389+
// comes as obj-start in obj and klass_offset_in_bytes in disp.
4390+
__ movq($dst$$Register, $mem$$Address.plus_disp(-oopDesc::klass_offset_in_bytes()));
4391+
__ shrq($dst$$Register, markWord::klass_shift);
4392+
} else {
4393+
__ movl($dst$$Register, $mem$$Address);
4394+
}
4395+
}
43794396
%}
43804397
ins_pipe(ialu_reg_mem); // XXX
43814398
%}
43824399

4383-
instruct loadNKlassCompactHeaders(rRegN dst, memory mem, rFlagsReg cr)
4384-
%{
4385-
predicate(UseCompactObjectHeaders);
4386-
match(Set dst (LoadNKlass mem));
4387-
effect(KILL cr);
4388-
ins_cost(125); // XXX
4389-
format %{ "movl $dst, $mem\t# compressed klass ptr" %}
4390-
ins_encode %{
4391-
__ load_nklass_compact_c2($dst$$Register, $mem$$Address);
4392-
%}
4393-
ins_pipe(pipe_slow); // XXX
4394-
%}
4395-
43964400
// Load Float
43974401
instruct loadF(regF dst, memory mem)
43984402
%{
@@ -11730,7 +11734,7 @@ instruct compN_rReg_imm_klass(rFlagsRegU cr, rRegN op1, immNKlass op2) %{
1173011734

1173111735
instruct compN_mem_imm_klass(rFlagsRegU cr, memory mem, immNKlass src)
1173211736
%{
11733-
predicate(!UseCompactObjectHeaders);
11737+
predicate(!UseNewCode && !UseCompactObjectHeaders);
1173411738
match(Set cr (CmpN src (LoadNKlass mem)));
1173511739

1173611740
format %{ "cmpl $mem, $src\t# compressed klass ptr" %}

src/hotspot/share/oops/oop.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ class oopDesc {
331331
static int klass_offset_in_bytes() {
332332
#ifdef _LP64
333333
if (UseCompactObjectHeaders) {
334+
assert(!UseNewCode, "the prototype solution should not rely on this function");
334335
// NOTE: The only place where this is used with compact headers is
335336
// the C2 compiler, and even there we don't use it to access the (narrow)Klass*
336337
// directly. It is used only as a placeholder to identify the special memory slice

src/hotspot/share/opto/arraycopynode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int ArrayCopyNode::get_count(PhaseGVN *phase) const {
140140
// 3 or 4 elements) might lead to the same length input
141141
// (e.g. 2 double-words).
142142
assert(!ary_src->size()->is_con() || (get_length_if_constant(phase) >= 0) ||
143-
phase->is_IterGVN() || phase->C->inlining_incrementally() || StressReflectiveCode, "inconsistent");
143+
phase->is_IterGVN() || phase->C->inlining_incrementally() || StressReflectiveCode || UseNewCode, "inconsistent");
144144
if (ary_src->size()->is_con()) {
145145
return ary_src->size()->get_con();
146146
}

src/hotspot/share/opto/compile.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
13621362
} else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
13631363
// range is OK as-is.
13641364
tj = ta = TypeAryPtr::RANGE;
1365-
} else if( offset == oopDesc::klass_offset_in_bytes() ) {
1365+
} else if( !UseNewCode && offset == oopDesc::klass_offset_in_bytes() ) {
13661366
tj = TypeInstPtr::KLASS; // all klass loads look alike
13671367
ta = TypeAryPtr::RANGE; // generic ignored junk
13681368
ptr = TypePtr::BotPTR;
@@ -1524,7 +1524,8 @@ const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
15241524
offset = tj->offset();
15251525
assert( offset != Type::OffsetTop, "Offset has fallen from constant" );
15261526

1527-
assert( (offset != Type::OffsetBot && tj->base() != Type::AryPtr) ||
1527+
assert( UseNewCode ||
1528+
(offset != Type::OffsetBot && tj->base() != Type::AryPtr) ||
15281529
(offset == Type::OffsetBot && tj->base() == Type::AryPtr) ||
15291530
(offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) ||
15301531
(offset == Type::OffsetBot && tj == TypePtr::BOTTOM) ||
@@ -1676,7 +1677,10 @@ Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_cr
16761677
// Add a new alias type.
16771678
idx = _num_alias_types++;
16781679
_alias_types[idx]->Init(idx, flat);
1679-
if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);
1680+
if (flat == TypeInstPtr::KLASS) {
1681+
assert(!UseNewCode, "should not exist");
1682+
alias_type(idx)->set_rewritable(false);
1683+
}
16801684
if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);
16811685
if (flat->isa_instptr()) {
16821686
if (flat->offset() == java_lang_Class::klass_offset()

src/hotspot/share/opto/doCall.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,12 @@ void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
942942
// Get the exception oop klass from its header
943943
Node* ex_klass_node = nullptr;
944944
if (has_exception_handler() && !ex_type->klass_is_exact()) {
945-
Node* p = basic_plus_adr( ex_node, ex_node, oopDesc::klass_offset_in_bytes());
946-
ex_klass_node = _gvn.transform(LoadKlassNode::make(_gvn, nullptr, immutable_memory(), p, TypeInstPtr::KLASS, TypeInstKlassPtr::OBJECT));
945+
if (UseNewCode) {
946+
ex_klass_node = _gvn.transform(LoadKlassNode::make(_gvn, nullptr, immutable_memory(), ex_node, TypeInstPtr::BOTTOM, TypeInstKlassPtr::OBJECT));
947+
} else {
948+
Node* p = basic_plus_adr( ex_node, ex_node, oopDesc::klass_offset_in_bytes());
949+
ex_klass_node = _gvn.transform(LoadKlassNode::make(_gvn, nullptr, immutable_memory(), p, TypeInstPtr::KLASS, TypeInstKlassPtr::OBJECT));
950+
}
947951

948952
// Compute the exception klass a little more cleverly.
949953
// Obvious solution is to simple do a LoadKlass from the 'ex_node'.
@@ -960,8 +964,13 @@ void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
960964
ex_klass_node->init_req(i, top());
961965
continue;
962966
}
963-
Node* p = basic_plus_adr(ex_in, ex_in, oopDesc::klass_offset_in_bytes());
964-
Node* k = _gvn.transform( LoadKlassNode::make(_gvn, nullptr, immutable_memory(), p, TypeInstPtr::KLASS, TypeInstKlassPtr::OBJECT));
967+
Node* k;
968+
if (UseNewCode) {
969+
k = _gvn.transform( LoadKlassNode::make(_gvn, nullptr, immutable_memory(), ex_in, TypeInstPtr::BOTTOM, TypeInstKlassPtr::OBJECT));
970+
} else {
971+
Node* p = basic_plus_adr(ex_in, ex_in, oopDesc::klass_offset_in_bytes());
972+
k = _gvn.transform( LoadKlassNode::make(_gvn, nullptr, immutable_memory(), p, TypeInstPtr::KLASS, TypeInstKlassPtr::OBJECT));
973+
}
965974
ex_klass_node->init_req( i, k );
966975
}
967976
ex_klass_node = _gvn.transform(ex_klass_node);

src/hotspot/share/opto/escape.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,7 +3385,7 @@ bool ConnectionGraph::is_oop_field(Node* n, int offset, bool* unsafe) {
33853385
bt = T_OBJECT;
33863386
}
33873387
}
3388-
} else if (offset != oopDesc::klass_offset_in_bytes()) {
3388+
} else if (UseNewCode || offset != oopDesc::klass_offset_in_bytes()) {
33893389
if (adr_type->isa_instptr()) {
33903390
ciField* field = _compile->alias_type(adr_type->isa_instptr())->field();
33913391
if (field != nullptr) {
@@ -4388,7 +4388,9 @@ void ConnectionGraph::split_unique_types(GrowableArray<Node *> &alloc_worklist,
43884388
// the header emitted during macro expansion wouldn't have
43894389
// correct memory state otherwise.
43904390
_compile->get_alias_index(tinst->add_offset(oopDesc::mark_offset_in_bytes()));
4391-
_compile->get_alias_index(tinst->add_offset(oopDesc::klass_offset_in_bytes()));
4391+
if (!UseNewCode) {
4392+
_compile->get_alias_index(tinst->add_offset(oopDesc::klass_offset_in_bytes()));
4393+
}
43924394
if (alloc->is_Allocate() && (t->isa_instptr() || t->isa_aryptr())) {
43934395

43944396
// First, put on the worklist all Field edges from Connection Graph

src/hotspot/share/opto/graphKit.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,9 @@ Node* GraphKit::load_object_klass(Node* obj) {
11981198
// Special-case a fresh allocation to avoid building nodes:
11991199
Node* akls = AllocateNode::Ideal_klass(obj, &_gvn);
12001200
if (akls != nullptr) return akls;
1201+
if (UseNewCode) {
1202+
return _gvn.transform(LoadKlassNode::make(_gvn, nullptr, immutable_memory(), obj, TypeInstPtr::BOTTOM, TypeInstKlassPtr::OBJECT));
1203+
}
12011204
Node* k_adr = basic_plus_adr(obj, oopDesc::klass_offset_in_bytes());
12021205
return _gvn.transform(LoadKlassNode::make(_gvn, nullptr, immutable_memory(), k_adr, TypeInstPtr::KLASS));
12031206
}
@@ -3661,7 +3664,9 @@ Node* GraphKit::set_output_for_allocation(AllocateNode* alloc,
36613664
// Add an edge in the MergeMem for the header fields so an access
36623665
// to one of those has correct memory state
36633666
set_memory(minit_out, C->get_alias_index(oop_type->add_offset(oopDesc::mark_offset_in_bytes())));
3664-
set_memory(minit_out, C->get_alias_index(oop_type->add_offset(oopDesc::klass_offset_in_bytes())));
3667+
if (!UseNewCode) {
3668+
set_memory(minit_out, C->get_alias_index(oop_type->add_offset(oopDesc::klass_offset_in_bytes())));
3669+
}
36653670
if (oop_type->isa_aryptr()) {
36663671
const TypePtr* telemref = oop_type->add_offset(Type::OffsetBot);
36673672
int elemidx = C->get_alias_index(telemref);

src/hotspot/share/opto/library_call.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,7 @@ bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, c
23952395
Compile::AliasType* alias_type = C->alias_type(adr_type);
23962396
assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
23972397

2398+
assert(!UseNewCode || alias_type->adr_type() != TypeInstPtr::KLASS, "should not exist");
23982399
if (alias_type->adr_type() == TypeInstPtr::KLASS ||
23992400
alias_type->adr_type() == TypeAryPtr::RANGE) {
24002401
set_map(old_map);

0 commit comments

Comments
 (0)