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
2222 */
2323package 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 ;
2528import com .oracle .truffle .api .frame .MaterializedFrame ;
2629import com .oracle .truffle .api .nodes .Node ;
2730import com .oracle .truffle .api .profiles .ValueProfile ;
31+ import com .oracle .truffle .r .runtime .context .RContext ;
32+ import com .oracle .truffle .r .runtime .context .TruffleRLanguage ;
2833import 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