Skip to content
Snippets Groups Projects
Commit 0d14338b authored by Mick Jordan's avatar Mick Jordan
Browse files

graphics subsystem only initialized once

parent 6c4dbdb6
Branches
No related tags found
No related merge requests found
......@@ -13,8 +13,7 @@
^com.oracle.truffle.r.test/rpackages/testrlibs_user
^com.oracle.truffle.r.test.native/urand/lib/liburand.so
^com.oracle.truffle.r.native/gnur/R-*
com.oracle.truffle.r.native/fficall/src/jni/arithmetic.c
com.oracle.truffle.r.native/fficall/src/jni/util.c
com.oracle.truffle.r.native/fficall/src/common/copy_appl_objects
^DEPARSE_ERROR
^Rpkgsource/*
^install.cran.logs/
......
......@@ -14,6 +14,8 @@
*/
package com.oracle.truffle.r.library.graphics;
import java.util.concurrent.atomic.AtomicBoolean;
import com.oracle.truffle.r.library.graphics.core.*;
import com.oracle.truffle.r.runtime.FastROptions;
import com.oracle.truffle.r.runtime.context.*;
......@@ -24,8 +26,14 @@ import com.oracle.truffle.r.runtime.ffi.DLL.SymbolInfo;
import com.oracle.truffle.r.runtime.ffi.RFFIFactory;
/**
* A placeholder to keep {@code REngine} limited to calling the {@link #initialize} method. It sets
* the {@code .Device} and {@code .Devices} variables in "base" as per GnuR.
* A placeholder to keep {@code REngine} limited to calling the {@link #initialize} method. Two
* possible implementations are available:
* <ul>
* <li>Native graphics from GnuR</li>
* <li>Internal (Java) graphics, very incomplete implementation</li>
* </ul>
* The default is native graphics, selected by a startup option. Graphics is not virtualized, so
* multiple contexts all share the same underlying implementation which is initialized exactly once.
*
*/
public class RGraphics {
......@@ -38,17 +46,20 @@ public class RGraphics {
*/
private static final String DOT_DEVICE = ".Device";
private static final String DOT_DEVICES = ".Devices";
private static final AtomicBoolean initialized = new AtomicBoolean();
public static void initialize() {
if (FastROptions.UseInternalGraphics.getBooleanValue()) {
REnvironment baseEnv = REnvironment.baseEnv();
baseEnv.safePut(DOT_DEVICE, NULL_DEVICE);
RPairList devices = RDataFactory.createPairList(NULL_DEVICE);
baseEnv.safePut(DOT_DEVICES, devices);
registerBaseGraphicsSystem();
} else {
SymbolInfo symbolInfo = DLL.findSymbolInfo("InitGraphics", null);
RFFIFactory.getRFFI().getCRFFI().invoke(symbolInfo.address, new Object[0]);
if (initialized.compareAndSet(false, true)) {
if (FastROptions.UseInternalGraphics.getBooleanValue()) {
REnvironment baseEnv = REnvironment.baseEnv();
baseEnv.safePut(DOT_DEVICE, NULL_DEVICE);
RPairList devices = RDataFactory.createPairList(NULL_DEVICE);
baseEnv.safePut(DOT_DEVICES, devices);
registerBaseGraphicsSystem();
} else {
SymbolInfo symbolInfo = DLL.findSymbolInfo("InitGraphics", null);
RFFIFactory.getRFFI().getCallRFFI().invokeVoidCall(symbolInfo.address, "InitGraphics", new Object[0]);
}
}
}
......
......@@ -27,7 +27,7 @@ ifneq ($(MAKECMDGOALS),clean)
include $(TOPDIR)/platform.mk
endif
.PHONY: all clean copy_appl_objects
.PHONY: all clean
# location of compiled code (.o files)
OBJ = ../../lib
......@@ -61,6 +61,7 @@ all: Makefile $(C_OBJECTS) $(F_OBJECTS) $(GNUR_C_OBJECTS) $(GNUR_F_OBJECTS) copy
copy_appl_objects: $(GNUR_APPL_F_OBJECTS)
cp $(GNUR_APPL_F_OBJECTS) $(OBJ)
touch copy_appl_objects
$(C_OBJECTS): | $(OBJ)
......@@ -87,5 +88,5 @@ $(OBJ)/%.o: %.f
$(F77) $(FFLAGS) $(FPICFLAGS) -c $< -o $@
clean:
rm -rf $(OBJ)
rm -rf $(OBJ) copy_appl_objects
......@@ -228,5 +228,17 @@ Java_com_oracle_truffle_r_runtime_ffi_jnr_JNI_1CallRFFI_callVoid1(JNIEnv *env, j
callExit(env);
}
typedef void (*callVoid0func)();
JNIEXPORT void JNICALL
Java_com_oracle_truffle_r_runtime_ffi_jnr_JNI_1CallRFFI_callVoid0(JNIEnv *env, jclass c, jlong address) {
callEnter(env, &error_jmpbuf);
if (!setjmp(error_jmpbuf)) {
callVoid0func call1 = (callVoid0func) address;
(*call1)();
}
callExit(env);
}
......@@ -130,6 +130,9 @@ public class JNI_CallRFFI implements CallRFFI {
try {
inCritical.acquire();
switch (args.length) {
case 0:
callVoid0(address);
break;
case 1:
callVoid1(address, args[0]);
break;
......@@ -142,6 +145,8 @@ public class JNI_CallRFFI implements CallRFFI {
}
}
private static native void callVoid0(long address);
private static native void callVoid1(long address, Object arg1);
public void setTempDir(String tempDir) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment