Skip to content

Commit b08a692

Browse files
committed
Merge branch '135936599-memory-calc-v3'
[resolves cloudfoundry#319]
2 parents 69ac301 + 8ecba51 commit b08a692

17 files changed

Lines changed: 87 additions & 252 deletions

File tree

.idea/.rakeTasks

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/components.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jres:
3535

3636
# Frameworks are processed in order. Any Java Opts added by the JavaOpts framework will be specified in the start
3737
# command after any Java Opts added by previous frameworks.
38-
3938
frameworks:
4039
# - "JavaBuildpack::Framework::AppDynamicsAgent"
4140
- "JavaBuildpack::Framework::ContainerCertificateTrustStore"

config/open_jdk_jre.yml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ jre:
2020
version: 1.8.0_12+
2121
repository_root: "{default.repository.root}/openjdk/{platform}/{architecture}"
2222
memory_calculator:
23-
version: 2.+
23+
version: 3.+
2424
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
2525
stack_threads: 300
26-
memory_sizes:
27-
heap:
28-
metaspace: 64m..
29-
native:
30-
permgen: 64m..
31-
stack: 228k..
32-
memory_heuristics:
33-
heap: 65
34-
metaspace: 10
35-
native: 15
36-
permgen: 10
37-
stack: 10
38-
memory_initials:
39-
heap: 100%
40-
metaspace: 100%
41-
permgen: 100%

config/oracle_jre.yml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,6 @@ jre:
2323
version: 1.8.0_12+
2424
repository_root: ""
2525
memory_calculator:
26-
version: 2.+
26+
version: 3.+
2727
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
2828
stack_threads: 300
29-
memory_sizes:
30-
heap:
31-
metaspace: 64m..
32-
native:
33-
permgen: 64m..
34-
stack: 228k..
35-
memory_heuristics:
36-
heap: 65
37-
metaspace: 10
38-
native: 15
39-
permgen: 10
40-
stack: 10
41-
memory_initials:
42-
heap: 100%
43-
metaspace: 100%
44-
permgen: 100%

config/zulu_jre.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Cloud Foundry Java Buildpack
2-
# Copyright 2016 the original author or authors.
2+
# Copyright 2013-2017 the original author or authors.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -23,22 +23,6 @@ jre:
2323
version: 1.8.0_12+
2424
repository_root: "https://cdn.azul.com/zulu/bin"
2525
memory_calculator:
26-
version: 2.+
27-
repository_root: ! '{default.repository.root}/memory-calculator/{platform}/{architecture}'
28-
stack_threads:
29-
memory_sizes:
30-
heap:
31-
metaspace: 64m..
32-
native:
33-
permgen: 64m..
34-
stack:
35-
memory_heuristics:
36-
heap: 75
37-
metaspace: 10
38-
native: 10
39-
permgen: 10
40-
stack: 5
41-
memory_initials:
42-
heap: 100%
43-
metaspace: 100%
44-
permgen: 100%
26+
version: 3.+
27+
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
28+
stack_threads: 300

java-buildpack.iml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,21 @@
278278
<orderEntry type="library" scope="PROVIDED" name="public_suffix (v2.0.5, rbenv: 2.2.6) [gem]" level="application" />
279279
<orderEntry type="library" scope="PROVIDED" name="rainbow (v2.2.1, rbenv: 2.2.6) [gem]" level="application" />
280280
<orderEntry type="library" scope="PROVIDED" name="rake (v12.0.0, rbenv: 2.2.6) [gem]" level="application" />
281-
<orderEntry type="library" scope="PROVIDED" name="redcarpet (v3.3.4, rbenv: 2.2.6) [gem]" level="application" />
281+
<orderEntry type="library" scope="PROVIDED" name="redcarpet (v3.4.0, rbenv: 2.2.6) [gem]" level="application" />
282282
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.5.0, rbenv: 2.2.6) [gem]" level="application" />
283283
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.5.4, rbenv: 2.2.6) [gem]" level="application" />
284284
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.5.0, rbenv: 2.2.6) [gem]" level="application" />
285285
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.5.0, rbenv: 2.2.6) [gem]" level="application" />
286286
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.5.0, rbenv: 2.2.6) [gem]" level="application" />
287-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.42.0, rbenv: 2.2.6) [gem]" level="application" />
288-
<orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v1.7.0, rbenv: 2.2.6) [gem]" level="application" />
287+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.47.1, rbenv: 2.2.6) [gem]" level="application" />
288+
<orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v1.12.0, rbenv: 2.2.6) [gem]" level="application" />
289289
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.8.1, rbenv: 2.2.6) [gem]" level="application" />
290-
<orderEntry type="library" scope="PROVIDED" name="rubyzip (v1.2.0, rbenv: 2.2.6) [gem]" level="application" />
290+
<orderEntry type="library" scope="PROVIDED" name="rubyzip (v1.2.1, rbenv: 2.2.6) [gem]" level="application" />
291291
<orderEntry type="library" scope="PROVIDED" name="safe_yaml (v1.0.4, rbenv: 2.2.6) [gem]" level="application" />
292292
<orderEntry type="library" scope="PROVIDED" name="tee (v1.0.0, rbenv: 2.2.6) [gem]" level="application" />
293293
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v1.1.3, rbenv: 2.2.6) [gem]" level="application" />
294294
<orderEntry type="library" scope="PROVIDED" name="webmock (v2.3.2, rbenv: 2.2.6) [gem]" level="application" />
295-
<orderEntry type="library" scope="PROVIDED" name="yard (v0.9.5, rbenv: 2.2.6) [gem]" level="application" />
295+
<orderEntry type="library" scope="PROVIDED" name="yard (v0.9.8, rbenv: 2.2.6) [gem]" level="application" />
296296
</component>
297297
<component name="RModuleSettingsStorage">
298298
<LOAD_PATH number="4" string0="$MODULE_DIR$/lib" string1="$MODULE_DIR$/spec" string2="$MODULE_DIR$/bin" string3="$MODULE_DIR$/spec/bin" />

lib/java_buildpack/framework/java_opts.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ def detect
3131
end
3232

3333
# (see JavaBuildpack::Component::BaseComponent#compile)
34-
def compile
35-
parsed_java_opts.each do |option|
36-
if memory_option? option
37-
raise "Java option '#{option}' configures a memory region. Use JRE configuration for this instead."
38-
end
39-
end
40-
end
34+
def compile; end
4135

4236
# (see JavaBuildpack::Component::BaseComponent#release)
4337
def release
@@ -54,11 +48,6 @@ def release
5448

5549
private_constant :CONFIGURATION_PROPERTY, :ENVIRONMENT_PROPERTY, :ENVIRONMENT_VARIABLE
5650

57-
def memory_option?(option)
58-
option =~ /-Xms/ || option =~ /-Xmx/ || option =~ /-XX:MaxMetaspaceSize/ || option =~ /-XX:MaxPermSize/ ||
59-
option =~ /-Xss/ || option =~ /-XX:MetaspaceSize/ || option =~ /-XX:PermSize/
60-
end
61-
6251
def parsed_java_opts
6352
parsed_java_opts = []
6453

lib/java_buildpack/jre/open_jdk_like_memory_calculator.rb

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require 'java_buildpack/util/shell'
2121
require 'java_buildpack/util/qualify_path'
2222
require 'open3'
23+
require 'tmpdir'
2324

2425
module JavaBuildpack
2526
module Jre
@@ -32,15 +33,19 @@ class OpenJDKLikeMemoryCalculator < JavaBuildpack::Component::VersionedDependenc
3233
def compile
3334
download(@version, @uri) do |file|
3435
FileUtils.mkdir_p memory_calculator.parent
36+
3537
if @version[0] < '2'
3638
unpack_calculator file
3739
else
3840
unpack_compressed_calculator file
3941
end
42+
4043
memory_calculator.chmod 0o755
41-
end
4244

43-
show_settings memory_calculation_string(Pathname.new(Dir.pwd))
45+
puts " Loaded Classes: #{class_count @configuration}, " \
46+
"Threads: #{stack_threads @configuration}, " \
47+
"JAVA_OPTS: '#{java_opts}'"
48+
end
4449
end
4550

