Skip to content

Commit f87293a

Browse files
author
Pavel Marek
committed
[GR-19768] Update Truffle import.
PullRequest: fastr/2696
2 parents 468e150 + a1125fd commit f87293a

File tree

60 files changed

+289
-200
lines changed

Some content is hidden

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

60 files changed

+289
-200
lines changed

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

Lines changed: 3 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
@@ -1413,6 +1413,7 @@ public Object R_make_altcomplex_class(String className, String packageName, Obje
14131413
* @param method A reference to a native function
14141414
* @param signature Signature of the {@code method}
14151415
*/
1416+
@TruffleBoundary
14161417
private static AltrepMethodDescriptor createAltrepMethodDescriptor(Object method, String signature) {
14171418
InteropLibrary interop = InteropLibrary.getUncached();
14181419
if (!interop.isExecutable(method)) {

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_Call.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import com.oracle.truffle.api.dsl.Cached;
3131
import com.oracle.truffle.api.dsl.ImportStatic;
3232
import com.oracle.truffle.api.dsl.Specialization;
33-
import com.oracle.truffle.api.frame.VirtualFrame;
3433
import com.oracle.truffle.api.interop.InteropLibrary;
3534
import com.oracle.truffle.api.interop.TruffleObject;
3635
import com.oracle.truffle.api.library.CachedLibrary;
3736
import com.oracle.truffle.api.nodes.Node;
3837
import com.oracle.truffle.nfi.api.SignatureLibrary;
3938
import com.oracle.truffle.r.ffi.impl.nfi.TruffleNFI_CallFactory.TruffleNFI_InvokeCallNodeGen;
39+
import com.oracle.truffle.r.ffi.impl.nfi.TruffleNFI_CallFactory.TruffleNFI_InvokeVoidCallNodeGen;
4040
import com.oracle.truffle.r.runtime.DSLConfig;
4141
import com.oracle.truffle.r.runtime.RInternalError;
4242
import com.oracle.truffle.r.runtime.ffi.CallRFFI;
@@ -135,32 +135,30 @@ protected static FFIToNativeMirrorNode[] createWrapperNodes(int count) {
135135
}
136136
}
137137

138-
private static class TruffleNFI_InvokeVoidCallNode extends NodeAdapter implements InvokeVoidCallNode {
139-
private static final String CallVoid1Sig = "(pointer, pointer): void";
140-
private static final String CallVoid0Sig = "(pointer): void";
141-
142-
@Child private InteropLibrary execute0Interop = InteropLibrary.getFactory().createDispatched(DSLConfig.getInteropLibraryCacheSize());
143-
@Child private InteropLibrary execute1Interop = InteropLibrary.getFactory().createDispatched(DSLConfig.getInteropLibraryCacheSize());
144-
@Children private final FFIMaterializeNode[] ffiMaterialize0 = FFIMaterializeNode.create(0);
145-
@Children private final FFIToNativeMirrorNode[] ffiWrapper0 = FFIToNativeMirrorNode.create(0);
146-
@Children private final FFIMaterializeNode[] ffiMaterialize1 = FFIMaterializeNode.create(1);
147-
@Children private final FFIToNativeMirrorNode[] ffiWrapper1 = FFIToNativeMirrorNode.create(1);
148-
149-
@Override
150-
public void execute(VirtualFrame frame, NativeCallInfo nativeCallInfo, Object[] args) {
138+
@ImportStatic(DSLConfig.class)
139+
public abstract static class TruffleNFI_InvokeVoidCallNode extends NodeAdapter implements InvokeVoidCallNode {
140+
protected static final String CallVoid1Sig = "(pointer, pointer): void";
141+
protected static final String CallVoid0Sig = "(pointer): void";
142+
143+
@Specialization
144+
public void invokeVoidCallCached(NativeCallInfo nativeCallInfo, Object[] args,
145+
@CachedLibrary(limit = "getInteropLibraryCacheSize()") InteropLibrary execute0Interop,
146+
@CachedLibrary(limit = "getInteropLibraryCacheSize()") InteropLibrary execute1Interop,
147+
@Cached("createMaterializeNodes(1)") FFIMaterializeNode[] ffiMaterialize1,
148+
@Cached("createWrapperNodes(1)") FFIToNativeMirrorNode[] ffiWrapper1,
149+
@Cached("getCallVoid0Function()") TruffleObject callVoid0Function,
150+
@Cached("getCallVoid1Function()") TruffleObject callVoid1Function) {
151151
FFIDownCallWrap ffiWrap = new FFIDownCallWrap(args.length);
152152
try {
153153
Object[] wrappedArgs;
154154
switch (args.length) {
155155
case 0:
156156
logCall(nativeCallInfo.name, args);
157-
TruffleObject callVoid0Function = getFunction("dot_call_void0", TruffleNFI_Context.parseSignature(CallVoid0Sig));
158157
execute0Interop.execute(callVoid0Function, nativeCallInfo.address.asTruffleObject());
159158
break;
160159
case 1:
161160
logCall(nativeCallInfo.name, args);
162161
wrappedArgs = ffiWrap.wrapAll(args, ffiMaterialize1, ffiWrapper1);
163-
TruffleObject callVoid1Function = getFunction("dot_call_void1", TruffleNFI_Context.parseSignature(CallVoid1Sig));
164162
execute1Interop.execute(callVoid1Function, nativeCallInfo.address.asTruffleObject(), wrappedArgs[0]);
165163
break;
166164
default:
@@ -172,6 +170,24 @@ public void execute(VirtualFrame frame, NativeCallInfo nativeCallInfo, Object[]
172170
ffiWrap.close();
173171
}
174172
}
173+
174+
protected TruffleObject getCallVoid0Function() {
175+
Object callVoid0Sig = TruffleNFI_Context.parseSignature(CallVoid0Sig);
176+
return getFunction("dot_call_void0", callVoid0Sig);
177+
}
178+
179+
protected TruffleObject getCallVoid1Function() {
180+
Object callVoid1Sig = TruffleNFI_Context.parseSignature(CallVoid1Sig);
181+
return getFunction("dot_call_void1", callVoid1Sig);
182+
}
183+
184+
protected static FFIMaterializeNode[] createMaterializeNodes(int count) {
185+
return FFIMaterializeNode.create(count);
186+
}
187+
188+
protected static FFIToNativeMirrorNode[] createWrapperNodes(int count) {
189+
return FFIToNativeMirrorNode.create(count);
190+
}
175191
}
176192

177193
private static void logCall(String name, Object[] args) {
@@ -187,7 +203,7 @@ public InvokeCallNode createInvokeCallNode() {
187203

188204
@Override
189205
public InvokeVoidCallNode createInvokeVoidCallNode() {
190-
return new TruffleNFI_InvokeVoidCallNode();
206+
return TruffleNFI_InvokeVoidCallNodeGen.create();
191207
}
192208

193209
}

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 {

0 commit comments

Comments
 (0)