Skip to content

Commit 0963b32

Browse files
committed
[GR-22670] Use context reference in GetBaseEnvFrameNode
(cherry picked from commit f4535a2)
1 parent b563f23 commit 0963b32

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/GetBaseEnvFrameNode.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,9 +22,14 @@
2222
*/
2323
package com.oracle.truffle.r.nodes.function;
2424

25+
import com.oracle.truffle.api.CompilerDirectives;
26+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
27+
import com.oracle.truffle.api.TruffleLanguage;
2528
import com.oracle.truffle.api.frame.MaterializedFrame;
2629
import com.oracle.truffle.api.nodes.Node;
2730
import com.oracle.truffle.api.profiles.ValueProfile;
31+
import com.oracle.truffle.r.runtime.context.RContext;
32+
import com.oracle.truffle.r.runtime.context.TruffleRLanguage;
2833
import com.oracle.truffle.r.runtime.env.REnvironment;
2934

3035
/**
@@ -35,13 +40,18 @@ public final class GetBaseEnvFrameNode extends Node {
3540
private final ValueProfile frameAccessProfile = ValueProfile.createClassProfile();
3641
private final ValueProfile frameProfile = ValueProfile.createClassProfile();
3742
private final ValueProfile baseEnvProfile = ValueProfile.createIdentityProfile();
43+
@CompilationFinal private TruffleLanguage.ContextReference<RContext> ctxRef;
3844

3945
public static GetBaseEnvFrameNode create() {
4046
return new GetBaseEnvFrameNode();
4147
}
4248

4349
public MaterializedFrame execute() {
44-
REnvironment baseEnv = baseEnvProfile.profile(REnvironment.baseEnv());
50+
if (ctxRef == null) {
51+
CompilerDirectives.transferToInterpreterAndInvalidate();
52+
ctxRef = lookupContextReference(TruffleRLanguage.class);
53+
}
54+
REnvironment baseEnv = baseEnvProfile.profile(REnvironment.baseEnv(ctxRef.get()));
4555
return frameProfile.profile(baseEnv.getFrame(frameAccessProfile));
4656
}
4757
}

0 commit comments

Comments
 (0)