Skip to content
Snippets Groups Projects
Commit c2b07398 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

maintain proper RContext for foreign access to R vectors

parent 730d98b9
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -30,12 +30,15 @@ import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.ForeignAccess.Factory18;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.r.engine.TruffleRLanguage;
import com.oracle.truffle.r.engine.interop.RAbstractVectorAccessFactoryFactory.VectorReadNodeGen;
import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode;
import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode;
import com.oracle.truffle.r.nodes.control.RLengthNode;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.context.RContext.RCloseable;
import com.oracle.truffle.r.runtime.data.RLogical;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
......@@ -60,6 +63,7 @@ public final class RAbstractVectorAccessFactory implements Factory18 {
@CompilationFinal private boolean lengthAccess;
@Child private ExtractVectorNode extract = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true);
@Child private RLengthNode lengthNode = RLengthNode.create();
@Child private Node findContext = TruffleRLanguage.INSTANCE.actuallyCreateFindContextNode();
VectorReadNode() {
super(TruffleRLanguage.class, null, null);
......@@ -67,10 +71,13 @@ public final class RAbstractVectorAccessFactory implements Factory18 {
}
@Override
@SuppressWarnings("try")
public final Object execute(VirtualFrame frame) {
Object label = ForeignAccess.getArguments(frame).get(0);
Object receiver = ForeignAccess.getReceiver(frame);
return execute(frame, receiver, label);
try (RCloseable c = RContext.withinContext(TruffleRLanguage.INSTANCE.actuallyFindContext0(findContext))) {
Object label = ForeignAccess.getArguments(frame).get(0);
Object receiver = ForeignAccess.getReceiver(frame);
return execute(frame, receiver, label);
}
}
protected abstract Object execute(VirtualFrame frame, Object reciever, Object label);
......
......@@ -67,12 +67,10 @@ public class RFunctionMR {
RArgsValuesAndNames actualArgs = new RArgsValuesAndNames(arguments, ArgumentsSignature.empty(arguments.length));
try (RCloseable c = RContext.withinContext(TruffleRLanguage.INSTANCE.actuallyFindContext0(findContext))) {
try {
dummyFrame.setObject(slot, actualArgs);
return call.execute(dummyFrame, receiver);
} finally {
dummyFrame.setObject(slot, null);
}
dummyFrame.setObject(slot, actualArgs);
return call.execute(dummyFrame, receiver);
} finally {
dummyFrame.setObject(slot, null);
}
}
}
......
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -27,7 +27,9 @@ import java.util.Deque;
import java.util.concurrent.ConcurrentLinkedDeque;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
/**
......@@ -71,10 +73,16 @@ public final class MemoryCopyTracer {
* no-op.
*/
public static void reportCopying(RAbstractVector source, RAbstractVector dest) {
assert RContext.getInstance() != null : "valid context needed whenever copying could be reported";
if (!noMemoryCopyTracingAssumption.isValid() && enabled) {
for (Listener listener : listeners) {
listener.reportCopying(source, dest);
}
notifyListeners(source, dest);
}
}
@TruffleBoundary
private static void notifyListeners(RAbstractVector source, RAbstractVector dest) {
for (Listener listener : listeners) {
listener.reportCopying(source, dest);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment