|
1 | 1 | /* |
2 | | - * Copyright (c) 2021 SAP SE. All rights reserved. |
| 2 | + * Copyright (c) 2022 SAP SE. All rights reserved. |
3 | 3 | * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. |
4 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 | 5 | * |
|
24 | 24 | */ |
25 | 25 |
|
26 | 26 | #include "precompiled.hpp" |
27 | | -#include "logging/log.hpp" |
28 | | -#include "os_linux.hpp" |
29 | | -#include "runtime/os.hpp" |
| 27 | +#include "runtime/os.inline.hpp" |
| 28 | +#include "trimCHeapDCmd.hpp" |
30 | 29 | #include "utilities/debug.hpp" |
| 30 | +#include "utilities/globalDefinitions.hpp" |
31 | 31 | #include "utilities/ostream.hpp" |
32 | | -#include "trimCHeapDCmd.hpp" |
33 | 32 |
|
34 | 33 | #include <malloc.h> |
35 | 34 |
|
36 | 35 | void TrimCLibcHeapDCmd::execute(DCmdSource source, TRAPS) { |
37 | | -#ifdef __GLIBC__ |
38 | | - stringStream ss_report(1024); // Note: before calling trim |
39 | | - |
40 | | - os::Linux::meminfo_t info1; |
41 | | - os::Linux::meminfo_t info2; |
42 | | - // Query memory before... |
43 | | - bool have_info1 = os::Linux::query_process_memory_info(&info1); |
44 | | - |
45 | | - _output->print_cr("Attempting trim..."); |
46 | | - ::malloc_trim(0); |
47 | | - _output->print_cr("Done."); |
48 | | - |
49 | | - // ...and after trim. |
50 | | - bool have_info2 = os::Linux::query_process_memory_info(&info2); |
51 | | - |
52 | | - // Print report both to output stream as well to UL |
53 | | - bool wrote_something = false; |
54 | | - if (have_info1 && have_info2) { |
55 | | - if (info1.vmsize != -1 && info2.vmsize != -1) { |
56 | | - ss_report.print_cr("Virtual size before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", |
57 | | - info1.vmsize, info2.vmsize, (info2.vmsize - info1.vmsize)); |
58 | | - wrote_something = true; |
59 | | - } |
60 | | - if (info1.vmrss != -1 && info2.vmrss != -1) { |
61 | | - ss_report.print_cr("RSS before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", |
62 | | - info1.vmrss, info2.vmrss, (info2.vmrss - info1.vmrss)); |
63 | | - wrote_something = true; |
64 | | - } |
65 | | - if (info1.vmswap != -1 && info2.vmswap != -1) { |
66 | | - ss_report.print_cr("Swap before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", |
67 | | - info1.vmswap, info2.vmswap, (info2.vmswap - info1.vmswap)); |
68 | | - wrote_something = true; |
| 36 | + if (os::can_trim_native_heap()) { |
| 37 | + os::size_change_t sc; |
| 38 | + if (os::trim_native_heap(&sc)) { |
| 39 | + _output->print("Trim native heap: "); |
| 40 | + if (sc.after != SIZE_MAX) { |
| 41 | + const size_t delta = sc.after < sc.before ? (sc.before - sc.after) : (sc.after - sc.before); |
| 42 | + const char sign = sc.after < sc.before ? '-' : '+'; |
| 43 | + _output->print_cr("RSS+Swap: " PROPERFMT "->" PROPERFMT " (%c" PROPERFMT ")", |
| 44 | + PROPERFMTARGS(sc.before), PROPERFMTARGS(sc.after), sign, PROPERFMTARGS(delta)); |
| 45 | + } else { |
| 46 | + _output->print_cr("(no details available)."); |
| 47 | + } |
69 | 48 | } |
| 49 | + } else { |
| 50 | + _output->print_cr("Not available."); |
70 | 51 | } |
71 | | - if (!wrote_something) { |
72 | | - ss_report.print_raw("No details available."); |
73 | | - } |
74 | | - |
75 | | - _output->print_raw(ss_report.base()); |
76 | | - log_info(os)("malloc_trim:\n%s", ss_report.base()); |
77 | | -#else |
78 | | - _output->print_cr("Not available."); |
79 | | -#endif |
80 | 52 | } |
0 commit comments