
-----------------------------------
btiffin
Fri Sep 05, 2008 8:06 pm

OpenJDK versus gcj
-----------------------------------
Hello java junkies;

I'm embarking on a How-To for linking OpenCOBOL to Java (gcj in particular), Ada (gnat), etc...   I just noticed a Debian package for OpenJDK.  I'll ask here before I RTFM.

Can OpenJDK be used to pump out object code ala gcj?  If not, then I can skip reading up, as the plan is to be able to link OC1.1 object code to other languages.

Or ... will I learn things reading through the OpenJDK docs that I can use for gcj native code?

Thanks in advance.
Cheers

-----------------------------------
Zeroth
Fri Sep 05, 2008 9:00 pm

Re: OpenJDK versus gcj
-----------------------------------
OpenJDK is also known as IcedTea, the Redhat open source Java replacement. It essentially behaves exactly like Sun's JDK, which means, no, afaik, no object code ala gcj.

-----------------------------------
btiffin
Fri Sep 05, 2008 9:06 pm

RE:OpenJDK versus gcj
-----------------------------------
Yeah, I assumed ... but I had hopes.  Well not really.  I'm finding development with gcj to be quite acceptable.  With the caveat that I've not put myself in a position to NEED something to work, only a position of wanting, and that always makes development systems seem more powerful than they may actually be "in real life".

Thanks Zeroth.

-----------------------------------
md
Fri Sep 05, 2008 10:38 pm

RE:OpenJDK versus gcj
-----------------------------------
What's wrong with the Sun JDK? It's open source...

-----------------------------------
wtd
Sat Sep 06, 2008 1:59 am

RE:OpenJDK versus gcj
-----------------------------------
Yeah, but linking to COBOL and Ada might be challenging.

-----------------------------------
btiffin
Sat Sep 06, 2008 12:38 pm

Re: RE:OpenJDK versus gcj
-----------------------------------
First I'll start by admitting this project may take a back burner while I absorb some of the technical details.

md; as wtd alluded to, the plan is to be able to write up a HowTo for linking/wrapping native object code for use with cob_resolve and the OpenCOBOL CALL interface.  It's going to take a fair bit more reading up on the libgcj init and rundown, and adainit and adafinal testing before I'll be worthy of writing the doc and samples for this one.

I'd like to avoid simply calling gij (or java) on a class file; even with CNI/JNI, but it may well come down to that, in which case OpenJDK will be an option.

And thanks for the opinions.  Every little bit helps.
Cheers

-----------------------------------
buu700
Sun Sep 07, 2008 12:40 am

Re: OpenJDK versus gcj
-----------------------------------
Not sure if this is what you're looking for, but: http://iced-tea.org/wiki/BrandWeg

-----------------------------------
btiffin
Mon Sep 08, 2008 4:19 am

Re: OpenJDK versus gcj
-----------------------------------
Diluting things here in Java land a little, but I'll add that bit shortly ... I promise ... kinda ...

Just added this to the opencobol.org forum for the Ada piece of the puzzle.  The gcj wrapper is only a few more cursin' and swearin' sessions away I hope.

Cheers
===


Hello coders,

One way of calling Ada (gnat) procedures and functions from OpenCOBOL.

This works for me with Debian 4.0, OC1.1 (recent), gnat 4.3

The idea is to compile object, bind, compile bound object and then let OpenCOBOL do its thing linking the gnat lib, the Ada body object and the Ada binding object (-n for no main on the gnatbind).


$ gnatgcc -c helloada.adb
$ gnatbind -n helloada
$ gnatgcc -c b~helloada.adb
$ cobc -x -lgnat caller.cob helloada.o b~helloada.o


