Help us shape the future of Go! Take the 2026 Go Developer Survey

jres

package
v1.5.2-0...-36bfd17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func DetectJREByEnv(jreName string) bool

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

func WriteJavaHomeProfileD(ctx *common.Context, jreDir, javaHome string) error

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:

  1. Exports JAVA_HOME using $DEPS_DIR runtime variable
  2. Exports JRE_HOME (same as JAVA_HOME)
  3. Prepends $JAVA_HOME/bin to PATH

It also sets these environment variables during staging for use by frameworks.

func WriteJavaOpts

func WriteJavaOpts(ctx *common.Context, opts string) error

WriteJavaOpts writes JAVA_OPTS to a .opts file for centralized assembly JRE components use priority 05 to run early (before frameworks)

func WriteJavaOptsWithPriority

func WriteJavaOptsWithPriority(ctx *common.Context, priority int, name string, opts string) error

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) Detect

func (b *BaseJRE) Detect() (bool, error)

func (*BaseJRE) ExtraFinalizeOpts

func (b *BaseJRE) ExtraFinalizeOpts() string

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) Finalize

func (b *BaseJRE) Finalize() error

func (*BaseJRE) JavaHome

func (b *BaseJRE) JavaHome() string

func (*BaseJRE) MemoryCalculatorCommand

func (b *BaseJRE) MemoryCalculatorCommand() string

func (*BaseJRE) Name

func (b *BaseJRE) Name() string

func (*BaseJRE) Supply

func (b *BaseJRE) Supply() error

func (*BaseJRE) Version

func (b *BaseJRE) Version() string

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 IBMJRE

type IBMJRE struct{ BaseJRE }

IBMJRE implements the JRE interface for IBM JRE.

func NewIBMJRE

func NewIBMJRE(ctx *common.Context) *IBMJRE

NewIBMJRE creates a new IBM 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) Name

func (j *JVMKillAgent) Name() string

Name returns the component name

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

func NewOracleJRE(ctx *common.Context) *OracleJRE

NewOracleJRE creates a new Oracle JRE provider.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages multiple JRE providers

func NewRegistry

func NewRegistry(ctx *common.Context) *Registry

NewRegistry creates a new JRE registry

func (*Registry) Detect

func (r *Registry) Detect() (JRE, string, error)

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

func (r *Registry) Get(name string) JRE

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) Register

func (r *Registry) Register(jre JRE)

Register adds a JRE provider to the registry

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

func (r *Registry) SetDefault(jre JRE)

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

func NewZingJRE(ctx *common.Context) *ZingJRE

NewZingJRE creates a new Zing JRE provider

func (*ZingJRE) Detect

func (z *ZingJRE) Detect() (bool, error)

Detect returns true if Zing JRE should be used Zing JRE requires explicit configuration via JBP_CONFIG_ZING_JRE environment variable

func (*ZingJRE) Finalize

func (z *ZingJRE) Finalize() error

Finalize performs final JRE configuration Adds -XX:+ExitOnOutOfMemoryError to JAVA_OPTS

func (*ZingJRE) JavaHome

func (z *ZingJRE) JavaHome() string

JavaHome returns the path to JAVA_HOME

func (*ZingJRE) MemoryCalculatorCommand

func (z *ZingJRE) MemoryCalculatorCommand() string

MemoryCalculatorCommand returns the shell command snippet to run memory calculator at runtime Zing JRE does not use memory calculator (uses -XX:+ExitOnOutOfMemoryError instead)

func (*ZingJRE) Name

func (z *ZingJRE) Name() string

Name returns the name of this JRE provider

func (*ZingJRE) Supply

func (z *ZingJRE) Supply() error

Supply installs the Zing JRE Note: Zing JRE does NOT install jvmkill or memory calculator components

func (*ZingJRE) Version

func (z *ZingJRE) Version() string

Version returns the installed JRE version

type ZuluJRE

type ZuluJRE struct{ BaseJRE }

ZuluJRE implements the JRE interface for Azul Zulu OpenJDK.

func NewZuluJRE

func NewZuluJRE(ctx *common.Context) *ZuluJRE

NewZuluJRE creates a new Zulu JRE provider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL