Finalize performs final JRE configuration Adds -XX:+ExitOnOutOfMemoryError to JAVA_OPTS
()
| 80 | // Finalize performs final JRE configuration |
| 81 | // Adds -XX:+ExitOnOutOfMemoryError to JAVA_OPTS |
| 82 | func (z *ZingJRE) Finalize() error { |
| 83 | z.ctx.Log.BeginStep("Finalizing Zing JRE configuration") |
| 84 | |
| 85 | // Find the actual JAVA_HOME (needed if finalize is called on a fresh instance) |
| 86 | if z.javaHome == "" { |
| 87 | javaHome, err := z.findJavaHome() |
| 88 | if err != nil { |
| 89 | z.ctx.Log.Warning("Failed to find JAVA_HOME: %s", err.Error()) |
| 90 | } else { |
| 91 | z.javaHome = javaHome |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Set JAVA_HOME in environment for frameworks that need it during finalize phase |
| 96 | // (e.g., Luna Security Provider, Container Security Provider) |
| 97 | if z.javaHome != "" { |
| 98 | if err := os.Setenv("JAVA_HOME", z.javaHome); err != nil { |
| 99 | z.ctx.Log.Warning("Failed to set JAVA_HOME environment variable: %s", err.Error()) |
| 100 | } else { |
| 101 | z.ctx.Log.Debug("Set JAVA_HOME=%s", z.javaHome) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // Add Zing-specific JVM option for OOM handling |
| 106 | // Unlike other JREs, Zing uses built-in -XX:+ExitOnOutOfMemoryError instead of jvmkill |
| 107 | if err := WriteJavaOpts(z.ctx, "-XX:+ExitOnOutOfMemoryError"); err != nil { |
| 108 | z.ctx.Log.Warning("Failed to write JAVA_OPTS: %s", err.Error()) |
| 109 | // Non-fatal |
| 110 | } |
| 111 | |
| 112 | z.ctx.Log.Info("Zing JRE finalization complete") |
| 113 | return nil |
| 114 | } |
| 115 | |
| 116 | // JavaHome returns the path to JAVA_HOME |
| 117 | func (z *ZingJRE) JavaHome() string { |
nothing calls this directly
no test coverage detected