Skip to content

Commit 8f0753d

Browse files
author
Pavel Marek
committed
Fix getting RContext in fast-path.
1 parent db78319 commit 8f0753d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+233
-173
lines changed

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ public Object R_ToplevelExec() {
967967
}
968968

969969
@Override
970-
public void restoreHandlerStacks(Object savedHandlerStack) {
971-
RErrorHandling.restoreHandlerStack(savedHandlerStack);
970+
public void restoreHandlerStacks(Object savedHandlerStack, RContext context) {
971+
RErrorHandling.restoreHandlerStack(savedHandlerStack, context);
972972
}
973973

974974
@Override

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/mixed/TruffleMixed_Call.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, 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
@@ -31,6 +31,7 @@
3131
import com.oracle.truffle.r.ffi.impl.mixed.TruffleMixed_CallFactory.TruffleMixed_InvokeVoidCallNodeGen;
3232
import com.oracle.truffle.r.ffi.impl.mixed.TruffleMixed_DLL.MixedLLVM_Handle;
3333
import com.oracle.truffle.r.ffi.impl.nfi.TruffleNFI_Call;
34+
import com.oracle.truffle.r.runtime.context.RContext;
3435
import com.oracle.truffle.r.runtime.data.RList;
3536
import com.oracle.truffle.r.runtime.ffi.CallRFFI;
3637
import com.oracle.truffle.r.runtime.ffi.DLL;
@@ -132,16 +133,17 @@ protected void handleLLVMInvocation(VirtualFrame frame, NativeCallInfo nativeCal
132133
protected void handleLLVMNFIInitLib(VirtualFrame frame, NativeCallInfo nativeCallInfo, Object[] args,
133134
@Cached("createLLVMInvocationNode()") InvokeVoidCallNode llvmDelegNode,
134135
@Cached("createNFIInvocationNode()") InvokeVoidCallNode nfiDelegNode) {
136+
RContext context = RContext.getInstance(this);
135137
if (nativeCallInfo.address.value instanceof RList) {
136138
RList symbols = (RList) nativeCallInfo.address.value;
137-
llvmDelegNode.dispatch(frame, new NativeCallInfo(nativeCallInfo.name, (SymbolHandle) symbols.getDataAt(0), nativeCallInfo.dllInfo), args);
139+
llvmDelegNode.dispatch(frame, new NativeCallInfo(nativeCallInfo.name, (SymbolHandle) symbols.getDataAt(0), nativeCallInfo.dllInfo), context, args);
138140
LibHandle nfiLibHandle = ((MixedLLVM_Handle) nativeCallInfo.dllInfo.handle).nfiLibHandle;
139141
if (nfiLibHandle != null) {
140142
DLLInfo nfiDllInfo = nativeCallInfo.dllInfo.replaceHandle(nfiLibHandle);
141-
nfiDelegNode.dispatch(frame, new NativeCallInfo(nativeCallInfo.name, (SymbolHandle) symbols.getDataAt(1), nfiDllInfo), new Object[]{nfiDllInfo});
143+
nfiDelegNode.dispatch(frame, new NativeCallInfo(nativeCallInfo.name, (SymbolHandle) symbols.getDataAt(1), nfiDllInfo), context, new Object[]{nfiDllInfo});
142144
}
143145
} else {
144-
llvmDelegNode.dispatch(frame, new NativeCallInfo(nativeCallInfo.name, nativeCallInfo.address, nativeCallInfo.dllInfo), args);
146+
llvmDelegNode.dispatch(frame, new NativeCallInfo(nativeCallInfo.name, nativeCallInfo.address, nativeCallInfo.dllInfo), context, args);
145147
}
146148
}
147149
}

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_UpCallsRFFIImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public Object Rf_mkCharLenCE(Object bytes, int len, int encoding) {
7474
}
7575

7676
@Override
77+
@TruffleBoundary
7778
public Object R_alloc(int n, int size) {
7879
long result = NativeMemory.allocate(n * (long) size, "R_alloc");
7980
getContext().transientAllocations.peek().add(result);

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RForceAndCallNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -48,7 +48,6 @@
4848
import com.oracle.truffle.r.runtime.RCaller;
4949
import com.oracle.truffle.r.runtime.RError;
5050
import com.oracle.truffle.r.runtime.builtins.RBuiltinDescriptor;
51-
import com.oracle.truffle.r.runtime.context.RContext;
5251
import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
5352
import com.oracle.truffle.r.runtime.data.RFunction;
5453
import com.oracle.truffle.r.runtime.data.RNull;
@@ -162,7 +161,7 @@ Object forceAndCall(Object e, RFunction fun, int n, REnvironment env,
162161
}
163162

164163
RCaller rCaller = RCaller.create(env.getFrame(), RCallerHelper.createFromArguments(fun, argsAndNames));
165-
return RContext.getEngine().evalFunction(fun, env.getFrame(), rCaller, false, argsAndNames.getSignature(), argsAndNames.getArguments());
164+
return getRContext().getThisEngine().evalFunction(fun, env.getFrame(), rCaller, false, argsAndNames.getSignature(), argsAndNames.getArguments());
166165
}
167166

168167
private static RArgsValuesAndNames createArgsAndNames(List<Object> argValues, RArgsValuesAndNames dotArgs) {

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/TryRfEvalNode.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, 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
@@ -26,6 +26,7 @@
2626
import com.oracle.truffle.api.interop.InteropLibrary;
2727
import com.oracle.truffle.r.runtime.DSLConfig;
2828
import com.oracle.truffle.r.runtime.RErrorHandling;
29+
import com.oracle.truffle.r.runtime.context.RContext;
2930
import com.oracle.truffle.r.runtime.data.RNull;
3031
import com.oracle.truffle.r.runtime.ffi.util.WritePointerNode;
3132

@@ -36,13 +37,14 @@ public final class TryRfEvalNode extends FFIUpCallNode.Arg4 {
3637

3738
@Override
3839
public Object executeObject(Object expr, Object env, Object errorFlag, Object silent) {
39-
Object handlerStack = RErrorHandling.getHandlerStack();
40-
Object restartStack = RErrorHandling.getRestartStack();
40+
RContext context = RContext.getInstance(this);
41+
Object handlerStack = RErrorHandling.getHandlerStack(context);
42+
Object restartStack = RErrorHandling.getRestartStack(context);
4143
boolean ok = true;
4244
Object result = RNull.instance;
4345
try {
4446
// TODO handle silent
45-
RErrorHandling.resetStacks();
47+
RErrorHandling.resetStacks(context);
4648
result = rfEvalNode.executeObject(expr, env);
4749
} catch (Throwable t) {
4850
ok = false;

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FastRUpCalls.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import com.oracle.truffle.r.ffi.impl.nodes.FASTR_DATAPTRNode;
2626
import com.oracle.truffle.r.ffi.impl.nodes.FASTR_serializeNode;
2727
import com.oracle.truffle.r.ffi.processor.RFFICpointer;
28+
import com.oracle.truffle.r.ffi.processor.RFFIInject;
2829
import com.oracle.truffle.r.ffi.processor.RFFIUpCallNode;
30+
import com.oracle.truffle.r.runtime.context.RContext;
2931

3032
/**
3133
* Up-calls specific to FastR used in FastR native code and not exported as part of any API.
@@ -50,7 +52,7 @@ public interface FastRUpCalls {
5052

5153
boolean isSeekable(Object x);
5254

53-
void restoreHandlerStacks(Object savedHandlerStack);
55+
void restoreHandlerStacks(Object savedHandlerStack, @RFFIInject RContext context);
5456

5557
/**
5658
* Implements {@code DATAPTR} for types that do not have specialized API function for accessing

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, 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
@@ -131,6 +131,7 @@ public void setCurrentDevice(String name, GridDevice currentDevice) {
131131
setCurrentDevice(name, currentDevice, null);
132132
}
133133

134+
@TruffleBoundary
134135
public void setCurrentDevice(String name, GridDevice currentDevice, String filenamePattern) {
135136
assert devices.size() == RGridGraphicsAdapter.getDevicesCount() : devices.size() + " vs " + RGridGraphicsAdapter.getDevicesCount();
136137
RContext rCtx = RContext.getInstance();
@@ -141,6 +142,7 @@ public void setCurrentDevice(String name, GridDevice currentDevice, String filen
141142
assert devices.size() == RGridGraphicsAdapter.getDevicesCount() : devices.size() + " vs " + RGridGraphicsAdapter.getDevicesCount();
142143
}
143144

145+
@TruffleBoundary
144146
public void setCurrentDevice(int deviceIdx) {
145147
assert deviceIdx > 0 && deviceIdx < this.devices.size();
146148
RContext rCtx = RContext.getInstance();
@@ -197,6 +199,7 @@ public GridDevice getDevice(int index) {
197199
/**
198200
* Runs arbitrary function from 'fastrGrid.R' file and returns its result.
199201
*/
202+
@TruffleBoundary
200203
public Object evalInternalRFunction(String functionName, Object... args) {
201204
if (internalCode == null) {
202205
RContext context = RContext.getInstance();

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/WindowDevice.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, 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,6 +22,7 @@
2222
*/
2323
package com.oracle.truffle.r.library.fastrGrid;
2424

25+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2526
import com.oracle.truffle.r.library.fastrGrid.device.GridDevice;
2627
import com.oracle.truffle.r.library.fastrGrid.device.awt.JFrameDevice;
2728
import com.oracle.truffle.r.nodes.function.PromiseHelperNode;
@@ -41,6 +42,7 @@ private WindowDevice() {
4142
// only static members
4243
}
4344

45+
@TruffleBoundary
4446
public static GridDevice createWindowDevice(boolean byGridServer, int width, int height) {
4547
return createWindowDevice(RContext.getInstance(), byGridServer, width, height);
4648
}

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/SVGDevice.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, 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
@@ -32,6 +32,7 @@
3232
import java.text.DecimalFormat;
3333
import java.util.Base64;
3434

35+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3536
import com.oracle.truffle.api.TruffleFile;
3637
import com.oracle.truffle.r.library.fastrGrid.GridColorUtils;
3738
import com.oracle.truffle.r.library.fastrGrid.device.DrawingContext.GridFontStyle;
@@ -214,6 +215,7 @@ private void drawPoly(DrawingContext ctx, double[] x, double[] y, int startIndex
214215
data.append("/>\n");
215216
}
216217

218+
@TruffleBoundary
217219
private void saveFile() throws DeviceCloseException {
218220
closeSVGDocument(data);
219221
try {

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedImageDevice.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, 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
@@ -32,6 +32,7 @@
3232

3333
import javax.imageio.ImageIO;
3434

35+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3536
import com.oracle.truffle.api.TruffleFile;
3637
import com.oracle.truffle.r.library.fastrGrid.device.FileGridDevice;
3738
import com.oracle.truffle.r.library.fastrGrid.device.NotSupportedImageFormatException;
@@ -73,6 +74,7 @@ public void close() throws DeviceCloseException {
7374
saveImage();
7475
}
7576

77+
@TruffleBoundary
7678
private void saveImage() throws DeviceCloseException {
7779
try {
7880
TruffleFile file = RContext.getInstance().getSafeTruffleFile(filename);

0 commit comments

Comments
 (0)