Skip to content

Commit

Permalink
8329605: hs errfile generic events - move memory protections and nmet…
Browse files Browse the repository at this point in the history
…hod flushes to separate sections

Reviewed-by: mdoerr
Backport-of: 397d94831033e91c7a849774bf4e80d8f1c8ec66
  • Loading branch information
MBaesken committed Jun 26, 2024
1 parent 859dda1 commit b99923c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ static bool checked_mprotect(char* addr, size_t size, int prot) {
//
// See http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/mprotect.htm

Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
Events::log_memprotect(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
bool rc = ::mprotect(addr, size, prot) == 0 ? true : false;

if (!rc) {
Expand Down Expand Up @@ -2107,7 +2107,7 @@ static bool checked_mprotect(char* addr, size_t size, int prot) {
// A valid strategy is just to try again. This usually works. :-/

::usleep(1000);
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
Events::log_memprotect(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
if (::mprotect(addr, size, prot) == 0) {
const bool read_protected_2 =
(SafeFetch32((int*)addr, 0x12345678) == 0x12345678 &&
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
#if defined(__OpenBSD__)
// XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
Events::log_memprotect(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
if (::mprotect(addr, size, prot) == 0) {
return true;
}
Expand Down Expand Up @@ -1711,7 +1711,7 @@ char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info
bool os::pd_uncommit_memory(char* addr, size_t size, bool exec) {
#if defined(__OpenBSD__)
// XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with PROT_NONE", p2i(addr), p2i(addr+size));
Events::log_memprotect(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with PROT_NONE", p2i(addr), p2i(addr+size));
return ::mprotect(addr, size, PROT_NONE) == 0;
#elif defined(__APPLE__)
if (exec) {
Expand Down Expand Up @@ -1781,7 +1781,7 @@ static bool bsd_mprotect(char* addr, size_t size, int prot) {
assert(addr == bottom, "sanity check");

size = align_up(pointer_delta(addr, bottom, 1) + size, os::Bsd::page_size());
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
Events::log_memprotect(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
return ::mprotect(bottom, size, prot) == 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3589,7 +3589,7 @@ static bool linux_mprotect(char* addr, size_t size, int prot) {
#ifdef CAN_SHOW_REGISTERS_ON_ASSERT
if (addr != g_assert_poison)
#endif
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
Events::log_memprotect(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
return ::mprotect(bottom, size, prot) == 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/code/nmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ void nmethod::flush() {
assert_locked_or_safepoint(CodeCache_lock);

// completely deallocate this method
Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this));
Events::log_nmethod_flush(Thread::current(), "flushing %s nmethod " INTPTR_FORMAT, is_osr_method() ? "osr" : "", p2i(this));
if (PrintMethodFlushing) {
tty->print_cr("*flushing %s nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT
"/Free CodeCache:" SIZE_FORMAT "Kb",
Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/share/utilities/events.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, 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
Expand Down Expand Up @@ -35,6 +35,8 @@

EventLog* Events::_logs = NULL;
StringEventLog* Events::_messages = NULL;
StringEventLog* Events::_memprotect_messages = NULL;
StringEventLog* Events::_nmethod_flush_messages = NULL;
StringEventLog* Events::_vm_operations = NULL;
ExceptionsEventLog* Events::_exceptions = NULL;
StringEventLog* Events::_redefinitions = NULL;
Expand Down Expand Up @@ -94,6 +96,8 @@ void Events::print() {
void Events::init() {
if (LogEvents) {
_messages = new StringEventLog("Events", "events");
_nmethod_flush_messages = new StringEventLog("Nmethod flushes", "nmethodflushes");
_memprotect_messages = new StringEventLog("Memory protections", "memprotects");
_vm_operations = new StringEventLog("VM Operations", "vmops");
_exceptions = new ExceptionsEventLog("Internal exceptions", "exc");
_redefinitions = new StringEventLog("Classes redefined", "redef");
Expand Down
30 changes: 29 additions & 1 deletion src/hotspot/share/utilities/events.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, 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
Expand Down Expand Up @@ -220,6 +220,12 @@ class Events : AllStatic {
// A log for generic messages that aren't well categorized.
static StringEventLog* _messages;

// A log for memory protection related messages
static StringEventLog* _memprotect_messages;

// A log for nmethod flush operations
static StringEventLog* _nmethod_flush_messages;

// A log for VM Operations
static StringEventLog* _vm_operations;

Expand Down Expand Up @@ -256,6 +262,10 @@ class Events : AllStatic {
// Logs a generic message with timestamp and format as printf.
static void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);

static void log_memprotect(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);

static void log_nmethod_flush(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);

static void log_vm_operation(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);

// Log exception related message
Expand Down Expand Up @@ -285,6 +295,24 @@ inline void Events::log(Thread* thread, const char* format, ...) {
}
}

inline void Events::log_memprotect(Thread* thread, const char* format, ...) {
if (LogEvents && _memprotect_messages != nullptr) {
va_list ap;
va_start(ap, format);
_memprotect_messages->logv(thread, format, ap);
va_end(ap);
}
}

inline void Events::log_nmethod_flush(Thread* thread, const char* format, ...) {
if (LogEvents && _nmethod_flush_messages != nullptr) {
va_list ap;
va_start(ap, format);
_nmethod_flush_messages->logv(thread, format, ap);
va_end(ap);
}
}

inline void Events::log_vm_operation(Thread* thread, const char* format, ...) {
if (LogEvents && _vm_operations != NULL) {
va_list ap;
Expand Down

1 comment on commit b99923c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.