Unaligned memory access with JDK
Владимир Кемпик
vladimir.kempik at gmail.com
Thu Jul 28 20:50:00 UTC 2022
Hello
I was recently playing with a simple risc-v core running on an fpga and found the idk crashes on it.
It crashes with SIG_ILL : ILL_TRP, on a simple load from memory instruction.
So I figured the main issue is unaligned memory access MacroAssembler::stop() and that risc-v core was pretty simple and didn’t support unaligned memory access.
Here is what I found:
void MacroAssembler::stop(const char* msg) {
const char * msg1 = ((uint64_t)msg) & ~0x07 + 0x08;
BLOCK_COMMENT(msg1);
illegal_instruction(Assembler::csr::time);
emit_int64((uintptr_t)msg1);
}
and emit_64 is :
void emit_int64( int64_t x) { *((int64_t*) end()) = x; set_end(end() + sizeof(int64_t)); }
the problem is that the end() pointer is shared between emit_int64, emit_int32, emit_int8, etc, and non of them do care about natural memory alignment for processed types:
void emit_int32(int32_t x) {
address curr = end();
*((int32_t*) curr) = x;
set_end(curr + sizeof(int32_t));
}
void emit_int8(int8_t x1) {
address curr = end();
*((int8_t*) curr++) = x1;
set_end(curr);
}
So my question is - risc-v cores without unaligned memory access support - are they supported by risc-v openjdk port ?
More information about the riscv-port-dev
mailing list