Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Call instance method from native function always failed,static isfine why?

Reply
Thread Tools

Call instance method from native function always failed,static isfine why?

 
 
MQ.john@gmail.com
Guest
Posts: n/a
 
      01-23-2009
Here is the class with instance method

public class NativeGrab {
private native void hello(String str);
private void cbhello(String str){
System.out.println(str);
}
/**
* @param argsdd
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
NativeGrab h = new NativeGrab();
h.hello("asdf");
}

static{
System.loadLibrary("hello");
}
}



the jvm always crushed with message like this.

# An unexpected error has been detected by Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x06245d02, pid=25430, tid=3084721040
#
# Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode, sharing
linux-x86)
# Problematic frame:
# V [libjvm.so+0x245d02]
#
# An error report file with more information is saved as:
# /home/john/share/hs_err_pid25430.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

If I changed the instance method cbhello to static,
GetMethodID to GetStaticMethodID
CallVoidMethod to CallStaticVoidMethod

it just works fine.
call instance method from native function doesn't work. how come??
 
Reply With Quote
 
 
 
 
MQ.john@gmail.com
Guest
Posts: n/a
 
      01-23-2009
error log


T H R E A D
Current thread (0x08058400): JavaThread "main" [_thread_in_vm,
id=32345, stack(0xb7cf8000,0xb7d49000)]

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR),
si_addr=0x000018d9

Registers:
EAX=0x0000062d, EBX=0x08058ae4, ECX=0x94813f40, EDX=0x00000025
ESP=0xb7d47e0c, EBP=0xb7d47f08, ESI=0xb7d47e20, EDI=0xb7d47e50
EIP=0x06244892, CR2=0x000018d9, EFLAGS=0x00210206

Top of Stack: (sp=0xb7d47e0c)
0xb7d47e0c: 94813f40 b7d71b20 08058ae4 b576340a
0xb7d47e1c: 08058ae0 00000000 00000000 00000005
0xb7d47e2c: 00000476 0813ac30 b7ecb568 b5763409
0xb7d47e3c: b7d7ba8c b5755b18 00000001 b7f0eff4
0xb7d47e4c: b7d47f14 0813a730 08058ae0 b7efd21a
0xb7d47e5c: b5755b18 b7d47f14 b7f0f7c4 b7d47e88
0xb7d47e6c: 00000000 8c03f550 00000008 b7d47e88
0xb7d47e7c: 00000000 8c03f550 00000008 b7d47ed8

Instructions: (pc=0x06244892)
0x06244882: 8b 51 0c 83 c2 1c 66 8b 40 26 51 25 ff ff 00 00
0x06244892: 8b 04 82 50 8b 45 20 50 56 e8 90 69 11 00 89 34

Stack: [0xb7cf8000,0xb7d49000], sp=0xb7d47e0c, free space=319k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code,
C=native code)
V [libjvm.so+0x244892]
V [libjvm.so+0x22b59a]
C [libhello.so+0x91e]
_ZN7JNIEnv_14CallVoidMethodEP8_jobjectP10_jmethodI Dz+0x34
C [libhello.so+0x845] Java_NativeGrab_hello+0xd9
j NativeGrab.hello(Ljava/lang/StringV+0
j NativeGrab.main([Ljava/lang/StringV+11
v ~StubRoutines::call_stub
V [libjvm.so+0x21b03d]
V [libjvm.so+0x30f778]
V [libjvm.so+0x21aed0]
V [libjvm.so+0x244686]
V [libjvm.so+0x235e88]
C [java+0x1b98] JavaMain+0x2c8
C [libpthread.so.0+0x54fb]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j NativeGrab.hello(Ljava/lang/StringV+0
j NativeGrab.main([Ljava/lang/StringV+11
v ~StubRoutines::call_stub

P R O C E S S
Java Threads: ( => current thread )
0x08090400 JavaThread "Low Memory Detector" daemon [_thread_blocked,
id=32351, stack(0xb58cd000,0xb591e000)]
0x0808d400 JavaThread "CompilerThread0" daemon [_thread_blocked,
id=32350, stack(0xb591e000,0xb599f000)]
0x0808b800 JavaThread "Signal Dispatcher" daemon [_thread_blocked,
id=32349, stack(0xb599f000,0xb59f0000)]
0x08082400 JavaThread "Finalizer" daemon [_thread_blocked, id=32348,
stack(0xb5a36000,0xb5a87000)]
0x08080c00 JavaThread "Reference Handler" daemon [_thread_blocked,
id=32347, stack(0xb5a87000,0xb5ad8000)]
=>0x08058400 JavaThread "main" [_thread_in_vm, id=32345, stack
(0xb7cf8000,0xb7d49000)]

Other Threads:
0x0807f000 VMThread [stack: 0xb5ad8000,0xb5b59000] [id=32346]
0x08092000 WatcherThread [stack: 0xb584c000,0xb58cd000] [id=32352]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None


Dynamic libraries:
06000000-0642a000 r-xp 00000000 08:01 16407 /home/john/jdk1.6/jre/lib/
i386/client/libjvm.so
0642a000-06444000 rwxp 0042a000 08:01 16407 /home/john/jdk1.6/jre/lib/
i386/client/libjvm.so


Signal Handlers:
SIGSEGV: [libjvm.so+0x3ccf60], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGBUS: [libjvm.so+0x3ccf60], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGFPE: [libjvm.so+0x30e830], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGPIPE: [libjvm.so+0x30e830], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGXFSZ: [libjvm.so+0x30e830], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGILL: [libjvm.so+0x30e830], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: [libjvm.so+0x310d00], sa_mask[0]=0x00000000,
sa_flags=0x10000004
SIGHUP: [libjvm.so+0x310aa0], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGINT: [libjvm.so+0x310aa0], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGTERM: [libjvm.so+0x310aa0], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004
SIGQUIT: [libjvm.so+0x310aa0], sa_mask[0]=0x7ffbfeff,
sa_flags=0x10000004

S Y S T E M
OS:lenny/sid

uname:Linux 2.6.24-19-generic #1 SMP Wed Jun 18 14:43:41 UTC 2008 i686
libc:glibc 2.7 NPTL 2.7
rlimit: STACK 8192k, CORE 0k, NPROC 8192, NOFILE 1024, AS infinity
load average:0.18 0.11 0.13

CPU:total 1 (2 cores per cpu, 1 threads per core) family 6 model 15
stepping 6, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3

Memory: 4k page, physical 1035372k(38316k free), swap 409616k(294452k
free)

vm_info: Java HotSpot(TM) Client VM (11.0-b15) for linux-x86 JRE
(1.6.0_10-rc-b2, built on Jul 21 2008 01:09:48 by "java_re" with gcc
3.2.1-7a (J2SE release)
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      01-23-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> public class NativeGrab {
> private native void hello(String str);
> private void cbhello(String str){
> System.out.println(str);
> }
> /**
> * @param argsdd
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> NativeGrab h = new NativeGrab();
> h.hello("asdf");
> }
>
> static{
> System.loadLibrary("hello");
> }
> }


> # An unexpected error has been detected by Java Runtime Environment:
> #
> # SIGSEGV (0xb) at pc=0x06245d02, pid=25430, tid=3084721040
> #
> # Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode, sharing
> linux-x86)
> # Problematic frame:
> # V [libjvm.so+0x245d02]
> #
> # An error report file with more information is saved as:
> # /home/john/share/hs_err_pid25430.log
> #
> # If you would like to submit a bug report, please visit:
> # http://java.sun.com/webapps/bugreport/crash.jsp
> #
>
> If I changed the instance method cbhello to static,
> GetMethodID to GetStaticMethodID
> CallVoidMethod to CallStaticVoidMethod
>
> it just works fine.
> call instance method from native function doesn't work. how come??


It works.

I have done it.

Why it does not work for you is impossible to tell without
you showing us the C code.

Arne
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-23-2009
On Thu, 22 Jan 2009 17:14:04 -0800 (PST), "(E-Mail Removed)"
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>CallVoidMethod to CallStaticVoidMethod


1. Avoid calling Java from C. If you want java, do that call on the
Java side. That is one way to sidestep your problem.

2. On the C side, making sure all impedances match is totally up you.
can't call an instance method with a static call, with the wrong parms
etc.

You did not show the code. You need EVERYTHING, C and Java to track
down problems.

I suggest finding a working JNI program posted on the web, and start
from that, gradually modifying it.
--
Roedy Green Canadian Mind Products
http://mindprod.com

We are almost certainly going to miss our [global warming] deadline.
We cannot get the 10 lost years back, and by the time a new global agreement to
replace the Kyoto accord is negotiated and put into effect, there will probably
not be enough time left to stop the warming short of the point where we must not
go. ~ Gwynne Dyer
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
exception when creating instance of a class with native method by JNI Mark_Galeck Java 1 08-10-2008 01:52 AM
why can't an instance instantiated within a class method access aprotected instance method? Greg Hauptmann Ruby 9 06-16-2008 10:16 AM
instance method adding another instance method to the class Raj Singh Ruby 2 05-29-2008 10:09 PM
Confused by Method(function) of a module and method of a class/instance Sullivan WxPyQtKinter Python 5 03-07-2006 05:23 PM
How to call an instance method from a static method allowing overrides? =?ISO-8859-1?Q?Thomas_Gagn=E9?= Java 9 07-02-2003 11:04 PM



Advertisments