FFI not available: on Raspberry Pi ARM linux JRuby #1561

Open
CootCraig opened this Issue Mar 14, 2014 · 8 comments

Projects

None yet

7 participants

require 'spoon' fails on Raspberry Pi ARM linux JRuby

---- system notes
$ uname -a
Linux pika 3.10-3-rpi #1 Debian 3.10.11-1+rpi4 (2014-01-24) armv6l GNU/Linux

$ jruby -v
jruby 1.7.11 (1.9.3p392) 2014-02-24 86339bb on Java HotSpot(TM) Client VM 1.8.0-b129 +indy [linux-arm]

-------------------------------- the Exception trace

LoadError: Could not load FFI Provider: (NotImplementedError) FFI not available: null
See http://jira.codehaus.org/browse/JRUBY-4583
require at org/jruby/RubyKernel.java:1085
(root) at /opt/jruby/jruby-1.7.11/lib/ruby/shared/ffi/ffi.rb:69
require at org/jruby/RubyKernel.java:1085
(root) at /opt/jruby/jruby-1.7.11/lib/ruby/shared/ffi.rb:1
require at org/jruby/RubyKernel.java:1085
(root) at /opt/jruby/jruby-1.7.11/lib/ruby/shared/ffi.rb:1
require at org/jruby/RubyKernel.java:1085
(root) at /opt/jruby/jruby-1.7.11/lib/ruby/gems/shared/gems/spoon-0.0.4/lib/spoon/unix.rb:1
require at org/jruby/RubyKernel.java:1085
(root) at spoon_socat.rb:8

--- From Gemfile.lock
GEM
remote: http://rubygems.org/
specs:
...
ffi (1.9.3-java)
...
spoon (0.0.4)
ffi
...

--- From the script
require 'rubygems'
require 'bundler/setup'

require 'celluloid/autostart'
require 'celluloid/io'

require 'spoon' <<<<<<<<<<<<<<<<<<<<<< line 8 - spoon_socat.rb:8

class SocatSpawnAndWait
include 'Celluloid'
include 'Celluloid::Notifications'

