RFR: 8269476: Skip nmethod entry barrier if there is no oops in the jit code [v2]
Zhengyu Gu
zgu at openjdk.java.net
Mon Jun 28 19:47:10 UTC 2021
On Mon, 28 Jun 2021 11:21:53 GMT, 王超 <github.com+25214855+casparcwang at openjdk.org> wrote:
>> Lots of c1 and c2 jit methods do not contain any oop, so the nmethod entry barrier can be skipped.
>>
>> 1, c1 jit code will patch oops or Klass into the nmethod, so the entry barrier cannot directly be eliminated, current implementation uses a jump instruction to replace the jcc instruction. If the jit code is patched to contain oops, the entry barrier is patched back to the jcc instruction.
>>
>> 2, only the jit code of core library methods do not contain any oops.
>>
>> 3, currently only support zgc
>
> 王超 has updated the pull request incrementally with one additional commit since the last revision:
>
> Only implement in x86
Following code should help you to find out if the method contains any relocatable oops, so you can generate nmethod entry barrier accordingly ...
`diff --git a/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp b/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp`
`index fb4e3f54400..4c2686d27db 100644`
`--- a/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp`
`+++ b/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp`
`@@ -1803,6 +1803,9 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,`
` // -2 because return address is already present and so is saved rbp
` __ subptr(rsp, stack_size - 2*wordSize);`
`+ bool can_elide_nmethod_barrier = !nmethod::has_relocatable_oops(masm->code());`
`+ // This nmethod has no relocatable oop, can elide the barrier.`
`+ // However, we still need to generate something to not crash nmethod arm/disarm calls.`
` BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();`
` bs->nmethod_entry_barrier(masm);`
`diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp`
`index e2b27e5f4f0..99c7276e952 100644`
`--- a/src/hotspot/share/code/nmethod.cpp`
`+++ b/src/hotspot/share/code/nmethod.cpp`
`@@ -879,6 +879,19 @@ void nmethod::log_identity(xmlStream* log) const {`
` #endif`
` }`
`+bool nmethod::has_relocatable_oops(const CodeBuffer* cb) {`
`+ for (int n = (int) CodeBuffer::SECT_FIRST; n < (int)CodeBuffer::SECT_LIMIT; n++) {`
`+ const CodeSection* cs = cb->code_section(n);`
`+ RelocIterator iter(const_cast<CodeSection*>(cs));`
`+ while (iter.next()) {`
`+ if (iter.type() == relocInfo::oop_type) {`
`+ // Found relocatable oop`
`+ return true;`
`+ }`
`+ }`
`+ }`
`+ return false;`
`+}`
`#define LOG_OFFSET(log, name) `
` if (p2i(name##_end()) - p2i(name##_begin())) `
`diff --git a/src/hotspot/share/code/nmethod.hpp b/src/hotspot/share/code/nmethod.hpp`
`index 893f28863a6..1504ae9bc51 100644`
`--- a/src/hotspot/share/code/nmethod.hpp`
`+++ b/src/hotspot/share/code/nmethod.hpp`
`@@ -555,6 +555,8 @@ public:`
` // Verify calls to dead methods have been cleaned.`
` void verify_clean_inline_caches();`
`+ static bool has_relocatable_oops(const CodeBuffer* cb);`
`+`
` // unlink and deallocate this nmethod`
` // Only NMethodSweeper class is expected to use this. NMethodSweeper is not`
` // expected to use any other private methods/data in this class.`
-------------
PR: https://git.openjdk.java.net/jdk/pull/4610
More information about the hotspot-dev
mailing list