-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[GR-49300] Break the initialization cycle in NIO/cgroups code. #7553
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
Conversation
First, we use a separate accessor for page-alignedness as it doesn't need the more sophisticated initialization of the directMemory field. Next, ensure PhysicalMemory initialization is serialized and when it is, set directMemory to a static value so that the container code can finish initialization without introducing a cyle. The final directMemory value based on the heap size is then published to JDK code by setting the VM init level to 1. Therefore, application code would use the non-static value as the upper bound. Closes: #556
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.
Thanks @christianhaeubl! This is sufficient for our use-case. +1 from me.
120ce63
to
06158a9
Compare
@jerboaa: I pushed another small fix, see the top commit. |
…ore thread-safe way.
d090636
to
a606940
Compare
/** | ||
* {@code java.nio.Bits} caches the max. direct memory size in the field {@code MAX_MEMORY}. We | ||
* disable this cache and always call {@link DirectMemoryAccessors#getDirectMemory()} instead, which | ||
* uses our own cache. Otherwise, it could happen that {@code MAX_MEMORY} caches a temporary value | ||
* that is used during early VM startup, before {@link PhysicalMemory} is fully initialized. | ||
*/ | ||
final class MaxMemoryAccessor { | ||
// Checkstyle: stop | ||
|
||
static long getMAX_MEMORY() { | ||
return DirectMemoryAccessors.getDirectMemory(); | ||
} | ||
|
||
static void setMAX_MEMORY(long value) { | ||
/* Nothing to do. */ | ||
} | ||
|
||
// Checkstyle: resume | ||
} |
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.
Instead of going through the accessor an alternative could be to leaverage the init hooks in JDK code and actually set the init level to 1
once we know the real MaxDirectMemorySize
(based on the heap size). For example here: https://github.com/oracle/graal/pull/7553/files#diff-db72af86eee732c8a7e3e53319b32fdd92ee0ec00735f413a02858c9dc0aff4dR126. That would mimic what HotSpot itself is doing. FWIW, that's what my original code was intending to do.
Both approaches work.
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.
The problem is that Native Image is already multi-threaded when this code is executed. Modifying the init level may have unexpected effects on other threads.
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.
OK, thanks.
@christianhaeubl Thanks for getting this fix in! Much appreciated. |
No description provided.