OS/2, eCS & ArcaOS - Technical > Programming

OW, JNI (GCC built java 1.6) and parameters

<< < (3/3)

Jan-Erik Lärka:
Hello,

I've managed to find out the problem and solve it.

Built BSF4Rexx (2009) with Open Watcom 2.0 IDE and resolved some calling convention difficulties and it output:

--- Code: ---Rexx interpreter:  REXXSAA 4.00 3 Feb 1999
BSF4Rexx (DLL/so): 282.20090420 org/rexxla/bsf/engines/rexx

--- End code ---

The problem there is now related to something when java call back into the library:

--- Code: ---Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at org.rexxla.bsf.engines.rexx.RexxAndJava.javaCallBSF(RexxAndJava.java:1306)
--- End code ---

Please feel free to help me out

The code is useful as you try to write code not only for Java6 (OpenJDK) but also SQLite3 and Cairo as well, as it take care of floating point errors that occur there.

//Jan-Erik

LoadLib.txt modified to allow versions to load, such as cario2.dll, cario.dll, cairo164.dll etc.

Dave Yeo:
I'm sure I'm missing something but the Cairo Clock in the Screensaver is an example of OpenWatcom code calling a GCC DLL, cairo2.dll and using floating point to draw the clock. It seems to work fine.
The OW code to include Cairo

--- Code: ---#define cairo_public __declspec(__cdecl)
#include <cairo\cairo.h>
#include <cairo\cairo-os2.h>

--- End code ---
and later has,

--- Code: ---  // Set FPU state which might have been changed by some Win* calls!
  // (Workaround for a PM bug)
  DisableFPUException();

  // Initialize cairo support
  cairo_os2_init();

--- End code ---
with DisableFPUException being,

--- Code: ---/* One helper function: */
static void inline DisableFPUException()
{
  unsigned short usCW;

  // Some OS/2 PM API calls modify the FPU Control Word,
  // but forgets to restore it.

  // This can result in XCPT_FLOAT_INVALID_OPCODE exceptions,
  // so to be sure, we always disable Invalid Opcode FPU exception
  // before using FPU stuffs with Cairo or from this thread.

  usCW = _control87(0, 0);
  usCW = usCW | EM_INVALID | 0x80;
  _control87(usCW, MCW_EM | 0x80);
}

--- End code ---
With the linker fed an Imports.lnk  consisting of the exports,

--- Code: ---IMPORT _cairo_os2_surface_paint_window     cairo2
IMPORT _cairo_save                         cairo2
IMPORT _cairo_scale                        cairo2
IMPORT _cairo_set_source_rgb               cairo2
IMPORT _cairo_rectangle                    cairo2
IMPORT _cairo_fill                         cairo2
IMPORT _cairo_translate                    cairo2
IMPORT _cairo_set_line_width               cairo2
IMPORT _cairo_move_to                      cairo2
IMPORT _cairo_line_to                      cairo2
IMPORT _cairo_close_path                   cairo2
IMPORT _cairo_stroke                       cairo2
IMPORT _cairo_arc                          cairo2
IMPORT _cairo_select_font_face             cairo2
IMPORT _cairo_set_font_size                cairo2
IMPORT _cairo_text_extents                 cairo2
IMPORT _cairo_text_path                    cairo2
IMPORT _cairo_set_source_rgba              cairo2
IMPORT _cairo_fill_preserve                cairo2
IMPORT _cairo_restore                      cairo2
IMPORT _cairo_os2_init                     cairo2
IMPORT _cairo_os2_surface_create_for_window cairo2
IMPORT _cairo_os2_surface_set_hwnd         cairo2
IMPORT _cairo_create                       cairo2
IMPORT _cairo_destroy                      cairo2
IMPORT _cairo_surface_destroy              cairo2
IMPORT _cairo_os2_fini                     cairo2

--- End code ---

The code is here, https://bitbucket.org/dryeo/doodle-screen-saver/src/work-v24/Modules/CairoClock/ in CaClock.c

Jan-Erik Lärka:
Nice,

Java was more of a challenge as it need the code fpeHandler that get called as various Floating point exceptions pop up.

--- Code: ---LoadLib *jVM = new LoadLib( "jvm" ); //find in before/after libpath, path etc.
if( jVM->rc != NO_ERROR ) //jvm.dll not found, try subfolder "client" of above and environment variable JAVA_HOME (if set), try as is if param 2 instead contain \.
       jVM->Load( "client\\jvm", "JAVA_HOME" );
--- End code ---

... do other stuff ...

--- Code: ---/* Define each function dynamically */
    int rc = NO_ERROR; //must be defined as InitFunc use rc
    InitFunc( jVM->hmod, jint, JNI_GetDefaultJavaVMInitArgs, ( void *vm_args ) );
    InitFunc( jVM->hmod, jint, JNI_CreateJavaVM, ( JavaVM **p_vm, JNIEnv **p_env, void *vm_args ) );
--- End code ---
InitFunc take care of decorations "_" in front or after.


--- Code: ---resVer = JNI_GetDefaultJavaVMInitArgs(&vm_args2);
--- End code ---
...

--- Code: ---res = JNI_CreateJavaVM( &currentJVM, &jniEnv, &vm_args2);
--- End code ---


Also tried with libsane and created my own version of scanimage, that use defaults. There I have problems to reach and set internal structures of variables in the memory created by the gcc compiled library

Dave Yeo:
Are you using OpenWatcom from openwatcom.org or the Github fork? The code from OpenWatcom has more recent OS/2 fixes including, I believe, some stuff for high memory.

Jan-Erik Lärka:
I use open-watcom-c-os2-2.0-beta3.zip wherever it may come from.

Ohh, LoadLib.txt should be adjusted ... change a ".dll" to "*dll" to allow it to use any version of the library you define. Especially useful with Cairo as it come in many versions.

Navigation

[0] Message Index

[*] Previous page

Go to full version