From ed0200ad98eb666dc8b67e9afd5c788075056b9a Mon Sep 17 00:00:00 2001 From: Ekaterina Vergizova Date: Tue, 2 Aug 2022 11:52:38 +0000 Subject: [PATCH] 8280684: JfrRecorderService failes with guarantee(num_written > 0) when no space left on device. Reviewed-by: yan Backport-of: 9471f24ca191832669a13e5a1ea73f7097a25927 --- src/hotspot/share/jfr/jni/jfrJavaSupport.cpp | 12 +++++++----- src/hotspot/share/jfr/jni/jfrJavaSupport.hpp | 3 ++- .../share/jfr/writers/jfrStreamWriterHost.inline.hpp | 4 ++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/jfr/jni/jfrJavaSupport.cpp b/src/hotspot/share/jfr/jni/jfrJavaSupport.cpp index 79a959872e9..ae2b03015d2 100644 --- a/src/hotspot/share/jfr/jni/jfrJavaSupport.cpp +++ b/src/hotspot/share/jfr/jni/jfrJavaSupport.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -547,14 +547,16 @@ void JfrJavaSupport::throw_runtime_exception(const char* message, TRAPS) { void JfrJavaSupport::abort(jstring errorMsg, Thread* t) { DEBUG_ONLY(check_java_thread_in_vm(t)); - ResourceMark rm(t); - const char* const error_msg = c_str(errorMsg, t); + abort(c_str(errorMsg, t)); +} + +void JfrJavaSupport::abort(const char* error_msg, bool dump_core /* true */) { if (error_msg != NULL) { - log_error(jfr, system)("%s",error_msg); + log_error(jfr, system)("%s", error_msg); } log_error(jfr, system)("%s", "An irrecoverable error in Jfr. Shutting down VM..."); - vm_abort(); + vm_abort(dump_core); } JfrJavaSupport::CAUSE JfrJavaSupport::_cause = JfrJavaSupport::VM_ERROR; diff --git a/src/hotspot/share/jfr/jni/jfrJavaSupport.hpp b/src/hotspot/share/jfr/jni/jfrJavaSupport.hpp index ce1ca7341ee..8024da90ef4 100644 --- a/src/hotspot/share/jfr/jni/jfrJavaSupport.hpp +++ b/src/hotspot/share/jfr/jni/jfrJavaSupport.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -100,6 +100,7 @@ class JfrJavaSupport : public AllStatic { // critical static void abort(jstring errorMsg, TRAPS); + static void abort(const char* error_msg, bool dump_core = true); static void uncaught_exception(jthrowable throwable, Thread* t); // asserts diff --git a/src/hotspot/share/jfr/writers/jfrStreamWriterHost.inline.hpp b/src/hotspot/share/jfr/writers/jfrStreamWriterHost.inline.hpp index bde8fa28689..f8900a13b4d 100644 --- a/src/hotspot/share/jfr/writers/jfrStreamWriterHost.inline.hpp +++ b/src/hotspot/share/jfr/writers/jfrStreamWriterHost.inline.hpp @@ -25,6 +25,7 @@ #ifndef SHARE_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP #define SHARE_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP +#include "jfr/jni/jfrJavaSupport.hpp" #include "jfr/writers/jfrStreamWriterHost.hpp" #include "runtime/os.hpp" @@ -76,6 +77,9 @@ inline void StreamWriterHost::write_bytes(const u1* buf, intptr_t l while (len > 0) { const unsigned int nBytes = len > INT_MAX ? INT_MAX : (unsigned int)len; const ssize_t num_written = (ssize_t)os::write(_fd, buf, nBytes); + if (errno == ENOSPC) { + JfrJavaSupport::abort("Failed to write to jfr stream because no space left on device", false); + } guarantee(num_written > 0, "Nothing got written, or os::write() failed"); _stream_pos += num_written; len -= num_written;