Skip to content

Commit

Permalink
8318636: Add jcmd to print annotated process memory map
Browse files Browse the repository at this point in the history
Reviewed-by: jsjolen, gziemski
  • Loading branch information
tstuefe committed Nov 13, 2023
1 parent e035637 commit 6f863b2
Show file tree
Hide file tree
Showing 9 changed files with 792 additions and 1 deletion.
84 changes: 84 additions & 0 deletions src/hotspot/os/linux/memMapPrinter_linux.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, Red Hat, Inc. and/or its affiliates.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#include "precompiled.hpp"

#include "runtime/os.hpp"
#include "nmt/memMapPrinter.hpp"
#include "utilities/globalDefinitions.hpp"
#include <limits.h>

struct ProcMapsInfo {
void* from = 0;
void* to = 0;
char prot[20 + 1];
char offset[20 + 1];
char dev[20 + 1];
char inode[20 + 1];
char filename[1024 + 1];

bool scan_proc_maps_line(const char* line) {
prot[0] = offset[0] = dev[0] = inode[0] = filename[0] = '\0';
const int items_read = ::sscanf(line, "%p-%p %20s %20s %20s %20s %1024s",
&from, &to, prot, offset, dev, inode, filename);
return items_read >= 2; // need at least from and to
}
};

class LinuxMappingPrintInformation : public MappingPrintInformation {
const ProcMapsInfo _info;
public:

LinuxMappingPrintInformation(const void* from, const void* to, const ProcMapsInfo* info) :
MappingPrintInformation(from, to), _info(*info) {}

void print_OS_specific_details(outputStream* st) const override {
st->print("%s %s ", _info.prot, _info.offset);
}

const char* filename() const override { return _info.filename; }
};

void MemMapPrinter::pd_print_header(outputStream* st) {
st->print_cr("size prot offset What");
}

void MemMapPrinter::pd_iterate_all_mappings(MappingPrintClosure& closure) {
FILE* f = os::fopen("/proc/self/maps", "r");
if (f == nullptr) {
return;
}
constexpr size_t linesize = sizeof(ProcMapsInfo);
char line[linesize];
while (fgets(line, sizeof(line), f) == line) {
line[sizeof(line) - 1] = '\0';
ProcMapsInfo info;
if (info.scan_proc_maps_line(line)) {
LinuxMappingPrintInformation mapinfo(info.from, info.to, &info);
closure.do_it(&mapinfo);
}
}
::fclose(f);
}
3 changes: 2 additions & 1 deletion src/hotspot/share/logging/logAsyncWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class AsyncLogWriter : public NonJavaThread {
NonJavaThread::pre_run();
log_debug(logging, thread)("starting AsyncLog Thread tid = " INTX_FORMAT, os::current_thread_id());
}
const char* name() const override { return "AsyncLog Thread"; }
const char* type_name() const override { return "AsyncLogWriter"; }
void print_on(outputStream* st) const override {
st->print("\"%s\" ", name());
Expand All @@ -203,6 +202,8 @@ class AsyncLogWriter : public NonJavaThread {
static AsyncLogWriter* instance();
static void initialize();
static void flush();

const char* name() const override { return "AsyncLog Thread"; }
};

#endif // SHARE_LOGGING_LOGASYNCWRITER_HPP
54 changes: 54 additions & 0 deletions src/hotspot/share/nmt/memFlagBitmap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#ifndef SHARE_NMT_MEMFLAGBITMAP_HPP
#define SHARE_NMT_MEMFLAGBITMAP_HPP

#include "memory/allocation.hpp" // for mt_number_of_types
#include "utilities/globalDefinitions.hpp"

class MemFlagBitmap {
uint32_t _v;
STATIC_ASSERT(sizeof(_v) * BitsPerByte >= mt_number_of_types);

public:
MemFlagBitmap(uint32_t v = 0) : _v(v) {}
MemFlagBitmap(const MemFlagBitmap& o) : _v(o._v) {}

uint32_t raw_value() const { return _v; }

void set_flag(MEMFLAGS f) {
const int bitno = (int)f;
_v |= nth_bit(bitno);
}

bool has_flag(MEMFLAGS f) const {
const int bitno = (int)f;
return _v & nth_bit(bitno);
}

bool has_any() const { return _v > 0; }
};

#endif // SHARE_NMT_NMTUSAGE_HPP

1 comment on commit 6f863b2

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