Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ergonomics Profile #9

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e84d698
Add option for dedicated ergonomics profile
Jul 17, 2023
9cea06f
change gb
Jul 17, 2023
f58c9cd
change gb to prevent overflow
Jul 17, 2023
e8e0324
test G
Jul 24, 2023
b84eba2
use G
Jul 24, 2023
765fc11
add GC selection for dedicated ergonomics profile
Jul 25, 2023
0bb062e
fix oopsie
Jul 25, 2023
5bc7f7e
wip
brunoborges Aug 7, 2023
08cc6ce
Remove auto import
brunoborges Aug 7, 2023
b254d08
Real world doc for ErgonomicsProfile flag
brunoborges Aug 7, 2023
b5ff702
Remove leading whitespace
brunoborges Aug 7, 2023
5768a4a
Validate ergonomic profile in a function
brunoborges Aug 7, 2023
613c117
Fix where we set the sys property
brunoborges Aug 7, 2023
6559389
Store after it may have been changed
brunoborges Aug 7, 2023
93cad80
Set the profile before the flags
brunoborges Aug 7, 2023
92c1df1
Minor fixes
brunoborges Aug 8, 2023
d8a19e6
No need to change MinRAMPercentage here.
brunoborges Aug 8, 2023
a7c5576
Remove unnecessary new line
brunoborges Aug 8, 2023
34fa5de
Merge branch 'main' into ergonomics-profile
brunoborges Oct 6, 2023
6fd0069
Expose selected GC name through JMX
brunoborges Oct 6, 2023
ce6d869
Merge branch 'master' into ergonomics-profile
brunoborges Apr 9, 2024
0bcc5b3
Merge remote-tracking branch 'upstream/master' into ergonomics-profile
brunoborges Apr 25, 2024
eafd4f4
use auto by default
brunoborges Apr 25, 2024
436ba32
missing qupte
brunoborges Apr 25, 2024
a0199e4
simplified
brunoborges Apr 26, 2024
439bae6
jtreg test for ergo profile
brunoborges Apr 26, 2024
9c4b3ec
test max ram percentage
brunoborges Apr 28, 2024
a7db925
Tests for ergo profiles
brunoborges Apr 29, 2024
4cd37d0
Do not consider ZGC for now
brunoborges May 8, 2024
6232c64
Remove getGCName API from Runtime MBean and VMManagement
brunoborges May 9, 2024
fc3e25b
Update src/hotspot/share/gc/shared/gcConfig.cpp
brunoborges May 10, 2024
7aa4ec5
ZGC is not part of initial implementation
brunoborges May 10, 2024
63bc938
ZGC is not part of initial implementation
brunoborges May 10, 2024
92fad0c
merge
brunoborges May 10, 2024
da546d2
Add AutoErgonomicsProfile bool flag to enable auto selection
brunoborges May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/hotspot/share/gc/shared/gcConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void GCConfig::fail_if_non_included_gc_is_selected() {
NOT_ZGC( FAIL_IF_SELECTED(UseZGC));
}

void GCConfig::select_gc_ergonomically() {
void select_gc_ergonomically_shared() {
if (os::is_server_class_machine()) {
#if INCLUDE_G1GC
FLAG_SET_ERGO_IF_DEFAULT(UseG1GC, true);
Expand All @@ -111,6 +111,38 @@ void GCConfig::select_gc_ergonomically() {
}
}

void select_gc_ergonomically_dedicated() {
brunoborges marked this conversation as resolved.
Show resolved Hide resolved
julong phys_mem = os::physical_memory();
if (os::active_processor_count() <= 1) {
#if INCLUDE_SERIALGC
FLAG_SET_ERGO_IF_DEFAULT(UseSerialGC, true);
#endif
} else if (phys_mem >= 16*G) {
#if INCLUDE_ZGC
FLAG_SET_ERGO_IF_DEFAULT(UseZGC, true);
#endif
} else if (phys_mem > 2048*M) {
#if INCLUDE_G1GC
FLAG_SET_ERGO_IF_DEFAULT(UseG1GC, true);
#endif
} else {
#if INCLUDE_PARALLELGC
FLAG_SET_ERGO_IF_DEFAULT(UseParallelGC, true);
#endif
}
}

void GCConfig::select_gc_ergonomically() {
if (strcmp(ErgonomicsProfile, "shared") == 0) {
select_gc_ergonomically_shared();
} else if (strcmp(ErgonomicsProfile, "dedicated") == 0) {
select_gc_ergonomically_dedicated();
} else {
// We have got to have at least one GC selected. Otherwise, we will crash.
ShouldNotReachHere();
}
brunoborges marked this conversation as resolved.
Show resolved Hide resolved
}

bool GCConfig::is_no_gc_selected() {
FOR_EACH_INCLUDED_GC(gc) {
if (gc->_flag) {
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/gc/shared/gc_globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
product(bool, UseShenandoahGC, false, \
"Use the Shenandoah garbage collector") \
\
product(ccstr, ErgonomicsProfile, "shared", \
"Ergonomics profile to use. " \
"\"shared\" (default) for when the JVM is running " \
brunoborges marked this conversation as resolved.
Show resolved Hide resolved
"in a traditional environment and \"dedicated\" for when the " \
"JVM is running on an environment such as containers") \
\
/* notice: the max range value here is INT_MAX not UINT_MAX */ \
/* to protect from overflows */ \
product(uint, ParallelGCThreads, 0, \
Expand Down
42 changes: 42 additions & 0 deletions src/hotspot/share/runtime/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
#if INCLUDE_JFR
#include "jfr/jfr.hpp"
#endif
#ifdef LINUX
#include "osContainer_linux.hpp"
#endif

#include <limits>

Expand Down Expand Up @@ -1487,6 +1490,12 @@ void Arguments::set_use_compressed_klass_ptrs() {
#endif // _LP64
}

static void validate_ergonomics_profile() {
if (strcmp(ErgonomicsProfile, "shared") != 0 && strcmp(ErgonomicsProfile, "dedicated") != 0) {
brunoborges marked this conversation as resolved.
Show resolved Hide resolved
vm_exit_during_initialization(err_msg("Unsupported ErgonomicsProfile: %s", ErgonomicsProfile));
}
}

void Arguments::set_conservative_max_heap_alignment() {
// The conservative maximum required alignment for the heap is the maximum of
// the alignments imposed by several sources: any requirements from the heap
Expand Down Expand Up @@ -1514,6 +1523,21 @@ jint Arguments::set_ergonomics_flags() {
return JNI_OK;
}

void Arguments::set_ergonomics_profile() {
validate_ergonomics_profile();

if (FLAG_IS_DEFAULT(ErgonomicsProfile)){
#ifdef LINUX
if (OSContainer::is_containerized()){
FLAG_SET_ERGO(ErgonomicsProfile, "dedicated");
}
brunoborges marked this conversation as resolved.
Show resolved Hide resolved
#endif //LINUX
}

// Store so we can expose through JMX RuntimeMBean
PropertyList_add(&_system_properties, new SystemProperty("java.vm.ergonomics.profile", ErgonomicsProfile, false));
}

size_t Arguments::limit_heap_by_allocatable_memory(size_t limit) {
size_t max_allocatable;
size_t result = limit;
Expand Down Expand Up @@ -1561,6 +1585,21 @@ void Arguments::set_heap_size() {
: (julong)MaxRAM;
}

// Update default heap size for dedicated ergonomics profile
if (strcmp(ErgonomicsProfile, "dedicated") == 0) {
FLAG_SET_DEFAULT(InitialRAMPercentage, 50.0);
if (phys_mem >= 16*G){
FLAG_SET_DEFAULT(MaxRAMPercentage, 90.0);
} else if (phys_mem >= 6*G){
FLAG_SET_DEFAULT(MaxRAMPercentage, 85.0);
} else if (phys_mem >= 4*G){
FLAG_SET_DEFAULT(MaxRAMPercentage, 80.0);
} else if (phys_mem >= 0.5*G){
FLAG_SET_DEFAULT(MaxRAMPercentage, 75.0);
} else {
FLAG_SET_DEFAULT(MaxRAMPercentage, 50.0);
}
}

// Convert deprecated flags
if (FLAG_IS_DEFAULT(MaxRAMPercentage) &&
Expand Down Expand Up @@ -3977,6 +4016,9 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
}

jint Arguments::apply_ergo() {
// Set the ergonomics profile
set_ergonomics_profile();

// Set flags based on ergonomics.
jint result = set_ergonomics_flags();
if (result != JNI_OK) return result;
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/runtime/arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class Arguments : AllStatic {
static bool _ClipInlining;

// GC ergonomics
static void set_ergonomics_profile();
static void set_conservative_max_heap_alignment();
static void set_use_compressed_oops();
static void set_use_compressed_klass_ptrs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,17 @@ public default long getPid() {
* to the system properties.
*/
public java.util.Map<String, String> getSystemProperties();

/**
* Returns the selected ergonomics profile for this Java virtual machine.
* The profile will be one of the following:
* <ul>
* <li>shared</li>
* <li>dedicated</li>
* </ul>
*
* @return the name of the selected ergonomics profile
*/
public String getJvmErgonomicsProfile();

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public Map<String,String> getSystemProperties() {
return map;
}

public String getJvmErgonomicsProfile() {
return jvm.getErgonomicsProfile();
}

public ObjectName getObjectName() {
return Util.newObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public interface VMManagement {
public long getStartupTime();
public long getUptime();
public int getAvailableProcessors();
public String getErgonomicsProfile();

// Compilation Subsystem
public String getCompilerName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

import java.util.Arrays;
import java.util.Collections;
import java.security.AccessController;
Expand Down Expand Up @@ -201,6 +202,10 @@ public synchronized List<String> getVmArguments() {
private native long getUptime0();
public native int getAvailableProcessors();

public String getErgonomicsProfile() {
return System.getProperty("java.vm.ergonomics.profile");
}

// Compilation Subsystem
public String getCompilerName() {
@SuppressWarnings("removal")
Expand Down