Skip to content

Commit

Permalink
fellow 8301997
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeihan committed Oct 18, 2023
1 parent 9ce5f59 commit 614b566
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 215 deletions.
92 changes: 15 additions & 77 deletions src/hotspot/cpu/riscv/interp_masm_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "oops/methodData.hpp"
#include "oops/resolvedFieldEntry.hpp"
#include "oops/resolvedIndyEntry.hpp"
#include "oops/resolvedMethodEntry.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/jvmtiThreadState.hpp"
#include "runtime/basicLock.hpp"
Expand Down Expand Up @@ -229,71 +230,6 @@ void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
}
}

// Return
// Rindex: index into constant pool
// Rcache: address of cache entry - ConstantPoolCache::base_offset()
//
// A caller must add ConstantPoolCache::base_offset() to Rcache to get
// the true address of the cache entry.
//
void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
Register index,
int bcp_offset,
size_t index_size) {
assert_different_registers(cache, index);
assert_different_registers(cache, xcpool);
// register "cache" is trashed in next shadd, so lets use it as a temporary register
get_cache_index_at_bcp(index, cache, bcp_offset, index_size);
assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
// Convert from field index to ConstantPoolCacheEntry
// riscv already has the cache in xcpool so there is no need to
// install it in cache. Instead we pre-add the indexed offset to
// xcpool and return it in cache. All clients of this method need to
// be modified accordingly.
shadd(cache, index, xcpool, cache, 5);
}


void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
Register index,
Register bytecode,
int byte_no,
int bcp_offset,
size_t index_size) {
get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
// We use a 32-bit load here since the layout of 64-bit words on
// little-endian machines allow us that.
// n.b. unlike x86 cache already includes the index offset
la(bytecode, Address(cache,
ConstantPoolCache::base_offset() +
ConstantPoolCacheEntry::indices_offset()));
membar(MacroAssembler::AnyAny);
lwu(bytecode, bytecode);
membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
const int shift_count = (1 + byte_no) * BitsPerByte;
slli(bytecode, bytecode, XLEN - (shift_count + BitsPerByte));
srli(bytecode, bytecode, XLEN - BitsPerByte);
}

void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
Register tmp,
int bcp_offset,
size_t index_size) {
assert_different_registers(cache, tmp);
// register "cache" is trashed in next ld, so lets use it as a temporary register
get_cache_index_at_bcp(tmp, cache, bcp_offset, index_size);
assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
// Convert from field index to ConstantPoolCacheEntry index
// and from word offset to byte offset
assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord,
"else change next line");
ld(cache, Address(fp, frame::interpreter_frame_cache_offset * wordSize));
// skip past the header
add(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
// construct pointer to cache entry
shadd(cache, tmp, cache, tmp, 2 + LogBytesPerWord);
}

// Load object from cpool->resolved_references(index)
void InterpreterMacroAssembler::load_resolved_reference_at_index(
Register result, Register index, Register tmp) {
Expand All @@ -319,18 +255,6 @@ void InterpreterMacroAssembler::load_resolved_klass_at_offset(
ld(klass, Address(klass, Array<Klass*>::base_offset_in_bytes()));
}

void InterpreterMacroAssembler::load_resolved_method_at_index(int byte_no,
Register method,
Register cache) {
const int method_offset = in_bytes(
ConstantPoolCache::base_offset() +
((byte_no == TemplateTable::f2_byte)
? ConstantPoolCacheEntry::f2_offset()
: ConstantPoolCacheEntry::f1_offset()));

ld(method, Address(cache, method_offset)); // get f1 Method*
}

// Generate a subtype check: branch to ok_is_subtype if sub_klass is a
// subtype of super_klass.
//
Expand Down Expand Up @@ -1992,6 +1916,20 @@ void InterpreterMacroAssembler::get_method_counters(Register method,
bind(has_counters);
}

void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) {
// Get index out of bytecode pointer
get_cache_index_at_bcp(index, cache ,bcp_offset, sizeof(u2));
mv(cache, sizeof(ResolvedMethodEntry));
mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedMethodEntry)

// Get address of field entries array
ld(cache, Address(xcpool, ConstantPoolCache::method_entries_offset()));
add(cache, cache, Array<ResolvedMethodEntry>::base_offset_in_bytes());
add(cache, cache, index);
la(cache, Address(cache, 0));
}


#ifdef ASSERT
void InterpreterMacroAssembler::verify_access_flags(Register access_flags, uint32_t flag,
const char* msg, bool stop_by_hit) {
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/riscv/interp_masm_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class InterpreterMacroAssembler: public MacroAssembler {

void load_resolved_indy_entry(Register cache, Register index);
void load_field_entry(Register cache, Register index, int bcp_offset = 1);
void load_method_entry(Register cache, Register index, int bcp_offset = 1);

#ifdef ASSERT
void verify_access_flags(Register access_flags, uint32_t flag,
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/cpu/riscv/templateInterpreterGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "oops/methodData.hpp"
#include "oops/oop.inline.hpp"
#include "oops/resolvedIndyEntry.hpp"
#include "oops/resolvedMethodEntry.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/jvmtiThreadState.hpp"
#include "runtime/arguments.hpp"
Expand Down Expand Up @@ -454,9 +455,9 @@ address TemplateInterpreterGenerator::generate_return_entry_for(TosState state,
__ shadd(esp, cache, esp, t0, 3);
} else {
// Pop N words from the stack
__ get_cache_and_index_at_bcp(cache, index, 1, index_size);
__ ld(cache, Address(cache, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
__ andi(cache, cache, ConstantPoolCacheEntry::parameter_size_mask);
assert(index_size == sizeof(u2), "Can only be u2");
__ load_method_entry(cache, index);
__ load_unsigned_short(cache, Address(cache, in_bytes(ResolvedMethodEntry::num_parameters_offset())));

__ shadd(esp, cache, esp, t0, 3);
}
Expand Down
Loading

0 comments on commit 614b566

Please sign in to comment.