Skip to content

Commit afed86e

Browse files
committed
Polishing
This change does some polishing to this contribution in order to bring it in line with current coding standard. Of note, this removes the jvmkill integration because the contributions needs to go into the 3.x branch where that does not exist. The jvmkill integration will be added back when this contribution is merged from 3.x to master. [resolves cloudfoundry#427]
1 parent 5bf6497 commit afed86e

7 files changed

Lines changed: 70 additions & 21 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ To learn how to configure various properties of the buildpack, follow the "Confi
9696
* [Spring Insight](docs/framework-spring_insight.md)
9797
* [YourKit Profiler](docs/framework-your_kit_profiler.md) ([Configuration](docs/framework-your_kit_profiler.md#configuration))
9898
* Standard JREs
99-
* [OpenJDK](docs/jre-open_jdk_jre.md) ([Configuration](docs/jre-open_jdk_jre.md#configuration))
100-
* [Oracle](docs/jre-oracle_jre.md) ([Configuration](docs/jre-oracle_jre.md#configuration))
10199
* [Azul Zulu](docs/jre-zulu_jre.md) ([Configuration](docs/jre-zulu_jre.md#configuration))
102100
* [IBM® SDK, Java™ Technology Edition](docs/jre-ibm_jre.md) ([Configuration](docs/jre-ibm_jre.md#configuration))
101+
* [OpenJDK](docs/jre-open_jdk_jre.md) ([Configuration](docs/jre-open_jdk_jre.md#configuration))
102+
* [Oracle](docs/jre-oracle_jre.md) ([Configuration](docs/jre-oracle_jre.md#configuration))
103103
* [Extending](docs/extending.md)
104104
* [Application](docs/extending-application.md)
105105
* [Droplet](docs/extending-droplet.md)

lib/java_buildpack/jre/ibm_jre.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
require 'java_buildpack/component/modular_component'
1717
require 'java_buildpack/jre'
1818
require 'java_buildpack/jre/ibm_jre_initializer'
19-
require 'java_buildpack/jre/jvmkill_agent'
2019
require 'java_buildpack/jre/open_jdk_like_security_providers'
2120

2221
module JavaBuildpack
@@ -36,8 +35,7 @@ def command
3635
def sub_components(context)
3736
[
3837
IbmJreInitializer.new(sub_configuration_context(context, 'jre')
39-
.merge(component_name: self.class.to_s.space_case)),
40-
JvmkillAgent.new(sub_configuration_context(context, 'jvmkill_agent')),
38+
.merge(component_name: self.class.to_s.space_case)),
4139
OpenJDKLikeSecurityProviders.new(context)
4240
]
4341
end

lib/java_buildpack/jre/ibm_jre_initializer.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
require 'digest'
1716
require 'fileutils'
1817
require 'java_buildpack/component/versioned_dependency_component'
1918
require 'java_buildpack/jre'
@@ -60,9 +59,11 @@ def release
6059
@droplet
6160
.java_opts
6261
.add_system_property('java.io.tmpdir', '$TMPDIR')
63-
@droplet.java_opts << '-Xtune:virtualized'
62+
.add_option('-XX:OnOutOfMemoryError', killjava)
63+
.add_preformatted_options('-Xtune:virtualized')
64+
.add_preformatted_options('-Xshareclasses:none')
65+
6466
@droplet.java_opts.concat mem_opts
65-
@droplet.java_opts << '-Xshareclasses:none'
6667
end
6768

6869
private
@@ -94,13 +95,13 @@ def install_bin(target_directory, file)
9495

9596
# Returns the max heap size ('-Xmx') value
9697
def mem_opts
97-
mopts = []
98+
mopts = []
9899
total_memory = memory_limit_finder
99100
if total_memory.nil?
100101
# if no memory option has been set by cloudfoundry, we just assume defaults
101102
else
102103
calculated_heap_ratio = heap_ratio_verification(heap_ratio)
103-
heap_size = heap_size_calculator(total_memory, calculated_heap_ratio)
104+
heap_size = heap_size_calculator(total_memory, calculated_heap_ratio)
104105
mopts.push "-Xmx#{heap_size}"
105106
end
106107
mopts
@@ -111,6 +112,10 @@ def heap_ratio
111112
@configuration['heap_ratio'] || HEAP_RATIO
112113
end
113114

115+
def killjava
116+
@droplet.sandbox + 'jre/bin/killjava.sh'
117+
end
118+
114119
# Returns the container total memory limit in bytes
115120
def memory_limit_finder
116121
memory_limit = ENV['MEMORY_LIMIT']
@@ -129,7 +134,7 @@ def memory_size_bytes(size)
129134
bytes = 0
130135
else
131136
raise "Invalid memory size '#{size}'" if !size || size.length < 2
132-
unit = size[-1]
137+
unit = size[-1]
133138
value = size[0..-2]
134139
raise "Invalid memory size '#{size}'" unless check_is_integer? value
135140
value = size.to_i

resources/ibm_jre/bin/killjava.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Cloud Foundry Java Buildpack
3+
# Copyright (c) 2013-2017 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Kill script for use as the parameter of OpenJDK's -XX:OnOutOfMemoryError
18+
19+
set -e
20+
21+
echo "
22+
Process Status (Before)
23+
=======================
24+
$(ps -ef)
25+
26+
ulimit (Before)
27+
===============
28+
$(ulimit -a)
29+
30+
Free Disk Space (Before)
31+
========================
32+
$(df -h)
33+
"
34+
35+
pkill -9 -f .*-XX:OnOutOfMemoryError=.*killjava.*
36+
37+
echo "
38+
Process Status (After)
39+
======================
40+
$(ps -ef)
41+
42+
ulimit (After)
43+
==============
44+
$(ulimit -a)
45+
46+
Free Disk Space (After)
47+
=======================
48+
$(df -h)
49+
"

spec/fixtures/stub-java.bin

100644100755
File mode changed.

spec/java_buildpack/jre/ibm_jre_initializer_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
expect(component.detect).to eq("ibm-jre-initializer=#{version}")
2828
end
2929

30-
it 'installs java from bin', cache_fixture: 'stub-java.bin' do
30+
it 'installs java from bin',
31+
cache_fixture: 'stub-java.bin' do
32+
33+
allow(component).to receive(:shell).with(%r{spec/fixtures/stub-java.bin -i silent -f .* 2>&1})
34+
3135
component.detect
3236
component.compile
33-
34-
expect(sandbox + 'jre/bin/java').to exist
3537
end
3638

3739
it 'adds JAVA_HOME to java_home' do

spec/java_buildpack/jre/ibm_jre_spec.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727

2828
let(:java_home) { JavaBuildpack::Component::MutableJavaHome.new }
2929

30-
let(:configuration) do
31-
{ 'jre' => jre_configuration,
32-
'jvmkill_agent' => jvmkill_agent_configuration }
33-
end
30+
let(:configuration) { { 'jre' => jre_configuration } }
3431

3532
let(:jre_configuration) { instance_double('jre_configuration') }
3633

@@ -45,8 +42,6 @@
4542

4643
allow(JavaBuildpack::Jre::IbmJreInitializer)
4744
.to receive(:new).with(sub_configuration_context(jre_configuration).merge(component_name: 'Stub Ibm JRE'))
48-
allow(JavaBuildpack::Jre::JvmkillAgent)
49-
.to receive(:new).with(sub_configuration_context(jvmkill_agent_configuration))
5045

5146
component.sub_components context
5247
end
@@ -64,7 +59,7 @@ def supports?
6459
end
6560

6661
def sub_configuration_context(configuration)
67-
cntxt = context.clone
62+
cntxt = context.clone
6863
cntxt[:configuration] = configuration
6964
cntxt
7065
end

0 commit comments

Comments
 (0)