Skip to content

Commit 7ba5130

Browse files
committed
Implement eden_allocate
1 parent 0c424a3 commit 7ba5130

File tree

3 files changed

+106
-5
lines changed

3 files changed

+106
-5
lines changed

mmtk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ lto = true
1717
[package.metadata.openjdk]
1818
# Our CI matches the following line and extract mmtk/openjdk. If this line is updated, please check ci yaml files and make sure it works.
1919
openjdk_repo = "https://github.com/caizixian/jdk-mmtk.git"
20-
openjdk_version = "0c5806b797026a902718eb83588b6adf181e3d80"
20+
openjdk_version = "b369f54e36e79d5cc3e67424209be3bbae60d644"
2121

2222
[dependencies]
2323
libc = "0.2"

openjdk/cpu/riscv/mmtkBarrierSetAssembler_riscv.cpp

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,102 @@
3535

3636
#define __ masm->
3737

38-
void MMTkBarrierSetAssembler::eden_allocate(MacroAssembler* masm, Register thread, Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Label& slow_case) {
39-
// assert(false, "Not implemented");
40-
__ j(slow_case); // just jal with x0/zr
38+
void MMTkBarrierSetAssembler::eden_allocate(MacroAssembler* masm, Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register tmp1, Register tmp2, Label& slow_case, bool is_far) {
39+
// XXX tmp1 seems to be -1
40+
assert_different_registers(obj, tmp2);
41+
assert_different_registers(obj, var_size_in_bytes);
42+
assert(tmp2->is_valid(), "need temp reg");
43+
44+
if (!MMTK_ENABLE_ALLOCATION_FASTPATH) {
45+
__ j(slow_case);
46+
} else {
47+
// printf("generating mmtk allocation fast path\n");
48+
// MMTk size check. If the alloc size is larger than the allowed max size for non los,
49+
// we jump to slow path and allodate with LOS in slowpath.
50+
// Note that OpenJDK has a slow path check. Search for layout_helper_needs_slow_path and FastAllocateSizeLimit.
51+
// I tried to set FastAllocateSizeLimit in MMTkHeap::initialize(). But there are still large objects allocated into the
52+
// default space.
53+
assert(MMTkMutatorContext::max_non_los_default_alloc_bytes != 0, "max_non_los_default_alloc_bytes hasn't been initialized");
54+
size_t max_non_los_bytes = MMTkMutatorContext::max_non_los_default_alloc_bytes;
55+
size_t extra_header = 0;
56+
// fastpath, we only use default allocator
57+
Allocator allocator = AllocatorDefault;
58+
// We need to figure out which allocator we are using by querying MMTk.
59+
AllocatorSelector selector = get_allocator_mapping(allocator);
60+
61+
// XXX riscv: disallow markcompact and global alloc bit for now
62+
assert(selector.tag != TAG_MARK_COMPACT, "mark compact not supported for now");
63+
64+
if (var_size_in_bytes == noreg) {
65+
// constant alloc size. If it is larger than max_non_los_bytes, we directly go to slowpath.
66+
if ((size_t)con_size_in_bytes > max_non_los_bytes - extra_header) {
67+
__ j(slow_case);
68+
return;
69+
}
70+
} else {
71+
// var alloc size. We compare with max_non_los_bytes and conditionally jump to slowpath.
72+
// printf("max_non_los_bytes %lu\n",max_non_los_bytes);
73+
__ li(t0, max_non_los_bytes - extra_header);
74+
__ bgeu(var_size_in_bytes, t0, slow_case, is_far);
75+
}
76+
77+
if (selector.tag == TAG_MALLOC || selector.tag == TAG_LARGE_OBJECT) {
78+
__ j(slow_case);
79+
return;
80+
}
81+
82+
// Calculate offsets of TLAB top and end
83+
Address cursor, limit;
84+
MMTkAllocatorOffsets alloc_offsets = get_tlab_top_and_end_offsets(selector);
85+
86+
cursor = Address(xthread, alloc_offsets.tlab_top_offset);
87+
limit = Address(xthread, alloc_offsets.tlab_end_offset);
88+
89+
// XXX disassembly
90+
// 0x7fffe85597e0: ld a0,688(s7)
91+
// 0x7fffe85597e4: add a1,a0,a3
92+
// 0x7fffe85597e8: bltu a1,a0,0x7fffe8559878
93+
// 0x7fffe85597ec: ld t0,696(s7)
94+
// 0x7fffe85597f0: bltu t0,a1,0x7fffe8559878
95+
// 0x7fffe85597f4: sd a1,688(s7)
96+
97+
// obj = load lab.cursor
98+
__ ld(obj, cursor);
99+
// end = obj + size
100+
Register end = tmp2;
101+
if (var_size_in_bytes == noreg) {
102+
__ la(end, Address(obj, con_size_in_bytes));
103+
} else {
104+
__ add(end, obj, var_size_in_bytes);
105+
}
106+
// slowpath if end < obj
107+
__ bltu(end, obj, slow_case, is_far);
108+
// slowpath if end > lab.limit
109+
__ ld(t0, limit);
110+
// XXX debug use, force slow path
111+
// __ bgtu(end, zr, slow_case, is_far);
112+
__ bgtu(end, t0, slow_case, is_far);
113+
// lab.cursor = end
114+
__ sd(end, cursor);
115+
116+
// recover var_size_in_bytes if necessary
117+
if (var_size_in_bytes == end) {
118+
__ sub(var_size_in_bytes, var_size_in_bytes, obj);
119+
}
120+
// if the above is removed, and the register holding the object size is
121+
// clobbered, operations that rely on the size, such as array copy will
122+
// crash
123+
124+
// XXX debug use, force segfault to disassemble in gdb
125+
// __ ld(t0, zr);
126+
127+
// XXX debug use, force double allocation
128+
// __ j(slow_case);
129+
130+
#ifdef MMTK_ENABLE_GLOBAL_ALLOC_BIT
131+
assert(false, "global alloc bit not supported");
132+
#endif
133+
}
41134
}
42135

43136
#undef __

openjdk/cpu/riscv/mmtkBarrierSetAssembler_riscv.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ class MMTkBarrierSetAssembler: public BarrierSetAssembler {
3030
virtual void generate_c1_write_barrier_runtime_stub(StubAssembler* sasm) const;
3131

3232
public:
33-
virtual void eden_allocate(MacroAssembler* masm, Register thread, Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Label& slow_case);
33+
virtual void eden_allocate(MacroAssembler* masm,
34+
Register obj, // result: pointer to object after successful allocation
35+
Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise
36+
int con_size_in_bytes, // object size in bytes if known at compile time
37+
Register tmp1, // temp register
38+
Register tmp2, // temp register
39+
Label& slow_case, // continuation point if fast allocation fails
40+
bool is_far = false
41+
) override;
3442
virtual void store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Address dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
3543
if (type == T_OBJECT || type == T_ARRAY) object_reference_write_pre(masm, decorators, dst, val, tmp1, tmp2);
3644
BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2, tmp3);

0 commit comments

Comments
 (0)