Skip to content

Commit 2c49fe4

Browse files
committed
Ensure handles are created in the global context.
1 parent 6cf69ff commit 2c49fe4

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/CompilationProxies.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@ public interface CompilationProxies {
7373
* @return a debug closeable object representing the debug context
7474
*/
7575
DebugCloseable withDebugContext(DebugContext debugContext);
76+
77+
/**
78+
* Enters the context of a method compilation.
79+
*
80+
* @return a scope for the context
81+
*/
82+
DebugCloseable enterCompilationContext();
7683
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/RecordingCompilationProxies.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ public List<OperationRecorder.RecordedOperation> collectOperationsForSerializati
139139
return recorder.getCurrentRecordedOperations();
140140
}
141141

142-
/**
143-
* Enters the context of a method compilation for the current compilation thread.
144-
*
145-
* @return a scope for the context
146-
*/
142+
@Override
147143
public DebugCloseable enterCompilationContext() {
148144
return recorder.enterCompilationContext();
149145
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/ReplayCompilationProxies.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import jdk.graal.compiler.debug.GlobalMetrics;
4242
import jdk.graal.compiler.debug.GraalError;
4343
import jdk.graal.compiler.debug.TimerKey;
44+
import jdk.graal.compiler.hotspot.CompilationContext;
45+
import jdk.graal.compiler.hotspot.HotSpotGraalServices;
4446
import jdk.graal.compiler.hotspot.Platform;
4547
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxy;
4648
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxyBase;
@@ -222,6 +224,17 @@ public DebugCloseable withDebugContext(DebugContext debugContext) {
222224
};
223225
}
224226

227+
@Override
228+
public DebugCloseable enterCompilationContext() {
229+
// The handles created during replay are cached across compilations.
230+
CompilationContext context = HotSpotGraalServices.enterGlobalCompilationContext();
231+
if (context == null) {
232+
return DebugCloseable.VOID_CLOSEABLE;
233+
} else {
234+
return context::close;
235+
}
236+
}
237+
225238
/**
226239
* Loads the recorded operations from a collection.
227240
*

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/ReplayCompilationSupport.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,16 @@ public DebugCloseable withDebugContext(DebugContext debug) {
263263
* @return a debug closeable that should be closed after the compilation
264264
*/
265265
public DebugCloseable enterCompilationContext(HotSpotCompilationRequest originalRequest, OptionValues initialOptions) {
266-
if (proxies instanceof RecordingCompilationProxies recordingCompilationProxies) {
267-
DebugCloseable context = recordingCompilationProxies.enterCompilationContext();
268-
return () -> {
269-
try {
266+
DebugCloseable context = proxies.enterCompilationContext();
267+
return () -> {
268+
try {
269+
if (proxies instanceof RecordingCompilationProxies) {
270270
serializeRecordedCompilation(originalRequest, initialOptions);
271-
} finally {
272-
context.close();
273271
}
274-
};
275-
} else {
276-
return DebugCloseable.VOID_CLOSEABLE;
277-
}
272+
} finally {
273+
context.close();
274+
}
275+
};
278276
}
279277

280278
private void serializeRecordedCompilation(HotSpotCompilationRequest originalRequest, OptionValues initialOptions) {

0 commit comments

Comments
 (0)