Skip to content

Commit a248d59

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 #427]
1 parent b2137c0 commit a248d59

7 files changed

Lines changed: 71 additions & 31 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ To learn how to configure various properties of the buildpack, follow the "Confi
9494
* [Spring Insight](docs/framework-spring_insight.md)
9595
* [YourKit Profiler](docs/framework-your_kit_profiler.md) ([Configuration](docs/framework-your_kit_profiler.md#configuration))
9696
* Standard JREs
97-
* [OpenJDK](docs/jre-open_jdk_jre.md) ([Configuration](docs/jre-open_jdk_jre.md#configuration))
98-
* [Oracle](docs/jre-oracle_jre.md) ([Configuration](docs/jre-oracle_jre.md#configuration))
9997
* [Azul Zulu](docs/jre-zulu_jre.md) ([Configuration](docs/jre-zulu_jre.md#configuration))
10098
* [IBM® SDK, Java™ Technology Edition](docs/jre-ibm_jre.md) ([Configuration](docs/jre-ibm_jre.md#configuration))
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))
101101
* [Extending](docs/extending.md)
102102
* [Application](docs/extending-application.md)
103103
* [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: 12 additions & 16 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'
@@ -47,8 +46,7 @@ def detect
4746

4847
# (see JavaBuildpack::Component::BaseComponent#compile)
4948
def compile
50-
download(@version, @uri['uri'], @component_name) do |file|
51-
check_sha256(file, @uri['sha256sum'])
49+
download(@version, @uri, @component_name) do |file|
5250
with_timing "Installing #{@component_name} to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do
5351
install_bin(@droplet.sandbox, file)
5452
end
@@ -61,9 +59,11 @@ def release
6159
@droplet
6260
.java_opts
6361
.add_system_property('java.io.tmpdir', '$TMPDIR')
64-
@droplet.java_opts << '-Xtune:virtualized'
62+
.add_option('-XX:OnOutOfMemoryError', killjava)
63+
.add_preformatted_options('-Xtune:virtualized')
64+
.add_preformatted_options('-Xshareclasses:none')
65+
6566
@droplet.java_opts.concat mem_opts
66-
@droplet.java_opts << '-Xshareclasses:none'
6767
end
6868

6969
private
@@ -93,23 +93,15 @@ def install_bin(target_directory, file)
9393
shell "#{file.path} -i silent -f #{response_file.path} 2>&1"
9494
end
9595

96-
# Checks the SHA256 Checksum of the file
97-
#
98-
# @param [File] file, The downloaded file
99-
# @param [String] checksum, The string containing the SHA256 of the file
100-
def check_sha256(file, checksum)
101-
raise 'sha256 checksum does not match' unless Digest::SHA256.hexdigest(File.read(file.path)) == checksum
102-
end
103-
10496
# Returns the max heap size ('-Xmx') value
10597
def mem_opts
106-
mopts = []
98+
mopts = []
10799
total_memory = memory_limit_finder
108100
if total_memory.nil?
109101
# if no memory option has been set by cloudfoundry, we just assume defaults
110102
else
111103
calculated_heap_ratio = heap_ratio_verification(heap_ratio)
112-
heap_size = heap_size_calculator(total_memory, calculated_heap_ratio)
104+
heap_size = heap_size_calculator(total_memory, calculated_heap_ratio)
113105
mopts.push "-Xmx#{heap_size}"
114106
end
115107
mopts
@@ -120,6 +112,10 @@ def heap_ratio
120112
@configuration['heap_ratio'] || HEAP_RATIO
121113
end
122114

115+
def killjava
116+
@droplet.sandbox + 'jre/bin/killjava.sh'
117+
end
118+
123119
# Returns the container total memory limit in bytes
124120
def memory_limit_finder
125121
memory_limit = ENV['MEMORY_LIMIT']
@@ -138,7 +134,7 @@ def memory_size_bytes(size)
138134
bytes = 0
139135
else
140136
raise "Invalid memory size '#{size}'" if !size || size.length < 2
141-
unit = size[-1]
137+
unit = size[-1]
142138
value = size[0..-2]
143139
raise "Invalid memory size '#{size}'" unless check_is_integer? value
144140
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)