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

Backport-of: 397d94831033e91c7a849774bf4e80d8f1c8ec66
  • Loading branch information
MBaesken committed May 21, 2024
1 parent f539469 commit 4541823
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,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(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
Events::log_memprotect(nullptr, "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
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 @@ -1572,7 +1572,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(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
Events::log_memprotect(nullptr, "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 @@ -1669,7 +1669,7 @@ bool os::numa_get_group_ids_for_range(const void** addresses, int* lgrp_ids, siz
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(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with PROT_NONE", p2i(addr), p2i(addr+size));
Events::log_memprotect(nullptr, "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 @@ -1739,7 +1739,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::vm_page_size());
Events::log(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
Events::log_memprotect(nullptr, "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 @@ -3639,7 +3639,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(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
Events::log_memprotect(nullptr, "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 @@ -1448,7 +1448,7 @@ void nmethod::purge(bool free_code_cache_data) {
MutexLocker ml(CodeCache_lock, Mutex::_no_safepoint_check_flag);

// completely deallocate this method
Events::log(Thread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this));
Events::log_nmethod_flush(Thread::current(), "flushing %s nmethod " INTPTR_FORMAT, is_osr_method() ? "osr" : "", p2i(this));
log_debug(codecache)("*flushing %s nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT
"/Free CodeCache:" SIZE_FORMAT "Kb",
is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(),
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, 2023, 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 @@ -36,6 +36,8 @@

EventLog* Events::_logs = nullptr;
StringEventLog* Events::_messages = nullptr;
StringEventLog* Events::_memprotect_messages = nullptr;
StringEventLog* Events::_nmethod_flush_messages = nullptr;
StringEventLog* Events::_vm_operations = nullptr;
StringEventLog* Events::_zgc_phase_switch = nullptr;
ExceptionsEventLog* Events::_exceptions = nullptr;
Expand Down Expand Up @@ -96,6 +98,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");
_zgc_phase_switch = new StringEventLog("ZGC Phase Switch", "zgcps");
_exceptions = new ExceptionsEventLog("Internal exceptions", "exc");
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, 2023, 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 @@ -259,6 +265,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);

static void log_zgc_phase_switch(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);
Expand Down Expand Up @@ -290,6 +300,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 != nullptr) {
va_list ap;
Expand Down

1 comment on commit 4541823

@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.