Permalink
Show file tree
Hide file tree
7 comments
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
8268893: jcmd to trim the glibc heap
Reviewed-by: simonis, dholmes
- Loading branch information
Showing
6 changed files
with
239 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2021 SAP SE. All rights reserved. | ||
* Copyright (c) 2021, 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. | ||
* | ||
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include "logging/log.hpp" | ||
#include "runtime/os.hpp" | ||
#include "utilities/debug.hpp" | ||
#include "utilities/ostream.hpp" | ||
#include "trimCHeapDCmd.hpp" | ||
|
||
#include <malloc.h> | ||
|
||
void TrimCLibcHeapDCmd::execute(DCmdSource source, TRAPS) { | ||
#ifdef __GLIBC__ | ||
stringStream ss_report(1024); // Note: before calling trim | ||
|
||
os::Linux::meminfo_t info1; | ||
os::Linux::meminfo_t info2; | ||
// Query memory before... | ||
bool have_info1 = os::Linux::query_process_memory_info(&info1); | ||
|
||
_output->print_cr("Attempting trim..."); | ||
::malloc_trim(0); | ||
_output->print_cr("Done."); | ||
|
||
// ...and after trim. | ||
bool have_info2 = os::Linux::query_process_memory_info(&info2); | ||
|
||
// Print report both to output stream as well to UL | ||
bool wrote_something = false; | ||
if (have_info1 && have_info2) { | ||
if (info1.vmsize != -1 && info2.vmsize != -1) { | ||
ss_report.print_cr("Virtual size before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", | ||
info1.vmsize, info2.vmsize, (info2.vmsize - info1.vmsize)); | ||
wrote_something = true; | ||
} | ||
if (info1.vmrss != -1 && info2.vmrss != -1) { | ||
ss_report.print_cr("RSS before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", | ||
info1.vmrss, info2.vmrss, (info2.vmrss - info1.vmrss)); | ||
wrote_something = true; | ||
} | ||
if (info1.vmswap != -1 && info2.vmswap != -1) { | ||
ss_report.print_cr("Swap before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", | ||
info1.vmswap, info2.vmswap, (info2.vmswap - info1.vmswap)); | ||
wrote_something = true; | ||
} | ||
} | ||
if (!wrote_something) { | ||
ss_report.print_raw("No details available."); | ||
} | ||
|
||
_output->print_raw(ss_report.base()); | ||
log_info(os)("malloc_trim:\n%s", ss_report.base()); | ||
#else | ||
_output->print_cr("Not available."); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2021 SAP SE. All rights reserved. | ||
* Copyright (c) 2021, 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 OS_LINUX_TRIMCHEAPDCMD_HPP | ||
#define OS_LINUX_TRIMCHEAPDCMD_HPP | ||
|
||
#include "services/diagnosticCommand.hpp" | ||
|
||
class outputStream; | ||
|
||
class TrimCLibcHeapDCmd : public DCmd { | ||
public: | ||
TrimCLibcHeapDCmd(outputStream* output, bool heap) : DCmd(output, heap) {} | ||
static const char* name() { | ||
return "System.trim_native_heap"; | ||
} | ||
static const char* description() { | ||
return "Attempts to free up memory by trimming the C-heap."; | ||
} | ||
static const char* impact() { | ||
return "Low"; | ||
} | ||
static const JavaPermission permission() { | ||
JavaPermission p = { "java.lang.management.ManagementPermission", "control", NULL }; | ||
return p; | ||
} | ||
virtual void execute(DCmdSource source, TRAPS); | ||
}; | ||
|
||
#endif // OS_LINUX_TRIMCHEAPDCMD_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2021 SAP SE. All rights reserved. | ||
* Copyright (c) 2021, 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. | ||
*/ | ||
|
||
import org.testng.annotations.Test; | ||
import jdk.test.lib.dcmd.CommandExecutor; | ||
import jdk.test.lib.dcmd.JMXExecutor; | ||
import jdk.test.lib.process.OutputAnalyzer; | ||
|
||
/* | ||
* @test | ||
* @summary Test of diagnostic command VM.trim_libc_heap | ||
* @library /test/lib | ||
* @requires os.family == "linux" | ||
* @modules java.base/jdk.internal.misc | ||
* java.compiler | ||
* java.management | ||
* jdk.internal.jvmstat/sun.jvmstat.monitor | ||
* @run testng TrimLibcHeapTest | ||
*/ | ||
public class TrimLibcHeapTest { | ||
public void run(CommandExecutor executor) { | ||
OutputAnalyzer output = executor.execute("System.trim_native_heap"); | ||
output.reportDiagnosticSummary(); | ||
output.shouldMatch("(Done|Not available)"); // Not available could happen on Linux + non-glibc (eg. muslc) | ||
if (output.firstMatch("Done") != null) { | ||
output.shouldMatch("(Virtual size before|RSS before|Swap before|No details available)"); | ||
} | ||
} | ||
|
||
@Test | ||
public void jmx() { | ||
run(new JMXExecutor()); | ||
} | ||
} |
6096dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues
6096dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/backport jdk17u-dev
6096dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tstuefe the target repository
jdk17u-dev
is not a valid target for backports.List of valid target repositories: openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk12u, openjdk/jdk13u, openjdk/jdk13u-dev, openjdk/jdk14u, openjdk/jdk15u, openjdk/jdk15u-dev, openjdk/jdk16u, openjdk/jdk17, openjdk/jdk17u.
Supplying the organization/group prefix is optional.
6096dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/backport openjdk/jdk17u
6096dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tstuefe the backport was successfully created on the branch tstuefe-backport-6096dd97 in my personal fork of openjdk/jdk17u. To create a pull request with this backport targeting openjdk/jdk17u:master, just click the following link:
The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u:
6096dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/backport jdk11u-dev
6096dd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tstuefe could not automatically backport
6096dd97
to Optional[openjdk/jdk11u-dev] due to conflicts in the following files:To manually resolve these conflicts run the following commands in your personal fork of Optional[openjdk/jdk11u-dev]:
Once you have resolved the conflicts as explained above continue with creating a pull request towards the Optional[openjdk/jdk11u-dev] with the title
Backport 6096dd9765eaf280890f65c0ff1ab64864b9316a
.