JavaSetup

Script: javasetup.sh Type: Auxiliary Script Version: 1.0.3

Parses Java command-line arguments and sets up paths for BBTools execution environment. This script configures JVM parameters, memory allocation, and environment-specific paths for optimal BBTools performance.

Basic Usage

source javasetup.sh [parameters]
# Or get Java command directly:
javasetup.sh [parameters]

This script is typically sourced by other BBTools scripts to configure the Java environment. It can also be run directly to output the complete Java command with all configured parameters.

Parameters

Parameters control Java Virtual Machine settings, memory allocation, and environment-specific configurations.

Memory Configuration

--mem=4g
Default memory size for automatic memory detection. Used when no explicit Xmx is set. Default: 4g
--percent=84
Percentage of available system memory to use for automatic memory detection. Default: 84
--mode=auto
Memory allocation mode. Options: auto (automatic detection), partial, fixed. Default: auto
Xmx=size
Maximum heap memory size. Accepts formats like 8g, 4096m, etc. Sets -Xmx flag
xmx=size
Alternative format for maximum heap memory size (case-insensitive)
-Xmx=size
Standard Java format for maximum heap memory size
-xmx=size
Alternative standard format for maximum heap memory size
Xms=size
Initial heap memory size. Sets -Xms flag. If only Xmx is set, Xms automatically matches Xmx
-Xms=size
Standard Java format for initial heap memory size

JVM Configuration

-ea
Enable assertions in the JVM. Default setting
ea
Enable assertions (alternative format)
-da
Disable assertions in the JVM
da
Disable assertions (alternative format)
ExitOnOutOfMemoryError
Enable JVM to exit when out of memory occurs. Sets -XX:+ExitOnOutOfMemoryError
exitonoutofmemoryerror
Alternative format for enabling exit on out of memory (case-insensitive)
eoom
Short form for ExitOnOutOfMemoryError
-ExitOnOutOfMemoryError
Standard Java format for enabling exit on out of memory
-exitonoutofmemoryerror
Alternative standard format for exit on out of memory
-eoom
Standard format short form for ExitOnOutOfMemoryError

Performance Parameters

simd
Enable SIMD (Single Instruction, Multiple Data) vector operations. Adds --add-modules jdk.incubator.vector
SIMD
Enable SIMD vector operations (case-insensitive)
simd=t
Enable SIMD vector operations (explicit true)
simd=true
Enable SIMD vector operations (explicit true)

Output Control

json
Enable JSON output format. Sets internal json flag to 1
json=t
Enable JSON output format (explicit true)
json=true
Enable JSON output format (explicit true)
format=json
Set output format to JSON
silent
Enable silent mode, suppressing non-essential output. Sets internal silent flag to 1
silent=t
Enable silent mode (explicit true)
silent=true
Enable silent mode (explicit true)

Environment Detection

The script automatically detects and configures paths for specific execution environments:

Supported Environments

Shifter Container
Detected via SHIFTER_RUNTIME=1 environment variable. Configures container-specific settings
AWS Environment
Detected via EC2_HOME environment variable. Adds paths for:
  • /test1/binaries/bgzip
  • /test1/binaries/lbzip2/bin
  • /test1/binaries/sambamba
  • /test1/binaries/pigz2/pigz-2.4
NERSC Environment
Detected via NERSC_HOST environment variable. Adds paths for:
  • /global/cfs/cdirs/bbtools/bgzip
  • /global/cfs/cdirs/bbtools/lbzip2/bin
  • /global/cfs/cdirs/bbtools/samtools116/samtools-1.16.1
  • /global/cfs/cdirs/bbtools/java/jdk-17/bin
  • /global/cfs/cdirs/bbtools/pigz2/pigz-2.4

Examples

Basic Memory Configuration

# Set 8GB maximum heap memory
javasetup.sh Xmx=8g

# Set both initial and maximum heap memory
javasetup.sh Xms=2g Xmx=8g

Configures JVM with specific memory allocation.

Performance Optimization

# Enable SIMD operations for better performance
javasetup.sh simd Xmx=8g

# Configure for high-memory analysis with error handling
javasetup.sh Xmx=32g eoom simd

Optimizes JVM settings for high-performance computing.

Automatic Memory Detection

# Use 90% of available system memory
javasetup.sh --percent=90

# Set default memory size for automatic detection
javasetup.sh --mem=8g --percent=80

Configures automatic memory detection based on system resources.

Sourcing in Other Scripts

# Source in BBTools script for environment setup
source "$SCRIPT_DIR/javasetup.sh"

# Get Java command for execution
JAVA_CMD=$(javasetup.sh Xmx=8g simd)
$JAVA_CMD -cp $CP my.package.MainClass $@

Integration pattern used by other BBTools scripts.

Algorithm Details

Memory Configuration Strategy

The script implements intelligent memory management with these features:

Environment Path Management

The script provides environment-specific PATH modifications to ensure optimal tool availability:

Parameter Processing Logic

The parseJavaArgs() function implements iterative argument processing with shell parameter expansion (${arg%%=*}) and cut-based value extraction:

Integration Architecture

The script is designed as a foundational component for the BBTools ecosystem:

Performance Considerations

The script optimizes Java performance through:

Implementation Notes

Script Structure

The script follows a modular design pattern:

Memory Detection Integration

Depends on memdetect.sh for:

Global Variables

The script maintains these global state variables:

Version History

Current version 1.0.3 includes contributions from:

Support

For questions and support: