-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add JVM config shortcuts #63
Conversation
@elevans I got a little carried away after we discussed these sorts of convenience functions this morning. 😅 I hope you like it! |
Ahh, it looks like we would need to run inside |
ad9eea8
to
2703df3
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #63 +/- ##
==========================================
- Coverage 54.47% 52.29% -2.18%
==========================================
Files 11 10 -1
Lines 1208 1218 +10
==========================================
- Hits 658 637 -21
- Misses 550 581 +31 ☔ View full report in Codecov by Sentry. |
2703df3
to
6394532
Compare
I want to use the f"{foo=}" f-string feature.
It needs to run in an isolated Python+Java process so that we can truly validate the before-and-after of version detection. Otherwise, the test simply checks the same thing twice, which is version reporting *after* the JVM is initialized.
Including: 1. heap allocation and limits 2. headless mode 3. interprocess debugging with JDWP
After the JVM has started, it is nice to be able to easily check characteristics of the JVM from the Runtime API, including current and maximum heap sizes, as well as number of available processors. (It is also nice to be able to easily split infinitives in a commit message.) Relatedly, it can be nice to be able to call the garbage collector directly. Note that we do not expose the Runtime.getRuntime().freeMemory() method, because it can be confusing: one would naively expect freeMemory() to equal maxMemory() - usedMemory(), but in actuality it represents the amount of free memory within the bounds of the memory already reserved by the JVM *at the moment*. So it is typically not a very useful number.
There are two classes of functions: 1. scyjava.config functions to instruct Java how much memory to use; and 2. scyjava._java functions to report back how much it is actually using. This integration test uses both to validate that it all works properly.
6394532
to
2bf3319
Compare
OK, this codecov check is annoying, so I'm going to quit working on this. I added integration tests exercising most of the functionality, but our codecov configuration does not appreciate it. |
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.
@ctrueden Great additions to scyjava
! I tried out all the new methods without issue and your docstrings are clear and comprehensive. I especially appreciate the remote debugging!
def set_heap_min(mb: int = None, gb: int = None): | ||
""" | ||
Set the initial amount of memory to allocate to the Java heap. | ||
|
||
Either mb or gb, but not both, must be given. | ||
|
||
Shortcut for passing -Xms###m or -Xms###g to Java. | ||
|
||
:param mb: | ||
The ### of megabytes of memory Java should start with. | ||
:param gb: | ||
The ### of gigabytes of memory Java should start with. | ||
:raise ValueError: If exactly one of mb or gb is not given. | ||
""" | ||
add_option(f"-Xms{_mem_value(mb, gb)}") |
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.
This is great! ty for adding in an option for GB 👍
This patch series adds functions to scyjava.config making it easier to configure commonly desired adjustments to the JVM, including initial and maximum heap sizes, headless mode, and JDWP-based remote debugging. It also adds API for querying the JVM's memory state and available processors, as well as a shortcut to Java's
System.gc()
function. Finally, it adds tests for the memory and headless settings, as well as improving the integration tests in general.