jruby-user - hitimes java extension in the works, some help needed

by Jeremy Hinegardneron 2010-07-26T17:06:13+00:00
Hi all,
I have the Hitimes gem (http://copiousfreetime.rubyforge.org/hitimes/), and I
received a request to have it work on JRuby. It has an embedded C extension,
and does not link to an external library. I figured, why not take the
opportunity to learn how to write a pure JRuby extension.
After looking at the extensions and Ruby class implmenations in the jruby
distribution I think I implemented what I needed correctly, using
annotations.
It compiles, and creates the .jar. Only now, the annotated classes and methods
do not appear to exist in the runtime.
I'm sure I have missed something simple, I just need the obvious pointed out
to me. If someone could take a few minutes and help me out, I would greatly
appreciate it.
http://github.com/copiousfreetime/hitimes/tree/java-ext
The gem list you need to run the rake tasks is:
configuration (0.0.4)
jruby-openssl (0.7)
json-pure (1.4.3)
rake (0.8.7)
rdoc (2.5.8)
rspec (1.3.0)
rubyforge (2.0.4)
If you check out that tree, then you can build and locally install the jar.
rake ext:build-jruby
I then drop into irb and attempt this:
% irb
NameError: uninitialized constant Hitimes::Interval
The Hitimes::Interval class is defined in the extension.
Any and all help is appreciated.
thanks,
-jeremy
http://xircles.codehaus.org/manage-email

Re: jruby-user - hitimes java extension in the works, some help needed

by Wayne Meissneron 2010-07-27T07:18:25+00:00.
Not answering the question that you asked, but just pointing out a bug
in your code:
Where you have code like:
if ( INSTANT-NOT-SET == this.start-instant ) {
return getRuntime().getFalseClass();
}
return getRuntime().getTrueClass();
the above will return the classes for true/false, not instances of true/false.
You probably want:
return getRuntime().newBoolean(INSTANT-NOT-SET == this.start-instant);
Also, its a good idea to pass in ThreadContext as your first
parameter, and use that to get the runtime.
e.g.
@JRubyMethod( name = "stopped?" )
public IRubyObject is-stopped(ThreadContext context) {
return context.getRuntime().newBoolean(INSTANT-NOT-SET ==
this.stop-instant);
}
IRubyObject#getRuntime() (used to be?/still is?) polymophic, so is
less efficient than ThreadContext#getRuntime()
btw, the hitimes C extension might work using the cext branch of
jruby. It would be interesting to see how badly performance is
affected vs native on MRI, and the java extension.

On Mon, Jul 26, 2010 at 11:06:13AM -0600, Jeremy Hinegardner wrote:
Most of the problem was attempting:
public class HitimesService implements Library {
}
Instead of :
public class HitimesService implements BasicLibraryService {
}
User error here. It is now building and passing all of the tests
that existed for the MRI extension. I'll make an official release
here in the next day or two.
I would still appreciate it if someone to take a look at the hitimes
java extension and let me know if I have developed it in an acceptable
manner, followed extension conventions (if there are any), etc.
enjoy,
-jeremy
http://xircles.codehaus.org/manage-email

Re: jruby-user - hitimes java extension in the works, some help needed

by Tim Felgentreffon 2010-07-27T17:32:27+00:00.

The hitimes spec on jruby cext currently has a very large number of failures. Comparing performance when/if it gets ready would be interesting.
-Tim
http://xircles.codehaus.org/manage-email

Re: jruby-user - hitimes java extension in the works, some help needed

by Jeremy Hinegardneron 2010-07-27T17:33:29+00:00.
Thanks!
This bug got caught by my existing tests once I could run them. true is not
TrueClass :-).
I'm working up some more thoughts/questions in general about java extensions,
stay tuned.
http://xircles.codehaus.org/manage-email

Re: jruby-user - hitimes java extension in the works, some help needed

by Jeremy Hinegardneron 2010-07-27T17:58:00+00:00.
On Tue, Jul 27, 2010 at 07:32:27PM +0200, Tim Felgentreff wrote:
I'll give it a look and see what I come up with.
-jeremy
http://xircles.codehaus.org/manage-email