Skip to content

Commit dee3212

Browse files
Andreas SteinerPaul Hohensee
authored andcommitted
8318636: Add jcmd to print annotated process memory map
Reviewed-by: stuefe Backport-of: 6f863b2a1baa67deb2a7b33fcd93d272aea01812
1 parent 16a593a commit dee3212

File tree

9 files changed

+792
-1
lines changed

9 files changed

+792
-1
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2023, Red Hat, Inc. and/or its affiliates.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
26+
#include "precompiled.hpp"
27+
28+
#include "runtime/os.hpp"
29+
#include "nmt/memMapPrinter.hpp"
30+
#include "utilities/globalDefinitions.hpp"
31+
#include <limits.h>
32+
33+
struct ProcMapsInfo {
34+
void* from = 0;
35+
void* to = 0;
36+
char prot[20 + 1];
37+
char offset[20 + 1];
38+
char dev[20 + 1];
39+
char inode[20 + 1];
40+
char filename[1024 + 1];
41+
42+
bool scan_proc_maps_line(const char* line) {
43+
prot[0] = offset[0] = dev[0] = inode[0] = filename[0] = '\0';
44+
const int items_read = ::sscanf(line, "%p-%p %20s %20s %20s %20s %1024s",
45+
&from, &to, prot, offset, dev, inode, filename);
46+
return items_read >= 2; // need at least from and to
47+
}
48+
};
49+
50+
class LinuxMappingPrintInformation : public MappingPrintInformation {
51+
const ProcMapsInfo _info;
52+
public:
53+
54+
LinuxMappingPrintInformation(const void* from, const void* to, const ProcMapsInfo* info) :
55+
MappingPrintInformation(from, to), _info(*info) {}
56+
57+
void print_OS_specific_details(outputStream* st) const override {
58+
st->print("%s %s ", _info.prot, _info.offset);
59+
}
60+
61+
const char* filename() const override { return _info.filename; }
62+
};
63+
64+
void MemMapPrinter::pd_print_header(outputStream* st) {
65+
st->print_cr("size prot offset What");
66+
}
67+
68+
void MemMapPrinter::pd_iterate_all_mappings(MappingPrintClosure& closure) {
69+
FILE* f = os::fopen("/proc/self/maps", "r");
70+
if (f == nullptr) {
71+
return;
72+
}
73+
constexpr size_t linesize = sizeof(ProcMapsInfo);
74+
char line[linesize];
75+
while (fgets(line, sizeof(line), f) == line) {
76+
line[sizeof(line) - 1] = '\0';
77+
ProcMapsInfo info;
78+
if (info.scan_proc_maps_line(line)) {
79+
LinuxMappingPrintInformation mapinfo(info.from, info.to, &info);
80+
closure.do_it(&mapinfo);
81+
}
82+
}
83+
::fclose(f);
84+
}

src/hotspot/share/logging/logAsyncWriter.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ class AsyncLogWriter : public NonJavaThread {
172172
NonJavaThread::pre_run();
173173
log_debug(logging, thread)("starting AsyncLog Thread tid = " INTX_FORMAT, os::current_thread_id());
174174
}
175-
const char* name() const override { return "AsyncLog Thread"; }
176175
const char* type_name() const override { return "AsyncLogWriter"; }
177176
void print_on(outputStream* st) const override {
178177
st->print("\"%s\" ", name());
@@ -197,6 +196,8 @@ class AsyncLogWriter : public NonJavaThread {
197196
static AsyncLogWriter* instance();
198197
static void initialize();
199198
static void flush();
199+
200+
const char* name() const override { return "AsyncLog Thread"; }
200201
};
201202

202203
#endif // SHARE_LOGGING_LOGASYNCWRITER_HPP
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#ifndef SHARE_NMT_MEMFLAGBITMAP_HPP
26+
#define SHARE_NMT_MEMFLAGBITMAP_HPP
27+
28+
#include "memory/allocation.hpp" // for mt_number_of_types
29+
#include "utilities/globalDefinitions.hpp"
30+
31+
class MemFlagBitmap {
32+
uint32_t _v;
33+
STATIC_ASSERT(sizeof(_v) * BitsPerByte >= mt_number_of_types);
34+
35+
public:
36+
MemFlagBitmap(uint32_t v = 0) : _v(v) {}
37+
MemFlagBitmap(const MemFlagBitmap& o) : _v(o._v) {}
38+
39+
uint32_t raw_value() const { return _v; }
40+
41+
void set_flag(MEMFLAGS f) {
42+
const int bitno = (int)f;
43+
_v |= nth_bit(bitno);
44+
}
45+
46+
bool has_flag(MEMFLAGS f) const {
47+
const int bitno = (int)f;
48+
return _v & nth_bit(bitno);
49+
}
50+
51+
bool has_any() const { return _v > 0; }
52+
};
53+
54+
#endif // SHARE_NMT_NMTUSAGE_HPP

0 commit comments

Comments
 (0)