DEFAULT_SPAWN_ARGV %w(/usr/bin/socat tcp-listen:54321,reuseaddr,fork file:/dev/Diavolino,raw,echo=0,b9600,waitlock=/var/run/Diavolino.lock')

def initialize(aspawn_argv=DEFAULT_SPAWN_ARGV)
@spawn_argv = aspawn_argv
end
def run
file_actions = Spoon::FileActions.new
spawn_attr = Spoon::SpawnAttributes.new
spawn_pid = Spoon.posix_spawn(SPAWN_PATH, file_actions, spawn_attr, @spawn_argv)
wait_pid,wait_status = Process.waitpid(spawn_pid)
[wait_pid,wait_status]
end
end

span_and_wait = SocatspawnAndWait.new
span_and_wait.run

cjdaly commented Apr 22, 2014

@CootCraig, did you find a solution to this?

I have an rPi, a BeagleBone Black and several other small ARM systems. On all of them (running Ubuntu), I see this error when using the hardware floating point version of the JRE. I also see failure running Process.pid which I described here: cjdaly/napkin#3 .

I can work around the issue by using the software float ('sflt') Oracle Java 7 downloads, but this presumably is lower performance.

This issue also looks related: #1137 .

No solution, you are the first feedback I've gotten. I put aside the RPi JRuby code and have been working on an Arduino sketch for a radio Arduino I hope to interface through JRuby on a RPi. I'm hoping to use the released JDK8 with JRuby along with some FFI gems.

TL;DR: the solution in the description of the suggested bug (http://jira.codehaus.org/browse/JRUBY-4583) is correct, you need to rebuild the native library.
Make sure you use the correct version of jffi (not necessarily v1.0.0) and keep in mind that the jffi repo in github moved.

Detailed answer:
Hello, I had this problem (or at least a similar one) today and wanted to offer my two cents on it.

In my case I was trying to run logstash on a Raspberry Pi (Model B) running the official raspbian image.
Running logstash with the provided jruby-complete-v1.7.11 or the official jruby-complete-v1.7.13 I got the above exception too.

The solution to the problem was to rebuild https://github.com/jnr/jffi from sources (from branch 1.2.0 and on the pi itself) and replace the new libjffi-1.2.so into the jruby-complete jar file.

I also noticed that:

  • If you remove (or rename) jni/arm-Linux/libjffi-1.2.so the error becomes something along the lines of file not found in jar (as you would expect).
  • On Fedora 20 64bits everything works fine.
  • Exception is thrown using both OpenJDK 1.7.0_40-b43 and Oracle JVM for Java 8.

It looks to me that the arm-Linux version of jffi provided in the jruby-complete jars is not compatible with the Raspberry Pi, or at the very least not with Raspberry Pi model B running the latest raspbian.

Cheers 😄,
Stefano

torgeir commented Dec 23, 2014

@stefano-pogliani You didn't by any chance jot down the steps you took? I was trying to accomplish the same thing :)

Edit:

These steps were needed to make logstash work with jruby on the raspberry pi

# get logstash-1.4.2
wget https://download.elasticsearch.org/logstash/logstash/logstash-1.4.2.zip
unzip logstash-1.4.2.zip

# get the latest jffi
$ git clone https://github.com/jnr/jffi.git
Cloning into 'jffi'...
remote: Counting objects: 6622, done.
remote: Total 6622 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6622/6622), 9.00 MiB | 1000 KiB/s, done.
Resolving deltas: 100% (2578/2578), done.

$ cd jffi/

$ ls
archive  build.xml  COPYING.GPL  COPYING.LESSER  jni  lib  libtest  LICENSE  pom.xml  src  version.xml

# compile jffi on the raspberry pi
$ ant jar
Buildfile: /home/pi/jffi/build.xml
# ...

# move to where jruby is inside logstash
$ cd logstash-1.4.2/vendor/jar

# create the folder where libjffi-1.2.so resides inside the jruby-complete-1.7.11.jar bundled with logstash
# note the capital L in arm-Linux
$ mkdir -p jni/arm-Linux/

# copy the built libjffi-1-2.so into the folder
$ cp ~/jffi/build/jni/libjffi-1.2.so ~/logstash-1.4.2/vendor/jar/jni/arm-Linux

# replace the libjffi-1.2.so inside the jruby-complete-1.7.11.jar
$ sudo apt-get install zip
$ zip -g jruby-complete-1.7.11.jar jni/arm-Linux/libjffi-1.2.so
updating: jni/arm-Linux/libjffi-1.2.so (deflated 63%)

# run logstash!
$ USE_JRUBY=1 LS_HEAP_SIZE=64m ./bin/logstash -e 'input { stdin { } } output { stdout { } }'

# type test
test

# ..some time later
2014-12-23T14:50:49.015+0000 pi test

@torgeir sorry not to respond in time but I did not remember the details anyways.
Recompiling and replacing was what I did too anyway.

@ph ph referenced this issue in elastic/logstash Jan 30, 2015
Closed

logstash does not work on ARM systems #1916

deveth0 commented Feb 21, 2015

Just a short note to the workaround:
the following packages are required to build jiffi:
apt-get install texinfo build-essential openjdk-7-jdk ant git

nthx commented Mar 16, 2015

Fix provided by @torgeir works perfectly on Linux odroid 3.10.58+ #13 SMP PREEMPT Tue Nov 4 14:09:41 KST 2014 armv7l armv7l armv7l GNU/Linux. Fixes Logstash 1.4. Thanks.

Oneiroi commented May 19, 2015

As an update for logstash 1.5 the location has changed, and only by overriding the original .so could I get logstash to start.

cp build/jni/libjffi-1.2.so /logstash-1.5.0/vendor/jruby/lib/jni/arm-Linux/libjffi-1.2.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment