Skip to content

Commit

Permalink
Fixes for -XX:MaxRAM and -XX:MaxDirectMemorySize at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
jerboaa committed Sep 14, 2023
1 parent 8329f13 commit 4c7cafe
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public static ClassLoader latestUserDefinedLoader0() {
public static void initLevel(int newVal) {
throw VMError.shouldNotReachHere("This is an alias to the method in the target class, so this code is unreachable");
}

@Alias //
@SuppressWarnings("unused")
public static int initLevel() {
return -1; // Aliased code. Should not reach here
}
}

final class DirectMemoryAccessors {
Expand Down Expand Up @@ -134,14 +140,28 @@ private static synchronized void initialize() {
newDirectMemory = STATIC_DIRECT_MEMORY_AMOUNT; // Static value during initialization
INIT_COUNT.incrementAndGet();
} else {
VMError.guarantee(INIT_COUNT.get() == 1, "Second cycle needs to have init count 1");
VMError.guarantee(INIT_COUNT.get() <= 1, "Runtime.maxMemory() invariant");
/*
* Once we know PhysicalMemory has been properly initialized we can use
* Runtime.maxMemory()
* Runtime.maxMemory(). Note that we might end up in this branch for code explicitly
* using the JDK cgroups code. At that point PhysicalMemory has likely been
* initialized.
*/
INIT_COUNT.incrementAndGet();
newDirectMemory = Runtime.getRuntime().maxMemory();
}
} else {
/*
* For explicitly set direct memory we are done
*/
Unsafe.getUnsafe().storeFence();
directMemory = newDirectMemory;
isInitialized = true;
if (Target_jdk_internal_misc_VM.initLevel() < 1) {
// only the first accessor needs to set this
Target_jdk_internal_misc_VM.initLevel(1);
}
return;
}
VMError.guarantee(newDirectMemory > 0, "New direct memory should be initialized");

Expand All @@ -154,7 +174,10 @@ private static synchronized void initialize() {
* MAX_MEMORY field.
*/
isInitialized = true;
Target_jdk_internal_misc_VM.initLevel(1);
if (Target_jdk_internal_misc_VM.initLevel() < 1) {
// only the first accessor needs to set this
Target_jdk_internal_misc_VM.initLevel(1);
}
}
}
}
Expand Down

0 comments on commit 4c7cafe

Please sign in to comment.