RFR: 8299570: [JVMCI] Insufficient error handling when CodeBuffer is exhausted [v4]

Andrew Haley aph at openjdk.org
Wed Mar 8 13:15:15 UTC 2023


On Wed, 8 Mar 2023 11:09:44 GMT, Doug Simon <dnsimon at openjdk.org> wrote:

>> Maybe it would be nicer to get the `! far_branches` code path out of the way first, and return immediately.
>
> Something like this?
> 
> diff --git a/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp b/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
> index 88dc59f80d0..83ec182d2c7 100644
> --- a/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
> +++ b/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
> @@ -532,21 +532,22 @@ void NativeCallTrampolineStub::set_destination(address new_destination) {
>  void NativeCall::trampoline_jump(CodeBuffer &cbuf, address dest, JVMCI_TRAPS) {
>    MacroAssembler a(&cbuf);
>  
> -  if (a.far_branches()) {
> -    if (!is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
> -      address stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
> -      if (stub == nullptr) {
> -        JVMCI_ERROR("could not emit trampoline stub - code cache is full");
> -      }
> -      // The relocation is created while emitting the stub will ensure this
> -      // call instruction is subsequently patched to call the stub.
> -    } else {
> -      // Not sure how this can be happen but be defensive
> -      JVMCI_ERROR("single-use stub should not exist");
> -    }
> -  } else {
> +  if (!a.far_branches()) {
>      // If not using far branches, patch this call directly to dest.
>      set_destination(dest);
> +    return;
> +  }
> +
> +  if (!is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
> +    address stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
> +    if (stub == nullptr) {
> +      JVMCI_ERROR("could not emit trampoline stub - code cache is full");
> +    }
> +    // The relocation is created while emitting the stub will ensure this
> +    // call instruction is subsequently patched to call the stub.
> +  } else {
> +    // Not sure how this can be happen but be defensive
> +    JVMCI_ERROR("single-use stub should not exist");
>    }
>  }
>  #endif

Yes. Or maybe


// Generate a trampoline for a branch to dest.  If there's no need for a                                                                                                                              
// trampoline, simply patch the call directly to dest.                                                                                                                                                
void NativeCall::trampoline_jump(CodeBuffer &cbuf, address dest, JVMCI_TRAPS) {
  MacroAssembler a(&cbuf);

  if (! a.far_branches()) {
    // If not using far branches, patch this call directly to dest.                                                                                                                                   
    set_destination(dest);
  } else if (!is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
    // If we want far branches and there isn't a trampoline stub, emit one.                                                                                                                           
    address stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
    if (stub == nullptr) {
      JVMCI_ERROR("could not emit trampoline stub - code cache is full");
    }
    // The relocation is created while emitting the stub will ensure this                                                                                                                             
    // call instruction is subsequently patched to call the stub.                                                                                                                                     
  } else {
    // Not sure how this can be happen but be defensive                                                                                                                                               
    JVMCI_ERROR("single-use stub should not exist");
  }
}

-------------

PR: https://git.openjdk.org/jdk/pull/11945


More information about the hotspot-compiler-dev mailing list