Skip to content

Commit de19e32

Browse files
committed
Include More Classes In Calculation
Previously, only the classes actually in the application were candidates for use when calculating the total number of classes in the application. There was a fixed 5500 class offset to account for the un-evaluated JRE. However, there were problems when downstream buildpacks added large servers to the application (e.g. Wildfly) and 10s of thousands classes were not accounted for. This change enumerates the number of classes in the _entire_ droplet, including the JRE, and removes the constant offset.
1 parent b08a692 commit de19e32

6 files changed

Lines changed: 13 additions & 7 deletions

File tree

.idea/dictionaries/bhale.xml

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

lib/java_buildpack/jre/open_jdk_like_memory_calculator.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require 'fileutils'
1818
require 'java_buildpack/component/versioned_dependency_component'
1919
require 'java_buildpack/jre'
20+
require 'java_buildpack/util/filtering_pathname'
2021
require 'java_buildpack/util/shell'
2122
require 'java_buildpack/util/qualify_path'
2223
require 'open3'
@@ -72,15 +73,19 @@ def supports?
7273
def actual_class_count(root)
7374
(root + '**/*.class').glob.count +
7475
(root + '**/*.groovy').glob.count +
75-
(root + '**/*.jar').glob.inject(0) { |a, e| a + archive_class_count(e) }
76+
(root + '**/*.jar').glob(File::FNM_DOTMATCH).inject(0) { |a, e| a + archive_class_count(e) }
7677
end
7778

7879
def archive_class_count(archive)
79-
`unzip -l #{archive} | grep '\\(\\.class\\|\\.groovy\\)$' | wc -l`.to_i
80+
a = `unzip -l #{archive} | grep '\\(\\.class\\|\\.groovy\\)$' | wc -l`.to_i
81+
$stderr.puts "#{archive}: #{a}"
82+
83+
a
8084
end
8185

8286
def class_count(configuration)
83-
configuration['class_count'] || (0.2 * actual_class_count(@application.root)).ceil + 5500
87+
root = JavaBuildpack::Util::FilteringPathname.new(@droplet.root, ->(_) { true }, true)
88+
configuration['class_count'] || (0.2 * actual_class_count(root)).ceil
8489
end
8590

8691
def java_opts
342 Bytes
Binary file not shown.
342 Bytes
Binary file not shown.

spec/java_buildpack/jre/open_jdk_like_memory_calculator_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
expect(command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like_memory_calculator/bin/' \
9393
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -stackThreads=200 ' \
94-
'-loadedClasses=5501 -poolType=metaspace)')
94+
'-loadedClasses=1 -poolType=metaspace)')
9595
end
9696

9797
context do
@@ -107,7 +107,7 @@
107107

108108
expect(command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like_memory_calculator/bin/' \
109109
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -stackThreads=200 ' \
110-
'-loadedClasses=5501 -poolType=metaspace -vmOptions=\'-Dalpha=bravo\')')
110+
'-loadedClasses=1 -poolType=metaspace -vmOptions=\'-Dalpha=bravo\')')
111111
end
112112

113113
end

spec/java_buildpack/jre/open_jdk_like_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@
6161
java_home.version = version_7
6262
expect(component.command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like/bin/' \
6363
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT' \
64-
' -stackThreads=200 -loadedClasses=5500 -poolType=permgen)')
64+
' -stackThreads=200 -loadedClasses=0 -poolType=permgen)')
6565

6666
end
6767

6868
it 'returns command for Java 8' do
6969
java_home.version = version_8
7070
expect(component.command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like/bin/' \
7171
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT' \
72-
' -stackThreads=200 -loadedClasses=5500 -poolType=metaspace)')
72+
' -stackThreads=200 -loadedClasses=0 -poolType=metaspace)')
7373

7474
end
7575

0 commit comments

Comments
 (0)