Path: blob/master/src/hotspot/os/linux/trimCHeapDCmd.cpp
64440 views
/*1* Copyright (c) 2021 SAP SE. All rights reserved.2* Copyright (c) 2021, 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "logging/log.hpp"27#include "runtime/os.hpp"28#include "utilities/debug.hpp"29#include "utilities/ostream.hpp"30#include "trimCHeapDCmd.hpp"3132#include <malloc.h>3334void TrimCLibcHeapDCmd::execute(DCmdSource source, TRAPS) {35#ifdef __GLIBC__36stringStream ss_report(1024); // Note: before calling trim3738os::Linux::meminfo_t info1;39os::Linux::meminfo_t info2;40// Query memory before...41bool have_info1 = os::Linux::query_process_memory_info(&info1);4243_output->print_cr("Attempting trim...");44::malloc_trim(0);45_output->print_cr("Done.");4647// ...and after trim.48bool have_info2 = os::Linux::query_process_memory_info(&info2);4950// Print report both to output stream as well to UL51bool wrote_something = false;52if (have_info1 && have_info2) {53if (info1.vmsize != -1 && info2.vmsize != -1) {54ss_report.print_cr("Virtual size before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)",55info1.vmsize, info2.vmsize, (info2.vmsize - info1.vmsize));56wrote_something = true;57}58if (info1.vmrss != -1 && info2.vmrss != -1) {59ss_report.print_cr("RSS before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)",60info1.vmrss, info2.vmrss, (info2.vmrss - info1.vmrss));61wrote_something = true;62}63if (info1.vmswap != -1 && info2.vmswap != -1) {64ss_report.print_cr("Swap before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)",65info1.vmswap, info2.vmswap, (info2.vmswap - info1.vmswap));66wrote_something = true;67}68}69if (!wrote_something) {70ss_report.print_raw("No details available.");71}7273_output->print_raw(ss_report.base());74log_info(os)("malloc_trim:\n%s", ss_report.base());75#else76_output->print_cr("Not available.");77#endif78}798081