Cheers,
Brian     
caller.cob

       >>SOURCE FORMAT IS FIXED
      ******************************************************************
      * Author:    Brian Tiffin 
      * Date:      08-Sep-2008 
      * Purpose:   Demonstrate using Ada sub-programs 
      * Tectonics: gnatgcc -c helloada.adb
      *            gnatbind -n helloada
      *            gnatgcc -c b~helloada.abd
      *            cobc -x -lgnat caller.cob helloada.o b~helloada.o 
      ******************************************************************
       identification division.
       program-id. caller.

       data division.
       working-storage section.
       01 ada-message      pic x(10) value "Ada echo" & x'0a' & x'00'.
       01 result           pic s9(9) value high-value.
      *****************************************************************
       procedure division.
       begin.
       call "adainit" end-call
      
       call "hello" using by value 42 end-call

       call "echo" using
           by reference ada-message
           returning result
       end-call
       display "Ada return: " result end-display

       call "adafinal" end-call

       goback
       .
       end program caller.


With a sample Ada Spec, helloada.ads

with Interfaces.C;
use Interfaces.C;
package HelloAda is

   procedure hello(value : in integer);
   function echo(message : in char_array) return integer;
   pragma export(C, hello);
   pragma export(C, echo);

end HelloAda;

And body helloada.adb

with Ada.Text_IO, Ada.Integer_Text_IO, Interfaces.C;
use  Ada.Text_IO, Ada.Integer_Text_IO, Interfaces.C;
package body HelloAda is

procedure hello(value : in integer) is
begin
   Put_Line("Hello WORLD! from Ada and OpenCOBOL");
   Put("OpenCOBOL passed: ");
   Put(value);
   New_Line;
end hello;

function echo(message : in char_array) return integer is
begin
    Put(To_Ada(message, true));
    return To_Ada(message, true)'length;
end echo;

end HelloAda;

Outputting ...

Hello WORLD! from Ada and OpenCOBOL
OpenCOBOL passed:          42
Ada echo
Ada return: +000000009


Note; the adafinal seems to toss an extra newline, at least here.

-----------------------------------
btiffin
Thu Dec 18, 2008 2:31 pm

Re: OpenJDK versus gcj
-----------------------------------
Excuse the old threading, but this is still on my plate;

Ok, so Java guru's.  I'm aiming to link a Java engine (I use gcj ... that may be a mistake, I'm open to have you in the know straighten me out ... with a big stick if needed) inside C code.

OpenCOBOL is a C based system.  It requires the C linkage model.

So ... given that the java launcher java --classpath yadayada myclass is a fairly thin layer of C to kick start a JVM, I'm thinking that this is a doable thing.

JNI is always documented as calling native methods ... and I want to wrap a JVM from C, so the instructions are bass-ackwards for what I'm aiming for.

The gjavah command is confusing me ... it doesn't seem to do produce anything in the .h file other than #include  (with some extraneous ifdef __cplusplus  extern "C" ...) and little else.

As you may know by now, I'm a huge fan of high-level embedding for my proof of concept passes, so I'm aiming to wrap a JVM, call a method (from C or OpenCOBOL) passing some arguments and returning a result.  Simple int or char * will do for now, the rest will come with a little work.

So ... any hints as to why I'm mentally blocked on how this should all fit together?

If I haven't explained myself enough yet; a use case would be


IDENTIFICATION DIVISION.
PROGRAM-ID. calljava.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 handle USAGE POINTER.
01 java-input PIC X(80) VALUE "this is the input argument".
01 java-output PIC X(80).
01 result USUAGE BINARY-LONG.

PROCEDURE DIVISION.
CALL "CBL_OC_JAVAINIT" RETURNING handle END-CALL

CALL "runsomejava"
    USING
        BY VALUE handle
        BY REFERENCE java-input
        BY REFERENCE java-output
    RETURNING result
END-CALL

IF result equal ZERO
    DISPLAY
        "Hey look at that, Java gave me back: "
        java-output
    END-DISPLAY
ELSE
    DISPLAY "Error result: " result END-DISPLAY
END-IF

CALL "CBL_OC_JAVARUNDOWN" END-CALL

GOBACK.
END PROGRAM calljava.

Details being incorrect perhaps, as this is imaginary COBOL.  Maybe it won't need a handle, maybe each method call will invoke an entire engine ...
 
Cheers,
Brian

P.S.  I guess I'm asking for help on where to find the document that explains the java launcher for use to pass in args and get results back.
