Skip to content

Commit e79fbe4

Browse files
committed
Merge branch '789-memory-assistant'
Signed-off-by: Ben Hale <[email protected]>
2 parents 59c0f0b + 4ab9a56 commit e79fbe4

File tree

5 files changed

+100
-14
lines changed

5 files changed

+100
-14
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Layout/EmptyLinesAroundModuleBody:
1818
Layout/MultilineOperationIndentation:
1919
Enabled: false
2020
Metrics/AbcSize:
21-
Max: 22
21+
Max: 25
2222
Metrics/BlockLength:
2323
Exclude:
2424
- 'spec/**/*.rb'

config/java_memory_assistant.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ agent:
3030
eden:
3131
survivor:
3232
old_gen: ">600MB"
33+
tenured_gen:
34+
code_heap.non_nmethods:
35+
code_heap.non_profiled_nmethods:
36+
code_heap.profiled_nmethods:
37+
3338
clean_up:
3439
version: 0.+
3540
repository_root: https://raw.githubusercontent.com/SAP/java-memory-assistant-tools/repository-cu

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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,24 @@ 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'
46-
add_system_prop_if_config_present 'max_frequency', 'jma.max_frequency'
54+
55+
if @configuration.key?('max_frequency')
56+
@droplet.java_opts.add_preformatted_options "'-Djma.max_frequency=#{@configuration['max_frequency']}'"
57+
end
4758

4859
return unless @configuration.key?('thresholds')
4960

5061
@configuration['thresholds'].each do |key, value|
51-
@droplet.java_opts.add_system_property "jma.thresholds.#{key}", value.to_s
62+
@droplet.java_opts.add_preformatted_options "'-Djma.thresholds.#{key}=#{value}'"
5263
end
5364
end
5465

spec/java_buildpack/framework/java_memory_assistant/agent_spec.rb

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,54 @@
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')
5860

5961
expect(java_opts).to include('-Djma.check_interval=5s')
60-
expect(java_opts).to include('-Djma.max_frequency=1/1m')
62+
expect(java_opts).to include('\'-Djma.max_frequency=1/1m\'')
63+
64+
expect(java_opts).to include('\'-Djma.thresholds.heap=90\'')
65+
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 '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
61102

62-
expect(java_opts).to include('-Djma.thresholds.heap=90')
63-
expect(java_opts).to include('-Djma.thresholds.old_gen=90')
64103
end
65104

66105
end
@@ -93,15 +132,15 @@
93132
'java-memory-assistant-0.1.0.jar')
94133
expect(java_opts).to include('-Djma.enabled=true')
95134
expect(java_opts).to include('-Djma.check_interval=10m')
96-
expect(java_opts).to include('-Djma.max_frequency=4/10h')
135+
expect(java_opts).to include('\'-Djma.max_frequency=4/10h\'')
97136
expect(java_opts).to include('-Djma.log_level=DEBUG')
98-
expect(java_opts).to include('-Djma.thresholds.heap=60')
99-
expect(java_opts).to include('-Djma.thresholds.code_cache=30')
100-
expect(java_opts).to include('-Djma.thresholds.metaspace=5')
101-
expect(java_opts).to include('-Djma.thresholds.perm_gen=45.5')
102-
expect(java_opts).to include('-Djma.thresholds.eden=90')
103-
expect(java_opts).to include('-Djma.thresholds.survivor=95.5')
104-
expect(java_opts).to include('-Djma.thresholds.old_gen=30')
137+
expect(java_opts).to include('\'-Djma.thresholds.heap=60\'')
138+
expect(java_opts).to include('\'-Djma.thresholds.code_cache=30\'')
139+
expect(java_opts).to include('\'-Djma.thresholds.metaspace=5\'')
140+
expect(java_opts).to include('\'-Djma.thresholds.perm_gen=45.5\'')
141+
expect(java_opts).to include('\'-Djma.thresholds.eden=90\'')
142+
expect(java_opts).to include('\'-Djma.thresholds.survivor=95.5\'')
143+
expect(java_opts).to include('\'-Djma.thresholds.old_gen=30\'')
105144
end
106145

107146
end
@@ -121,6 +160,30 @@
121160

122161
end
123162

163+
context do
164+
let(:configuration) do
165+
{
166+
'thresholds' => {
167+
'heap' => '>600MB',
168+
'eden' => '< 30MB'
169+
}
170+
}
171+
end
172+
173+
let(:version) { '0.1.0' }
174+
175+
it 'escapses redirection characters' do
176+
component.release
177+
178+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/java_memory_assistant_agent/' \
179+
'java-memory-assistant-0.1.0.jar')
180+
181+
expect(java_opts).to include('\'-Djma.thresholds.heap=>600MB\'')
182+
expect(java_opts).to include('\'-Djma.thresholds.eden=< 30MB\'')
183+
end
184+
185+
end
186+
124187
context do
125188
let(:configuration) do
126189
{

0 commit comments

Comments
 (0)