## 4.1.3.5.1.3.7.1  Memory Calculator V2
When deploying applications on Cloud Foundry, developers can specify the memory limit of the application.
The main goal of this Memory Calculator is to provide mechanism to fine-tune the Java Virtual Machine (SAP JVM or SapMachine) so that the JVM's memory grows below this memory limit.
There are three memory types, which can be sized -stack\_threads , class\_count , and headroom .
Customize the memory options by using the JBP\_CONFIG\_JAVA\_OPTS environment variable:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_JAVA_OPTS: "[java_opts: '-Xms144M -Xss3M -Xmx444444K -XX:MetaspaceSize=66666K -XX:MaxMetaspaceSize=88888K']"
```
## Default Settings
SAP Java Buildpack is delivered with a default built-in configuration of the memory sizing options in YML format - see the configuration files in the table below. These configuration files are parsed during application
staging, and the memory configuration specified in them is used for calculating the memory sizes of stack\_threads , class\_count , and headroom .
Default structures of the relevant configuration files:
config/sapjvm.yml
##  Sample Code
```
# Configuration for SAP JVM repository ---repository_root: "{default.repository.root}/sapjvm/ {platform}/{architecture}" version: + memory_calculator_v2: version: 1.+ repository_root: "{default.repository.root}/ memory-calculator-v2/{platform}/{architecture}" class_count: stack_threads: 250 headroom: 0 jvm_kill: version: 1.+ repository_root: "{default.repository.root}/ jvmkill/{platform}/{architecture}"
```
## config/ sap\_machine\_jre.yml  Sample Code # Configuration for JRE repository repository\_root\_offline: "{default.repository.root}/
```
---repository_root: "https://sap.github.io/SapMachine/ assets/cf/jre/{platform}/{architecture}" version: 17.+ use_offline_repository: true sap_machine_jre/{platform}/{architecture}" memory_calculator_v2: version: 1.+ repository_root: "{default.repository.root}/ memory-calculator/{platform}/{architecture}" class_count: headroom: 0 stack_threads: 250 jvmkill_agent: version: 1.+ repository_root: "{default.repository.root}/ jvmkill/{platform}/{architecture}"
```
config/
## sap\_machine\_jdk.yml  Sample Code
```
# Configuration for JDK repository ---repository_root: "https://sap.github.io/SapMachine/ assets/cf/jdk/{platform}/{architecture}" version: 17.+ repository_root_offline: "{default.repository.root}/ sap_machine_jre/{platform}/{architecture}" memory_calculator_v2: version: 1.+ repository_root: "{default.repository.root}/ memory-calculator/{platform}/{architecture}" class_count: headroom: 7 stack_threads: 250 jvmkill_agent: version: 1.+ repository_root: "{default.repository.root}/ jvmkill/{platform}/{architecture}"
```
The memory\_calculator\_v2 section encloses the input data for the memory calculation techniques utilized in determining the JVM memory sizing options.
- stack\_threads - the number of threads to be used by the application. Default value: 250
- headroom - the percentage of the container's total memory (available to the application) that can be excluded from the memory calculator's algorithm and used for covering JVM overhead (non-JVM operations). The maximum recommended value for headroom is 10 . Default value: 0
- class\_count - the number of classes to be loaded. Default behavior: Estimating the number of class names in the application, adding a constant 42,215 to it, and then multiplying the final result by 0.35 . If you set a particular number, for example 500, only 500 classes will be loaded.
##  Note
If you're using SAP Java Buildpack 1, the constant 42,215 is not used in the calculation; only the number of class names in the application is considered.
Depending on the Java version you use (8, 11, 17, or 21), you can customize these three memory options by using the relevant environment variables:
- JBP\_CONFIG\_SAPJVM
- JBP\_CONFIG\_SAP\_MACHINE\_JRE
- JBP\_CONFIG\_SAP\_MACHINE\_JDK
## Java 8
##  Note
Only relevant for SAP Java Buildpack 1!
If you need JRE with Java 8, you have to use SAP JVM. Customize your memory options as follows:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_SAPJVM: "[memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
## Java 11
```
 Note Only relevant for SAP Java Buildpack 1!
```
If you need JRE with Java 11, you have to use SapMachine 11. Customize your memory options as follows:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jre.SAPMachineJRE']" JBP_CONFIG_SAP_MACHINE_JRE: "[version: 11.+, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
If you want to point to the SapMachine JDK component, you need to provide a specific version as follows:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jdk.SAPMachineJDK']" JBP_CONFIG_SAP_MACHINE_JDK: "[ version: 11.0.22, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
You can also point to the major version of the SapMachine JDK, in order to always get the latest patch versions. In this case, specify it the following way:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jdk.SAPMachineJDK']" JBP_CONFIG_SAP_MACHINE_JDK: "[ version: 11.+, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
## Java 17
##  Note
Relevant for all Java buildpacks.
If you need JRE with Java 17, you use SapMachine 17. Customize your memory options as follows:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jre.SAPMachineJRE']" JBP_CONFIG_SAP_MACHINE_JRE: "[version: 17.+, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
If you want to point to the SapMachine JDK component, you need to provide a specific version as follows:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jdk.SAPMachineJDK']" JBP_CONFIG_SAP_MACHINE_JDK: "[ version: 17.0.10, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
You can also point to the major version of the SapMachine JDK, in order to always get the latest patch versions. In this case, specify it the following way:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jdk.SAPMachineJDK']" JBP_CONFIG_SAP_MACHINE_JDK: "[ version: 17.+, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
## Java 21
##  Note Only relevant for SAP Java Buildpack 2!
If you need JRE with Java 21, you use SapMachine 21. Customize your memory options as follows:
```
---applications: - name: <app-name> ...
```
```
env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jre.SAPMachineJRE']" JBP_CONFIG_SAP_MACHINE_JRE: "[version: 21.+, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
If you want to point to the SapMachine JDK component, you need to provide a specific version as follows:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jdk.SAPMachineJDK']" JBP_CONFIG_SAP_MACHINE_JDK: "[ version: 21.0.2, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
You can also point to the major version of the SapMachine JDK, in order to always get the latest patch versions. In this case, specify it the following way:
```
---applications: - name: <app-name> ... env: JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jdk.SAPMachineJDK']" JBP_CONFIG_SAP_MACHINE_JDK: "[ version: 21.+, memory_calculator_v2: {stack_threads: 266, class_count: 1001, headroom: 5}]"
```
## Related Information
```
GitHub: Java Buildpack Memory Calculator SapMachine [page 301]
```