Re: Graal and Tomcat Native

2019-07-22 Thread Giorgio Zoppi
Just a comment the function choosenum is not safe, the rand() is not a good
PRG, i would use if it is possible arc4random in bsd/linux.
Best Regards,
Giorgio.

El lun., 22 jul. 2019 a las 9:12, jean-frederic clere ()
escribió:

> On 18/07/2019 11:05, Rainer Jung wrote:
> > Hi Jean-Frederic and Rémy,
> >
> > I do not have a real answer, but a workaround. It is possible to get the
> > same result without any printf style functions or atoi, just by doing
> > arithmetics. But: maybe then the crash simply moves to another position.
>
> That is what happened, I have now:
> +++
> Thread 20 "apr-8443-exec-2" received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7fffaf7fe700 (LWP 11074)]
> 0x0169aa0d in free ()
> Missing separate debuginfos, use: dnf debuginfo-install
> sssd-client-2.2.0-3.fc30.x86_64 zlib-1.2.11-15.fc30.x86_64
> (gdb) bt
> #0  0x0169aa0d in free ()
> #1  0x016956cd in _dlerror_run ()
> #2  0x0169528d in __dlsym ()
> +++
>
> >
> > In src/ssl.c you can use:
> >
> > static int ssl_rand_choosenum(int l, int h)
> > {
> > double dbl;
> > int i;
> >
> > dbl = 1.0 * (rand() % RAND_MAX) * (h - l);
> > i = (dbl / RAND_MAX + 0.5) + 1;
> > if (i < l) i = l;
> > if (i > h) i = h;
> > return i;
> > }
> >
> > This will also be much faster.
>
> Cool, Please commit the improvement ;-)
>
> >
> > I tested the formula against the original one for each value of l and h
> > Note, that currently the function is always called with l==0 and h==127!
> > So you could also drop the h and l params and use fixed values, but of
> > course would loose future flexibility.
> >
> > between 0 and 499 (and h>=l) and for each seed between 0 and 499 on twi
> > different architectures (Linux 64 Bit on x64 and Solaris Sparc 32 Bit).
> > You can run the following test program to convince yourself about the
> > formula correctness on your platform:
> >
> > #include 
> > #include 
> >
> > #define MAX_SEED 500
> > #define MAX_BOUNDARY 500
> > #define FEEDBACK 10
> >
> > int main ()
> > {
> > int seed;
> > int l;
> > int h;
> > int i1;
> > int i2;
> > int rand_orig;
> > int rand_reduced;
> > double rand_normalized;
> > double rand_prod;
> > char buf[50];
> > long count = 0;
> >
> > fprintf(stdout, "RAND_MAX is %d\n", RAND_MAX);
> > fprintf(stdout, "Number of tests to run: %ld\n",
> > 1L*MAX_BOUNDARY*MAX_BOUNDARY/2*MAX_SEED);
> > fprintf(stdout, "Feedback dot every %d tests\n", FEEDBACK);
> > fprintf(stdout, "Expect %d feedback dots\n",
> > 1L*MAX_BOUNDARY*MAX_BOUNDARY/2*MAX_SEED / FEEDBACK);
> >
> > fprintf(stdout,
> > "l\th\tseed\trand\tred\tnorm\torig\tnew\tprod\tround\n");
> > fflush(stdout);
> >
> > for (seed = 0; seed < MAX_SEED; seed++) {
> > srand(seed);
> > for (l = 0; l < MAX_BOUNDARY; l++) {
> > for (h = l; h < MAX_BOUNDARY; h++) {
> > rand_orig = rand();
> > rand_reduced = rand_orig % RAND_MAX;
> >
> > rand_normalized = ((double)rand_reduced / RAND_MAX) * (h
> > - l);
> > /* %.0f does rounding */
> > sprintf(buf, "%.0f", rand_normalized);
> > i1 = atoi(buf) + 1;
> > if (i1 < l) i1 = l;
> > if (i1 > h) i1 = h;
> >
> > rand_prod = 1.0 * rand_reduced * (h - l);
> > i2 = (rand_prod / RAND_MAX + 0.5) + 1;
> > if (i2 < l) i2 = l;
> > if (i2 > h) i2 = h;
> >
> > if (i1 != i2) {
> > fprintf(stdout,
> "%d\t%d\t%d\t%d\t%d\t%f\t%d\t%d\t%f\n",
> > l, h, seed, rand_orig, rand_reduced,
> > rand_normalized,
> > i1, i2, rand_prod);
> > }
> > count++;
> > if (count % FEEDBACK == 0) {
> > fprintf(stderr, ".");
> > fflush(stderr);
> > }
> > }
> > }
> > }
> > }
> >
> > Regards,
> >
> > Rainer
> >
> > Am 18.07.2019 um 08:57 schrieb jean-frederic clere:
> >> On 12/07/2019 11:21, Rémy Maucherat wrote:
> >>> On Thu, Jul 11, 2019 at 11:01 PM Rainer Jung  >>> > wrote:
> >>>
> >>>  Am 11.07.2019 um 22:10 schrieb Rémy Maucherat:
> >>>  > On Thu, Jul 11, 2019 at 8:42 PM Rainer Jung
> >>>  mailto:rainer.j...@kippdata.de>
> >>>  >  >>> >>
> >>>  wrote:
> >>>  >
> >>>  > Hi Rémy,
> >>>  >
> >>>  > When one looks up the macros in native/include/tcn.h, this
> >>> boils
> >>>  > down to
> >>>  > the following returning null:
> >>>  >
> >>>  > (*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")
> >>>  >
> >>>  > So our own FileInfo class can not be found. FindClass docs
> >>>  indicate its
> >>> 

Re: Graal and Tomcat Native

2019-07-22 Thread jean-frederic clere
On 18/07/2019 11:05, Rainer Jung wrote:
> Hi Jean-Frederic and Rémy,
> 
> I do not have a real answer, but a workaround. It is possible to get the
> same result without any printf style functions or atoi, just by doing
> arithmetics. But: maybe then the crash simply moves to another position.

That is what happened, I have now:
+++
Thread 20 "apr-8443-exec-2" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffaf7fe700 (LWP 11074)]
0x0169aa0d in free ()
Missing separate debuginfos, use: dnf debuginfo-install
sssd-client-2.2.0-3.fc30.x86_64 zlib-1.2.11-15.fc30.x86_64
(gdb) bt
#0  0x0169aa0d in free ()
#1  0x016956cd in _dlerror_run ()
#2  0x0169528d in __dlsym ()
+++

> 
> In src/ssl.c you can use:
> 
> static int ssl_rand_choosenum(int l, int h)
> {
>     double dbl;
>     int i;
> 
>     dbl = 1.0 * (rand() % RAND_MAX) * (h - l);
>     i = (dbl / RAND_MAX + 0.5) + 1;
>     if (i < l) i = l;
>     if (i > h) i = h;
>     return i;
> }
> 
> This will also be much faster.

Cool, Please commit the improvement ;-)

> 
> I tested the formula against the original one for each value of l and h
> Note, that currently the function is always called with l==0 and h==127!
> So you could also drop the h and l params and use fixed values, but of
> course would loose future flexibility.
> 
> between 0 and 499 (and h>=l) and for each seed between 0 and 499 on twi
> different architectures (Linux 64 Bit on x64 and Solaris Sparc 32 Bit).
> You can run the following test program to convince yourself about the
> formula correctness on your platform:
> 
> #include 
> #include 
> 
> #define MAX_SEED 500
> #define MAX_BOUNDARY 500
> #define FEEDBACK 10
> 
> int main ()
> {
>     int seed;
>     int l;
>     int h;
>     int i1;
>     int i2;
>     int rand_orig;
>     int rand_reduced;
>     double rand_normalized;
>     double rand_prod;
>     char buf[50];
>     long count = 0;
> 
>     fprintf(stdout, "RAND_MAX is %d\n", RAND_MAX);
>     fprintf(stdout, "Number of tests to run: %ld\n",
> 1L*MAX_BOUNDARY*MAX_BOUNDARY/2*MAX_SEED);
>     fprintf(stdout, "Feedback dot every %d tests\n", FEEDBACK);
>     fprintf(stdout, "Expect %d feedback dots\n",
> 1L*MAX_BOUNDARY*MAX_BOUNDARY/2*MAX_SEED / FEEDBACK);
> 
>     fprintf(stdout,
> "l\th\tseed\trand\tred\tnorm\torig\tnew\tprod\tround\n");
>     fflush(stdout);
> 
>     for (seed = 0; seed < MAX_SEED; seed++) {
>     srand(seed);
>     for (l = 0; l < MAX_BOUNDARY; l++) {
>     for (h = l; h < MAX_BOUNDARY; h++) {
>     rand_orig = rand();
>     rand_reduced = rand_orig % RAND_MAX;
> 
>     rand_normalized = ((double)rand_reduced / RAND_MAX) * (h
> - l);
>     /* %.0f does rounding */
>     sprintf(buf, "%.0f", rand_normalized);
>     i1 = atoi(buf) + 1;
>     if (i1 < l) i1 = l;
>     if (i1 > h) i1 = h;
> 
>     rand_prod = 1.0 * rand_reduced * (h - l);
>     i2 = (rand_prod / RAND_MAX + 0.5) + 1;
>     if (i2 < l) i2 = l;
>     if (i2 > h) i2 = h;
> 
>     if (i1 != i2) {
>     fprintf(stdout, "%d\t%d\t%d\t%d\t%d\t%f\t%d\t%d\t%f\n",
>     l, h, seed, rand_orig, rand_reduced,
> rand_normalized,
>     i1, i2, rand_prod);
>     }
>     count++;
>     if (count % FEEDBACK == 0) {
>     fprintf(stderr, ".");
>     fflush(stderr);
>     }
>     }
>     }
>     }
> }
> 
> Regards,
> 
> Rainer
> 
> Am 18.07.2019 um 08:57 schrieb jean-frederic clere:
>> On 12/07/2019 11:21, Rémy Maucherat wrote:
>>> On Thu, Jul 11, 2019 at 11:01 PM Rainer Jung >> > wrote:
>>>
>>>  Am 11.07.2019 um 22:10 schrieb Rémy Maucherat:
>>>  > On Thu, Jul 11, 2019 at 8:42 PM Rainer Jung
>>>  mailto:rainer.j...@kippdata.de>
>>>  > >> >>
>>>  wrote:
>>>  >
>>>  >     Hi Rémy,
>>>  >
>>>  >     When one looks up the macros in native/include/tcn.h, this
>>> boils
>>>  >     down to
>>>  >     the following returning null:
>>>  >
>>>  >     (*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")
>>>  >
>>>  >     So our own FileInfo class can not be found. FindClass docs
>>>  indicate its
>>>  >     searched in the CLASSPATH although I'm not sure whether its
>>>  really the
>>>  >     classpath or some search paths of a class loader hierarchy.
>>>  >
>>>  >     You might want to add the JVM commandline flag
>>>  "-verbose:class" for any
>>>  >     easy way to track class loading.
>>>  >
>>>  >     I didn't really grok what you meant with "define in JNI
>>>  configuration".
>>>  >     For normal JVMs the code just works, so what might be 

Re: Graal and Tomcat Native

2019-07-18 Thread Rainer Jung

Hi Jean-Frederic and Rémy,

I do not have a real answer, but a workaround. It is possible to get the 
same result without any printf style functions or atoi, just by doing 
arithmetics. But: maybe then the crash simply moves to another position.


In src/ssl.c you can use:

static int ssl_rand_choosenum(int l, int h)
{
double dbl;
int i;

dbl = 1.0 * (rand() % RAND_MAX) * (h - l);
i = (dbl / RAND_MAX + 0.5) + 1;
if (i < l) i = l;
if (i > h) i = h;
return i;
}

This will also be much faster.

I tested the formula against the original one for each value of l and h 
Note, that currently the function is always called with l==0 and h==127! 
So you could also drop the h and l params and use fixed values, but of 
course would loose future flexibility.


between 0 and 499 (and h>=l) and for each seed between 0 and 499 on twi 
different architectures (Linux 64 Bit on x64 and Solaris Sparc 32 Bit).
You can run the following test program to convince yourself about the 
formula correctness on your platform:


#include 
#include 

#define MAX_SEED 500
#define MAX_BOUNDARY 500
#define FEEDBACK 10

int main ()
{
int seed;
int l;
int h;
int i1;
int i2;
int rand_orig;
int rand_reduced;
double rand_normalized;
double rand_prod;
char buf[50];
long count = 0;

fprintf(stdout, "RAND_MAX is %d\n", RAND_MAX);
fprintf(stdout, "Number of tests to run: %ld\n", 
1L*MAX_BOUNDARY*MAX_BOUNDARY/2*MAX_SEED);

fprintf(stdout, "Feedback dot every %d tests\n", FEEDBACK);
fprintf(stdout, "Expect %d feedback dots\n", 
1L*MAX_BOUNDARY*MAX_BOUNDARY/2*MAX_SEED / FEEDBACK);


fprintf(stdout, 
"l\th\tseed\trand\tred\tnorm\torig\tnew\tprod\tround\n");

fflush(stdout);

for (seed = 0; seed < MAX_SEED; seed++) {
srand(seed);
for (l = 0; l < MAX_BOUNDARY; l++) {
for (h = l; h < MAX_BOUNDARY; h++) {
rand_orig = rand();
rand_reduced = rand_orig % RAND_MAX;

rand_normalized = ((double)rand_reduced / RAND_MAX) * 
(h - l);

/* %.0f does rounding */
sprintf(buf, "%.0f", rand_normalized);
i1 = atoi(buf) + 1;
if (i1 < l) i1 = l;
if (i1 > h) i1 = h;

rand_prod = 1.0 * rand_reduced * (h - l);
i2 = (rand_prod / RAND_MAX + 0.5) + 1;
if (i2 < l) i2 = l;
if (i2 > h) i2 = h;

if (i1 != i2) {
fprintf(stdout, "%d\t%d\t%d\t%d\t%d\t%f\t%d\t%d\t%f\n",
l, h, seed, rand_orig, rand_reduced, 
rand_normalized,

i1, i2, rand_prod);
}
count++;
if (count % FEEDBACK == 0) {
fprintf(stderr, ".");
fflush(stderr);
}
}
}
}
}

Regards,

Rainer

Am 18.07.2019 um 08:57 schrieb jean-frederic clere:

On 12/07/2019 11:21, Rémy Maucherat wrote:

On Thu, Jul 11, 2019 at 11:01 PM Rainer Jung mailto:rainer.j...@kippdata.de>> wrote:

 Am 11.07.2019 um 22:10 schrieb Rémy Maucherat:
 > On Thu, Jul 11, 2019 at 8:42 PM Rainer Jung
 mailto:rainer.j...@kippdata.de>
 > >>
 wrote:
 >
 >     Hi Rémy,
 >
 >     When one looks up the macros in native/include/tcn.h, this boils
 >     down to
 >     the following returning null:
 >
 >     (*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")
 >
 >     So our own FileInfo class can not be found. FindClass docs
 indicate its
 >     searched in the CLASSPATH although I'm not sure whether its
 really the
 >     classpath or some search paths of a class loader hierarchy.
 >
 >     You might want to add the JVM commandline flag
 "-verbose:class" for any
 >     easy way to track class loading.
 >
 >     I didn't really grok what you meant with "define in JNI
 configuration".
 >     For normal JVMs the code just works, so what might be special
 for Graal
 >     that org.apache.tomcat.jni.FileInfo can't be found?
 >
 >
 > A Graal native image is indeed not a normal JVM and does not
 support any
 > kind of dynamic class loading, it has to be declared first in these
 > configuration files.

 Ah OK.

 > So I am adding this to the jni one:
 > { "name":"org.apache.tomcat.jni.FileInfo" },
 > { "name":"org.apache.tomcat.jni.Sockaddr" },
 > { "name":"org.apache.tomcat.jni.FileInfo" },

 Again FileInfo? I think instead "org.apache.tomcat.jni.Error" should be
 the third one.

 > { "name":"java.lang.String", "methods" :
 >
 
[{"name":"","parameterTypes":["byte[]"]},{"name":"getBytes","parameterTypes":[]}]

 > }
 > And loading now works.
 > Jul 11, 2019 9:39:28 PM 

Re: Graal and Tomcat Native

2019-07-18 Thread jean-frederic clere
On 12/07/2019 11:21, Rémy Maucherat wrote:
> On Thu, Jul 11, 2019 at 11:01 PM Rainer Jung  > wrote:
> 
> Am 11.07.2019 um 22:10 schrieb Rémy Maucherat:
> > On Thu, Jul 11, 2019 at 8:42 PM Rainer Jung
> mailto:rainer.j...@kippdata.de>
> > >>
> wrote:
> >
> >     Hi Rémy,
> >
> >     When one looks up the macros in native/include/tcn.h, this boils
> >     down to
> >     the following returning null:
> >
> >     (*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")
> >
> >     So our own FileInfo class can not be found. FindClass docs
> indicate its
> >     searched in the CLASSPATH although I'm not sure whether its
> really the
> >     classpath or some search paths of a class loader hierarchy.
> >
> >     You might want to add the JVM commandline flag
> "-verbose:class" for any
> >     easy way to track class loading.
> >
> >     I didn't really grok what you meant with "define in JNI
> configuration".
> >     For normal JVMs the code just works, so what might be special
> for Graal
> >     that org.apache.tomcat.jni.FileInfo can't be found?
> >
> >
> > A Graal native image is indeed not a normal JVM and does not
> support any
> > kind of dynamic class loading, it has to be declared first in these
> > configuration files.
> 
> Ah OK.
> 
> > So I am adding this to the jni one:
> > { "name":"org.apache.tomcat.jni.FileInfo" },
> > { "name":"org.apache.tomcat.jni.Sockaddr" },
> > { "name":"org.apache.tomcat.jni.FileInfo" },
> 
> Again FileInfo? I think instead "org.apache.tomcat.jni.Error" should be
> the third one.
> 
> > { "name":"java.lang.String", "methods" :
> >
> 
> [{"name":"","parameterTypes":["byte[]"]},{"name":"getBytes","parameterTypes":[]}]
> 
> > }
> > And loading now works.
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > lifecycleEvent
> > INFO: Loaded APR based Apache Tomcat Native library [1.2.23] using
> APR
> > version [1.6.5].
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > lifecycleEvent
> > INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters
> > [false], random [true].
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > lifecycleEvent
> > INFO: APR/OpenSSL configuration: useAprConnector [false],
> useOpenSSL [true]
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > initializeSSL
> > INFO: OpenSSL successfully initialized [OpenSSL 1.1.1c FIPS  28
> May 2019]
> >
> > However when trying to actually connect I got:
> > Segmentation fault (core dumped)
> >
> > Oops.
> 
> If the above duplicate class was just a copy and paste typo, but you
> had
> it right in your actual work, the next one could try, would be
> activating writing core dumps in the underlying OS. The resulting core
> should be inspectable depending on OS via gdb or similar tools. The
> simplest gdb invocation would be
> 
> gdb /path/to/my/bin/java /path/to/my/corefile
> 
> and then at the gdb prompt the command
> 
>    bt
> 
> or
> 
>    bt full
> 
> or
> 
>    thread apply all bt
> 
> or
> 
>    thread apply all bt full
> 
> That way we should at least see, in which function the crash happens.
> Depending on symbols etc. you might even get line numbers.
> 
> 
> In the native code, it crashes on:
> https://github.com/apache/tomcat-native/blob/master/native/src/ssl.c#L635
> 
> I modified the code to:
>     double d = (((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l));
>     apr_snprintf(buf, sizeof(buf), "%.0f", d);
> 
> And it cores on the apr_snprintf. I don't see how it is unsafe though.
> 
> Rémy
> 

I also have the same core using the AprConnector I can't really see what
is wrong there.

gdb doesn't really help :-( I have replaced the apr_snprintf by snprintf
and I also have a core:
+++
Thread 19 "apr-8443-exec-1" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffa700 (LWP 24724)]
0x7792e41a in __GI___printf_fp_l (fp=,
loc=, info=, args=) at
../include/ctype.h:53
53return __libc_tsd_address (const int32_t *, CTYPE_TOLOWER);
Missing separate debuginfos, use: dnf debuginfo-install
sssd-client-2.2.0-3.fc30.x86_64 zlib-1.2.11-15.fc30.x86_64
(gdb) bt
#0  0x7792e41a in __GI___printf_fp_l (fp=,
loc=, info=, args=) at
../include/ctype.h:53
#1  0x77946f71 in __vfprintf_internal (s=0x7fffafffe660,
format=0x77ff05f7 "%.0f", ap=0x7fffafffe7e0, mode_flags=) at vfprintf-internal.c:1644
#2  0x77959f8a in __vsnprintf_internal (string=0x77ffa2a0
 "", maxlen=, format=0x77ff05f7 "%.0f",
args=0x7fffafffe7e0, 

Re: Graal and Tomcat Native

2019-07-15 Thread Rémy Maucherat
On Fri, Jul 12, 2019 at 11:21 AM Rémy Maucherat  wrote:

> In the native code, it crashes on:
> https://github.com/apache/tomcat-native/blob/master/native/src/ssl.c#L635
>
> I modified the code to:
> double d = (((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l));
> apr_snprintf(buf, sizeof(buf), "%.0f", d);
>
> And it cores on the apr_snprintf. I don't see how it is unsafe though.
>
> Ok, going back to it on Monday, things are magically going better
(summary: everything works fine). The problem is "simply" that "--static"
doesn't provide a working native image when using TLS. The problem also
actually occurs with JSSE as well (since the EC support is also an external
JNI library).

Note: Not being able to statically link ties the native image to the
platform it is built on (= not good for cloud in some cases, unless the
target is good enough to build the binary), so that's not great and TLS
becomes non viable in many cases.

Rémy


Re: Graal and Tomcat Native

2019-07-12 Thread Rémy Maucherat
On Thu, Jul 11, 2019 at 11:01 PM Rainer Jung 
wrote:

> Am 11.07.2019 um 22:10 schrieb Rémy Maucherat:
> > On Thu, Jul 11, 2019 at 8:42 PM Rainer Jung  > > wrote:
> >
> > Hi Rémy,
> >
> > When one looks up the macros in native/include/tcn.h, this boils
> > down to
> > the following returning null:
> >
> > (*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")
> >
> > So our own FileInfo class can not be found. FindClass docs indicate
> its
> > searched in the CLASSPATH although I'm not sure whether its really
> the
> > classpath or some search paths of a class loader hierarchy.
> >
> > You might want to add the JVM commandline flag "-verbose:class" for
> any
> > easy way to track class loading.
> >
> > I didn't really grok what you meant with "define in JNI
> configuration".
> > For normal JVMs the code just works, so what might be special for
> Graal
> > that org.apache.tomcat.jni.FileInfo can't be found?
> >
> >
> > A Graal native image is indeed not a normal JVM and does not support any
> > kind of dynamic class loading, it has to be declared first in these
> > configuration files.
>
> Ah OK.
>
> > So I am adding this to the jni one:
> > { "name":"org.apache.tomcat.jni.FileInfo" },
> > { "name":"org.apache.tomcat.jni.Sockaddr" },
> > { "name":"org.apache.tomcat.jni.FileInfo" },
>
> Again FileInfo? I think instead "org.apache.tomcat.jni.Error" should be
> the third one.
>
> > { "name":"java.lang.String", "methods" :
> >
> [{"name":"","parameterTypes":["byte[]"]},{"name":"getBytes","parameterTypes":[]}]
>
> > }
> > And loading now works.
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > lifecycleEvent
> > INFO: Loaded APR based Apache Tomcat Native library [1.2.23] using APR
> > version [1.6.5].
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > lifecycleEvent
> > INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters
> > [false], random [true].
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > lifecycleEvent
> > INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL
> [true]
> > Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
> > initializeSSL
> > INFO: OpenSSL successfully initialized [OpenSSL 1.1.1c FIPS  28 May 2019]
> >
> > However when trying to actually connect I got:
> > Segmentation fault (core dumped)
> >
> > Oops.
>
> If the above duplicate class was just a copy and paste typo, but you had
> it right in your actual work, the next one could try, would be
> activating writing core dumps in the underlying OS. The resulting core
> should be inspectable depending on OS via gdb or similar tools. The
> simplest gdb invocation would be
>
> gdb /path/to/my/bin/java /path/to/my/corefile
>
> and then at the gdb prompt the command
>
>bt
>
> or
>
>bt full
>
> or
>
>thread apply all bt
>
> or
>
>thread apply all bt full
>
> That way we should at least see, in which function the crash happens.
> Depending on symbols etc. you might even get line numbers.
>

In the native code, it crashes on:
https://github.com/apache/tomcat-native/blob/master/native/src/ssl.c#L635

I modified the code to:
double d = (((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l));
apr_snprintf(buf, sizeof(buf), "%.0f", d);

And it cores on the apr_snprintf. I don't see how it is unsafe though.

Rémy


Re: Graal and Tomcat Native

2019-07-11 Thread Rainer Jung

Am 11.07.2019 um 22:10 schrieb Rémy Maucherat:
On Thu, Jul 11, 2019 at 8:42 PM Rainer Jung > wrote:


Hi Rémy,

When one looks up the macros in native/include/tcn.h, this boils
down to
the following returning null:

(*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")

So our own FileInfo class can not be found. FindClass docs indicate its
searched in the CLASSPATH although I'm not sure whether its really the
classpath or some search paths of a class loader hierarchy.

You might want to add the JVM commandline flag "-verbose:class" for any
easy way to track class loading.

I didn't really grok what you meant with "define in JNI configuration".
For normal JVMs the code just works, so what might be special for Graal
that org.apache.tomcat.jni.FileInfo can't be found?


A Graal native image is indeed not a normal JVM and does not support any 
kind of dynamic class loading, it has to be declared first in these 
configuration files.


Ah OK.


So I am adding this to the jni one:
{ "name":"org.apache.tomcat.jni.FileInfo" },
{ "name":"org.apache.tomcat.jni.Sockaddr" },
{ "name":"org.apache.tomcat.jni.FileInfo" },


Again FileInfo? I think instead "org.apache.tomcat.jni.Error" should be 
the third one.


{ "name":"java.lang.String", "methods" : 
[{"name":"","parameterTypes":["byte[]"]},{"name":"getBytes","parameterTypes":[]}] 
}

And loading now works.
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener 
lifecycleEvent
INFO: Loaded APR based Apache Tomcat Native library [1.2.23] using APR 
version [1.6.5].
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener 
lifecycleEvent
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters 
[false], random [true].
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener 
lifecycleEvent

INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener 
initializeSSL

INFO: OpenSSL successfully initialized [OpenSSL 1.1.1c FIPS  28 May 2019]

However when trying to actually connect I got:
Segmentation fault (core dumped)

Oops.


If the above duplicate class was just a copy and paste typo, but you had 
it right in your actual work, the next one could try, would be 
activating writing core dumps in the underlying OS. The resulting core 
should be inspectable depending on OS via gdb or similar tools. The 
simplest gdb invocation would be


gdb /path/to/my/bin/java /path/to/my/corefile

and then at the gdb prompt the command

  bt

or

  bt full

or

  thread apply all bt

or

  thread apply all bt full

That way we should at least see, in which function the crash happens. 
Depending on symbols etc. you might even get line numbers.


Regards,

Rainer

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: Graal and Tomcat Native

2019-07-11 Thread Rémy Maucherat
On Thu, Jul 11, 2019 at 8:42 PM Rainer Jung  wrote:

> Hi Rémy,
>
> Am 11.07.2019 um 18:35 schrieb Rémy Maucherat:
> > On Thu, Jul 11, 2019 at 4:36 PM Rainer Jung  > > wrote:
> >
> > Probably not very helup, but to make sure, the GetEnv is failing, I
> > would add a little code to native/src/jnilib.c in JNI_OnLoad() that
> > creates an observable side effect while executing int he function.
> E.g.
> > on Unix/Linux you could add something like
> >
> > #include 
> >
> > ...
> >
> > FILE *fd = fopen("/tmp/mytrace", "w");
> > int fputs("At step 1", fd);
> > int fflush(fd);
> > ...
> > int fputs("At step 2", fd);
> > int fflush(fd);
> > ...
> > int fputs("At step N", fd);
> > int fflush(fd);
> > int fclose(fd);
> >
> > Sure poor man's tacing, but it will show, how for you get through
> > JNI_OnLoad() before it is returning.
> >
> > Sorry for not being more helpful,
> >
> >
> > Good idea. So it's failing on:
> > TCN_LOAD_CLASS(env, jFinfo_class, TCN_FINFO_CLASS, JNI_ERR);
> > And I need to define this in the JNI configuration, much like it's done
> > for Java reflection and dynamic class loading. Only difference I haven't
> > really been using it yet. The classes are traced but the configure tool
> > which converts the trace into the config does not work properly [yet].
>
> When one looks up the macros in native/include/tcn.h, this boils down to
> the following returning null:
>
> (*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")
>
> So our own FileInfo class can not be found. FindClass docs indicate its
> searched in the CLASSPATH although I'm not sure whether its really the
> classpath or some search paths of a class loader hierarchy.
>
> You might want to add the JVM commandline flag "-verbose:class" for any
> easy way to track class loading.
>
> I didn't really grok what you meant with "define in JNI configuration".
> For normal JVMs the code just works, so what might be special for Graal
> that org.apache.tomcat.jni.FileInfo can't be found?
>

A Graal native image is indeed not a normal JVM and does not support any
kind of dynamic class loading, it has to be declared first in these
configuration files.
So I am adding this to the jni one:
{ "name":"org.apache.tomcat.jni.FileInfo" },
{ "name":"org.apache.tomcat.jni.Sockaddr" },
{ "name":"org.apache.tomcat.jni.FileInfo" },
{ "name":"java.lang.String", "methods" :
[{"name":"","parameterTypes":["byte[]"]},{"name":"getBytes","parameterTypes":[]}]
}
And loading now works.
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
lifecycleEvent
INFO: Loaded APR based Apache Tomcat Native library [1.2.23] using APR
version [1.6.5].
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
lifecycleEvent
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters
[false], random [true].
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
lifecycleEvent
INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
Jul 11, 2019 9:39:28 PM org.apache.catalina.core.AprLifecycleListener
initializeSSL
INFO: OpenSSL successfully initialized [OpenSSL 1.1.1c FIPS  28 May 2019]

However when trying to actually connect I got:
Segmentation fault (core dumped)

Oops.

Rémy


> Regards,
>
> Rainer
>
> -
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>


Re: Graal and Tomcat Native

2019-07-11 Thread Rainer Jung

Hi Rémy,

Am 11.07.2019 um 18:35 schrieb Rémy Maucherat:
On Thu, Jul 11, 2019 at 4:36 PM Rainer Jung > wrote:


Probably not very helup, but to make sure, the GetEnv is failing, I
would add a little code to native/src/jnilib.c in JNI_OnLoad() that
creates an observable side effect while executing int he function. E.g.
on Unix/Linux you could add something like

#include 

...

FILE *fd = fopen("/tmp/mytrace", "w");
int fputs("At step 1", fd);
int fflush(fd);
...
int fputs("At step 2", fd);
int fflush(fd);
...
int fputs("At step N", fd);
int fflush(fd);
int fclose(fd);

Sure poor man's tacing, but it will show, how for you get through
JNI_OnLoad() before it is returning.

Sorry for not being more helpful,


Good idea. So it's failing on:
TCN_LOAD_CLASS(env, jFinfo_class, TCN_FINFO_CLASS, JNI_ERR);
And I need to define this in the JNI configuration, much like it's done 
for Java reflection and dynamic class loading. Only difference I haven't 
really been using it yet. The classes are traced but the configure tool 
which converts the trace into the config does not work properly [yet].


When one looks up the macros in native/include/tcn.h, this boils down to 
the following returning null:


(*env)->FindClass(env, "org/apache/tomcat/jni/FileInfo")

So our own FileInfo class can not be found. FindClass docs indicate its 
searched in the CLASSPATH although I'm not sure whether its really the 
classpath or some search paths of a class loader hierarchy.


You might want to add the JVM commandline flag "-verbose:class" for any 
easy way to track class loading.


I didn't really grok what you meant with "define in JNI configuration". 
For normal JVMs the code just works, so what might be special for Graal 
that org.apache.tomcat.jni.FileInfo can't be found?


Regards,

Rainer

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: Graal and Tomcat Native

2019-07-11 Thread Rémy Maucherat
On Thu, Jul 11, 2019 at 4:36 PM Rainer Jung  wrote:

> Probably not very helup, but to make sure, the GetEnv is failing, I
> would add a little code to native/src/jnilib.c in JNI_OnLoad() that
> creates an observable side effect while executing int he function. E.g.
> on Unix/Linux you could add something like
>
> #include 
>
> ...
>
> FILE *fd = fopen("/tmp/mytrace", "w");
> int fputs("At step 1", fd);
> int fflush(fd);
> ...
> int fputs("At step 2", fd);
> int fflush(fd);
> ...
> int fputs("At step N", fd);
> int fflush(fd);
> int fclose(fd);
>
> Sure poor man's tacing, but it will show, how for you get through
> JNI_OnLoad() before it is returning.
>
> Sorry for not being more helpful,
>

Good idea. So it's failing on:
TCN_LOAD_CLASS(env, jFinfo_class, TCN_FINFO_CLASS, JNI_ERR);
And I need to define this in the JNI configuration, much like it's done for
Java reflection and dynamic class loading. Only difference I haven't really
been using it yet. The classes are traced but the configure tool which
converts the trace into the config does not work properly [yet].

Rémy


Re: Graal and Tomcat Native

2019-07-11 Thread Rainer Jung
Probably not very helup, but to make sure, the GetEnv is failing, I 
would add a little code to native/src/jnilib.c in JNI_OnLoad() that 
creates an observable side effect while executing int he function. E.g. 
on Unix/Linux you could add something like


#include 

...

FILE *fd = fopen("/tmp/mytrace", "w");
int fputs("At step 1", fd);
int fflush(fd);
...
int fputs("At step 2", fd);
int fflush(fd);
...
int fputs("At step N", fd);
int fflush(fd);
int fclose(fd);

Sure poor man's tacing, but it will show, how for you get through 
JNI_OnLoad() before it is returning.


Sorry for not being more helpful,

Rainer

Am 11.07.2019 um 10:59 schrieb Rémy Maucherat:
On Thu, Jul 11, 2019 at 9:18 AM Rainer Jung > wrote:


Hi Rémy,

for which Java version and distribution is this? The docs for Java 7
and
8 are much less precise about return codes than the cited docs for Java
9. So older versions might give a generic error. The used code for
checking versions is in the HotSpot sources for version 8 inside
hotspot/src/share/vm/runtime/thread.cpp (functions
Threads::is_supported_jni_version_including_1_1 and
Threads::is_supported_jni_version):

jboolean Threads::is_supported_jni_version_including_1_1(jint version) {
    if (version == JNI_VERSION_1_1) return JNI_TRUE;
    return is_supported_jni_version(version);
}

It is called from hotspot/src/share/vm/prims/jni.cpp in jni_GetEnv().

I don't see a code path returning -1 in the version I am looking at
(outdated Java 8 source code).

What is rather special about that environment w.r.t. platform/JVM/Arch
or so?


The environment is a Graal native image, built on the same machine.
https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/JNILibraryLoadFeature.java#L87
So the OnLoad of tomcat-native seems to be invoked successfully, but 
returns -1 signifying an error. I have no idea what the error really is.


Overall, I'm having TLS problems: the SunEC library (non) packaging is a 
problem, there's no ALPN with JSSE, and tomcat-native doesn't work. 
However, the rest works as I expected.


Rémy


Regards,

Rainer

Am 10.07.2019 um 20:42 schrieb Rémy Maucherat:
 > Hi,
 >
 > I'm a bit stumped there, as I'm trying to get native to work in that
 > rather special environment.
 >
 > JNI_OnLoad fails with:
 > WARNING: The APR based Apache Tomcat Native library failed to
load. The
 > error reported was [Unsupported JNI version 0x, required by
 > bin/libtcnative-1.so.0.2.23]
 > java.lang.UnsatisfiedLinkError: Unsupported JNI version 0x,
 > required by bin/libtcnative-1.so.0.2.23
 > at
 >

com.oracle.svm.jni.JNILibraryInitializer.initialize(JNILibraryLoadFeature.java:87)
 > at
 >

com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary0(NativeLibrarySupport.java:153)
 > at
 >

com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary(NativeLibrarySupport.java:98)
 > at
java.lang.ClassLoader.loadLibrary(Target_java_lang_ClassLoader.java:126)
 > at java.lang.Runtime.load0(Runtime.java:809)
 > at java.lang.Runtime.load(Runtime.java:241)
 > at java.lang.System.load(System.java:366)
 > at org.apache.tomcat.jni.Library.(Library.java:42)
 >
 > Although this looks weird, this is actually returning -1 and it's
normal
 > when it fails [it's a bad error message]. Most likely this
doesn't work:
 >      if ((*vm)->GetEnv(vm, , JNI_VERSION_1_4)) {
 >          return JNI_ERR;
 >      }
 >
 > Any ideas ?
 >
 > Rémy

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org

For additional commands, e-mail: dev-h...@tomcat.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: Graal and Tomcat Native

2019-07-11 Thread Rémy Maucherat
On Thu, Jul 11, 2019 at 9:18 AM Rainer Jung  wrote:

> Hi Rémy,
>
> for which Java version and distribution is this? The docs for Java 7 and
> 8 are much less precise about return codes than the cited docs for Java
> 9. So older versions might give a generic error. The used code for
> checking versions is in the HotSpot sources for version 8 inside
> hotspot/src/share/vm/runtime/thread.cpp (functions
> Threads::is_supported_jni_version_including_1_1 and
> Threads::is_supported_jni_version):
>
> jboolean Threads::is_supported_jni_version_including_1_1(jint version) {
>if (version == JNI_VERSION_1_1) return JNI_TRUE;
>return is_supported_jni_version(version);
> }
>
> It is called from hotspot/src/share/vm/prims/jni.cpp in jni_GetEnv().
>
> I don't see a code path returning -1 in the version I am looking at
> (outdated Java 8 source code).
>
> What is rather special about that environment w.r.t. platform/JVM/Arch
> or so?
>

The environment is a Graal native image, built on the same machine.
https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/JNILibraryLoadFeature.java#L87
So the OnLoad of tomcat-native seems to be invoked successfully, but
returns -1 signifying an error. I have no idea what the error really is.

Overall, I'm having TLS problems: the SunEC library (non) packaging is a
problem, there's no ALPN with JSSE, and tomcat-native doesn't work.
However, the rest works as I expected.

Rémy


>
> Regards,
>
> Rainer
>
> Am 10.07.2019 um 20:42 schrieb Rémy Maucherat:
> > Hi,
> >
> > I'm a bit stumped there, as I'm trying to get native to work in that
> > rather special environment.
> >
> > JNI_OnLoad fails with:
> > WARNING: The APR based Apache Tomcat Native library failed to load. The
> > error reported was [Unsupported JNI version 0x, required by
> > bin/libtcnative-1.so.0.2.23]
> > java.lang.UnsatisfiedLinkError: Unsupported JNI version 0x,
> > required by bin/libtcnative-1.so.0.2.23
> > at
> >
> com.oracle.svm.jni.JNILibraryInitializer.initialize(JNILibraryLoadFeature.java:87)
> > at
> >
> com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary0(NativeLibrarySupport.java:153)
> > at
> >
> com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary(NativeLibrarySupport.java:98)
> > at
> java.lang.ClassLoader.loadLibrary(Target_java_lang_ClassLoader.java:126)
> > at java.lang.Runtime.load0(Runtime.java:809)
> > at java.lang.Runtime.load(Runtime.java:241)
> > at java.lang.System.load(System.java:366)
> > at org.apache.tomcat.jni.Library.(Library.java:42)
> >
> > Although this looks weird, this is actually returning -1 and it's normal
> > when it fails [it's a bad error message]. Most likely this doesn't work:
> >  if ((*vm)->GetEnv(vm, , JNI_VERSION_1_4)) {
> >  return JNI_ERR;
> >  }
> >
> > Any ideas ?
> >
> > Rémy
>
> -
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>


Re: Graal and Tomcat Native

2019-07-11 Thread Rainer Jung

Hi Rémy,

for which Java version and distribution is this? The docs for Java 7 and 
8 are much less precise about return codes than the cited docs for Java 
9. So older versions might give a generic error. The used code for 
checking versions is in the HotSpot sources for version 8 inside 
hotspot/src/share/vm/runtime/thread.cpp (functions 
Threads::is_supported_jni_version_including_1_1 and 
Threads::is_supported_jni_version):


jboolean Threads::is_supported_jni_version_including_1_1(jint version) {
  if (version == JNI_VERSION_1_1) return JNI_TRUE;
  return is_supported_jni_version(version);
}

It is called from hotspot/src/share/vm/prims/jni.cpp in jni_GetEnv().

I don't see a code path returning -1 in the version I am looking at 
(outdated Java 8 source code).


What is rather special about that environment w.r.t. platform/JVM/Arch 
or so?


Regards,

Rainer

Am 10.07.2019 um 20:42 schrieb Rémy Maucherat:

Hi,

I'm a bit stumped there, as I'm trying to get native to work in that 
rather special environment.


JNI_OnLoad fails with:
WARNING: The APR based Apache Tomcat Native library failed to load. The 
error reported was [Unsupported JNI version 0x, required by 
bin/libtcnative-1.so.0.2.23]
java.lang.UnsatisfiedLinkError: Unsupported JNI version 0x, 
required by bin/libtcnative-1.so.0.2.23
at 
com.oracle.svm.jni.JNILibraryInitializer.initialize(JNILibraryLoadFeature.java:87)
at 
com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary0(NativeLibrarySupport.java:153)
at 
com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary(NativeLibrarySupport.java:98)

at java.lang.ClassLoader.loadLibrary(Target_java_lang_ClassLoader.java:126)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.Runtime.load(Runtime.java:241)
at java.lang.System.load(System.java:366)
at org.apache.tomcat.jni.Library.(Library.java:42)

Although this looks weird, this is actually returning -1 and it's normal 
when it fails [it's a bad error message]. Most likely this doesn't work:

     if ((*vm)->GetEnv(vm, , JNI_VERSION_1_4)) {
         return JNI_ERR;
     }

Any ideas ?

Rémy


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: Graal and Tomcat Native

2019-07-10 Thread Rémy Maucherat
On Wed, Jul 10, 2019 at 9:10 PM Igal Sapir  wrote:

> Rémy,
>
> At the risk of pointing out the obvious as I'm sure that you are much
> more familiar with this than I am:
>
> On 7/10/2019 11:42 AM, Rémy Maucherat wrote:
> > Hi,
> >
> > I'm a bit stumped there, as I'm trying to get native to work in that
> > rather special environment.
> >
> > JNI_OnLoad fails with:
> > WARNING: The APR based Apache Tomcat Native library failed to load.
> > The error reported was [Unsupported JNI version 0x, required
> > by bin/libtcnative-1.so.0.2.23]
> > java.lang.UnsatisfiedLinkError: Unsupported JNI version 0x,
> > required by bin/libtcnative-1.so.0.2.23
> > at
> >
> com.oracle.svm.jni.JNILibraryInitializer.initialize(JNILibraryLoadFeature.java:87)
> > at
> >
> com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary0(NativeLibrarySupport.java:153)
> > at
> >
> com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary(NativeLibrarySupport.java:98)
> > at
> > java.lang.ClassLoader.loadLibrary(Target_java_lang_ClassLoader.java:126)
> > at java.lang.Runtime.load0(Runtime.java:809)
> > at java.lang.Runtime.load(Runtime.java:241)
> > at java.lang.System.load(System.java:366)
> > at org.apache.tomcat.jni.Library.(Library.java:42)
> >
> > Although this looks weird, this is actually returning -1 and it's
> > normal when it fails [it's a bad error message]. Most likely this
> > doesn't work:
> > if ((*vm)->GetEnv(vm, , JNI_VERSION_1_4)) {
> > return JNI_ERR;
> > }
> >
> > Any ideas ?
>
>  From [1]: "JNI_OnLoad must return the JNI version needed by the native
> library".  -1 is translated into 0x, which is the invalid result.
>
>  From the snippet you posted I'm guessing that the returned value is
> supposed to be JNI_VERSION_1_4 or greater.
>
> Do you know what that snippet is trying to check?
>

https://docs.oracle.com/javase/9/docs/specs/jni/invocation.html#getenv
So it seems to fail and return JNI_ERR (-1). I think it's failing there
because there's no other error message.

Rémy


>
> Igal
>
> [1]
>
> https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#JNJI_OnLoad
>
>
>
> -
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>


Re: Graal and Tomcat Native

2019-07-10 Thread Igal Sapir

Rémy,

At the risk of pointing out the obvious as I'm sure that you are much 
more familiar with this than I am:


On 7/10/2019 11:42 AM, Rémy Maucherat wrote:

Hi,

I'm a bit stumped there, as I'm trying to get native to work in that 
rather special environment.


JNI_OnLoad fails with:
WARNING: The APR based Apache Tomcat Native library failed to load. 
The error reported was [Unsupported JNI version 0x, required 
by bin/libtcnative-1.so.0.2.23]
java.lang.UnsatisfiedLinkError: Unsupported JNI version 0x, 
required by bin/libtcnative-1.so.0.2.23
at 
com.oracle.svm.jni.JNILibraryInitializer.initialize(JNILibraryLoadFeature.java:87)
at 
com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary0(NativeLibrarySupport.java:153)
at 
com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary(NativeLibrarySupport.java:98)
at 
java.lang.ClassLoader.loadLibrary(Target_java_lang_ClassLoader.java:126)

at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.Runtime.load(Runtime.java:241)
at java.lang.System.load(System.java:366)
at org.apache.tomcat.jni.Library.(Library.java:42)

Although this looks weird, this is actually returning -1 and it's 
normal when it fails [it's a bad error message]. Most likely this 
doesn't work:

    if ((*vm)->GetEnv(vm, , JNI_VERSION_1_4)) {
        return JNI_ERR;
    }

Any ideas ?


From [1]: "JNI_OnLoad must return the JNI version needed by the native 
library".  -1 is translated into 0x, which is the invalid result.


From the snippet you posted I'm guessing that the returned value is 
supposed to be JNI_VERSION_1_4 or greater.


Do you know what that snippet is trying to check?

Igal

[1] 
https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#JNJI_OnLoad




-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Graal and Tomcat Native

2019-07-10 Thread Rémy Maucherat
Hi,

I'm a bit stumped there, as I'm trying to get native to work in that rather
special environment.

JNI_OnLoad fails with:
WARNING: The APR based Apache Tomcat Native library failed to load. The
error reported was [Unsupported JNI version 0x, required by
bin/libtcnative-1.so.0.2.23]
java.lang.UnsatisfiedLinkError: Unsupported JNI version 0x,
required by bin/libtcnative-1.so.0.2.23
at
com.oracle.svm.jni.JNILibraryInitializer.initialize(JNILibraryLoadFeature.java:87)
at
com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary0(NativeLibrarySupport.java:153)
at
com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibrary(NativeLibrarySupport.java:98)
at java.lang.ClassLoader.loadLibrary(Target_java_lang_ClassLoader.java:126)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.Runtime.load(Runtime.java:241)
at java.lang.System.load(System.java:366)
at org.apache.tomcat.jni.Library.(Library.java:42)

Although this looks weird, this is actually returning -1 and it's normal
when it fails [it's a bad error message]. Most likely this doesn't work:
if ((*vm)->GetEnv(vm, , JNI_VERSION_1_4)) {
return JNI_ERR;
}

Any ideas ?

Rémy