Skip to main content

cannot find the native function !!

10 replies [Last post]
jy870052
Offline
Joined: 2007-04-01

Hi :

when i compiled cvm liks this : make
cvm is works.

[root@baoj-xp bin]# mips-nm cvm | grep "initIDs"

00498c90 T Java_java_io_FileDescriptor_initIDs
00498da0 T Java_java_io_FileInputStream_initIDs
00499270 T Java_java_io_FileOutputStream_initIDs
/*****************************************************************************/
004af610 T Java_java_io_UnixFileSystem_initIDs
/*****************************************************************************/
004915a0 T Java_java_lang_ClassLoader_00024NativeLibrary_initIDs
0049c890 T Java_java_util_zip_Inflater_initIDs
0049eec0 T Java_java_util_zip_ZipEntry_initIDs
0049e560 T Java_java_util_zip_ZipFile_initIDs

[root@baoj-xp linux-mips-cobalt]# mips-nm aaa.a | grep "initIDs"

00000880 T Java_java_lang_ClassLoader_00024NativeLibrary_initIDs
00000000 T Java_java_io_FileDescriptor_initIDs
00000000 T Java_java_io_FileInputStream_initIDs
00000000 T Java_java_io_FileOutputStream_initIDs
00000000 T Java_java_util_zip_Inflater_initIDs
U Java_java_io_FileDescriptor_initIDs
U Java_java_io_FileInputStream_initIDs
U Java_java_io_FileOutputStream_initIDs
U Java_java_lang_ClassLoader_00024NativeLibrary_initIDs
U Java_java_util_zip_Inflater_initIDs
U Java_java_util_zip_ZipEntry_initIDs
U Java_java_util_zip_ZipFile_initIDs
/*****************************************************************************/
00000000 T Java_java_io_UnixFileSystem_initIDs
/*****************************************************************************/
00000000 T Java_java_util_zip_ZipEntry_initIDs
00000000 T Java_java_util_zip_ZipFile_initIDs

/linux-mips-cobalt/bin # ./cvm -Djava.class.path=../ TestThread

Class ThreadA :: ThreadID:1
Class ThreadA :: ThreadID:1
Class ThreadA :: ThreadID:1
Class ThreadA :: ThreadID:1
Class ThreadA :: ThreadID:1

/*****************************************************************************/
cvm is works
/*****************************************************************************/

/linux-mips-cobalt/bin # ./0621

I'm in main function !
create thread is success now !
I'm in main function !
I'm in main function !
Can't find TestThread class !!

/*****************************************************************************/

app cannot find the link of UnixFileSystem.c : initIDs()

/*****************************************************************************/

java.lang.UnsatisfiedLinkError: java.io.UnixFileSystem.initIDs()V

/*****************************************************************************/

