Skip to content

Commit 9da6dbd

Browse files
authored
Update (2023.09.22)
32609: LA port of 8308869: C2: use profile data in subtype checks when profile has more than one class 32608: LA port of 8292692: Move MethodCounters inline functions out of method.hpp
1 parent 1cc7139 commit 9da6dbd

File tree

5 files changed

+47
-114
lines changed

5 files changed

+47
-114
lines changed

src/hotspot/cpu/loongarch/c1_LIRAssembler_loongarch_64.cpp

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,8 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success,
12891289
assert(data->is_ReceiverTypeData(), "need ReceiverTypeData for type check");
12901290
}
12911291

1292-
Label profile_cast_success, profile_cast_failure;
1293-
Label *success_target = should_profile ? &profile_cast_success : success;
1294-
Label *failure_target = should_profile ? &profile_cast_failure : failure;
1292+
Label* success_target = success;
1293+
Label* failure_target = failure;
12951294

12961295
if (obj == k_RInfo) {
12971296
k_RInfo = dst;
@@ -1309,16 +1308,24 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success,
13091308

13101309
if (should_profile) {
13111310
Label not_null;
1312-
__ bnez(obj, not_null);
1313-
// Object is null; update MDO and exit
13141311
Register mdo = klass_RInfo;
13151312
__ mov_metadata(mdo, md->constant_encoding());
1313+
__ bnez(obj, not_null);
1314+
// Object is null; update MDO and exit
13161315
Address data_addr = Address(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()));
13171316
__ ld_bu(SCR2, data_addr);
13181317
__ ori(SCR2, SCR2, BitData::null_seen_byte_constant());
13191318
__ st_b(SCR2, data_addr);
13201319
__ b(*obj_is_null);
13211320
__ bind(not_null);
1321+
1322+
Label update_done;
1323+
Register recv = k_RInfo;
1324+
__ load_klass(recv, obj);
1325+
type_profile_helper(mdo, md, data, recv, &update_done);
1326+
Address counter_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()));
1327+
__ increment(counter_addr, DataLayout::counter_increment);
1328+
__ bind(update_done);
13221329
} else {
13231330
__ beqz(obj, *obj_is_null);
13241331
}
@@ -1378,23 +1385,6 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success,
13781385
// successful cast, fall through to profile or jump
13791386
}
13801387
}
1381-
if (should_profile) {
1382-
Register mdo = klass_RInfo, recv = k_RInfo;
1383-
__ bind(profile_cast_success);
1384-
__ mov_metadata(mdo, md->constant_encoding());
1385-
__ load_klass(recv, obj);
1386-
Label update_done;
1387-
type_profile_helper(mdo, md, data, recv, success);
1388-
__ b(*success);
1389-
1390-
__ bind(profile_cast_failure);
1391-
__ mov_metadata(mdo, md->constant_encoding());
1392-
Address counter_addr = Address(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()));
1393-
__ ld_d(SCR2, counter_addr);
1394-
__ addi_d(SCR2, SCR2, -DataLayout::counter_increment);
1395-
__ st_d(SCR2, counter_addr);
1396-
__ b(*failure);
1397-
}
13981388
__ b(*success);
13991389
}
14001390

@@ -1424,22 +1414,30 @@ void LIR_Assembler::emit_opTypeCheck(LIR_OpTypeCheck* op) {
14241414
assert(data != nullptr, "need data for type check");
14251415
assert(data->is_ReceiverTypeData(), "need ReceiverTypeData for type check");
14261416
}
1427-
Label profile_cast_success, profile_cast_failure, done;
1428-
Label *success_target = should_profile ? &profile_cast_success : &done;
1429-
Label *failure_target = should_profile ? &profile_cast_failure : stub->entry();
1417+
Label done;
1418+
Label* success_target = &done;
1419+
Label* failure_target = stub->entry();
14301420

14311421
if (should_profile) {
14321422
Label not_null;
1433-
__ bnez(value, not_null);
1434-
// Object is null; update MDO and exit
14351423
Register mdo = klass_RInfo;
14361424
__ mov_metadata(mdo, md->constant_encoding());
1425+
__ bnez(value, not_null);
1426+
// Object is null; update MDO and exit
14371427
Address data_addr = Address(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()));
14381428
__ ld_bu(SCR2, data_addr);
14391429
__ ori(SCR2, SCR2, BitData::null_seen_byte_constant());
14401430
__ st_b(SCR2, data_addr);
14411431
__ b(done);
14421432
__ bind(not_null);
1433+
1434+
Label update_done;
1435+
Register recv = k_RInfo;
1436+
__ load_klass(recv, value);
1437+
type_profile_helper(mdo, md, data, recv, &update_done);
1438+
Address counter_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()));
1439+
__ increment(counter_addr, DataLayout::counter_increment);
1440+
__ bind(update_done);
14431441
} else {
14441442
__ beqz(value, done);
14451443
}
@@ -1464,25 +1462,6 @@ void LIR_Assembler::emit_opTypeCheck(LIR_OpTypeCheck* op) {
14641462
__ beqz(k_RInfo, *failure_target);
14651463
// fall through to the success case
14661464

1467-
if (should_profile) {
1468-
Register mdo = klass_RInfo, recv = k_RInfo;
1469-
__ bind(profile_cast_success);
1470-
__ mov_metadata(mdo, md->constant_encoding());
1471-
__ load_klass(recv, value);
1472-
Label update_done;
1473-
type_profile_helper(mdo, md, data, recv, &done);
1474-
__ b(done);
1475-
1476-
__ bind(profile_cast_failure);
1477-
__ mov_metadata(mdo, md->constant_encoding());
1478-
Address counter_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()));
1479-
__ lea(SCR2, counter_addr);
1480-
__ ld_d(SCR1, Address(SCR2));
1481-
__ addi_d(SCR1, SCR1, -DataLayout::counter_increment);
1482-
__ st_d(SCR1, Address(SCR2));
1483-
__ b(*stub->entry());
1484-
}
1485-
14861465
__ bind(done);
14871466
} else if (code == lir_checkcast) {
14881467
Register obj = op->object()->as_register();

src/hotspot/cpu/loongarch/interp_masm_loongarch.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,14 @@ class InterpreterMacroAssembler: public MacroAssembler {
225225
Label& not_equal_continue);
226226

227227
void record_klass_in_profile(Register receiver, Register mdp,
228-
Register reg2, bool is_virtual_call);
228+
Register reg2);
229229
void record_klass_in_profile_helper(Register receiver, Register mdp,
230230
Register reg2, int start_row,
231-
Label& done, bool is_virtual_call);
232-
231+
Label& done);
233232
void record_item_in_profile_helper(Register item, Register mdp,
234233
Register reg2, int start_row, Label& done, int total_rows,
235-
OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn,
236-
int non_profiled_offset);
234+
OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn);
235+
237236
void update_mdp_by_offset(Register mdp_in, int offset_of_offset);
238237
void update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp);
239238
void update_mdp_by_constant(Register mdp_in, int constant);

src/hotspot/cpu/loongarch/interp_masm_loongarch_64.cpp

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@ void InterpreterMacroAssembler::gen_subtype_check( Register Rsup_klass, Register
405405

406406
// Do the check.
407407
check_klass_subtype(Rsub_klass, Rsup_klass, T1, ok_is_subtype); // blows T1
408-
409-
// Profile the failure of the check.
410-
profile_typecheck_failed(T4); // blows T4
411-
412408
}
413409

414410

@@ -1252,7 +1248,7 @@ void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
12521248
}
12531249

12541250
// Record the receiver type.
1255-
record_klass_in_profile(receiver, mdp, reg2, true);
1251+
record_klass_in_profile(receiver, mdp, reg2);
12561252
bind(skip_receiver_profile);
12571253

12581254
// The method data pointer needs to be updated to reflect the new target.
@@ -1277,36 +1273,18 @@ void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
12771273
void InterpreterMacroAssembler::record_klass_in_profile_helper(
12781274
Register receiver, Register mdp,
12791275
Register reg2, int start_row,
1280-
Label& done, bool is_virtual_call) {
1276+
Label& done) {
12811277
if (TypeProfileWidth == 0) {
1282-
if (is_virtual_call) {
1283-
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1284-
}
1285-
#if INCLUDE_JVMCI
1286-
else if (EnableJVMCI) {
1287-
increment_mdp_data_at(mdp, in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset()));
1288-
}
1289-
#endif // INCLUDE_JVMCI
1278+
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
12901279
} else {
1291-
int non_profiled_offset = -1;
1292-
if (is_virtual_call) {
1293-
non_profiled_offset = in_bytes(CounterData::count_offset());
1294-
}
1295-
#if INCLUDE_JVMCI
1296-
else if (EnableJVMCI) {
1297-
non_profiled_offset = in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset());
1298-
}
1299-
#endif // INCLUDE_JVMCI
1300-
13011280
record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1302-
&VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset, non_profiled_offset);
1281+
&VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
13031282
}
13041283
}
13051284

13061285
void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp,
13071286
Register reg2, int start_row, Label& done, int total_rows,
1308-
OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn,
1309-
int non_profiled_offset) {
1287+
OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn) {
13101288
int last_row = total_rows - 1;
13111289
assert(start_row <= last_row, "must be work left to do");
13121290
// Test this row for both the item and for null.
@@ -1337,24 +1315,20 @@ void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Reg
13371315
// Failed the equality check on item[n]... Test for null.
13381316
if (start_row == last_row) {
13391317
// The only thing left to do is handle the null case.
1340-
if (non_profiled_offset >= 0) {
1341-
beqz(reg2, found_null);
1342-
// Item did not match any saved item and there is no empty row for it.
1343-
// Increment total counter to indicate polymorphic case.
1344-
increment_mdp_data_at(mdp, non_profiled_offset);
1345-
b(done);
1346-
bind(found_null);
1347-
} else {
1348-
bnez(reg2, done);
1349-
}
1318+
beqz(reg2, found_null);
1319+
// Item did not match any saved item and there is no empty row for it.
1320+
// Increment total counter to indicate polymorphic case.
1321+
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1322+
b(done);
1323+
bind(found_null);
13501324
break;
13511325
}
13521326
// Since null is rare, make it be the branch-taken case.
13531327
beqz(reg2, found_null);
13541328

13551329
// Put all the "Case 3" tests here.
13561330
record_item_in_profile_helper(item, mdp, reg2, start_row + 1, done, total_rows,
1357-
item_offset_fn, item_count_offset_fn, non_profiled_offset);
1331+
item_offset_fn, item_count_offset_fn);
13581332

13591333
// Found a null. Keep searching for a matching item,
13601334
// but remember that this is an empty (unused) slot.
@@ -1401,12 +1375,11 @@ void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Reg
14011375
// done:
14021376

14031377
void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1404-
Register mdp, Register reg2,
1405-
bool is_virtual_call) {
1378+
Register mdp, Register reg2) {
14061379
assert(ProfileInterpreter, "must be profiling");
14071380
Label done;
14081381

1409-
record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1382+
record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
14101383

14111384
bind (done);
14121385
}
@@ -1469,26 +1442,6 @@ void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
14691442
}
14701443
}
14711444

1472-
1473-
void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1474-
if (ProfileInterpreter && TypeProfileCasts) {
1475-
Label profile_continue;
1476-
1477-
// If no method data exists, go to profile_continue.
1478-
test_method_data_pointer(mdp, profile_continue);
1479-
1480-
int count_offset = in_bytes(CounterData::count_offset());
1481-
// Back up the address, since we have already bumped the mdp.
1482-
count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1483-
1484-
// *Decrement* the counter. We expect to see zero or small negatives.
1485-
increment_mdp_data_at(mdp, count_offset, true);
1486-
1487-
bind (profile_continue);
1488-
}
1489-
}
1490-
1491-
14921445
void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
14931446
if (ProfileInterpreter) {
14941447
Label profile_continue;
@@ -1502,7 +1455,7 @@ void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass,
15021455
mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
15031456

15041457
// Record the object type.
1505-
record_klass_in_profile(klass, mdp, reg2, false);
1458+
record_klass_in_profile(klass, mdp, reg2);
15061459
}
15071460
update_mdp_by_constant(mdp, mdp_delta);
15081461

src/hotspot/cpu/loongarch/templateInterpreterGenerator_loongarch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
#include "interpreter/templateInterpreterGenerator.hpp"
3535
#include "interpreter/templateTable.hpp"
3636
#include "oops/arrayOop.hpp"
37-
#include "oops/methodData.hpp"
3837
#include "oops/method.hpp"
38+
#include "oops/methodCounters.hpp"
39+
#include "oops/methodData.hpp"
3940
#include "oops/oop.inline.hpp"
4041
#include "oops/resolvedIndyEntry.hpp"
4142
#include "prims/jvmtiExport.hpp"

src/hotspot/cpu/loongarch/templateTable_loongarch_64.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "gc/shared/collectedHeap.hpp"
3333
#include "memory/universe.hpp"
3434
#include "oops/klass.inline.hpp"
35+
#include "oops/methodCounters.hpp"
3536
#include "oops/methodData.hpp"
3637
#include "oops/objArrayKlass.hpp"
3738
#include "oops/oop.inline.hpp"

0 commit comments

Comments
 (0)