Skip to content

Commit cde1bb4

Browse files
mmanciopnebhale
authored andcommitted
Update Java Memory Assistant
Update Java Memory Assistant to version 0.4.0, which adds support for the following JVMs: - AdoptOpenJDK HotSpot 8.x - AdoptOpenJDK HotSpot 11.x - OpenJDK 11.x - Oracle JVM 11.x - Pivotal JDK 8.x - SAP Machine 11.x On Java 9+, an exception to the Java Module system must be added (--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED) to allow access to com.sun.management.HotSpotDiagnosticMXBean, which is needed to created heapdumps in live mode. [#789] Signed-off-by: Ben Hale <[email protected]>
1 parent 59c0f0b commit cde1bb4

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

docs/framework-java_memory_assistant.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ The timestamp pattern `%ts:yyyyMMdd'T'mmssSSSZ%` is equivalent to the `%FT%T%z`
4646
| Eden | `eden` |
4747
| Survivor | `survivor` |
4848
| Old Generation | `old_gen` |
49+
| Tenured Gen | `tenured_gen` |
50+
| CodeHeap 'non-nmethods' | `code_heap.non_nmethods` |
51+
| CodeHeap 'profiled nmethods' | `code_heap.profiled_nmethods` |
52+
| CodeHeap 'non-profiled nmethods' | `code_heap.non_profiled_nmethods` |
53+
54+
Different builds and versions of Java Virtual Machines offer different memory areas.
55+
The list of supported Java Virtual Machines and the respective memory areas can be found in the [Java Memory Assistant documentation](https://github.com/SAP/java-memory-assistant#supported-jvms).
4956

5057
The default values can be found in the [`config/java_memory_assistant.yml`][] file.
5158

lib/java_buildpack/framework/java_memory_assistant/agent.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def release
4242
.add_system_property('jma.heap_dump_name', %("#{name_pattern}"))
4343
.add_system_property 'jma.log_level', normalized_log_level
4444

45+
if @droplet.java_home.java_9_or_later?
46+
# Enable access to com.sun.management.HotSpotDiagnosticMXBean to circumvent
47+
# Java modules limitations in Java 9+
48+
# See https://github.com/SAP/java-memory-assistant#running-the-java-memory-assistant-on-java-11
49+
@droplet.java_opts
50+
.add_preformatted_options('--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED')
51+
end
52+
4553
add_system_prop_if_config_present 'check_interval', 'jma.check_interval'
4654
add_system_prop_if_config_present 'max_frequency', 'jma.max_frequency'
4755

spec/java_buildpack/framework/java_memory_assistant/agent_spec.rb

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
it 'updates JAVA_OPTS with default values' do
5353
component.release
5454

55+
expect(java_opts).not_to include('--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED')
56+
5557
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/java_memory_assistant_agent/' \
5658
'java-memory-assistant-1.2.3.jar')
5759
expect(java_opts).to include('-Djma.enabled=true')
@@ -61,6 +63,43 @@
6163

6264
expect(java_opts).to include('-Djma.thresholds.heap=90')
6365
expect(java_opts).to include('-Djma.thresholds.old_gen=90')
66+
67+
end
68+
69+
context do
70+
71+
let(:java_home_delegate) do
72+
delegate = JavaBuildpack::Component::MutableJavaHome.new
73+
delegate.root = app_dir + '.test-java-home'
74+
delegate.version = JavaBuildpack::Util::TokenizedVersion.new('1.8.0_55')
75+
76+
delegate
77+
end
78+
79+
it 'it does not add the --add-opens on Java 8' do
80+
component.release
81+
82+
expect(java_opts).not_to include('--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED')
83+
end
84+
85+
end
86+
87+
context do
88+
89+
let(:java_home_delegate) do
90+
delegate = JavaBuildpack::Component::MutableJavaHome.new
91+
delegate.root = app_dir + '.test-java-home'
92+
delegate.version = JavaBuildpack::Util::TokenizedVersion.new('9.0.1')
93+
94+
delegate
95+
end
96+
97+
it 'adds the --add-opens on Java 11' do
98+
component.release
99+
100+
expect(java_opts).to include('--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED')
101+
end
102+
64103
end
65104

66105
end
@@ -200,7 +239,7 @@
200239
end
201240

202241
it 'falls back on JBP log_level when no log_level specified via configuration',
203-
:enable_log_file, log_level: 'WARN' do
242+
:enable_log_file, log_level: 'WARN' do
204243
component.release
205244

206245
expect(java_opts).to include('-Djma.log_level=WARNING')

0 commit comments

Comments
 (0)