Skip to content
Snippets Groups Projects
Commit c02b7610 authored by Tomas Stupka's avatar Tomas Stupka
Browse files

rJava rewrite - fastr changes:

- removed jri
- removed all native code and replced with fastr interop based impl in R
- some tweaks in original rjava R code
- java build part of install
parent 30adbacc
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 3058 deletions
R_HOME=$(RHOME)
JAVA_HOME=$(JAVAHOME)
JAVAINC=-I$(JAVAHOME)/include -I$(JAVAHOME)/include/win32
RINC=-I$(R_HOME)/include
JNISO=.dll
JAVA_LIBS=-Lwin32 -ljvm
JNILD=-shared $(JAVA_LIBS) -L$(RHOME)/src/gnuwin32 -L$(RHOME)/bin$(R_ARCH) -lR -Wl,--kill-at
CFLAGS+=-DWin32 -D_JNI_IMPLEMENTATION_
JAVA_PROG=$(JAVAHOME)/bin/java
JAVA=$(JAVAHOME)/bin/java
JAVAC=$(JAVAHOME)/bin/javac
JAVAH=$(JAVAHOME)/bin/javah
JAR=$(JAVAHOME)/bin/jar
JRIDEPS=win32/libjvm.dll.a
JNIPREFIX=
PLATFORMT=run.bat
JRILIB=jri.dll
package org.rosuda.JRI;
/** This class implements a (not so) simple mutex. The initial state of the mutex is unlocked. */
public class Mutex {
public static boolean verbose=false;
/** defines the current mutex state */
private boolean locked=false;
/** thread that locked this mutex (used for simple deadlock-detection) */
private Thread lockedBy=null;
/** locks the mutex. If the mutex is already locked, waits until the mutex becomes free. Make sure the same thread doesn't issue two locks, because that will cause a deadlock. Use {@link #safeLock()} instead if you wish to detect such deadlocks. */
public synchronized void lock()
{
while (locked) {
if (lockedBy==Thread.currentThread())
System.err.println("FATAL ERROR: org.rosuda.JRI.Mutex detected a deadlock! The application is likely to hang indefinitely!");
if (verbose)
System.out.println("INFO: "+toString()+" is locked by "+lockedBy+", but "+Thread.currentThread()+" waits for release (no timeout)");
try {
wait();
} catch (InterruptedException e) {
if (verbose)
System.out.println("INFO: "+toString()+" caught InterruptedException");
}
}
locked=true;
lockedBy=Thread.currentThread();
if (verbose) System.out.println("INFO: "+toString()+" locked by "+lockedBy);
}
/** locks the mutex. If the mutex is already locked, waits until the mutex becomes free. Make sure the same thread doesn't issue two locks, because that will cause a deadlock.
@param to timeout in milliseconds, see {@link #wait()}.
@return <code>true</code> if the lock was successful, <code>false</code> if not
*/
public synchronized boolean lockWithTimeout(long to)
{
if (locked) {
if (lockedBy==Thread.currentThread())
System.err.println("FATAL ERROR: org.rosuda.JRI.Mutex detected a deadlock! The application is likely to hang indefinitely!");
if (verbose)
System.out.println("INFO: "+toString()+" is locked by "+lockedBy+", but "+Thread.currentThread()+" waits for release (timeout "+to+" ms)");
try {
wait(to);
} catch (InterruptedException e) {
if (verbose)
System.out.println("INFO: "+toString()+" caught InterruptedException");
}
}
if (!locked) {
locked=true;
lockedBy=Thread.currentThread();
if (verbose) System.out.println("INFO: "+toString()+" locked by "+lockedBy);
return true;
}
if (verbose) System.out.println("INFO: "+toString()+" timeout, failed to obtain lock for "+Thread.currentThread());
return false;
}
/** attempts to lock the mutex and returns information about its success.
@return 0 if the mutex was locked sucessfully<br>1 if the mutex is already locked by another thread<br>-1 is the mutex is already locked by the same thread (hence a call to {@link #lock()} would cause a deadlock). */
public synchronized int tryLock()
{
if (verbose) System.out.println("INFO: "+toString()+" tryLock by "+Thread.currentThread());
if (locked) return (lockedBy==Thread.currentThread())?-1:1;
locked=true;
lockedBy=Thread.currentThread();
if (verbose) System.out.println("INFO: "+toString()+" locked by "+lockedBy);
return 0;
}
/** Locks the mutex. It works like {@link #lock()} except that it returns immediately if the same thread already owns the lock. It is safer to use this function rather than {@link #lock()}, because lock can possibly cause a deadlock which won't be resolved.
@return <code>true</code> is the mutex was successfully locked, <code>false</code> if deadlock was detected (i.e. the same thread has already the lock). */
public synchronized boolean safeLock()
{
if (locked && lockedBy==Thread.currentThread()) {
if (verbose) System.out.println("INFO: "+toString()+" unable to provide safe lock for "+Thread.currentThread());
return false;
}
lock();
return true;
}
/** Locks the mutex. It works like {@link #lockWithTimeout(long)} except that it returns immediately if the same thread already owns the lock. It is safer to use this function rather than {@link #lockWithTimeout(long)}, because lock can possibly cause a deadlock which won't be resolved.
@return <code>true</code> is the mutex was successfully locked, <code>false</code> if deadlock was detected or timeout elapsed. */
public synchronized boolean safeLockWithTimeout(long to)
{
if (locked && lockedBy==Thread.currentThread()) {
if (verbose) System.out.println("INFO: "+toString()+" unable to provide safe lock (deadlock detected) for "+Thread.currentThread());
return false;
}
return lockWithTimeout(to);
}
/** unlocks the mutex. It is possible to unlock an unlocked mutex, but a warning may be issued. */
public synchronized void unlock()
{
if (locked && lockedBy!=Thread.currentThread())
System.err.println("WARNING: org.rosuda.JRI.Mutex was unlocked by other thread than locked! This may soon lead to a crash...");
locked=false;
if (verbose) System.out.println("INFO: "+toString()+" unlocked by "+Thread.currentThread());
// notify just 1 in case more of them are waiting
notify();
}
public String toString()
{
return super.toString()+"["+((locked)?"":"un")+"locked"+((!locked)?"":(", by "+((lockedBy==Thread.currentThread())?"current":"another")+" thread"))+"]";
}
}
NEWS/ChangeLog for JRI
--------------------------
0.5-5 (under development)
o fix compilation in parallel using the -j switch for GNU Make
o some more Win64 fixes
0.5-4 2010-09-17
o added more options to rniStop() on unix and changed the
default to use interrupt flags instead of signals since
signals cause problems in some JVM implmentations. The
previous behavior can be achieved by rniStop(1).
0.5-3 2010-09-02
o fixed changed by the Win64 support which broke some other OSes by
using sign extension when converting to long storage.
o avoid the use of the sign of pointers for signaling. Note
that rniEval() now returns 0 on error and not -1 or -2. The
old behavior was undocumented (and dangerous) and thus should
not be relied upon. (fixes #172)
0.5-2 2010-04-28
o fixed handling of NAs in strings - they are now correctly
converted to <null>s on the Java side.
IMPORTANT: previously NAs would come as the string "NA"
from R which is incorrect since it is not distinguishable from
a literal "NA" string. Code that deals with NAs must be prepared
to receive nulls in string arrays (note that nulls where
correctly converted to NA string, it's just that incoming
string were not converted).
(Thanks to Stephan Wahlbrink for pointing out the inconsistency)
o multiple fixes to Windows support: common command line
arguments are now correctly processed, sub-architectures are
supported, Win64 is now also supported
0.5-1 2010-03-16
o API 1.10: rniAssign now returns boolean to denote success/failure
o numerous bug fixes and additions
0.5-0 2009-08-22
o API 1.9: added rniPreserve, rniRelease, rniParentEnv, rniFindVar,
rniListEnv, rniSpecialObject, rniPrintValue,
rniGetRawArray, rniPutRawArray, rniGetAttrNames methods
added jriLoaded field (boolean)
o new REngine-based API (org.rosuda.REngine.JRI.JRIEngine)
has been created - this allows the same code to interface
JRI or Rserve without re-compilation
Note: the JAR files are currently shipped separately from the JRI
installation and can be obtained from
http://rforge.net/JRI/files/
o proxy references are now preserved until finalized
o if jri.ignore.ule=yes property is set, JRI will not abort on
failing to load the JRI library (UnsatisfiedLinkException).
This can be used by GUIs to display a more meaningful message
instead of abort. The jriLoaded flag is false in that case.
0.4-2
o declare string encoding as UTF-8 and convert incoming strings
to UTF-8 if possible (R >= 2.7.0 required).
0.4-1 (part of rJava 0.5-1 and later)
o fixed configuration to work with multi-arch builds
0.4-0 2007-08-22 (part of rJava 0.5-0)
o adapt to changes in R-devel
o add -I. to CFLAGS for compatibility (thanks to BDR)
o added RConsoleOuputStream class
o API 1.8: added rniPrint, added int oType parameter to the
rWriteConsole callback
o work around broken MinGW runtimes
o allow JRI to hook into a running R process (and thusly provide
rJava with callbacks)
o added: inMainRThread(), isStandAlone()
o include configure in SVN and don't rebuild it on mkdist
0.3-7 2006-01-14
o make sure rniJavaToXref creates a global reference
o API 1.7: rniCons can accept two new arguments: tag and lang
rniLCons was added
o assign now supports raw REXPs (XT_NONE)
o createRJavaRef was added to create jobjRef R objects from
Java objects
0.3-6 2006-11-29
o adapted to API change in R-devel
o fixed double-inclusion of JFLAGS which throws off GIJ
0.3-5 2006-10-06
o remove variadic macros to be compatible with compilers
that don't support C99
0.3-4 2006-09-14
o updated Makefiles to force 1.4 target and sources
0.3-3 2006-09-12
o fixed API version in Java sources and added version check
to examples
0.3-2 2006-09-11
o New API (1.6): add handling of boolean type
0.3-1 2006-08-31
0.3-0 2006-05-31
o New API (1.5) entries: rniGetTAG, rniInherits,
rniGetSymbolName, rniInstallName
allows handling of symbols, named lists and inheritance
o fixed/improved REXP, RList and RFactor
0.2-5 2006-05-08
o Use configure to detect CStackXXX and R_SignalHandlers
set the latter to 0 if present (solves threading issues)
0.2-4 2006-05-03
o added support for pre-configuration passed from rJava
0.2-3 2006-04-20
o fix warnings and issues with R 2.3.0
0.2-2 2006-04-11
o licensed under LGPL
0.2-1 2006-03-07
o fixed Java detection, fixed eval double-unlock,
use R shlib flags, added FreeBSD support
0.2-0 2005-12-19
o switched to autoconf process for configuration/installation
0.1-0
o First JRI release
package org.rosuda.JRI;
// JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/
// Copyright (C) 2004 Simon Urbanek
// --- for licensing information see LICENSE file in the original JRclient distribution ---
/** Implementation of tri-state logical data type in R.
The three states are TRUE, FALSE and NA. To obtain truly boolean
value, you'll need to use {@link #isTRUE} or {@link #isFALSE} since there is
no canonical representation of RBool in boolean
@version $Id: RBool.java 2720 2007-03-15 17:35:42Z urbanek $
*/
public class RBool extends Object {
int val;
public RBool(boolean b) {
val=(b)?1:0;
};
public RBool(RBool r) {
val=r.val;
};
public RBool(int i) { /* 0=FALSE, 2=NA, anything else = TRUE */
val=(i==0||i==2)?i:1;
};
public boolean isNA() { return (val==2); };
public boolean isTRUE() { return (val==1); };
public boolean isFALSE() { return (val==0); };
public String toString() { return (val==0)?"FALSE":((val==2)?"NA":"TRUE"); };
}
// RConsoleOutputStream, part of Java/R Interface
//
// (C)Copyright 2007 Simon Urbanek
//
// For licensing terms see LICENSE in the root if the JRI distribution
package org.rosuda.JRI;
import java.io.OutputStream;
import java.io.IOException;
/** RConsoleOutputStream provides an OutputStream which causes its output to be written to the R console. It is a pseudo-stream as there is no real descriptor connected to the R console and thusly it is legal to have multiple console streams open. The synchonization happens at the RNI level.<p>Note that stdout/stderr are not connected to the R console by default, so one way of using this stream is to re-route Java output to R console:<pre>
System.setOut(new PrintStream(new RConsoleOutputStream(engine, 0)));
System.setErr(new PrintStream(new RConsoleOutputStream(engine, 1)));
</pre>
@since JRI 0.4-0
*/
public class RConsoleOutputStream extends OutputStream {
Rengine eng;
int oType;
boolean isOpen;
/** opens a new output stream to R console
@param eng R engine
@param oType output type (0=regular, 1=error/warning) */
public RConsoleOutputStream(Rengine eng, int oType) {
this.eng = eng;
this.oType = oType;
isOpen = true;
}
public void write(byte[] b, int off, int len) throws IOException {
if (!isOpen) throw new IOException("cannot write to a closed stream");
if (eng == null) throw new IOException("missing R engine");
String s = new String(b, off, len);
eng.rniPrint(s, oType);
}
public void write(byte[] b) throws IOException { write(b, 0, b.length); }
public void write(int b) throws IOException { write(new byte[] { (byte)(b&255) }); }
public void close() throws IOException { isOpen=false; eng=null; }
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
## there are two ways to compile JRIEngine - either use
## already installed REngine and JRI and then just
## compile JRIEngine against those jars or use this
## Makefile with all org sources checked out
## in which case the JRIEngine.jar will implicitly
## contain org.rosuda.JRI classes as well
## However, that requires both:
## org/rosuda/JRI
## org/rosuda/REngine
JRI_MAIN_SRC=$(wildcard ../../*.java)
JRIENGINE_SRC=JRIEngine.java
JAVAC=javac
JAR=jar
JFLAGS=-source 1.6 -target 1.6
all: JRIEngine.jar
JRIEngine.jar: $(JRI_MAIN_SRC) $(JRIENGINE_SRC)
rm -rf org
$(JAVAC) $(JFLAGS) -classpath ../REngine.jar -d . $^
$(JAR) fc $@ org
clean:
rm -rf org *~ JRIEngine.jar *.class
make -C test clean
/**
* REngine-based interface to JRI
*
* <p>
* Currently it uses low-level calls from org.rosuda.JRI.Rengine, but
* all REXP representations are created based on the org.rosuda.REngine API
*/
package org.rosuda.REngine.JRI ;
This diff is collapsed.
This diff is collapsed.
REngine - Java interface to R
Copyright (C) 2004,5,6,7 Simon Urbanek
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This diff is collapsed.
package org.rosuda.REngine;
public interface MutableREXP {
public void setAttribute(String name, REXP value);
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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