Documentation
¶
Index ¶
- Constants
- func DetectJREByEnv(jreName string) bool
- func GetJREVersion(ctx *common.Context, jreName string) (libbuildpack.Dependency, error)
- func WriteJavaHomeProfileD(ctx *common.Context, jreDir, javaHome string) error
- func WriteJavaOpts(ctx *common.Context, opts string) error
- func WriteJavaOptsWithPriority(ctx *common.Context, priority int, name string, opts string) error
- type BaseComponent
- type BaseJRE
- func (b *BaseJRE) Detect() (bool, error)
- func (b *BaseJRE) ExtraFinalizeOpts() string
- func (b *BaseJRE) Finalize() error
- func (b *BaseJRE) JavaHome() string
- func (b *BaseJRE) MemoryCalculatorCommand() string
- func (b *BaseJRE) Name() string
- func (b *BaseJRE) Supply() error
- func (b *BaseJRE) Version() string
- type Component
- type GraalVMJRE
- type IBMJRE
- type JRE
- type JVMKillAgent
- type MemoryCalculator
- func (m *MemoryCalculator) Finalize() error
- func (m *MemoryCalculator) GetCalculatorCommand() string
- func (m *MemoryCalculator) LoadConfig()
- func (m *MemoryCalculator) Name() string
- func (m *MemoryCalculator) RunMemoryCalculator(memoryLimit string) (string, error)
- func (m *MemoryCalculator) Supply() error
- type OpenJDKJRE
- type OracleJRE
- type Registry
- type SapMachineJRE
- type ZingJRE
- type ZuluJRE
Constants ¶
const ( DefaultStackThreads = 250 DefaultHeadroom = 0 DefaultClassCount = 18000 // Default class count when counting fails (after 35% factor: ~6300) Java9ClassCount = 42215 // Classes in Java 9+ JRE )
Memory calculator constants
const DefaultJREProvider = "openjdk"
Default JRE provider Change this value to set which JRE is used by default when no JRE is explicitly configured Valid values: "openjdk", "zulu", "sapmachine", "graalvm", "oracle", "ibm", "zing"
Variables ¶
This section is empty.
Functions ¶
func DetectJREByEnv ¶
DetectJREByEnv checks environment variables for JRE selection Takes the internal JRE name (e.g., "sapmachine", "openjdk", "zulu") Checks both auto-generated and documented environment variable names This matches the behavior of GetJREVersion
func GetJREVersion ¶
func GetJREVersion(ctx *common.Context, jreName string) (libbuildpack.Dependency, error)
GetJREVersion gets the desired JRE version from environment or uses default Supports BP_JAVA_VERSION (simple version) and JBP_CONFIG_<JRE_NAME> (complex config)
func WriteJavaHomeProfileD ¶
WriteJavaHomeProfileD creates a profile.d script that exports JAVA_HOME, JRE_HOME, and PATH at runtime This is needed for containers that use startup scripts expecting $JAVA_HOME environment variable
Parameters:
- ctx: JRE context with Stager and Logger
- jreDir: The directory where the JRE was installed (e.g., $DEPS_DIR/<idx>/jre)
- javaHome: The actual JAVA_HOME path (may be jreDir or a subdirectory)
The function creates a java.sh script in profile.d that:
- Exports JAVA_HOME using $DEPS_DIR runtime variable
- Exports JRE_HOME (same as JAVA_HOME)
- Prepends $JAVA_HOME/bin to PATH
It also sets these environment variables during staging for use by frameworks.
func WriteJavaOpts ¶
WriteJavaOpts writes JAVA_OPTS to a .opts file for centralized assembly JRE components use priority 05 to run early (before frameworks)
func WriteJavaOptsWithPriority ¶
WriteJavaOptsWithPriority writes JAVA_OPTS to a numbered .opts file for centralized assembly Priority determines execution order (lower numbers run first) Multiple calls with the same priority/name will append to the same file
Types ¶
type BaseComponent ¶
type BaseComponent struct {
Ctx *common.Context
JREDir string
JREVersion string
ComponentID string
}
BaseComponent provides common functionality for JRE components
type BaseJRE ¶
type BaseJRE struct {
// contains filtered or unexported fields
}
BaseJRE provides the shared implementation for all standard JRE providers. Variation between JREs is injected via fields — implementers never override Supply/Finalize, avoiding the "forgot to call base" footgun.
func (*BaseJRE) ExtraFinalizeOpts ¶
ExtraFinalizeOpts returns the JRE-specific JVM options written during Finalize. These are opts beyond the universal base opts (-Djava.io.tmpdir) — e.g. HotSpot flags for OpenJDK-like JREs, or J9 tuning flags for IBM JRE.
func (*BaseJRE) MemoryCalculatorCommand ¶
type Component ¶
type Component interface {
// Name returns the component name
Name() string
// Supply installs the component
Supply() error
// Finalize performs final configuration
Finalize() error
}
Component represents a JRE component (memory calculator, jvmkill, etc.)
type GraalVMJRE ¶
type GraalVMJRE struct{ BaseJRE }
GraalVMJRE implements the JRE interface for GraalVM.
func NewGraalVMJRE ¶
func NewGraalVMJRE(ctx *common.Context) *GraalVMJRE
NewGraalVMJRE creates a new GraalVM JRE provider.
type JRE ¶
type JRE interface {
// Name returns the name of this JRE provider (e.g., "OpenJDK", "Zulu")
Name() string
// Detect returns true if this JRE should be used
Detect() (bool, error)
// Supply installs the JRE and its components (memory calculator, jvmkill)
Supply() error
// Finalize performs any final JRE configuration
Finalize() error
// JavaHome returns the path to JAVA_HOME
JavaHome() string
// Version returns the installed JRE version
Version() string
// MemoryCalculatorCommand returns the shell command snippet to run memory calculator
// This command is prepended to the container startup command
// Returns empty string if memory calculator is not installed
MemoryCalculatorCommand() string
}
JRE represents a Java Runtime Environment provider
type JVMKillAgent ¶
type JVMKillAgent struct {
// contains filtered or unexported fields
}
JVMKillAgent manages the JVMKill agent JVMKill is an agent that forcibly terminates the JVM when it is unable to allocate memory or throws an OutOfMemoryError.
func NewJVMKillAgent ¶
func NewJVMKillAgent(ctx *common.Context, jreDir, jreVersion string) *JVMKillAgent
NewJVMKillAgent creates a new JVMKill agent
func (*JVMKillAgent) Finalize ¶
func (j *JVMKillAgent) Finalize() error
Finalize adds JVMKill to JAVA_OPTS
func (*JVMKillAgent) Supply ¶
func (j *JVMKillAgent) Supply() error
Supply installs the JVMKill agent
type MemoryCalculator ¶
type MemoryCalculator struct {
// contains filtered or unexported fields
}
MemoryCalculator manages the Java memory calculator The memory calculator determines optimal JVM memory settings based on available container memory
func NewMemoryCalculator ¶
func NewMemoryCalculator(ctx *common.Context, jreDir, jreVersion string, javaMajorVersion int, jreName string) *MemoryCalculator
NewMemoryCalculator creates a new memory calculator
func (*MemoryCalculator) Finalize ¶
func (m *MemoryCalculator) Finalize() error
Finalize configures the memory calculator in the startup command
func (*MemoryCalculator) GetCalculatorCommand ¶
func (m *MemoryCalculator) GetCalculatorCommand() string
GetCalculatorCommand returns the memory calculator command for use in startup scripts This is called by containers when building their start commands Returns a shell command snippet that: 1. Runs the memory calculator with runtime $MEMORY_LIMIT 2. Echoes the calculated memory settings 3. Appends the settings to $JAVA_OPTS 4. Exports MALLOC_ARENA_MAX to reduce memory overhead
func (*MemoryCalculator) LoadConfig ¶
func (m *MemoryCalculator) LoadConfig()
LoadConfig loads memory calculator configuration from the JRE-specific env var (e.g. JBP_CONFIG_OPEN_JDK_JRE, JBP_CONFIG_SAP_MACHINE_JRE) and falls back to MEMORY_CALCULATOR_* env vars. Must be called at the start of Supply(), before countClasses().
func (*MemoryCalculator) Name ¶
func (m *MemoryCalculator) Name() string
Name returns the component name
func (*MemoryCalculator) RunMemoryCalculator ¶
func (m *MemoryCalculator) RunMemoryCalculator(memoryLimit string) (string, error)
RunMemoryCalculator runs the memory calculator and returns the calculated JAVA_OPTS This is primarily for testing
func (*MemoryCalculator) Supply ¶
func (m *MemoryCalculator) Supply() error
Supply installs the memory calculator
type OpenJDKJRE ¶
type OpenJDKJRE struct{ BaseJRE }
OpenJDKJRE implements the JRE interface for OpenJDK.
func NewOpenJDKJRE ¶
func NewOpenJDKJRE(ctx *common.Context) *OpenJDKJRE
NewOpenJDKJRE creates a new OpenJDK JRE provider.
type OracleJRE ¶
type OracleJRE struct{ BaseJRE }
OracleJRE implements the JRE interface for Oracle JRE.
func NewOracleJRE ¶
NewOracleJRE creates a new Oracle JRE provider.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages multiple JRE providers
func NewRegistry ¶
NewRegistry creates a new JRE registry
func (*Registry) Detect ¶
Detect finds the JRE provider that should be used If a JRE is explicitly configured, it uses that JRE and fails if detection errors If no JRE is explicitly configured, it uses the configured default JRE Returns the JRE, its name, and any error
func (*Registry) Get ¶
Get returns the JRE whose Name() matches the given name, or nil if not found. Used by the finalize phase to resolve a JRE by the name stored in config.yml.
func (*Registry) RegisterStandardJREs ¶
func (r *Registry) RegisterStandardJREs()
RegisterStandardJREs registers all standard JRE providers in the correct priority order. This ensures Supply and Finalize phases use the same detection order. The default JRE is determined by the DefaultJREProvider constant.
func (*Registry) SetDefault ¶
SetDefault sets the default JRE to use when no JRE is explicitly configured
type SapMachineJRE ¶
type SapMachineJRE struct{ BaseJRE }
SapMachineJRE implements the JRE interface for SAP Machine OpenJDK.
func NewSapMachineJRE ¶
func NewSapMachineJRE(ctx *common.Context) *SapMachineJRE
NewSapMachineJRE creates a new SAP Machine JRE provider.
type ZingJRE ¶
type ZingJRE struct {
// contains filtered or unexported fields
}
ZingJRE implements the JRE interface for Azul Platform Prime (Zing) JRE Zing JRE requires a user-provided repository via JBP_CONFIG_ZING_JRE environment variable Unlike other JREs, Zing does NOT use jvmkill or memory calculator - only adds -XX:+ExitOnOutOfMemoryError
func NewZingJRE ¶
NewZingJRE creates a new Zing JRE provider
func (*ZingJRE) Detect ¶
Detect returns true if Zing JRE should be used Zing JRE requires explicit configuration via JBP_CONFIG_ZING_JRE environment variable
func (*ZingJRE) Finalize ¶
Finalize performs final JRE configuration Adds -XX:+ExitOnOutOfMemoryError to JAVA_OPTS
func (*ZingJRE) MemoryCalculatorCommand ¶
MemoryCalculatorCommand returns the shell command snippet to run memory calculator at runtime Zing JRE does not use memory calculator (uses -XX:+ExitOnOutOfMemoryError instead)