at java.io.UnixFileSystem.()V(Unknown Source)
at java.lang.Class.runStaticInitializers()V(Unknown Source)
at java.io.FileSystem.getFileSystem()Ljava/io/FileSystem;(Native Method)
at java.io.File.()V(Unknown Source)
at java.lang.Class.runStaticInitializers()V(Unknown Source)
at sun.misc.Launcher.getClassPath(Ljava/lang/String;)[Ljava/io/File;(Unknown Source)
at sun.misc.Launcher.access$200(Ljava/lang/String;)[Ljava/io/File;(Unknown Source)
at sun.misc.Launcher$AppClassLoader.getAppClassLoader(Ljava/lang/ClassLoader;)Ljava/lang/ClassLoader;(Unknown Source)
at sun.misc.Launcher.()V(Unknown Source)
at sun.misc.Launcher$1.run()Ljava/lang/Object;(Unknown Source)
at java.security.AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;(Unknown Source)
at java.security.AccessController.doPrivileged(Ljava/security/PrivilegedAction;)Ljava/lang/Object;(Unknown Source)
at sun.misc.Launcher.()V(Unknown Source)
at java.lang.Class.runStaticInitializers()V(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader()Ljava/lang/ClassLoader;(Unknown Source)
I'm in main function !
I'm in main function !
I'm in main function !

/*****************************************************************************/
when i use nm check the symbol ,i cannot found the Java_java_io_UnixFileSystem_initIDs
/*****************************************************************************/

/*****************************************************************************/
anybody can tell me why ?? Is parameter error when i link the static lib ?
/*****************************************************************************/

Regards

yanghui

Message was edited by: jy870052

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
xyzzy
Offline
Joined: 2006-08-30

> > hi Chris
> >
> > Is there anyway to add this function's symbol to
> > application that use a parameter which is belong
> to
> > gcc or ld ??
> >
> >
> > yanghui
> >
>
> I don't know of an easy automated way of doing this.
> Once you know the set of symbols you need to include
> from the archive, you could create a C file that
> references all of them (from a global structure of
> symbols), and then compile and link this file with
> your executable. I suppose you could even us nm to
> produce this list of symbols.
>
> Chris

There is a gcc/ld -u option to force a symbol to start out as undefined,
but like Chris said, you want to do this for all the JNI functions. You could
also combine all the individual .o files in your .a into a single .o or .so file.

Dean

jy870052
Offline
Joined: 2007-04-01

Hi Chris

i have build cvm with CVM_PRELOAD_LIB=true, but the binary
as before

i build cvm as follow :

#define CVM_BUILD_OPTIONS \
"CVM_CCM_COLLECT_STATS=false\n" \
"CVM_CLASSLIB_JCOV=false\n" \
"CVM_CLASSLOADING=true\n" \
"CVM_CSTACKANALYSIS=false\n" \
"CVM_DEBUG=false\n" \
"CVM_DEBUG_ASSERTS=false\n" \
"CVM_DEBUG_CLASSINFO=false\n" \
"CVM_DEBUG_DUMPSTACK=false\n" \
"CVM_DEBUG_STACKTRACES=true\n" \
"CVM_DUAL_STACK=false\n" \
"CVM_DYNAMIC_LINKING=true\n" \
"CVM_GCCHOICE=generational\n" \
"CVM_GPROF=false\n" \
"CVM_HOST=i686-redhat-linux\n" \
"CVM_INSTRUCTION_COUNTING=false\n" \
"CVM_INTERPRETER_LOOP=Standard\n" \
"CVM_JAVAC_DEBUG=true\n" \
"CVM_JIT=false\n" \
"CVM_JIT_COLLECT_STATS=false\n" \
"CVM_JIT_DEBUG=false\n" \
"CVM_JIT_ESTIMATE_COMPILATION_SPEED=false\n" \
"CVM_JIT_PROFILE=false\n" \
"CVM_JIT_USE_FP_HARDWARE=false\n" \
"CVM_JVMDI=false\n" \
"CVM_JVMPI=false\n" \
"CVM_JVMPI_TRACE_INSTRUCTION=false\n" \
"CVM_LVM=false\n" \
"CVM_NO_CODE_COMPACTION=false\n" \
"CVM_NO_LOSSY_OPCODES=false\n" \
"CVM_OPTIMIZED=true\n" \
"CVM_PRELOAD_LIB=ture\n" \
"CVM_PRELOAD_TEST=ture\n" \
"CVM_PRODUCT=premium\n" \
"CVM_REFLECT=true\n" \
"CVM_SERIALIZATION=true\n" \
"CVM_STATICLINK_LIBS=ture\n" \
"CVM_SYMBOLS=false\n" \
"CVM_TEST_GC=false\n" \
"CVM_TEST_GENERATION_GC=false\n" \
"CVM_TIMESTAMPING=false\n" \
"CVM_TRACE=false\n" \
"CVM_TRACE_JIT=false\n" \
"CVM_USE_CVM_MEMALIGN=false\n" \
"CVM_USE_NATIVE_TOOLS=false\n" \
"CVM_VERIFY_HEAP=false\n" \
"CVM_XRUN=false\n" \
"J2ME_CLASSLIB=cdc\n" \
"OPT_PKGS=\n" \

#define CVM_PROP_JAVA_VERSION "1.0.2-b08"
#define CVM_PROP_JAVA_VENDOR "Sun Microsystems Inc."
#define CVM_PROP_JAVA_VENDOR_URL "http://java.sun.com/"
#define CVM_PROP_JAVA_VENDOR_URL_BUG "http://java.sun.com/cgi-bin/bugreport.cgi"
#define CVM_PROP_JAVA_SPEC_NAME "J2ME(TM) CDC Specification"
#define CVM_PROP_JAVA_SPEC_VERSION "1.0b"
#define CVM_PROP_JAVA_SPEC_VENDOR "Sun Microsystems Inc."
#define CVM_PROP_JAVA_CLASS_VERSION "47.0"
#define CVM_PROP_JAVA_VM_NAME "Java ME CDC VM"
#define CVM_PROP_JAVA_VM_VERSION "1.0.2-b08"
#define CVM_PROP_SUN_MISC_PRODUCT "Java ME CDC"
#define CVM_PROP_JAVA_VM_INFO "interpreter loop"
#define CVM_PROP_JAVA_VM_VENDOR "Sun Microsystems Inc."
#define CVM_PROP_JAVA_VM_SPEC_NAME "Java Virtual Machine Specification"
#define CVM_PROP_JAVA_VM_SPEC_VERSION "1.0"
#define CVM_PROP_JAVA_VM_SPEC_VENDOR "Sun Microsystems Inc."
#define CVM_CLASSLIB_JAR_NAME "cdc.jar"

#endif /* _BUILD_DEFS_H */

cjplummer
Offline
Joined: 2006-10-16

> Hi Chris
>
>
> i have build cvm with CVM_PRELOAD_LIB=true, but the
> binary
> as before
>

I can see from the settings you provided that you have typo. You specified "ture" instead of "true".

Chris

jy870052
Offline
Joined: 2007-04-01

Chris :

hehe ,,sorry !
my application is works !!

thank you very much !

yanghui

jy870052
Offline
Joined: 2007-04-01

my english is very bad ,,,,sorry

Message was edited by: jy870052

jy870052
Offline
Joined: 2007-04-01

hi Chris

Is there anyway to add this function's symbol to application that use a parameter which is belong to gcc or ld ??

yanghui

Message was edited by: jy870052

cjplummer
Offline
Joined: 2006-10-16

> hi Chris
>
> Is there anyway to add this function's symbol to
> application that use a parameter which is belong to
> gcc or ld ??
>
>
> yanghui
>

I don't know of an easy automated way of doing this. Once you know the set of symbols you need to include from the archive, you could create a C file that references all of them (from a global structure of symbols), and then compile and link this file with your executable. I suppose you could even us nm to produce this list of symbols.

Chris

jy870052
Offline
Joined: 2007-04-01

Chris:

Thanks for you help !

yanghui

cjplummer
Offline
Joined: 2006-10-16

I believe your answer can be found in the output of the following command you gave:

[root@baoj-xp linux-mips-cobalt]# mips-nm aaa.a | grep "initIDs"

You will notice in the output that although the Java_java_io_UnixFileSystem_initIDs symbol is defined, there are no references to it. I believe when using --export-dynamic with an archive, files are only pulled in from the archive if they contain a symbol that is referenced. You may want to try a simple experiment to confirm this.

The reason that Java_java_io_UnixFileSystem_initIDs is not referenced is because it is a JNI method, and cvm will look it up dynamically at runtime using dlsym. The reason the other JNI symbols are referenced is because they belong to romized (preloaded) classes, so there are already class data structures pointing to the JNI methods (they are not looked up at runtime). If you want to work around this problem for non-romized classes, just romize everything by building with CVM_PRELOAD_LIB=true.

Chris

jy870052
Offline
Joined: 2007-04-01

Thanks !

i will try it tomorrow !!

yanghui