Skip to content

Issue 1257 fix mem calc vars and update compare doc#1258

Open
stokpop wants to merge 6 commits intocloudfoundry:mainfrom
stokpop:issue-1257-fix-mem-calc-vars-and-update-compare-doc
Open

Issue 1257 fix mem calc vars and update compare doc#1258
stokpop wants to merge 6 commits intocloudfoundry:mainfrom
stokpop:issue-1257-fix-mem-calc-vars-and-update-compare-doc

Conversation

@stokpop
Copy link
Copy Markdown
Contributor

@stokpop stokpop commented Apr 29, 2026

Fixes #1257 — Memory calculator config not applied at startup

What changed

Bug fixes

  • LoadConfig() is now called in both Supply() and Finalize(), so memory calculator settings are applied at staging time (needed for class counting) and at runtime command generation.
  • JBP_CONFIG_OPEN_JDK_JRE is now parsed for memory_calculator settings (stack_threads, headroom, class_count). Previously these were silently ignored.
  • ValidateFields is scoped to the memory_calculator sub-section only, so legitimate top-level keys like jre: no longer produce a spurious WARNING.

Improved logging

  • Install log now shows whether each value was user-supplied or auto-detected/default:
    Memory Calculator installed: Loaded Classes: 23826 (auto-detected), Threads: 250 (default), Headroom: 0% (default)

Documentation

  • RUBY_VS_GO_BUILDPACK_COMPARISON.md: updated memory calculator row and added migration section explaining the v3 → v4 behaviour change. The difference only affects apps with an explicit -Xmx in JAVA_OPTS (bad practice in containerised environments). Migration options: lower stack_threads, remove -Xmx, or increase manifest memory.

Tests

  • Added memory_calculator_issues_test.go covering the above fixes.

stokpop added 6 commits April 29, 2026 08:28
…undry#1257)

- Add memory_calculator_issues_test.go with 4 failing tests documenting
  bugs tracked in cloudfoundry#1257:
  * MEMORY_CALCULATOR_STACK_THREADS ignored (LoadConfig() not called)
  * MEMORY_CALCULATOR_HEADROOM ignored (LoadConfig() not called)
  * JBP_CONFIG_OPEN_JDK_JRE stack_threads not parsed
  * JBP_CONFIG_OPEN_JDK_JRE class_count not parsed
- Update RUBY_VS_GO_BUILDPACK_COMPARISON.md: memory calculator is no
  longer 'Identical' — v4 includes user-pinned -Xmx in total memory
  check (v3 did not), which can cause startup failures in small
  containers after migration from the Ruby buildpack
…fig() in Supply/Finalize

- Add openJDKJREConfig / memoryCalculatorConfig structs for YAML parsing
- Rewrite LoadConfig() to parse JBP_CONFIG_OPEN_JDK_JRE using
  common.YamlHandler (standard CF config pattern); MEMORY_CALCULATOR_*
  env vars remain supported as a more specific override
- Guard with configLoaded flag to prevent double-loading when both
  Supply() and Finalize() are called on the same instance
- Call LoadConfig() at start of Supply() so class_count override takes
  effect before countClasses() runs; skip countClasses() if already set
- Call LoadConfig() in Finalize() so stackThreads/headroom/classCount
  are applied when building the calculator command (separate process)

Fixes: MEMORY_CALCULATOR_STACK_THREADS/HEADROOM silently ignored
Fixes: JBP_CONFIG_OPEN_JDK_JRE stack_threads/class_count silently ignored
…DK_JRE

Avoids spurious WARNING when jre: or other valid top-level keys are
present in JBP_CONFIG_OPEN_JDK_JRE alongside memory_calculator:.

Previously ValidateFields was run on the full config struct, which
caused warnings for unknown fields like 'jre' that are handled
elsewhere in the buildpack. Now only the memory_calculator sub-section
is validated, so typos in memory_calculator fields (e.g. stack_thread
instead of stack_threads) still produce a WARNING while legitimate
top-level keys are silently ignored.

Added two tests:
- no WARNING when jre: is present alongside memory_calculator:
- WARNING when memory_calculator: contains an unknown/typo'd field
Log message now shows whether each value was user-supplied or not:
- Loaded Classes: 23826 (auto-detected)  vs  23826 when user-set
- Threads: 250 (default)  vs  50 when user-set
- Headroom: 0% (default)  vs  5% when user-set

Adds classCountUserSet, stackThreadsUserSet, headroomUserSet flags
to MemoryCalculator set during LoadConfig() when a value comes from
JBP_CONFIG_OPEN_JDK_JRE or MEMORY_CALCULATOR_* env vars.
- Fix table: show that v3 squeezes non-heap to fit, v4 calculates
  non-heap independently and correctly includes fixed -Xmx in check
- Remove incorrect '(or via JBP_CONFIG_*)' — -Xmx can only be set
  in JAVA_OPTS, not via JBP_CONFIG_*
- Remove stale 'known bug' note about JBP_CONFIG_OPEN_JDK_JRE parsing
  (now fixed)
- Add explanation that v4 behaviour is correct: v3 silently undersized
  non-heap (thread stacks, metaspace, code cache) when -Xmx was set
- Reorder migration options: lower stack_threads moved to option 2
- Add virtual threads note: carrier threads only consume native stack
  memory; virtual thread continuations live on the heap — set
  stack_threads to carrier thread count (~CPU cores) for Java 21+ apps
- Use realistic memory estimates (~900-1000M for -Xmx512M app)
- Clarify the v3 vs v4 difference only applies when explicit -Xmx is set
- Note that without explicit -Xmx the startup failure does not occur
- Note v3 claimed less memory by squeezing non-heap alongside fixed -Xmx
- Reorder migration options: lower stack_threads first, with caveat to
  only do so when app actually uses fewer than 250 threads
- Clarify that removing -Xmx still likely requires increasing manifest memory
- Fix memory figure to at least 1300M based on actual observed error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JBP_CONFIG_OPEN_JDK_JRE memory calculator settings ignored

1 participant