MCPcopy Create free account
hub / github.com/cloudfoundry/java-buildpack / Finalize

Method Finalize

src/java/jres/jvmkill.go:135–177  ·  view source on GitHub ↗

Finalize adds JVMKill to JAVA_OPTS

()

Source from the content-addressed store, hash-verified

133
134// Finalize adds JVMKill to JAVA_OPTS
135func (j *JVMKillAgent) Finalize() error {
136 // If agentPath not set, try to detect it from previous installation
137 if j.agentPath == "" {
138 j.detectInstalledAgent()
139 }
140
141 if j.agentPath == "" {
142 return nil // Not installed
143 }
144
145 j.ctx.Log.Info("Configuring JVMKill Agent")
146 j.ctx.Log.Debug("JVMKill agent staging path: %s", j.agentPath)
147
148 // Convert absolute staging path to runtime-relative path
149 // Staging path: /tmp/contents.../deps/<idx>/jre/bin/jvmkill-1.16.0.so
150 // Runtime path: $DEPS_DIR/<idx>/jre/bin/jvmkill-1.16.0.so
151 runtimeAgentPath := j.convertToRuntimePath(j.agentPath)
152 j.ctx.Log.Debug("JVMKill agent runtime path: %s", runtimeAgentPath)
153
154 // Check if there's a volume service for heap dumps
155 heapDumpPath := j.getHeapDumpPath()
156
157 // Build agentpath with options
158 // Format: -agentpath:/path/to/jvmkill.so=printHeapHistogram=1,heapDumpPath=/path
159 var agentOpt string
160 if heapDumpPath != "" {
161 agentOpt = fmt.Sprintf("-agentpath:%s=printHeapHistogram=1,heapDumpPath=%s", runtimeAgentPath, heapDumpPath)
162 j.ctx.Log.Info("Write terminal heap dumps to %s", heapDumpPath)
163 } else {
164 agentOpt = fmt.Sprintf("-agentpath:%s=printHeapHistogram=1", runtimeAgentPath)
165 }
166
167 j.ctx.Log.Debug("Adding to JAVA_OPTS: %s", agentOpt)
168
169 // Add to JAVA_OPTS
170 if err := WriteJavaOpts(j.ctx, agentOpt); err != nil {
171 return fmt.Errorf("failed to add JVMKill to JAVA_OPTS: %w", err)
172 }
173
174 j.ctx.Log.Debug("JVMKill Agent added to JAVA_OPTS")
175
176 return nil
177}
178
179// convertToRuntimePath converts a staging path to a runtime path using $DEPS_DIR.
180// The path ends up in a .opts file that is read by the profile.d assembly script,

Callers

nothing calls this directly

Calls 4

detectInstalledAgentMethod · 0.95
convertToRuntimePathMethod · 0.95
getHeapDumpPathMethod · 0.95
WriteJavaOptsFunction · 0.85

Tested by

no test coverage detected