Skip to content

Commit 82aae94

Browse files
committed
Java 9 Class Count
Previously, when attempting to count the classes that could be loaded from the JRE, Java 9 JVMs were underrepresented due to the new module packaging format. The format is not examinable using tools shipped in the JRE (jimage from the JDK would be able to do it) so this change places a constant in for the number of classes contributed by the Java 9 JRE. [resolves cloudfoundry#543]
1 parent d16e44c commit 82aae94

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/java_buildpack/jre/open_jdk_like_memory_calculator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def actual_class_count(root)
7676
(root + '**/*.class').glob.count +
7777
(root + '**/*.groovy').glob.count +
7878
(root + '**/*.jar').glob(File::FNM_DOTMATCH).reject(&:directory?)
79-
.inject(0) { |a, e| a + archive_class_count(e) }
79+
.inject(0) { |a, e| a + archive_class_count(e) } +
80+
(@droplet.java_home.java_9_or_later? ? 42_215 : 0)
8081
end
8182

8283
def archive_class_count(archive)

spec/java_buildpack/jre/open_jdk_like_memory_calculator_spec.rb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@
2727

2828
let(:configuration) { { 'stack_threads' => '200' } }
2929

30-
let(:java_home) { JavaBuildpack::Component::MutableJavaHome.new }
30+
let(:java_home) do
31+
java_home = JavaBuildpack::Component::MutableJavaHome.new
32+
java_home.version = version_8
33+
return java_home
34+
end
3135

32-
let(:version_8) { VERSION_8 = JavaBuildpack::Util::TokenizedVersion.new('1.8.0_+') }
36+
let(:version_8) { JavaBuildpack::Util::TokenizedVersion.new('1.8.0_162') }
37+
38+
let(:version_9) { JavaBuildpack::Util::TokenizedVersion.new('9.0.4_11') }
3339

3440
it 'copies executable to bin directory',
3541
cache_fixture: 'stub-memory-calculator.tar.gz' do
@@ -105,4 +111,21 @@
105111
expect(environment_variables).to include('MALLOC_ARENA_MAX=2')
106112
end
107113

114+
context 'when java 9' do
115+
116+
it 'creates memory calculation command',
117+
app_fixture: 'jre_memory_calculator_application' do
118+
119+
java_home.version = version_9
120+
121+
command = component.memory_calculation_command
122+
123+
expect(command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like_memory_calculator/bin/' \
124+
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -stackThreads=200 ' \
125+
'-loadedClasses=14777 -poolType=metaspace -vmOptions="$JAVA_OPTS") && echo JVM Memory ' \
126+
'Configuration: $CALCULATED_MEMORY && JAVA_OPTS="$JAVA_OPTS $CALCULATED_MEMORY"')
127+
end
128+
129+
end
130+
108131
end

0 commit comments

Comments
 (0)