4651
# Returns a fully qualified memory calculation command to be prepended to the buildpack's command sequence
@@ -64,6 +69,24 @@ def supports?
6469

6570
private
6671

72+
def actual_class_count(root)
73+
(root + '**/*.class').glob.count +
74+
(root + '**/*.groovy').glob.count +
75+
(root + '**/*.jar').glob.inject(0) { |a, e| a + archive_class_count(e) }
76+
end
77+
78+
def archive_class_count(archive)
79+
`unzip -l #{archive} | grep '\\(\\.class\\|\\.groovy\\)$' | wc -l`.to_i
80+
end
81+
82+
def class_count(configuration)
83+
configuration['class_count'] || (0.2 * actual_class_count(@application.root)).ceil + 5500
84+
end
85+
86+
def java_opts
87+
ENV['JAVA_OPTS']
88+
end
89+
6790
def memory_calculator
6891
@droplet.sandbox + "bin/java-buildpack-memory-calculator-#{@version}"
6992
end
@@ -74,24 +97,22 @@ def memory_calculator_tar
7497
end
7598

7699
def memory_calculation_string(relative_path)
77-
"#{qualify_path memory_calculator, relative_path} -memorySizes=#{memory_sizes @configuration} " \
78-
"-memoryWeights=#{memory_weights @configuration} -memoryInitials=#{memory_initials @configuration}" \
79-
"#{stack_threads @configuration} -totMemory=$MEMORY_LIMIT"
80-
end
81-
82-
def memory_sizes(configuration)
83-
memory_sizes = version_specific configuration['memory_sizes']
84-
memory_sizes.map { |k, v| "#{k}:#{v}" }.join(',')
100+
memory_calculation_string = [qualify_path(memory_calculator, relative_path)]
101+
memory_calculation_string << '-totMemory=$MEMORY_LIMIT'
102+
memory_calculation_string << "-stackThreads=#{stack_threads @configuration}"
103+
memory_calculation_string << "-loadedClasses=#{class_count @configuration}"
104+
memory_calculation_string << "-poolType=#{pool_type}"
105+
memory_calculation_string << "-vmOptions='#{java_opts}'" if java_opts
106+
107+
memory_calculation_string.join(' ')
85108
end
86109

87-
def memory_weights(configuration)
88-
memory_heuristics = version_specific configuration['memory_heuristics']
89-
memory_heuristics.map { |k, v| "#{k}:#{v}" }.join(',')
110+
def pool_type
111+
@droplet.java_home.java_8_or_later? ? 'metaspace' : 'permgen'
90112
end
91113

92-
def memory_initials(configuration)
93-
memory_initials = version_specific configuration['memory_initials']
94-
memory_initials.map { |k, v| "#{k}:#{v}" }.join(',')
114+
def stack_threads(configuration)
115+
configuration['stack_threads']
95116
end
96117

97118
def unpack_calculator(file)
@@ -103,33 +124,6 @@ def unpack_compressed_calculator(file)
103124
FileUtils.mv(memory_calculator_tar, memory_calculator)
104125
end
105126

106-
def stack_threads(configuration)
107-
configuration['stack_threads'] ? " -stackThreads=#{configuration['stack_threads']}" : ''
108-
end
109-
110-
def version_specific(configuration)
111-
if @droplet.java_home.java_8_or_later?
112-
configuration.delete 'permgen'
113-
else
114-
configuration.delete 'metaspace'
115-
end
116-
117-
configuration
118-
end
119-
120-
def show_settings(*args)
121-
Open3.popen3(*args) do |_stdin, stdout, stderr, wait_thr|
122-
status = wait_thr.value
123-
stderr_content = stderr.gets nil
124-
stdout_content = stdout.gets nil
125-
126-
puts " #{stderr_content}" if stderr_content
127-
128-
raise unless status.success?
129-
puts " Memory Settings: #{stdout_content}"
130-
end
131-
end
132-
133127
end
134128

135129
end
File renamed without changes.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Manifest-Version: 1.0
2-
Class-Path: .
3-
Main-Class: com.gopivotal.SimpleJava
2+
Main-Class: io.pivotal.SimpleJava
43

0 commit comments

Comments
 (0)