tinyj2c
tinyj2c copied to clipboard
Compile issues
Thank you for your previous reply in /mini_jvm I have some problems when compile minijvm_rt.jar to C code
- I use intelliJ Idea to compile class2c.jar and run it to make /out/c .c file, it's ok
but file generated "metadata.h" have struct
struct java_lang_Class {InstProp prop; VMTable* vm_table; struct java_lang_ClassLoader* classLoader_3; struct java_lang_String* name_4; JArray * enumConstants_5; struct java_util_Map* enumConstantDirectory_6; s64 classHandle_7; struct org_mini_reflect_ReflectClass* refClass_8;};
it's not compatible with default jvc.c, native_std.c :JObject *ins_of_Class_create_get(JThreadRuntime *runtime, JClass *clazz) { JClass *java_lang_class = g_procache.java_lang_class_raw->clazz; if (java_lang_class) { if (clazz->ins_of_Class) { return clazz->ins_of_Class; } else { struct java_lang_Class *ins = (struct java_lang_Class *) new_instance_with_class(runtime, java_lang_class); gc_refer_hold(ins); Java_java_lang_Class__init____V(runtime, ins); clazz->ins_of_Class = (__refer) ins; ins->classHandle_6 = (s64) (intptr_t) clazz;//todo , find it use field refer return (JObject *) ins; } } return NULL; }
So I changed classHandle_6 to classHandle_7, before that vm/.c file could be compiled to .obj file
- after that I use CMake to genarate Makefile, but it stuck when compile jvm.c file
so I remove {GUI_FILES} in CMake, it ran OK, compiled all /out/c/*c file to obj
But there are errors at last combination:
CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x4938e): undefined reference to
new_instance_with_classraw_index' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x49408): undefined reference toconstruct_string_with_utfraw_index' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x49445): undefined reference to
new_instance_with_classraw_index' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x49488): undefined reference tothrow_exception' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x49571): undefined reference to
new_instance_with_classraw_index' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x495b4): undefined reference tothrow_exception' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x495ee): undefined reference to
new_instance_with_classraw_index' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x49631): undefined reference tothrow_exception' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x496ca): undefined reference to
new_instance_with_classraw_index' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x49744): undefined reference toconstruct_string_with_utfraw_index' CMakeFiles\ccjvm.dir/objects.a(com.sun.cldc.util.mini.TimeZoneImpl.c.obj):com.sun.cldc.util.mini.TimeZoneImpl.c:(.text+0x49781): undefined reference to
new_instance_with_classraw_indexCMakeFiles\ccjvm.dir\build.make:11704: recipe for target 'ccjvm.exe' failed mingw32-make[2]: *** [ccjvm.exe] Interrupt CMakeFiles\Makefile2:93: recipe for target 'CMakeFiles/ccjvm.dir/all' failed mingw32-make[1]: *** [CMakeFiles/ccjvm.dir/all] Error 130 Makefile:101: recipe for target 'all' failed mingw32-make: *** [all] Error 130` Could you help me handle there problems. Thank you!
`Searching 27 files for "arr_body"
E:\Projects\Setup\miniJVM\java2c-master\java2c-master\app\vm\native_std.c: 1052 #if defined(JVM_OS_MINGW) || defined(JVM_OS_CYGWIN) || defined(JVM_OS_VS) 1053 utf8_append_c(libname, "/lib"); 1054: utf8_append_c(libname, name_arr->arr_body); 1055 utf8_append_c(libname, ".dll"); 1056 utf8_replace_c(libname, "//", "/"); .... 1362 if (p0) { 1363 #if JVM_OS_MINGW || JVM_OS_CYGWIN || JVM_OS_VS 1364: ret = mkdir(path_arr->arr_body); 1365 #else 1366 ret = mkdir(p0->prop.as_s8_arr, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
2 matches in 1 file`
E:\Projects\Setup\miniJVM\java2c-master\java2c-master\app\vm\native_std.c:1054:40: error: 'JArray {aka struct _JObject}' has no member named 'arr_body' utf8_append_c(libname, name_arr->arr_body); ^~ E:\Projects\Setup\miniJVM\java2c-master\java2c-master\app\vm\native_std.c:1066:20: error: 'jnienv' undeclared (first use in this function) f(&jnienv); ^~~~~~ E:\Projects\Setup\miniJVM\java2c-master\java2c-master\app\vm\native_std.c:1066:20: note: each undeclared identifier is reported only once for each function it appears in E:\Projects\Setup\miniJVM\java2c-master\java2c-master\app\vm\native_std.c: In function 'Java_org_mini_fs_InnerFile_mkdir0___3B_I': E:\Projects\Setup\miniJVM\java2c-master\java2c-master\app\vm\native_std.c:1364:21: error: 'path_arr' undeclared (first use in this function) ret = mkdir(path_arr->arr_body);
There isn't any define for arr_body, path_arr, name_arr, jnienv
update code ,recompile it
Still dont have denfination for arr_body, path_arr, name_arr, jnienv in native_std.c. So I changed:
102. err("set socket non_block error: %s\n", strerror(errno)); => //err("set socket non_block error: %s\n", strerror(errno))
Dont have err() function in Mingw/Windows
1053. utf8_append_c(libname,name_arr->arr_body); => utf8_append_c(libname, p0->prop.as_s8_ar);
1065. f(&jnienv) => f(&g_jvm->env);
1374. ret = mkdir(path_arr->arr_body); => ret = mkdir(p0->prop.as_s8_arr);
In jvm.c file:
826. if (argc > 1) { => if (argc >= 1) {
the ccjvm only take argv[1] ?
The Gcc dont recognize #pragma direct for winsock and pthread library so I insert Cmake code
TARGET_LINK_LIBRARIES(ccjvm pthread ws2_32)
The compilication was fine, it make ccjvm.exe
But when I run some .class, it show only text
E:\Projects\Setup\miniJVM\java2c-master2\java2c-master\cmake-build-release>ccjvm HelloWorld
jvm created
[INFO]gc obj: 0->0 heap : 0 -> 0 stop_world: 0 gc:0
what is the problem? Thanks.
fixed win platform
It lost sched_yield function on linking, so I added pthread on Cmake But it still display nothing (I copied test folder with classes .class file into it - which extracted from minijvm_test.jar)
E:\Projects\Setup\miniJVM\java2c-master3\java2c-master\cmake-build-release\ccjvm.exe test.Foo3
jvm created
Process finished with exit code -1073741819 (0xC0000005)
fix and tested on mingw32