From 919596e3069a14887dae5cbf34e042f2ca9856ac Mon Sep 17 00:00:00 2001 From: Gust Date: Fri, 1 Mar 2024 22:28:06 +0800 Subject: [PATCH] fix gettime in vs , fix spinlock, add -version, move vm classes package --- minijvm/c/jvm/class.c | 10 +- minijvm/c/jvm/class_load.c | 28 +- minijvm/c/jvm/garbage.c | 55 +- minijvm/c/jvm/global.c | 4 +- minijvm/c/jvm/interpreter.c | 8 +- minijvm/c/jvm/jdwp.c | 6 +- minijvm/c/jvm/jit.c | 12 +- minijvm/c/jvm/jni_io.c | 98 +-- minijvm/c/jvm/jni_reflect.c | 222 +++---- minijvm/c/jvm/jni_std.c | 4 +- minijvm/c/jvm/jvm.c | 12 +- minijvm/c/jvm/jvm.h | 12 +- minijvm/c/jvm/jvm_util.c | 36 +- minijvm/c/jvm/jvm_util.h | 4 +- minijvm/c/main.c | 9 +- minijvm/c/utils/spinlock.h | 6 +- .../java/src/main/java/java/lang/Class.java | 4 +- .../src/main/java/java/lang/ClassLoader.java | 4 +- .../java/lang/invoke/LambdaMetafactory.java | 13 +- .../java/java/lang/invoke/MethodType.java | 4 +- .../main/java/java/lang/reflect/Array.java | 2 +- .../java/java/lang/reflect/Constructor.java | 2 +- .../main/java/java/lang/reflect/Method.java | 3 +- .../main/java/java/net/URLClassLoader.java | 2 +- .../main/java/java/nio/ByteBufferImpl.java | 2 +- .../src/main/java/java/nio/ByteOrder.java | 2 +- .../src/main/java/org/mini/fs/InnerFile.java | 2 - .../java/org/mini/reflect/DirectMemObj.java | 4 +- .../java/org/mini/reflect/ReflectClass.java | 2 +- .../java/org/mini/reflect/ReflectField.java | 4 +- .../java/org/mini/reflect/ReflectMethod.java | 3 +- .../java/org/mini/reflect/StackFrame.java | 2 +- .../{reflect => }/vm/ByteCodeAssembler.java | 268 ++++----- .../vm/ByteCodeConstantPool.java | 558 +++++++++--------- .../mini/{reflect => }/vm/ByteCodeStream.java | 172 +++--- .../org/mini/{reflect => }/vm/LambdaUtil.java | 2 +- .../main/java/org/mini/vm/PrintVersion.java | 11 + .../org/mini/{reflect => }/vm/RConst.java | 158 ++--- .../org/mini/{reflect => }/vm/RefNative.java | 218 +++---- .../org/mini/{reflect => }/vm/ValueType.java | 54 +- .../mini/reflect => sun/misc}/Launcher.java | 4 +- .../java/src/main/java/sun/misc/Unsafe.java | 4 +- minijvm/java/src/main/resource/sys.properties | 2 +- 43 files changed, 1051 insertions(+), 981 deletions(-) rename minijvm/java/src/main/java/org/mini/{reflect => }/vm/ByteCodeAssembler.java (92%) mode change 100755 => 100644 rename minijvm/java/src/main/java/org/mini/{reflect => }/vm/ByteCodeConstantPool.java (94%) mode change 100755 => 100644 rename minijvm/java/src/main/java/org/mini/{reflect => }/vm/ByteCodeStream.java (95%) mode change 100755 => 100644 rename minijvm/java/src/main/java/org/mini/{reflect => }/vm/LambdaUtil.java (97%) create mode 100644 minijvm/java/src/main/java/org/mini/vm/PrintVersion.java rename minijvm/java/src/main/java/org/mini/{reflect => }/vm/RConst.java (96%) rename minijvm/java/src/main/java/org/mini/{reflect => }/vm/RefNative.java (96%) rename minijvm/java/src/main/java/org/mini/{reflect => }/vm/ValueType.java (90%) rename minijvm/java/src/main/java/{org/mini/reflect => sun/misc}/Launcher.java (98%) diff --git a/minijvm/c/jvm/class.c b/minijvm/c/jvm/class.c index 6ac9543b4..1a824110f 100644 --- a/minijvm/c/jvm/class.c +++ b/minijvm/c/jvm/class.c @@ -114,7 +114,7 @@ s32 class_prepar(Instance *loader, JClass *clazz, Runtime *runtime) { find_supers(clazz, runtime); - int i; + s32 i; // if (utf8_equals_c(clazz->name, "espresso/parser/JavaParser")) { // int debug = 1; @@ -271,9 +271,9 @@ s32 class_prepar(Instance *loader, JClass *clazz, Runtime *runtime) { jvm_runtime_cache->doubleclass = clazz; jvm_runtime_cache->double_value = find_fieldInfo_by_name_c(STR_CLASS_JAVA_LANG_DOUBLE, "value", "D", NULL, runtime); jvm_runtime_cache->double_valueOf = find_methodInfo_by_name_c(STR_CLASS_JAVA_LANG_DOUBLE, "valueOf", "(D)Ljava/lang/Double;", NULL, runtime); - } else if (utf8_equals_c(clazz->name, STR_CLASS_ORG_MINI_REFLECT_LAUNCHER)) { - jvm_runtime_cache->launcher_loadClass = find_methodInfo_by_name_c(STR_CLASS_ORG_MINI_REFLECT_LAUNCHER, "loadClass", "(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/Class;", NULL, runtime); - jvm_runtime_cache->launcher_getSystemClassLoader = find_methodInfo_by_name_c(STR_CLASS_ORG_MINI_REFLECT_LAUNCHER, "getSystemClassLoader", "()Ljava/lang/ClassLoader;", NULL, runtime); + } else if (utf8_equals_c(clazz->name, STR_CLASS_SUN_MISC_LAUNCHER)) { + jvm_runtime_cache->launcher_loadClass = find_methodInfo_by_name_c(STR_CLASS_SUN_MISC_LAUNCHER, "loadClass", "(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/Class;", NULL, runtime); + jvm_runtime_cache->launcher_getSystemClassLoader = find_methodInfo_by_name_c(STR_CLASS_SUN_MISC_LAUNCHER, "getSystemClassLoader", "()Ljava/lang/ClassLoader;", NULL, runtime); } else if (utf8_equals_c(clazz->name, STR_CLASS_JAVA_LANG_REF_REFERENCE)) { jvm_runtime_cache->reference_target = find_fieldInfo_by_name_c(STR_CLASS_JAVA_LANG_REF_REFERENCE, "target", STR_INS_JAVA_LANG_OBJECT, NULL, runtime); jvm_runtime_cache->reference_target->is_ref_target = 1;//mark as weakreference.target field @@ -352,7 +352,7 @@ void class_clinit(JClass *clazz, Runtime *runtime) { if (clazz->finalizeMethod && utf8_equals_c(clazz->finalizeMethod->_this_class->name, STR_CLASS_JAVA_LANG_OBJECT)) { clazz->finalizeMethod = NULL; } else { - int debug = 1; + s32 debug = 1; } // init javastring diff --git a/minijvm/c/jvm/class_load.c b/minijvm/c/jvm/class_load.c index 955acbff8..bf13fc479 100644 --- a/minijvm/c/jvm/class_load.c +++ b/minijvm/c/jvm/class_load.c @@ -303,7 +303,7 @@ void *_parseCPInvokeDynamic(JClass *_this, ByteBuf *buf, s32 index) { } s32 _class_constant_pool_destory(JClass *clazz) { - int i; + s32 i; for (i = 0; i < clazz->constant_item_count; i++) { ConstantItem *cptr = clazz->constant_item_ptr[i]; if (cptr) { @@ -739,7 +739,7 @@ void _changeBytesOrder(MethodInfo *method) { // if (utf8_equals_c(method->name, "test_typecast")) // jvm_printf("%8d, %s\n", pc, inst_name[cur_inst]); } else { - int debug = 1; +// int debug = 1; } switch (cur_inst) { case op_nop: @@ -1065,7 +1065,7 @@ void _changeBytesOrder(MethodInfo *method) { *((s32 *) addr) = i2c.i; s32 i, key; - int offset = default_offset; + s32 offset = default_offset; for (i = 0; i < n; i++) { i2c.c3 = ip[pos++]; i2c.c2 = ip[pos++]; @@ -1418,7 +1418,7 @@ s32 _convert_to_code_attribute(CodeAttribute *ca, AttributeInfo *attr, JClass *c ca->exception_table_length = s2c.s; s32 bytelen = sizeof(ExceptionTable) * ca->exception_table_length; ca->exception_table = jvm_calloc(bytelen); - int i; + s32 i; for (i = 0; i < 4 * ca->exception_table_length; i++) { s2c.c1 = attr->info[info_p++]; s2c.c0 = attr->info[info_p++]; @@ -1540,7 +1540,7 @@ s32 parseMethodPara(Utf8String *methodType, Utf8String *out) { Utf8String *para = utf8_create_copy(methodType); utf8_substring(para, utf8_indexof_c(para, "(") + 1, utf8_last_indexof_c(para, ")")); //从后往前拆分方法参数,从栈中弹出放入本地变量 - int i = 0; + s32 i = 0; while (para->length > 0) { c8 ch = utf8_char_at(para, 0); switch (ch) { @@ -1877,6 +1877,24 @@ JClass *class_parse(Instance *loader, ByteBuf *bytebuf, Runtime *runtime) { } return tmpclazz; } +/** + * Loads a Java class from the classpath using specified ClassLoader or the bootstrap classloader. + * + * @param jloader The Instance pointer representing the ClassLoader to use for loading, or NULL for the bootstrap classloader. + * @param pClassName The Utf8String containing the fully-qualified name of the class to load. + * @param runtime A pointer to the Runtime instance that represents the current execution context. + * @return A JClass* pointer to the loaded class on success; NULL if the class could not be found or loaded. + + * This function performs the following steps: + * 1. Copies and normalizes the class name (replacing '.' with '/'). + * 2. Tries to find the class in the JVM's classes map using the given ClassLoader. + * If the class name starts with "[", it creates an array class instead. + * 3. If the class is not found, attempts to load the ".class" file from the classpath associated with the ClassLoader. + * 4. Parses the loaded bytecode into a JClass structure using `class_parse`. + * 5. If loading through ClassLoader fails, and a custom `launcher_loadClass` method is available, calls this method to attempt loading. + * 6. Cleans up resources and returns the loaded class, or NULL if the class was not found or could not be loaded. + * 7. Logs debug information if the class cannot be found and `_JVM_DEBUG_LOG_LEVEL > 2`. + */ JClass *load_class(Instance *jloader, Utf8String *pClassName, Runtime *runtime) { if (!pClassName)return NULL; diff --git a/minijvm/c/jvm/garbage.c b/minijvm/c/jvm/garbage.c index dbfa6ad11..c74cbac93 100644 --- a/minijvm/c/jvm/garbage.c +++ b/minijvm/c/jvm/garbage.c @@ -256,6 +256,22 @@ s64 gc_sum_heap(GcCollector *collector) { return hsize; } //============================== thread_run() ===================================== +/** + * Garbage Collection Thread Function. + * + * @param para A pointer to the GcCollector instance which provides garbage collection context. + * @return 0 on successful termination of the thread. + + * This function implements a dedicated garbage collection thread that performs the following tasks: + * 1. Continuously monitors the JVM's heap status and garbage collection parameters. + * It uses `currentTimeMillis()` to track time and `gc_sum_heap` to get current heap usage. + * 2. Checks the garbage collector thread's status (`collector->_garbage_thread_status`) and pauses or terminates as needed. + * 3. If the specified garbage collection period has elapsed (determined by `jvm->garbage_collect_period_ms`) or the heap usage exceeds a pre-defined threshold (`jvm->max_heap_size * jvm->heap_overload_percent / 100`), + * it initiates a garbage collection cycle with `_garbage_collect`. + * 4. Updates the last garbage collection timestamp (`collector->lastgc`) after successfully completing a GC cycle. + * 5. Sleeps for 1 second if no garbage collection is required. + * 6. When signaled to stop, changes the garbage collector thread status to `GARBAGE_THREAD_DEAD` and exits gracefully using `thrd_exit(0)`. + */ s32 _gc_thread_run(void *para) { GcCollector *collector = (GcCollector *) para; @@ -288,11 +304,27 @@ s32 _gc_thread_run(void *para) { /** - * 查找所有实例,如果发现没有被引用时 mb->garbage_mark , - * 去除掉此对象对其他对象的引用,并销毁对象 + * Executes a full garbage collection cycle. * - * @return ret + * @param collector A pointer to the GcCollector instance that manages garbage collection for the JVM. + * @return The number of objects deleted during this GC cycle. + + * This function performs a complete garbage collection process, including: + * 1. Initiates garbage collection by setting the `isgc` flag and recording the start time. + * 2. Pauses the world by stopping all threads and preparing resources for GC using `_gc_pause_the_world`. + * If pausing fails, resumes the world and returns -1. + * 3. Merges temporary object lists into the main list and copies references from runtime stacks. + * 4. Begins the mark phase with `_gc_big_search`, incrementing the mark counter and marking reachable objects. + * 5. Processes finalize methods for eligible objects and enqueues weak references for objects no longer reachable. + * Re-marks these objects for collection on the next cycle. + * 6. Clears unreachable objects, updates total memory usage stats, and destroys them. + * 7. Updates the count of live objects and heap size after clearing dead objects. + * 8. Logs performance metrics related to GC timing. + * 9. Resumes the world and unlocks shared resources. + * 10. Optionally calls `jvm_squeeze` if MEM_ALLOC_LTALLOC is defined. + * 11. Resets the `isgc` flag and returns the number of deleted objects. */ + s64 _garbage_collect(GcCollector *collector) { collector->isgc = 1; s64 mem_total = 0, mem_free = 0; @@ -614,15 +646,20 @@ void _gc_copy_objs(MiniJVM *jvm) { } /** - * 判定某个对象是否被所有线程的runtime引用 - * 被运行时的栈或局部变量所引用, - * 这两种情况下,对象是不能被释放的 + * Copies object references from a thread's runtime stack and temporary holder for garbage collection. * - * @param pruntime son of runtime - * @return how many marked + * @param pruntime A pointer to the Runtime instance representing the current thread. + * @return 0 on successful completion. + + * This function performs the following actions: + * 1. Retrieves the GcCollector instance associated with the JVM. + * 2. Adds the thread's JavaThreadInfo (`pruntime->thrd_info->jthread`) to the collector's runtime reference copy list (`collector->runtime_refer_copy`). + * 3. Resets the free stack space by marking the current stack pointer as the clean point, and clears unused stack entries. + * 4. Iterates over the stack of the given thread's Runtime and adds each non-null reference value found in the StackEntry to the reference copy list. + * 5. Traverses the temporary holder list (`runtime->thrd_info->tmp_holder`) for the thread and adds each MemoryBlock to the reference copy list. + * 6. Upon completion, it signals that the references have been copied and are ready for garbage collection. */ - s32 _gc_copy_objs_from_thread(Runtime *pruntime) { GcCollector *collector = pruntime->jvm->collector; arraylist_push_back_unsafe(collector->runtime_refer_copy, pruntime->thrd_info->jthread); diff --git a/minijvm/c/jvm/global.c b/minijvm/c/jvm/global.c index 67fe2ec8c..d65b76bac 100644 --- a/minijvm/c/jvm/global.c +++ b/minijvm/c/jvm/global.c @@ -28,7 +28,7 @@ s32 DATA_TYPE_BYTES[DATATYPE_COUNT] = {0, 0, 0, 0, }; -char *STRS_CLASS_EXCEPTION[] = { +c8 *STRS_CLASS_EXCEPTION[] = { "java.lang.OutOfMemoryError", "java.lang.VirtualMachineError", "java.lang.NoClassDefFoundError", @@ -68,7 +68,7 @@ c8 const *STR_CLASS_JAVA_LANG_INVOKE_METHODHANDLES_LOOKUP = "java/lang/invoke/Me c8 const *STR_CLASS_JAVA_LANG_STACKTRACE = "java/lang/StackTraceElement"; c8 const *STR_CLASS_JAVA_LANG_THROWABLE = "java/lang/Throwable"; c8 const *STR_CLASS_ORG_MINI_REFLECT_DIRECTMEMOBJ = "org/mini/reflect/DirectMemObj"; -c8 const *STR_CLASS_ORG_MINI_REFLECT_LAUNCHER = "org/mini/reflect/Launcher"; +c8 const *STR_CLASS_SUN_MISC_LAUNCHER = "sun/misc/Launcher"; c8 const *STR_CLASS_ORG_MINI_REFLECT_REFLECTMETHOD = "org/mini/reflect/ReflectMethod"; c8 const *STR_FIELD_STACKFRAME = "stackFrame"; diff --git a/minijvm/c/jvm/interpreter.c b/minijvm/c/jvm/interpreter.c index f75caef29..7fa4da16f 100755 --- a/minijvm/c/jvm/interpreter.c +++ b/minijvm/c/jvm/interpreter.c @@ -271,7 +271,7 @@ s32 invokedynamic_prepare(Runtime *runtime, BootstrapMethod *bootMethod, Constan } else { s32 ret = execute_method_impl(boot_m, runtime); if (ret == RUNTIME_STATUS_NORMAL) { - MethodInfo *finder = find_methodInfo_by_name_c("org/mini/reflect/vm/LambdaUtil", + MethodInfo *finder = find_methodInfo_by_name_c("org/mini/vm/LambdaUtil", "getMethodInfoHandle", "(Ljava/lang/invoke/CallSite;)J", NULL, runtime); @@ -390,7 +390,7 @@ static inline void _optimize_empty_method_call(MethodInfo *subm, CodeAttribute * } -static inline int _optimize_inline_getter(JClass *clazz, s32 cfrIdx, Runtime *runtime) { +static inline s32 _optimize_inline_getter(JClass *clazz, s32 cfrIdx, Runtime *runtime) { RuntimeStack *stack = runtime->stack; FieldInfo *fi = class_get_constant_fieldref(clazz, cfrIdx)->fieldInfo; @@ -445,7 +445,7 @@ static inline int _optimize_inline_getter(JClass *clazz, s32 cfrIdx, Runtime *ru return RUNTIME_STATUS_NORMAL; } -static inline int _optimize_inline_setter(JClass *clazz, s32 cfrIdx, Runtime *runtime) { +static inline s32 _optimize_inline_setter(JClass *clazz, s32 cfrIdx, Runtime *runtime) { RuntimeStack *stack = runtime->stack; FieldInfo *fi = class_get_constant_fieldref(clazz, cfrIdx)->fieldInfo; @@ -1809,7 +1809,7 @@ s32 execute_method_impl(MethodInfo *method, Runtime *pruntime) { --sp; fval1 = (sp - 0)->fvalue; fval2 = (sp - 1)->fvalue; - f32 v = fval2 - ((int) (fval2 / fval1) * fval1); + f32 v = fval2 - ((s32) (fval2 / fval1) * fval1); #if _JVM_DEBUG_LOG_LEVEL > 5 invoke_deepth(runtime); jvm_printf("frem: %f\n", (sp - 1)->fvalue); diff --git a/minijvm/c/jvm/jdwp.c b/minijvm/c/jvm/jdwp.c index 1cefa49e6..fd1b9d820 100644 --- a/minijvm/c/jvm/jdwp.c +++ b/minijvm/c/jvm/jdwp.c @@ -580,7 +580,7 @@ s32 getClassType(JClass *clazz) { c8 getSimpleTag(u8 type) { - char bytes = '0'; + c8 bytes = '0'; switch (type) { case JDWP_TAG_BYTE: case JDWP_TAG_BOOLEAN: @@ -642,10 +642,10 @@ void writeValueType(JdwpPacket *res, ValueType *vt) { jdwppacket_write_byte(res, (s8) vt->value); break; case '2': - jdwppacket_write_short(res, (short) vt->value); + jdwppacket_write_short(res, (s16) vt->value); break; case '4': - jdwppacket_write_int(res, (int) vt->value); + jdwppacket_write_int(res, (s32) vt->value); break; case '8': jdwppacket_write_long(res, vt->value); diff --git a/minijvm/c/jvm/jit.c b/minijvm/c/jvm/jit.c index e63b9b441..9345b2828 100644 --- a/minijvm/c/jvm/jit.c +++ b/minijvm/c/jvm/jit.c @@ -50,7 +50,7 @@ SwitchTable *switchtable_create(Jit *jit, s32 size); s32 gen_jit_bytecode_func(struct sljit_compiler *C, MethodInfo *method, Runtime *runtime); -void _gen_jump_to_suspend_check(struct sljit_compiler *C, int offset); +void _gen_jump_to_suspend_check(struct sljit_compiler *C, s32 offset); void _gen_save_sp_ip(struct sljit_compiler *C); //------------------------ jit util ---------------------------- @@ -1026,7 +1026,7 @@ void _gen_jdwp(struct sljit_compiler *C) { // } } -void _gen_jump_to_suspend_check(struct sljit_compiler *C, int offset) { +void _gen_jump_to_suspend_check(struct sljit_compiler *C, s32 offset) { if (offset < 0) sljit_emit_ijump(C, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(check_suspend)); } @@ -1040,7 +1040,7 @@ s32 multiarray(Runtime *runtime, Utf8String *desc, s32 count) { #else s32 dim[count]; #endif - int i; + s32 i; for (i = 0; i < count; i++) dim[i] = pop_int(stack); @@ -1093,7 +1093,7 @@ s32 invokevirtual(Runtime *runtime, s32 idx) { static float frem(float value1, float value2) { - return value2 - ((int) (value2 / value1) * value1); + return value2 - ((s32) (value2 / value1) * value1); } static double drem_1(double value1, double value2) { @@ -1208,7 +1208,7 @@ s32 gen_jit_bytecode_func(struct sljit_compiler *C, MethodInfo *method, Runtime && utf8_equals_c(method->descriptor, "(J)V") && utf8_equals_c(method->name, "paint_title")) ) { - int debug = 1; + s32 debug = 1; } else { return JIT_GEN_ERROR; @@ -3347,7 +3347,7 @@ void construct_jit(MethodInfo *method, Runtime *runtime) { ca->jit.state = gen_jit_bytecode_func(C, method, runtime); if (ca->jit.state == JIT_GEN_SUCCESS) { - int debug = 1; + s32 debug = 1; } #if(JIT_CODE_DUMP) if (utf8_equals_c(runtime->method->_this_class->name, "org/mini/json/JsonParser") diff --git a/minijvm/c/jvm/jni_io.c b/minijvm/c/jvm/jni_io.c index 5df094512..85ccb3820 100644 --- a/minijvm/c/jvm/jni_io.c +++ b/minijvm/c/jvm/jni_io.c @@ -96,9 +96,9 @@ extern "C" { * will be copied. Always NUL terminates (unless siz == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */ -size_t strlcpy(char *dst, const char *src, size_t siz) { - char *d = dst; - const char *s = src; +size_t strlcpy(c8 *dst, const c8 *src, size_t siz) { + c8 *d = dst; + const c8 *s = src; size_t n = siz; /* Copy as many bytes as will fit */ @@ -135,9 +135,9 @@ size_t strlcpy(char *dst, const char *src, size_t siz) { * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static char *inet_ntop4(const unsigned char *src, char *dst, socklen_t size); +static c8 *inet_ntop4(const u8 *src, c8 *dst, socklen_t size); -static char *inet_ntop6(const unsigned char *src, char *dst, socklen_t size); +static c8 *inet_ntop6(const u8 *src, c8 *dst, socklen_t size); /* char * * inet_ntop(af, src, dst, size) @@ -147,12 +147,12 @@ static char *inet_ntop6(const unsigned char *src, char *dst, socklen_t size); * author: * Paul Vixie, 1996. */ -char *inet_ntop(int af, const void *src, char *dst, socklen_t size) { +c8 *inet_ntop(s32 af, const void *src, c8 *dst, socklen_t size) { switch (af) { case AF_INET: - return (inet_ntop4((const unsigned char *) src, dst, size)); + return (inet_ntop4((const u8 *) src, dst, size)); case AF_INET6: - return (inet_ntop6((const unsigned char *) src, dst, size)); + return (inet_ntop6((const u8 *) src, dst, size)); default: return (NULL); } @@ -170,10 +170,10 @@ char *inet_ntop(int af, const void *src, char *dst, socklen_t size) { * author: * Paul Vixie, 1996. */ -static char *inet_ntop4(const unsigned char *src, char *dst, socklen_t size) { - static const char fmt[] = "%u.%u.%u.%u"; - char tmp[sizeof "255.255.255.255"]; - int l; +static c8 *inet_ntop4(const u8 *src, c8 *dst, socklen_t size) { + static const c8 fmt[] = "%u.%u.%u.%u"; + c8 tmp[sizeof "255.255.255.255"]; + s32 l; l = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); if (l <= 0 || (socklen_t) l >= size) { @@ -189,7 +189,7 @@ static char *inet_ntop4(const unsigned char *src, char *dst, socklen_t size) { * author: * Paul Vixie, 1996. */ -static char *inet_ntop6(const unsigned char *src, char *dst, socklen_t size) { +static c8 *inet_ntop6(const u8 *src, c8 *dst, socklen_t size) { /* * Note that int32_t and int16_t need only be "at least" large enough * to contain a value of the specified size. On some systems, like @@ -197,14 +197,14 @@ static char *inet_ntop6(const unsigned char *src, char *dst, socklen_t size) { * Keep this in mind if you think this function should have been coded * to use pointer overlays. All the world's not a VAX. */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; + c8 tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; struct { - int base, len; + s32 base, len; } best, cur; #define NS_IN6ADDRSZ 16 #define NS_INT16SZ 2 u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; + s32 i; /* * Preprocess: @@ -290,9 +290,9 @@ static char *inet_ntop6(const unsigned char *src, char *dst, socklen_t size) { * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static int inet_pton4(const char *src, u_char *dst); +static s32 inet_pton4(const c8 *src, u_char *dst); -static int inet_pton6(const char *src, u_char *dst); +static s32 inet_pton6(const c8 *src, u_char *dst); /* int * inet_pton(af, src, dst) @@ -305,12 +305,12 @@ static int inet_pton6(const char *src, u_char *dst); * author: * Paul Vixie, 1996. */ -int inet_pton(int af, const char *src, void *dst) { +s32 inet_pton(s32 af, const c8 *src, void *dst) { switch (af) { case AF_INET: - return (inet_pton4(src, (unsigned char *) dst)); + return (inet_pton4(src, (u8 *) dst)); case AF_INET6: - return (inet_pton6(src, (unsigned char *) dst)); + return (inet_pton6(src, (u8 *) dst)); default: return (-1); } @@ -327,9 +327,9 @@ int inet_pton(int af, const char *src, void *dst) { * author: * Paul Vixie, 1996. */ -static int inet_pton4(const char *src, u_char *dst) { - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; +static s32 inet_pton4(const c8 *src, u_char *dst) { + static const c8 digits[] = "0123456789"; + s32 saw_digit, octets, ch; #define NS_INADDRSZ 4 u_char tmp[NS_INADDRSZ], *tp; @@ -337,7 +337,7 @@ static int inet_pton4(const char *src, u_char *dst) { octets = 0; *(tp = tmp) = 0; while ((ch = *src++) != '\0') { - const char *pch; + const c8 *pch; if ((pch = strchr(digits, ch)) != NULL) { u_int uiNew = *tp * 10 + (pch - digits); @@ -379,14 +379,14 @@ static int inet_pton4(const char *src, u_char *dst) { * author: * Paul Vixie, 1996. */ -static int inet_pton6(const char *src, u_char *dst) { - static const char xdigits_l[] = "0123456789abcdef", +static s32 inet_pton6(const c8 *src, u_char *dst) { + static const c8 xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF"; #define NS_IN6ADDRSZ 16 #define NS_INT16SZ 2 u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, seen_xdigits; + const c8 *xdigits, *curtok; + s32 ch, seen_xdigits; u_int val; memset((tp = tmp), '\0', NS_IN6ADDRSZ); @@ -400,7 +400,7 @@ static int inet_pton6(const char *src, u_char *dst) { seen_xdigits = 0; val = 0; while ((ch = *src++) != '\0') { - const char *pch; + const c8 *pch; if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) pch = strchr((xdigits = xdigits_u), ch); @@ -448,8 +448,8 @@ static int inet_pton6(const char *src, u_char *dst) { * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; - int i; + const s32 n = tp - colonp; + s32 i; if (tp == endp) return (0); @@ -531,25 +531,25 @@ s32 sock_option(VmSock *vmsock, s32 opType, s32 opValue, s32 opValue2) { } case SOCK_OP_TYPE_REUSEADDR: {// s32 x = 1; - ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_REUSEADDR, (char *) &x, sizeof(x)); + ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_REUSEADDR, (c8 *) &x, sizeof(x)); vmsock->reuseaddr = 1; break; } case SOCK_OP_TYPE_RCVBUF: {//缓冲区设置 - int nVal = opValue;//设置为 opValue K - ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVBUF, (const char *) &nVal, sizeof(nVal)); + s32 nVal = opValue;//设置为 opValue K + ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVBUF, (const c8 *) &nVal, sizeof(nVal)); break; } case SOCK_OP_TYPE_SNDBUF: {//缓冲区设置 s32 nVal = opValue;//设置为 opValue K - ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_SNDBUF, (const char *) &nVal, sizeof(nVal)); + ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_SNDBUF, (const c8 *) &nVal, sizeof(nVal)); break; } case SOCK_OP_TYPE_TIMEOUT: { vmsock->rcv_time_out = opValue; #if __JVM_OS_MINGW__ || __JVM_OS_VS__ s32 nTime = opValue; - ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVTIMEO, (const char *) &nTime, sizeof(nTime)); + ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVTIMEO, (const c8 *) &nTime, sizeof(nTime)); #else struct timeval timeout = {opValue / 1000, (opValue % 1000) * 1000}; ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); @@ -565,12 +565,12 @@ s32 sock_option(VmSock *vmsock, s32 opType, s32 opValue, s32 opValue2) { // 如果m_sLinger.l_onoff=0;则功能和2.)作用相同; m_sLinger.l_onoff = opValue; m_sLinger.l_linger = opValue2;//(容许逗留的时间为5秒) - ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVTIMEO, (const char *) &m_sLinger, sizeof(m_sLinger)); + ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVTIMEO, (const c8 *) &m_sLinger, sizeof(m_sLinger)); break; } case SOCK_OP_TYPE_KEEPALIVE: { s32 val = opValue; - ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVTIMEO, (const char *) &val, sizeof(val)); + ret = setsockopt(vmsock->contex.fd, SOL_SOCKET, SO_RCVTIMEO, (const c8 *) &val, sizeof(val)); break; } } @@ -588,7 +588,7 @@ s32 sock_get_option(VmSock *vmsock, s32 opType) { u_long flags = 1; ret = NO_ERROR == ioctlsocket(vmsock->contex.fd, FIONBIO, &flags); #else - int flags; + s32 flags; if ((flags = fcntl(vmsock->contex.fd, F_GETFL, NULL)) < 0) { ret = -1; } else { @@ -650,14 +650,14 @@ s32 sock_get_option(VmSock *vmsock, s32 opType) { } -s32 host_2_ip(c8 *hostname, char *buf, s32 buflen) { +s32 host_2_ip(c8 *hostname, c8 *buf, s32 buflen) { #if __JVM_OS_VS__ || __JVM_OS_MINGW__ WSADATA wsaData; WSAStartup(MAKEWORD(1, 1), &wsaData); #endif /* WIN32 */ struct addrinfo hints; struct addrinfo *result, *rp; - int s; + s32 s; struct sockaddr_in *ipv4; struct sockaddr_in6 *ipv6; @@ -1010,8 +1010,8 @@ s32 org_mini_net_SocketNative_getSockAddr(Runtime *runtime, JClass *clazz) { struct sockaddr_in *ipv4 = NULL; struct sockaddr_in6 *ipv6 = NULL; - char ipAddr[INET6_ADDRSTRLEN];//保存点分十进制的地址 - int port = -1; + c8 ipAddr[INET6_ADDRSTRLEN];//保存点分十进制的地址 + s32 port = -1; if (sock.ss_family == AF_INET) {// IPv4 address ipv4 = ((struct sockaddr_in *) &sock); port = ipv4->sin_port; @@ -1045,7 +1045,7 @@ s32 org_mini_net_SocketNative_host2ip(Runtime *runtime, JClass *clazz) { Instance *jbyte_arr = NULL; if (host) { - char buf[50]; + c8 buf[50]; s32 ret = host_2_ip(host->arr_body, buf, sizeof(buf)); if (ret >= 0) { s32 buflen = strlen(buf); @@ -1192,8 +1192,8 @@ s32 is_ascii(const c8 *str) { } //gpt -int is_utf8(const c8 *string) { - const unsigned char *bytes = (const unsigned char *) string; +s32 is_utf8(const c8 *string) { + const u8 *bytes = (const u8 *) string; while (*bytes) { if ((// ASCII // 0xxxxxxx @@ -1229,7 +1229,7 @@ int is_utf8(const c8 *string) { s32 is_platform_encoding_utf8() { s32 ret = 0; setlocale(LC_ALL, ""); - char *locstr = setlocale(LC_CTYPE, NULL); + c8 *locstr = setlocale(LC_CTYPE, NULL); Utf8String *utfs = utf8_create_c(locstr); utf8_lowercase(utfs); if (utf8_indexof_c(utfs, "utf-8") >= 0) { @@ -1246,7 +1246,7 @@ s32 conv_platform_encoding_2_unicode(ByteBuf *dst, const c8 *src) { setlocale(LC_ALL, ""); s32 len = (s32) strlen(src); bytebuf_expand(dst, len * sizeof(wchar_t)); - int read = mbstowcs((wchar_t *) dst->buf, src, len); + s32 read = mbstowcs((wchar_t *) dst->buf, src, len); setlocale(LC_ALL, "C"); return read; } diff --git a/minijvm/c/jvm/jni_reflect.c b/minijvm/c/jvm/jni_reflect.c index 33108d81b..93b818d0b 100644 --- a/minijvm/c/jvm/jni_reflect.c +++ b/minijvm/c/jvm/jni_reflect.c @@ -17,32 +17,32 @@ static c8 *JDWP_CLASS_METHOD = "org/mini/reflect/ReflectMethod"; static c8 *JDWP_CLASS_ARRAY = "org/mini/reflect/ReflectArray"; static c8 *JDWP_CLASS_RUNTIME = "org/mini/reflect/StackFrame"; static c8 *JDWP_CLASS_LOCALVARTABLE = "org/mini/reflect/LocalVarTable"; -static c8 *JDWP_CLASS_VALUETYPE = "org/mini/reflect/vm/ValueType"; +static c8 *JDWP_CLASS_VALUETYPE = "org/mini/vm/ValueType"; //======== native============================================================================ -s32 org_mini_reflect_vm_RefNative_refIdSize(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_refIdSize(Runtime *runtime, JClass *clazz) { push_int(runtime->stack, sizeof(__refer)); #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_refIdSize\n"); + jvm_printf("org_mini_vm_RefNative_refIdSize\n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_obj2id(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_obj2id(Runtime *runtime, JClass *clazz) { Instance *ins = (Instance *) localvar_getRefer(runtime->localvar, 0); Long2Double l2d; l2d.l = (u64) (intptr_t) ins; push_long(runtime->stack, l2d.l); #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_obj2id\n"); + jvm_printf("org_mini_vm_RefNative_obj2id\n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_id2obj(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_id2obj(Runtime *runtime, JClass *clazz) { Long2Double l2d; l2d.l = localvar_getLong(runtime->localvar, 0); __refer r = (__refer) (intptr_t) l2d.l;//这里不能直接转化,可能在外部发生了数据精度丢失,只能从低位强转 @@ -54,7 +54,7 @@ s32 org_mini_reflect_vm_RefNative_id2obj(Runtime *runtime, JClass *clazz) { return 0; } -s32 org_mini_reflect_vm_RefNative_getClasses(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getClasses(Runtime *runtime, JClass *clazz) { Utf8String *ustr = utf8_create_c(STR_CLASS_JAVA_LANG_CLASS); Instance *jarr = NULL; @@ -85,12 +85,12 @@ s32 org_mini_reflect_vm_RefNative_getClasses(Runtime *runtime, JClass *clazz) { push_ref(runtime->stack, jarr);//先放入栈,再关联回收器,防止多线程回收 #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_getClasses\n"); + jvm_printf("org_mini_vm_RefNative_getClasses\n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_getBootstrapClassByName(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getBootstrapClassByName(Runtime *runtime, JClass *clazz) { Instance *jstr = (Instance *) localvar_getRefer(runtime->localvar, 0); Utf8String *ustr = utf8_create(); jstring_2_utf8(jstr, ustr, runtime); @@ -106,7 +106,7 @@ s32 org_mini_reflect_vm_RefNative_getBootstrapClassByName(Runtime *runtime, JCla } -s32 org_mini_reflect_vm_RefNative_newWithoutInit(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_newWithoutInit(Runtime *runtime, JClass *clazz) { RuntimeStack *stack = runtime->stack; JClass *cl = insOfJavaLangClass_get_classHandle(runtime, (Instance *) localvar_getRefer(runtime->localvar, 0)); Instance *ins = NULL; @@ -124,14 +124,14 @@ s32 org_mini_reflect_vm_RefNative_newWithoutInit(Runtime *runtime, JClass *clazz } #if _JVM_DEBUG_LOG_LEVEL > 5 invoke_deepth(runtime); - jvm_printf("org_mini_reflect_vm_RefNative_newWithoutInit class:[%llx] ins:[%llx]\n", (s64) (intptr_t) cl, (s64) (intptr_t) ins); + jvm_printf("org_mini_vm_RefNative_newWithoutInit class:[%llx] ins:[%llx]\n", (s64) (intptr_t) cl, (s64) (intptr_t) ins); #endif return ret; } -s32 org_mini_reflect_vm_RefNative_setLocalVal(Runtime *runtime, JClass *clazz) { - int pos = 0; +s32 org_mini_vm_RefNative_setLocalVal(Runtime *runtime, JClass *clazz) { + s32 pos = 0; Long2Double l2d; l2d.l = l2d.l = localvar_getLong(runtime->localvar, pos); pos += 2; @@ -164,8 +164,8 @@ s32 org_mini_reflect_vm_RefNative_setLocalVal(Runtime *runtime, JClass *clazz) { return 0; } -s32 org_mini_reflect_vm_RefNative_getLocalVal(Runtime *runtime, JClass *clazz) { - int pos = 0; +s32 org_mini_vm_RefNative_getLocalVal(Runtime *runtime, JClass *clazz) { + s32 pos = 0; Long2Double l2d; l2d.l = l2d.l = localvar_getLong(runtime->localvar, pos); pos += 2; @@ -201,7 +201,7 @@ s32 org_mini_reflect_vm_RefNative_getLocalVal(Runtime *runtime, JClass *clazz) { } s32 org_mini_reflect_ReflectField_getFieldVal(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Long2Double l2d; Instance *ins = localvar_getRefer(runtime->localvar, pos); pos++; @@ -244,7 +244,7 @@ s32 org_mini_reflect_ReflectField_getFieldVal(Runtime *runtime, JClass *clazz) { } s32 org_mini_reflect_ReflectField_setFieldVal(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Long2Double l2d; Instance *ins = localvar_getRefer(runtime->localvar, pos); pos++; @@ -345,7 +345,7 @@ void _list_iter_getthread(ArrayListValue value, void *para) { } } -s32 org_mini_reflect_vm_RefNative_getThreads(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getThreads(Runtime *runtime, JClass *clazz) { // garbage_thread_lock(); Utf8String *ustr = utf8_create_c(STR_CLASS_JAVA_LANG_THREAD); Instance *jarr = jarray_create_by_type_name(runtime, runtime->jvm->thread_list->length, ustr, NULL); @@ -366,12 +366,12 @@ s32 org_mini_reflect_vm_RefNative_getThreads(Runtime *runtime, JClass *clazz) { push_ref(runtime->stack, jarr);//先放入栈,再关联回收器,防止多线程回收 // garbage_thread_unlock(); #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_getThreads\n"); + jvm_printf("org_mini_vm_RefNative_getThreads\n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_getStatus(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getStatus(Runtime *runtime, JClass *clazz) { Instance *thread = (Instance *) localvar_getRefer(runtime->localvar, 0); Runtime *trun = (Runtime *) jthread_get_stackframe_value(runtime->jvm, thread);//线程结束之后会清除掉runtime,因为其是一个栈变量,不可再用 if (trun) @@ -384,7 +384,7 @@ s32 org_mini_reflect_vm_RefNative_getStatus(Runtime *runtime, JClass *clazz) { return 0; } -s32 org_mini_reflect_vm_RefNative_suspendThread(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_suspendThread(Runtime *runtime, JClass *clazz) { Instance *thread = (Instance *) localvar_getRefer(runtime->localvar, 0); Runtime *trun = (Runtime *) jthread_get_stackframe_value(runtime->jvm, thread);//线程结束之后会清除掉runtime,因为其是一个栈变量,不可再用 if (trun) { @@ -398,7 +398,7 @@ s32 org_mini_reflect_vm_RefNative_suspendThread(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_resumeThread(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_resumeThread(Runtime *runtime, JClass *clazz) { Instance *thread = (Instance *) localvar_getRefer(runtime->localvar, 0); Runtime *trun = (Runtime *) jthread_get_stackframe_value(runtime->jvm, thread);//线程结束之后会清除掉runtime,因为其是一个栈变量,不可再用 if (trun) { @@ -413,7 +413,7 @@ s32 org_mini_reflect_vm_RefNative_resumeThread(Runtime *runtime, JClass *clazz) } -s32 org_mini_reflect_vm_RefNative_getSuspendCount(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getSuspendCount(Runtime *runtime, JClass *clazz) { Instance *thread = (Instance *) localvar_getRefer(runtime->localvar, 0); Runtime *trun = (Runtime *) jthread_get_stackframe_value(runtime->jvm, thread);//线程结束之后会清除掉runtime,因为其是一个栈变量,不可再用 if (trun) { @@ -426,10 +426,10 @@ s32 org_mini_reflect_vm_RefNative_getSuspendCount(Runtime *runtime, JClass *claz return 0; } -s32 org_mini_reflect_vm_RefNative_getFrameCount(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getFrameCount(Runtime *runtime, JClass *clazz) { Instance *thread = (Instance *) localvar_getRefer(runtime->localvar, 0); Runtime *trun = (Runtime *) jthread_get_stackframe_value(runtime->jvm, thread);//线程结束之后会清除掉runtime,因为其是一个栈变量,不可再用 - int i = 0; + s32 i = 0; while (trun) { i++; trun = trun->son; @@ -439,7 +439,7 @@ s32 org_mini_reflect_vm_RefNative_getFrameCount(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_stopThread(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_stopThread(Runtime *runtime, JClass *clazz) { Instance *thread = (Instance *) localvar_getRefer(runtime->localvar, 0); Long2Double l2d; l2d.l = localvar_getLong(runtime->localvar, 1); @@ -456,7 +456,7 @@ s32 org_mini_reflect_vm_RefNative_stopThread(Runtime *runtime, JClass *clazz) { } -s32 org_mini_reflect_vm_RefNative_getStackFrame(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getStackFrame(Runtime *runtime, JClass *clazz) { Instance *thread = (Instance *) localvar_getRefer(runtime->localvar, 0); Runtime *trun = (Runtime *) jthread_get_stackframe_value(runtime->jvm, thread);//线程结束之后会清除掉runtime,因为其是一个栈变量,不可再用 if (trun) { @@ -468,31 +468,31 @@ s32 org_mini_reflect_vm_RefNative_getStackFrame(Runtime *runtime, JClass *clazz) } else push_long(runtime->stack, 0); #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_getStackFrame %llx\n", (u64) (intptr_t) trun); + jvm_printf("org_mini_vm_RefNative_getStackFrame %llx\n", (u64) (intptr_t) trun); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_getGarbageMarkCounter(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getGarbageMarkCounter(Runtime *runtime, JClass *clazz) { push_int(runtime->stack, runtime->jvm->collector->mark_cnt); #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_getGarbageMarkCounter \n"); + jvm_printf("org_mini_vm_RefNative_getGarbageMarkCounter \n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_getGarbageStatus(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getGarbageStatus(Runtime *runtime, JClass *clazz) { push_int(runtime->stack, runtime->jvm->collector->_garbage_thread_status);//先放入栈,再关联回收器,防止多线程回收 #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_getGarbageStatus %d\n", runtime->jvm->collector->_garbage_thread_status); + jvm_printf("org_mini_vm_RefNative_getGarbageStatus %d\n", runtime->jvm->collector->_garbage_thread_status); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_defineClass(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_defineClass(Runtime *runtime, JClass *clazz) { s32 pos = 0; Instance *cloader = localvar_getRefer(runtime->localvar, pos++); Instance *namejstr = localvar_getRefer(runtime->localvar, pos++); @@ -515,12 +515,12 @@ s32 org_mini_reflect_vm_RefNative_defineClass(Runtime *runtime, JClass *clazz) { // push_ref(runtime->stack, NULL); #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_defineClass %d\n", runtime->jvm->collector->_garbage_thread_status); + jvm_printf("org_mini_vm_RefNative_defineClass %d\n", runtime->jvm->collector->_garbage_thread_status); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_findLoadedClass0(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_findLoadedClass0(Runtime *runtime, JClass *clazz) { s32 pos = 0; Instance *jloader = localvar_getRefer(runtime->localvar, pos++); Instance *namejstr = localvar_getRefer(runtime->localvar, pos++); @@ -536,19 +536,19 @@ s32 org_mini_reflect_vm_RefNative_findLoadedClass0(Runtime *runtime, JClass *cla push_ref(runtime->stack, NULL); } #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_findLoadedClass0 \n"); + jvm_printf("org_mini_vm_RefNative_findLoadedClass0 \n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_findResource0(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_findResource0(Runtime *runtime, JClass *clazz) { push_ref(runtime->stack, NULL); return 0; } -s32 org_mini_reflect_vm_RefNative_initNativeClassLoader(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_initNativeClassLoader(Runtime *runtime, JClass *clazz) { s32 pos = 0; Instance *jloader = localvar_getRefer(runtime->localvar, pos++); Instance *parent = localvar_getRefer(runtime->localvar, pos++); @@ -563,12 +563,12 @@ s32 org_mini_reflect_vm_RefNative_initNativeClassLoader(Runtime *runtime, JClass #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_initNativeClassLoader \n"); + jvm_printf("org_mini_vm_RefNative_initNativeClassLoader \n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_destroyNativeClassLoader(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_destroyNativeClassLoader(Runtime *runtime, JClass *clazz) { s32 pos = 0; Instance *jloader = localvar_getRefer(runtime->localvar, pos++); Instance *parent = localvar_getRefer(runtime->localvar, pos++); @@ -578,12 +578,12 @@ s32 org_mini_reflect_vm_RefNative_destroyNativeClassLoader(Runtime *runtime, JCl PeerClassLoader *cloader = classLoaders_find_by_instance(jvm, jloader); #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_destroyNativeClassLoader \n"); + jvm_printf("org_mini_vm_RefNative_destroyNativeClassLoader \n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_getCallerClass(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_getCallerClass(Runtime *runtime, JClass *clazz) { s32 found = 0; if (runtime->parent) { if (runtime->parent->parent) { @@ -596,12 +596,12 @@ s32 org_mini_reflect_vm_RefNative_getCallerClass(Runtime *runtime, JClass *clazz } #if _JVM_DEBUG_LOG_LEVEL > 5 - jvm_printf("org_mini_reflect_vm_RefNative_getCallerClass\n"); + jvm_printf("org_mini_vm_RefNative_getCallerClass\n"); #endif return 0; } -s32 org_mini_reflect_vm_RefNative_addJarToClasspath(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_addJarToClasspath(Runtime *runtime, JClass *clazz) { s32 pos = 0; Instance *jstr = localvar_getRefer(runtime->localvar, pos++); Utf8String *ustr = utf8_create(); @@ -615,7 +615,7 @@ s32 org_mini_reflect_vm_RefNative_addJarToClasspath(Runtime *runtime, JClass *cl } s32 org_mini_reflect_ReflectClass_mapClass(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Instance *ins = (Instance *) localvar_getRefer(runtime->localvar, pos++); Long2Double l2d; l2d.l = l2d.l = localvar_getLong(runtime->localvar, pos); @@ -701,7 +701,7 @@ s32 org_mini_reflect_ReflectClass_mapClass(Runtime *runtime, JClass *clazz) { } s32 org_mini_reflect_ReflectField_mapField(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Instance *ins = (Instance *) localvar_getRefer(runtime->localvar, pos++); Long2Double l2d; l2d.l = l2d.l = localvar_getLong(runtime->localvar, pos); @@ -774,7 +774,7 @@ Instance *localVarTable2java(JClass *clazz, LocalVarTable *lvt, Runtime *runtime } s32 org_mini_reflect_ReflectMethod_mapMethod(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Instance *ins = (Instance *) localvar_getRefer(runtime->localvar, pos++); Long2Double l2d; l2d.l = l2d.l = localvar_getLong(runtime->localvar, pos); @@ -967,7 +967,7 @@ s32 org_mini_reflect_ReflectMethod_invokeMethod(Runtime *runtime, JClass *clazz) } s32 org_mini_reflect_StackFrame_mapRuntime(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Instance *ins = (Instance *) localvar_getRefer(runtime->localvar, pos++); Long2Double l2d; l2d.l = localvar_getLong(runtime->localvar, pos); @@ -1025,7 +1025,7 @@ s32 org_mini_reflect_ReflectMethod_findMethod0(Runtime *runtime, JClass *clazz) } s32 org_mini_reflect_ReflectMethod_getExceptionTypes0(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Instance *ins = (Instance *) localvar_getRefer(runtime->localvar, pos++); Long2Double l2d; l2d.l = localvar_getLong(runtime->localvar, pos); @@ -1052,7 +1052,7 @@ s32 org_mini_reflect_ReflectMethod_getExceptionTypes0(Runtime *runtime, JClass * } s32 org_mini_reflect_ReflectArray_mapArray(Runtime *runtime, JClass *clazz) { - int pos = 0; + s32 pos = 0; Instance *ins = (Instance *) localvar_getRefer(runtime->localvar, pos++); Long2Double l2d; l2d.l = l2d.l = localvar_getLong(runtime->localvar, pos); @@ -1258,7 +1258,7 @@ s32 org_mini_reflect_DirectMemObj_copyFrom0(Runtime *runtime, JClass *clazz) { return ret; } -s32 org_mini_reflect_vm_RefNative_heap_calloc(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_calloc(Runtime *runtime, JClass *clazz) { s32 pos = 0; s32 size = localvar_getInt(runtime->localvar, pos++); @@ -1269,7 +1269,7 @@ s32 org_mini_reflect_vm_RefNative_heap_calloc(Runtime *runtime, JClass *clazz) { return 0; } -s32 org_mini_reflect_vm_RefNative_heap_free(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_free(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1279,7 +1279,7 @@ s32 org_mini_reflect_vm_RefNative_heap_free(Runtime *runtime, JClass *clazz) { return 0; } -s32 org_mini_reflect_vm_RefNative_heap_put_byte(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_put_byte(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1291,7 +1291,7 @@ s32 org_mini_reflect_vm_RefNative_heap_put_byte(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_get_byte(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_get_byte(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1301,7 +1301,7 @@ s32 org_mini_reflect_vm_RefNative_heap_get_byte(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_put_short(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_put_short(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1313,7 +1313,7 @@ s32 org_mini_reflect_vm_RefNative_heap_put_short(Runtime *runtime, JClass *clazz return 0; } -s32 org_mini_reflect_vm_RefNative_heap_get_short(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_get_short(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1323,7 +1323,7 @@ s32 org_mini_reflect_vm_RefNative_heap_get_short(Runtime *runtime, JClass *clazz return 0; } -s32 org_mini_reflect_vm_RefNative_heap_put_int(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_put_int(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1335,7 +1335,7 @@ s32 org_mini_reflect_vm_RefNative_heap_put_int(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_get_int(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_get_int(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1345,7 +1345,7 @@ s32 org_mini_reflect_vm_RefNative_heap_get_int(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_put_long(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_put_long(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1357,7 +1357,7 @@ s32 org_mini_reflect_vm_RefNative_heap_put_long(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_get_long(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_get_long(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1367,7 +1367,7 @@ s32 org_mini_reflect_vm_RefNative_heap_get_long(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_put_ref(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_put_ref(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1379,7 +1379,7 @@ s32 org_mini_reflect_vm_RefNative_heap_put_ref(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_get_ref(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_get_ref(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer ptr = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1389,7 +1389,7 @@ s32 org_mini_reflect_vm_RefNative_heap_get_ref(Runtime *runtime, JClass *clazz) return 0; } -s32 org_mini_reflect_vm_RefNative_heap_copy(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_copy(Runtime *runtime, JClass *clazz) { s32 pos = 0; __refer src = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1406,7 +1406,7 @@ s32 org_mini_reflect_vm_RefNative_heap_copy(Runtime *runtime, JClass *clazz) { return 0; } -s32 org_mini_reflect_vm_RefNative_heap_bin_search(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_bin_search(Runtime *runtime, JClass *clazz) { s32 pos = 0; c8 *src = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1442,7 +1442,7 @@ s32 org_mini_reflect_vm_RefNative_heap_bin_search(Runtime *runtime, JClass *claz return 0; } -s32 org_mini_reflect_vm_RefNative_heap_fill(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_fill(Runtime *runtime, JClass *clazz) { s32 pos = 0; c8 *src = (__refer) (intptr_t) localvar_getLong(runtime->localvar, pos); pos += 2; @@ -1467,7 +1467,7 @@ s32 org_mini_reflect_vm_RefNative_heap_fill(Runtime *runtime, JClass *clazz) { return 0; } -s32 org_mini_reflect_vm_RefNative_heap_little_endian(Runtime *runtime, JClass *clazz) { +s32 org_mini_vm_RefNative_heap_little_endian(Runtime *runtime, JClass *clazz) { push_int(runtime->stack, __JVM_LITTLE_ENDIAN__); return 0; } @@ -1625,51 +1625,51 @@ s32 com_misc_Unsafe_unpack(Runtime *runtime, JClass *clazz) { static java_native_method METHODS_REFLECT_TABLE[] = { - {"org/mini/reflect/vm/RefNative", "refIdSize", "()I", org_mini_reflect_vm_RefNative_refIdSize}, - {"org/mini/reflect/vm/RefNative", "obj2id", "(Ljava/lang/Object;)J", org_mini_reflect_vm_RefNative_obj2id}, - {"org/mini/reflect/vm/RefNative", "id2obj", "(J)Ljava/lang/Object;", org_mini_reflect_vm_RefNative_id2obj}, - {"org/mini/reflect/vm/RefNative", "getClasses", "()[Ljava/lang/Class;", org_mini_reflect_vm_RefNative_getClasses}, - {"org/mini/reflect/vm/RefNative", "getBootstrapClassByName", "(Ljava/lang/String;)Ljava/lang/Class;", org_mini_reflect_vm_RefNative_getBootstrapClassByName}, - {"org/mini/reflect/vm/RefNative", "newWithoutInit", "(Ljava/lang/Class;)Ljava/lang/Object;", org_mini_reflect_vm_RefNative_newWithoutInit}, - {"org/mini/reflect/vm/RefNative", "setLocalVal", "(JIBJI)I", org_mini_reflect_vm_RefNative_setLocalVal}, - {"org/mini/reflect/vm/RefNative", "getLocalVal", "(JILorg/mini/jdwp/type/ValueType;)I", org_mini_reflect_vm_RefNative_getLocalVal}, - {"org/mini/reflect/vm/RefNative", "getThreads", "()[Ljava/lang/Thread;", org_mini_reflect_vm_RefNative_getThreads}, - {"org/mini/reflect/vm/RefNative", "getStatus", "(Ljava/lang/Thread;)I", org_mini_reflect_vm_RefNative_getStatus}, - {"org/mini/reflect/vm/RefNative", "suspendThread", "(Ljava/lang/Thread;)I", org_mini_reflect_vm_RefNative_suspendThread}, - {"org/mini/reflect/vm/RefNative", "resumeThread", "(Ljava/lang/Thread;)I", org_mini_reflect_vm_RefNative_resumeThread}, - {"org/mini/reflect/vm/RefNative", "getSuspendCount", "(Ljava/lang/Thread;)I", org_mini_reflect_vm_RefNative_getSuspendCount}, - {"org/mini/reflect/vm/RefNative", "getFrameCount", "(Ljava/lang/Thread;)I", org_mini_reflect_vm_RefNative_getFrameCount}, - {"org/mini/reflect/vm/RefNative", "stopThread", "(Ljava/lang/Thread;J)I", org_mini_reflect_vm_RefNative_stopThread}, - {"org/mini/reflect/vm/RefNative", "getStackFrame", "(Ljava/lang/Thread;)J", org_mini_reflect_vm_RefNative_getStackFrame}, - {"org/mini/reflect/vm/RefNative", "getGarbageMarkCounter", "()I", org_mini_reflect_vm_RefNative_getGarbageMarkCounter}, - {"org/mini/reflect/vm/RefNative", "getGarbageStatus", "()I", org_mini_reflect_vm_RefNative_getGarbageStatus}, - {"org/mini/reflect/vm/RefNative", "getCallerClass", "()Ljava/lang/Class;", org_mini_reflect_vm_RefNative_getCallerClass}, - {"org/mini/reflect/vm/RefNative", "defineClass", "(Ljava/lang/ClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;", org_mini_reflect_vm_RefNative_defineClass}, - {"org/mini/reflect/vm/RefNative", "findLoadedClass0", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;", org_mini_reflect_vm_RefNative_findLoadedClass0}, - {"org/mini/reflect/vm/RefNative", "findResource0", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/net/URL;", org_mini_reflect_vm_RefNative_findResource0}, - {"org/mini/reflect/vm/RefNative", "initNativeClassLoader", "(Ljava/lang/ClassLoader;Ljava/lang/ClassLoader;)V", org_mini_reflect_vm_RefNative_initNativeClassLoader}, - {"org/mini/reflect/vm/RefNative", "destroyNativeClassLoader", "(Ljava/lang/ClassLoader;)V", org_mini_reflect_vm_RefNative_destroyNativeClassLoader}, - {"org/mini/reflect/vm/RefNative", "addJarToClasspath", "(Ljava/lang/String;)V", org_mini_reflect_vm_RefNative_addJarToClasspath}, - {"org/mini/reflect/vm/RefNative", "heap_calloc", "(I)J", org_mini_reflect_vm_RefNative_heap_calloc}, - {"org/mini/reflect/vm/RefNative", "heap_free", "(J)V", org_mini_reflect_vm_RefNative_heap_free}, - {"org/mini/reflect/vm/RefNative", "heap_put_byte", "(JIB)V", org_mini_reflect_vm_RefNative_heap_put_byte}, - {"org/mini/reflect/vm/RefNative", "heap_get_byte", "(JI)B", org_mini_reflect_vm_RefNative_heap_get_byte}, - {"org/mini/reflect/vm/RefNative", "heap_put_short", "(JIS)V", org_mini_reflect_vm_RefNative_heap_put_short}, - {"org/mini/reflect/vm/RefNative", "heap_get_short", "(JI)S", org_mini_reflect_vm_RefNative_heap_get_short}, - {"org/mini/reflect/vm/RefNative", "heap_put_int", "(JII)V", org_mini_reflect_vm_RefNative_heap_put_int}, - {"org/mini/reflect/vm/RefNative", "heap_get_int", "(JI)I", org_mini_reflect_vm_RefNative_heap_get_int}, - {"org/mini/reflect/vm/RefNative", "heap_put_long", "(JIJ)V", org_mini_reflect_vm_RefNative_heap_put_long}, - {"org/mini/reflect/vm/RefNative", "heap_get_long", "(JI)J", org_mini_reflect_vm_RefNative_heap_get_long}, - {"org/mini/reflect/vm/RefNative", "heap_put_float", "(JIF)V", org_mini_reflect_vm_RefNative_heap_put_int}, - {"org/mini/reflect/vm/RefNative", "heap_get_float", "(JI)F", org_mini_reflect_vm_RefNative_heap_get_int}, - {"org/mini/reflect/vm/RefNative", "heap_put_double", "(JID)V", org_mini_reflect_vm_RefNative_heap_put_long}, - {"org/mini/reflect/vm/RefNative", "heap_get_double", "(JI)D", org_mini_reflect_vm_RefNative_heap_get_long}, - {"org/mini/reflect/vm/RefNative", "heap_put_ref", "(JILjava/lang/Object;)V", org_mini_reflect_vm_RefNative_heap_put_ref}, - {"org/mini/reflect/vm/RefNative", "heap_get_ref", "(JI)Ljava/lang/Object;", org_mini_reflect_vm_RefNative_heap_get_ref}, - {"org/mini/reflect/vm/RefNative", "heap_copy", "(JIJII)V", org_mini_reflect_vm_RefNative_heap_copy}, - {"org/mini/reflect/vm/RefNative", "heap_bin_search", "(JIJI)I", org_mini_reflect_vm_RefNative_heap_bin_search}, - {"org/mini/reflect/vm/RefNative", "heap_fill", "(JIJI)V", org_mini_reflect_vm_RefNative_heap_fill}, - {"org/mini/reflect/vm/RefNative", "heap_endian", "()I", org_mini_reflect_vm_RefNative_heap_little_endian}, + {"org/mini/vm/RefNative", "refIdSize", "()I", org_mini_vm_RefNative_refIdSize}, + {"org/mini/vm/RefNative", "obj2id", "(Ljava/lang/Object;)J", org_mini_vm_RefNative_obj2id}, + {"org/mini/vm/RefNative", "id2obj", "(J)Ljava/lang/Object;", org_mini_vm_RefNative_id2obj}, + {"org/mini/vm/RefNative", "getClasses", "()[Ljava/lang/Class;", org_mini_vm_RefNative_getClasses}, + {"org/mini/vm/RefNative", "getBootstrapClassByName", "(Ljava/lang/String;)Ljava/lang/Class;", org_mini_vm_RefNative_getBootstrapClassByName}, + {"org/mini/vm/RefNative", "newWithoutInit", "(Ljava/lang/Class;)Ljava/lang/Object;", org_mini_vm_RefNative_newWithoutInit}, + {"org/mini/vm/RefNative", "setLocalVal", "(JIBJI)I", org_mini_vm_RefNative_setLocalVal}, + {"org/mini/vm/RefNative", "getLocalVal", "(JILorg/mini/jdwp/type/ValueType;)I", org_mini_vm_RefNative_getLocalVal}, + {"org/mini/vm/RefNative", "getThreads", "()[Ljava/lang/Thread;", org_mini_vm_RefNative_getThreads}, + {"org/mini/vm/RefNative", "getStatus", "(Ljava/lang/Thread;)I", org_mini_vm_RefNative_getStatus}, + {"org/mini/vm/RefNative", "suspendThread", "(Ljava/lang/Thread;)I", org_mini_vm_RefNative_suspendThread}, + {"org/mini/vm/RefNative", "resumeThread", "(Ljava/lang/Thread;)I", org_mini_vm_RefNative_resumeThread}, + {"org/mini/vm/RefNative", "getSuspendCount", "(Ljava/lang/Thread;)I", org_mini_vm_RefNative_getSuspendCount}, + {"org/mini/vm/RefNative", "getFrameCount", "(Ljava/lang/Thread;)I", org_mini_vm_RefNative_getFrameCount}, + {"org/mini/vm/RefNative", "stopThread", "(Ljava/lang/Thread;J)I", org_mini_vm_RefNative_stopThread}, + {"org/mini/vm/RefNative", "getStackFrame", "(Ljava/lang/Thread;)J", org_mini_vm_RefNative_getStackFrame}, + {"org/mini/vm/RefNative", "getGarbageMarkCounter", "()I", org_mini_vm_RefNative_getGarbageMarkCounter}, + {"org/mini/vm/RefNative", "getGarbageStatus", "()I", org_mini_vm_RefNative_getGarbageStatus}, + {"org/mini/vm/RefNative", "getCallerClass", "()Ljava/lang/Class;", org_mini_vm_RefNative_getCallerClass}, + {"org/mini/vm/RefNative", "defineClass", "(Ljava/lang/ClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;", org_mini_vm_RefNative_defineClass}, + {"org/mini/vm/RefNative", "findLoadedClass0", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;", org_mini_vm_RefNative_findLoadedClass0}, + {"org/mini/vm/RefNative", "findResource0", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/net/URL;", org_mini_vm_RefNative_findResource0}, + {"org/mini/vm/RefNative", "initNativeClassLoader", "(Ljava/lang/ClassLoader;Ljava/lang/ClassLoader;)V", org_mini_vm_RefNative_initNativeClassLoader}, + {"org/mini/vm/RefNative", "destroyNativeClassLoader", "(Ljava/lang/ClassLoader;)V", org_mini_vm_RefNative_destroyNativeClassLoader}, + {"org/mini/vm/RefNative", "addJarToClasspath", "(Ljava/lang/String;)V", org_mini_vm_RefNative_addJarToClasspath}, + {"org/mini/vm/RefNative", "heap_calloc", "(I)J", org_mini_vm_RefNative_heap_calloc}, + {"org/mini/vm/RefNative", "heap_free", "(J)V", org_mini_vm_RefNative_heap_free}, + {"org/mini/vm/RefNative", "heap_put_byte", "(JIB)V", org_mini_vm_RefNative_heap_put_byte}, + {"org/mini/vm/RefNative", "heap_get_byte", "(JI)B", org_mini_vm_RefNative_heap_get_byte}, + {"org/mini/vm/RefNative", "heap_put_short", "(JIS)V", org_mini_vm_RefNative_heap_put_short}, + {"org/mini/vm/RefNative", "heap_get_short", "(JI)S", org_mini_vm_RefNative_heap_get_short}, + {"org/mini/vm/RefNative", "heap_put_int", "(JII)V", org_mini_vm_RefNative_heap_put_int}, + {"org/mini/vm/RefNative", "heap_get_int", "(JI)I", org_mini_vm_RefNative_heap_get_int}, + {"org/mini/vm/RefNative", "heap_put_long", "(JIJ)V", org_mini_vm_RefNative_heap_put_long}, + {"org/mini/vm/RefNative", "heap_get_long", "(JI)J", org_mini_vm_RefNative_heap_get_long}, + {"org/mini/vm/RefNative", "heap_put_float", "(JIF)V", org_mini_vm_RefNative_heap_put_int}, + {"org/mini/vm/RefNative", "heap_get_float", "(JI)F", org_mini_vm_RefNative_heap_get_int}, + {"org/mini/vm/RefNative", "heap_put_double", "(JID)V", org_mini_vm_RefNative_heap_put_long}, + {"org/mini/vm/RefNative", "heap_get_double", "(JI)D", org_mini_vm_RefNative_heap_get_long}, + {"org/mini/vm/RefNative", "heap_put_ref", "(JILjava/lang/Object;)V", org_mini_vm_RefNative_heap_put_ref}, + {"org/mini/vm/RefNative", "heap_get_ref", "(JI)Ljava/lang/Object;", org_mini_vm_RefNative_heap_get_ref}, + {"org/mini/vm/RefNative", "heap_copy", "(JIJII)V", org_mini_vm_RefNative_heap_copy}, + {"org/mini/vm/RefNative", "heap_bin_search", "(JIJI)I", org_mini_vm_RefNative_heap_bin_search}, + {"org/mini/vm/RefNative", "heap_fill", "(JIJI)V", org_mini_vm_RefNative_heap_fill}, + {"org/mini/vm/RefNative", "heap_endian", "()I", org_mini_vm_RefNative_heap_little_endian}, {"org/mini/reflect/ReflectClass", "mapClass", "(J)V", org_mini_reflect_ReflectClass_mapClass}, {"org/mini/reflect/ReflectField", "mapField", "(J)V", org_mini_reflect_ReflectField_mapField}, {"org/mini/reflect/ReflectField", "getFieldVal", "(Ljava/lang/Object;J)J", org_mini_reflect_ReflectField_getFieldVal}, diff --git a/minijvm/c/jvm/jni_std.c b/minijvm/c/jvm/jni_std.c index c7808bd72..26fa4e936 100644 --- a/minijvm/c/jvm/jni_std.c +++ b/minijvm/c/jvm/jni_std.c @@ -703,9 +703,9 @@ s32 java_lang_String_replace0(Runtime *runtime, JClass *clazz) { u16 *dst_value = (u16 *) jstring_get_value_array(dst, runtime)->arr_body; ByteBuf *sb = bytebuf_create(count); - int i, j; + s32 i, j; for (i = 0; i < count;) { - int index = i + offset; + s32 index = i + offset; u16 ch = value[index]; s32 match = 0; if (ch == src_value[src_offset] && index + src_count <= offset + count) { diff --git a/minijvm/c/jvm/jvm.c b/minijvm/c/jvm/jvm.c index 36080658b..3d939d532 100644 --- a/minijvm/c/jvm/jvm.c +++ b/minijvm/c/jvm/jvm.c @@ -213,7 +213,7 @@ void classloaders_destroy_all(MiniJVM *jvm) { jvm->classloaders = NULL; } -void set_jvm_state(MiniJVM *jvm, int state) { +void set_jvm_state(MiniJVM *jvm, s32 state) { jvm->jvm_state = state; } @@ -221,11 +221,11 @@ s32 get_jvm_state(MiniJVM *jvm) { return jvm->jvm_state; } -void _on_jvm_sig_print(int no) { +void _on_jvm_sig_print(s32 no) { jvm_printf("[SIGNAL]jvm sig:%d errno: %d , %s\n", no, errno, strerror(errno)); } -void _on_jvm_sig(int no) { +void _on_jvm_sig(s32 no) { _on_jvm_sig_print(no); exit(no); } @@ -320,7 +320,7 @@ s32 jvm_init(MiniJVM *jvm, c8 *p_bootclasspath, c8 *p_classpath) { utf8_append_c(clsName, STR_CLASS_JAVA_LANG_THREAD); classes_load_get(NULL, clsName, runtime); utf8_clear(clsName); - utf8_append_c(clsName, STR_CLASS_ORG_MINI_REFLECT_LAUNCHER); + utf8_append_c(clsName, STR_CLASS_SUN_MISC_LAUNCHER); classes_load_get(NULL, clsName, runtime); //开始装载类 utf8_destory(clsName); @@ -398,7 +398,7 @@ s32 call_main(MiniJVM *jvm, c8 *p_mainclass, ArrayList *java_para) { Instance *arr = jarray_create_by_type_name(runtime, count, ustr, NULL); instance_hold_to_thread(arr, runtime); utf8_destory(ustr); - int i; + s32 i; for (i = 0; i < count; i++) { Utf8String *utfs = utf8_create_c(arraylist_get_value(java_para, i)); Instance *jstr = jstring_create(utfs, runtime); @@ -470,7 +470,9 @@ s32 call_method(MiniJVM *jvm, c8 *p_classname, c8 *p_methodname, c8 *p_methoddes if (_JVM_JDWP_ENABLE) { if (jvm->jdwp_enable) { if (jvm->jdwp_suspend_on_start)jthread_suspend(runtime); +#if _JVM_DEBUG_LOG_LEVEL > 0 jvm_printf("[JDWP]jdwp listening (port:%s) ...\n", JDWP_TCP_PORT); +#endif }//jdwp 会启动调试器 } runtime->method = NULL; diff --git a/minijvm/c/jvm/jvm.h b/minijvm/c/jvm/jvm.h index e5451484b..8d0c0e07b 100644 --- a/minijvm/c/jvm/jvm.h +++ b/minijvm/c/jvm/jvm.h @@ -27,7 +27,7 @@ extern "C" { //======================= micro define ============================= //_JVM_DEBUG 01=thread info, 02=garage&jit info , 03=class load, 04=method call, 06=all bytecode -#define _JVM_DEBUG_LOG_LEVEL 01 +#define _JVM_DEBUG_LOG_LEVEL 0 #define _JVM_DEBUG_LOG_TO_FILE 0 #define _JVM_DEBUG_GARBAGE_DUMP 0 #define _JVM_DEBUG_PROFILE 0 @@ -465,7 +465,7 @@ enum { THREAD_TYPE_JDWP, }; -extern char *STRS_CLASS_EXCEPTION[]; +extern c8 *STRS_CLASS_EXCEPTION[]; extern c8 const *STR_CLASS_JAVA_LANG_STRING; extern c8 const *STR_CLASS_JAVA_LANG_STRINGBUILDER; @@ -489,7 +489,7 @@ extern c8 const *STR_CLASS_JAVA_LANG_INVOKE_METHODTYPE; extern c8 const *STR_CLASS_JAVA_LANG_INVOKE_METHODHANDLE; extern c8 const *STR_CLASS_JAVA_LANG_INVOKE_METHODHANDLES_LOOKUP; extern c8 const *STR_CLASS_ORG_MINI_REFLECT_DIRECTMEMOBJ; -extern c8 const *STR_CLASS_ORG_MINI_REFLECT_LAUNCHER; +extern c8 const *STR_CLASS_SUN_MISC_LAUNCHER; extern c8 const *STR_CLASS_ORG_MINI_REFLECT_REFLECTMETHOD; extern c8 const *STR_FIELD_STACKFRAME; @@ -1681,9 +1681,9 @@ struct _JNIENV { Utf8String *(*utf8_create)(); - Utf8String *(*utf8_create_part_c)(char const *str, int start, int len); + Utf8String *(*utf8_create_part_c)(c8 const *str, s32 start, s32 len); - char const *(*utf8_cstr)(Utf8String *a1); + c8 const *(*utf8_cstr)(Utf8String *a1); void (*utf8_destory)(Utf8String *); @@ -1894,7 +1894,7 @@ s32 execute_method(MethodInfo *method, Runtime *runtime); s32 get_jvm_state(MiniJVM *jvm); -void set_jvm_state(MiniJVM *jvm, int state); +void set_jvm_state(MiniJVM *jvm, s32 state); //======================= ============================= diff --git a/minijvm/c/jvm/jvm_util.c b/minijvm/c/jvm/jvm_util.c index 945c2b72d..32b0d22f7 100644 --- a/minijvm/c/jvm/jvm_util.c +++ b/minijvm/c/jvm/jvm_util.c @@ -355,7 +355,7 @@ void vm_share_wait(MiniJVM *jvm) { void vm_share_timedwait(MiniJVM *jvm, s64 ms) { struct timespec t; - clock_gettime(CLOCK_REALTIME, &t); + timespec_get(&t, TIME_UTC); t.tv_sec += ms / 1000; t.tv_nsec += (ms % 1000) * 1000000; s32 ret = cnd_timedwait(&jvm->threadlock.thread_cond, &jvm->threadlock.mutex_lock, &t); @@ -406,7 +406,7 @@ s32 enc_get_utf8_size(const c8 *pInput) { s32 utf8_2_unicode(Utf8String *ustr, u16 *arr) { c8 const *pInput = utf8_cstr(ustr); //assert(pInput != NULL && Unic != NULL); - int outputSize = 0; //记录转换后的Unicode字符串的字节数 + s32 outputSize = 0; //记录转换后的Unicode字符串的字节数 // b1 表示UTF-8编码的pInput中的高字节, b2 表示次高字节, ... c8 b1, b2, b3, b4, b5, b6; s32 codepoint = 0; @@ -414,7 +414,7 @@ s32 utf8_2_unicode(Utf8String *ustr, u16 *arr) { while (*pInput) { //*Unic = 0x0; // 把 *Unic 初始化为全零 - int utfbytes = enc_get_utf8_size(pInput); + s32 utfbytes = enc_get_utf8_size(pInput); //printf("%d", utfbytes); codepoint = 0; switch (utfbytes) { @@ -521,11 +521,11 @@ s32 unicode_2_utf8(u16 *jchar_arr, Utf8String *ustr, s32 totalSize) { s32 unic = jchar_arr[i]; if (unic >= 0xd800 && unic <= 0xdbff) { if (i + 1 < totalSize) { - int c1 = jchar_arr[i + 1]; + s32 c1 = jchar_arr[i + 1]; if (c1 >= 0xdc00 && c1 <= 0xdfff) { i++; - int lead = unic & 0x3ff; - int trail = c1 & 0x3ff; + s32 lead = unic & 0x3ff; + s32 trail = c1 & 0x3ff; unic = (lead << 10) | trail | 0x10000; } } @@ -581,7 +581,7 @@ s32 unicode_2_utf8(u16 *jchar_arr, Utf8String *ustr, s32 totalSize) { * @param size len */ void swap_endian_little_big(u8 *ptr, s32 size) { - int i; + s32 i; for (i = 0; i < size / 2; i++) { u8 tmp = ptr[i]; ptr[i] = ptr[size - 1 - i]; @@ -823,10 +823,10 @@ void close_log() { #endif } -int jvm_printf(const char *format, ...) { +s32 jvm_printf(const c8 *format, ...) { va_list vp; va_start(vp, format); - int result = 0; + s32 result = 0; #if _JVM_DEBUG_LOG_TO_FILE if (logfile) { @@ -847,7 +847,7 @@ int jvm_printf(const char *format, ...) { void invoke_deepth(Runtime *runtime) { vm_share_lock(runtime->jvm); - int i = 0; + s32 i = 0; Runtime *r = runtime; while (r) { i++; @@ -1218,7 +1218,7 @@ Instance *jarray_multi_create(Runtime *runtime, s32 *dim, s32 dim_size, Utf8Stri jvm_printf("multi arr deep :%d type(%c) arr[%x] size:%d\n", deep, ch, arr, len); #endif if (ch == '[') { - int i; + s32 i; s64 val; for (i = 0; i < len; i++) { Instance *elem = jarray_multi_create(runtime, dim, dim_size, desc, deep + 1); @@ -1577,7 +1577,7 @@ u16 jstring_char_at(Instance *jstr, s32 index, Runtime *runtime) { s32 jstring_index_of(Instance *jstr, u16 ch, s32 startAt, Runtime *runtime) { c8 *fieldPtr = jstring_get_value_ptr(jstr, runtime); - Instance *ptr = (Instance *) getFieldRefer(fieldPtr);//char[]数组实例 + Instance *ptr = (Instance *) getFieldRefer(fieldPtr);//c8[]数组实例 if (ptr && ptr->arr_body && startAt >= 0) { u16 *jchar_arr = (u16 *) ptr->arr_body; s32 count = jstring_get_count(jstr, runtime); @@ -1600,8 +1600,8 @@ s32 jstring_equals(Instance *jstr1, Instance *jstr2, Runtime *runtime) { } else if (!jstr2) { return 0; } - Instance *arr1 = jstring_get_value_array(jstr1, runtime);//取得 char[] value - Instance *arr2 = jstring_get_value_array(jstr2, runtime);//取得 char[] value + Instance *arr1 = jstring_get_value_array(jstr1, runtime);//取得 c8[] value + Instance *arr2 = jstring_get_value_array(jstr2, runtime);//取得 c8[] value s32 count1 = 0, offset1 = 0, count2 = 0, offset2 = 0; //0长度字符串可能value[] 是空值,也可能不是空值但count是0 if (arr1) { @@ -1840,14 +1840,14 @@ void threadinfo_destory(JavaThreadInfo *threadInfo) { s64 currentTimeMillis() { struct timespec tv; - clock_gettime(CLOCK_REALTIME, &tv); + timespec_get(&tv, TIME_UTC); return ((s64) tv.tv_sec) * MILL_2_SEC_SCALE + tv.tv_nsec / NANO_2_MILLS_SCALE; } s64 nanoTime() { struct timespec tv; - clock_gettime(CLOCK_REALTIME, &tv); + timespec_get(&tv, TIME_UTC); if (!nano_sec_start_at) { nano_sec_start_at = ((s64) tv.tv_sec) * NANO_2_SEC_SCALE + tv.tv_nsec; @@ -1901,7 +1901,7 @@ void instance_release_from_thread(Instance *ins, Runtime *runtime) { } } -CStringArr *cstringarr_create(Instance *jstr_arr) { //byte[][] to char** +CStringArr *cstringarr_create(Instance *jstr_arr) { //byte[][] to c8** if (!jstr_arr)return NULL; CStringArr *cstr_arr = jvm_calloc(sizeof(CStringArr)); cstr_arr->arr_length = jstr_arr->arr_length; @@ -1956,7 +1956,7 @@ s32 _loadFileContents(c8 const *file, ByteBuf *buf) { FILE *pFile; long lSize; - char *buffer; + c8 *buffer; size_t result; /* 若要一个byte不漏地读入整个文件,只能采用二进制方式打开 */ diff --git a/minijvm/c/jvm/jvm_util.h b/minijvm/c/jvm/jvm_util.h index 578d48911..9feeba524 100644 --- a/minijvm/c/jvm/jvm_util.h +++ b/minijvm/c/jvm/jvm_util.h @@ -22,7 +22,7 @@ s32 isDir(Utf8String *path); s32 utf8_2_unicode(Utf8String *ustr, u16 *arr); -int unicode_2_utf8(u16 *jchar_arr, Utf8String *ustr, s32 totalSize); +s32 unicode_2_utf8(u16 *jchar_arr, Utf8String *ustr, s32 totalSize); void swap_endian_little_big(u8 *ptr, s32 size); @@ -58,7 +58,7 @@ void instance_release_from_thread(Instance *ref, Runtime *runtime); void instance_hold_to_thread(Instance *ins, Runtime *runtime); -int jvm_printf(const char *, ...); +s32 jvm_printf(const c8 *, ...); void invoke_deepth(Runtime *runtime); diff --git a/minijvm/c/main.c b/minijvm/c/main.c index f581de202..61a3b6843 100644 --- a/minijvm/c/main.c +++ b/minijvm/c/main.c @@ -26,6 +26,7 @@ int main(int argc, char **argv) { c8 *bootclasspath = NULL; c8 *classpath = NULL; c8 *main_name = NULL; + s32 print_version = 0; s32 main_set = 0; ArrayList *java_para = arraylist_create(0); s32 jdwp = 0; @@ -42,8 +43,9 @@ int main(int argc, char **argv) { s32 dpos = utf8_last_indexof_c(startup_dir, "/"); if (dpos > 0)utf8_substring(startup_dir, 0, dpos); utf8_append_c(startup_dir, "/"); +#if _JVM_DEBUG_LOG_LEVEL > 0 jvm_printf("App dir:%s\n", utf8_cstr(startup_dir)); - +#endif //default value { utf8_append(bootcp, startup_dir); @@ -127,6 +129,11 @@ int main(int argc, char **argv) { if (strcmp(argv[i], "-bootclasspath") == 0) { bootclasspath = argv[i + 1]; i++; + } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) { + print_version = 1; + classpath = NULL; + main_name = "org.mini.vm.PrintVersion"; + i++; } else if (strcmp(argv[i], "-cp") == 0 || strcmp(argv[i], "-classpath") == 0) { classpath = argv[i + 1]; i++; diff --git a/minijvm/c/utils/spinlock.h b/minijvm/c/utils/spinlock.h index d873f7f30..0977b14c1 100755 --- a/minijvm/c/utils/spinlock.h +++ b/minijvm/c/utils/spinlock.h @@ -28,7 +28,7 @@ static inline s64 __sync_bool_compare_and_swap64(volatile s64* lock, s64 compara if (InterlockedCompareExchange64(lock, exchange, comparand) == comparand)return 1; else return 0; } -static inline int __sync_bool_compare_and_swap(volatile int *lock,int comparand, int exchange) { +static inline s32 __sync_bool_compare_and_swap(volatile s32 *lock,int comparand, s32 exchange) { //if *lock == comparand then *lock = exchange and return old *lock value if(InterlockedCompareExchange(lock, exchange, comparand) == comparand)return 1; else return 0; @@ -54,7 +54,7 @@ static inline int spin_lock_count(volatile spinlock_t *lock, s32 count) { int i; for (i = 0; i < count; i++) { // if *lock == 0,then *lock = 1 , return true else return false - if (lock->owner == thrd_current()) { + if (thrd_equal(lock->owner, thrd_current())) { lock->count++; return 0; } @@ -86,7 +86,7 @@ static inline int spin_lock(volatile spinlock_t *lock) { //} static inline int spin_unlock(volatile spinlock_t *lock) { - if (lock->owner != thrd_current()) { + if (!thrd_equal(lock->owner, thrd_current())) { return 1; } lock->count--; diff --git a/minijvm/java/src/main/java/java/lang/Class.java b/minijvm/java/src/main/java/java/lang/Class.java index e2d404a3d..6e8ce3d16 100644 --- a/minijvm/java/src/main/java/java/lang/Class.java +++ b/minijvm/java/src/main/java/java/lang/Class.java @@ -29,8 +29,8 @@ import org.mini.reflect.ReflectClass; import org.mini.reflect.ReflectField; import org.mini.reflect.ReflectMethod; -import org.mini.reflect.vm.RConst; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RConst; +import org.mini.vm.RefNative; import java.lang.reflect.*; import java.util.HashMap; diff --git a/minijvm/java/src/main/java/java/lang/ClassLoader.java b/minijvm/java/src/main/java/java/lang/ClassLoader.java index 7809e2927..583407ee3 100755 --- a/minijvm/java/src/main/java/java/lang/ClassLoader.java +++ b/minijvm/java/src/main/java/java/lang/ClassLoader.java @@ -9,8 +9,8 @@ details. */ package java.lang; -import org.mini.reflect.Launcher; -import org.mini.reflect.vm.RefNative; +import sun.misc.Launcher; +import org.mini.vm.RefNative; import java.io.IOException; import java.io.InputStream; diff --git a/minijvm/java/src/main/java/java/lang/invoke/LambdaMetafactory.java b/minijvm/java/src/main/java/java/lang/invoke/LambdaMetafactory.java index 7af41de45..f14265d43 100644 --- a/minijvm/java/src/main/java/java/lang/invoke/LambdaMetafactory.java +++ b/minijvm/java/src/main/java/java/lang/invoke/LambdaMetafactory.java @@ -9,11 +9,10 @@ details. */ package java.lang.invoke; -import org.mini.reflect.vm.ByteCodeAssembler; -import org.mini.reflect.vm.ByteCodeAssembler.*; -import org.mini.reflect.vm.ByteCodeConstantPool; -import org.mini.reflect.vm.ByteCodeConstantPool.PoolEntry; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.ByteCodeAssembler; +import org.mini.vm.ByteCodeConstantPool; +import org.mini.vm.ByteCodeConstantPool.PoolEntry; +import org.mini.vm.RefNative; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -24,8 +23,8 @@ import java.util.Iterator; import java.util.List; -import static org.mini.reflect.vm.ByteCodeAssembler.*; -import static org.mini.reflect.vm.ByteCodeStream.*; +import static org.mini.vm.ByteCodeAssembler.*; +import static org.mini.vm.ByteCodeStream.*; // To understand what this is all about, please read: // diff --git a/minijvm/java/src/main/java/java/lang/invoke/MethodType.java b/minijvm/java/src/main/java/java/lang/invoke/MethodType.java index e2246b7d9..5ffa4d666 100755 --- a/minijvm/java/src/main/java/java/lang/invoke/MethodType.java +++ b/minijvm/java/src/main/java/java/lang/invoke/MethodType.java @@ -11,12 +11,12 @@ import org.mini.reflect.ReflectClass; import org.mini.reflect.ReflectMethod; -import org.mini.reflect.vm.ByteCodeAssembler; +import org.mini.vm.ByteCodeAssembler; import java.util.ArrayList; import java.util.List; -import static org.mini.reflect.vm.ByteCodeAssembler.*; +import static org.mini.vm.ByteCodeAssembler.*; public final class MethodType implements java.io.Serializable { diff --git a/minijvm/java/src/main/java/java/lang/reflect/Array.java b/minijvm/java/src/main/java/java/lang/reflect/Array.java index a336f50b6..9eace8fd1 100644 --- a/minijvm/java/src/main/java/java/lang/reflect/Array.java +++ b/minijvm/java/src/main/java/java/lang/reflect/Array.java @@ -27,7 +27,7 @@ package java.lang.reflect; import org.mini.reflect.ReflectArray; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RefNative; /** * The Array class provides static methods to dynamically create diff --git a/minijvm/java/src/main/java/java/lang/reflect/Constructor.java b/minijvm/java/src/main/java/java/lang/reflect/Constructor.java index 214642e71..b9d762d4b 100755 --- a/minijvm/java/src/main/java/java/lang/reflect/Constructor.java +++ b/minijvm/java/src/main/java/java/lang/reflect/Constructor.java @@ -27,7 +27,7 @@ package java.lang.reflect; import org.mini.reflect.ReflectMethod; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RefNative; /** * Constructor provides information about, and access to, a single diff --git a/minijvm/java/src/main/java/java/lang/reflect/Method.java b/minijvm/java/src/main/java/java/lang/reflect/Method.java index 534f42714..abdb2b80c 100755 --- a/minijvm/java/src/main/java/java/lang/reflect/Method.java +++ b/minijvm/java/src/main/java/java/lang/reflect/Method.java @@ -26,9 +26,8 @@ package java.lang.reflect; -import org.mini.reflect.ReflectField; import org.mini.reflect.ReflectMethod; -import org.mini.reflect.vm.RConst; +import org.mini.vm.RConst; import java.lang.annotation.Annotation; diff --git a/minijvm/java/src/main/java/java/net/URLClassLoader.java b/minijvm/java/src/main/java/java/net/URLClassLoader.java index b18aa5098..6f9f8787a 100755 --- a/minijvm/java/src/main/java/java/net/URLClassLoader.java +++ b/minijvm/java/src/main/java/java/net/URLClassLoader.java @@ -10,7 +10,7 @@ package java.net; -import org.mini.reflect.Launcher; +import sun.misc.Launcher; public class URLClassLoader extends ClassLoader { diff --git a/minijvm/java/src/main/java/java/nio/ByteBufferImpl.java b/minijvm/java/src/main/java/java/nio/ByteBufferImpl.java index 9364331b9..2aa10a23d 100644 --- a/minijvm/java/src/main/java/java/nio/ByteBufferImpl.java +++ b/minijvm/java/src/main/java/java/nio/ByteBufferImpl.java @@ -2,7 +2,7 @@ import org.mini.reflect.ReflectArray; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RefNative; class ByteBufferImpl extends ByteBuffer { protected byte[] array; diff --git a/minijvm/java/src/main/java/java/nio/ByteOrder.java b/minijvm/java/src/main/java/java/nio/ByteOrder.java index 74957ee3d..5ffe910e3 100755 --- a/minijvm/java/src/main/java/java/nio/ByteOrder.java +++ b/minijvm/java/src/main/java/java/nio/ByteOrder.java @@ -10,7 +10,7 @@ package java.nio; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RefNative; public final class ByteOrder { public static final ByteOrder BIG_ENDIAN = new ByteOrder("BIG_ENDIAN"); diff --git a/minijvm/java/src/main/java/org/mini/fs/InnerFile.java b/minijvm/java/src/main/java/org/mini/fs/InnerFile.java index 5f747c9aa..65f53e382 100644 --- a/minijvm/java/src/main/java/org/mini/fs/InnerFile.java +++ b/minijvm/java/src/main/java/org/mini/fs/InnerFile.java @@ -6,12 +6,10 @@ package org.mini.fs; import org.mini.net.SocketNative; -import org.mini.reflect.vm.RefNative; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; /** * diff --git a/minijvm/java/src/main/java/org/mini/reflect/DirectMemObj.java b/minijvm/java/src/main/java/org/mini/reflect/DirectMemObj.java index f6a1e2e1e..4c706c964 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/DirectMemObj.java +++ b/minijvm/java/src/main/java/org/mini/reflect/DirectMemObj.java @@ -5,8 +5,8 @@ */ package org.mini.reflect; -import org.mini.reflect.vm.RConst; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RConst; +import org.mini.vm.RefNative; import java.lang.reflect.Array; diff --git a/minijvm/java/src/main/java/org/mini/reflect/ReflectClass.java b/minijvm/java/src/main/java/org/mini/reflect/ReflectClass.java index bda691fe6..6e74879eb 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/ReflectClass.java +++ b/minijvm/java/src/main/java/org/mini/reflect/ReflectClass.java @@ -5,7 +5,7 @@ */ package org.mini.reflect; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RefNative; import java.util.ArrayList; import java.util.List; diff --git a/minijvm/java/src/main/java/org/mini/reflect/ReflectField.java b/minijvm/java/src/main/java/org/mini/reflect/ReflectField.java index 96368dd7a..9eac54b22 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/ReflectField.java +++ b/minijvm/java/src/main/java/org/mini/reflect/ReflectField.java @@ -5,8 +5,8 @@ */ package org.mini.reflect; -import org.mini.reflect.vm.RConst; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RConst; +import org.mini.vm.RefNative; import java.lang.reflect.Type; diff --git a/minijvm/java/src/main/java/org/mini/reflect/ReflectMethod.java b/minijvm/java/src/main/java/org/mini/reflect/ReflectMethod.java index c3b78ecb0..4e6386474 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/ReflectMethod.java +++ b/minijvm/java/src/main/java/org/mini/reflect/ReflectMethod.java @@ -5,8 +5,7 @@ */ package org.mini.reflect; -import org.mini.reflect.vm.RConst; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RConst; import java.lang.reflect.Type; import java.util.List; diff --git a/minijvm/java/src/main/java/org/mini/reflect/StackFrame.java b/minijvm/java/src/main/java/org/mini/reflect/StackFrame.java index 8dc1ab36e..bfb040a60 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/StackFrame.java +++ b/minijvm/java/src/main/java/org/mini/reflect/StackFrame.java @@ -5,7 +5,7 @@ */ package org.mini.reflect; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RefNative; /** * diff --git a/minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeAssembler.java b/minijvm/java/src/main/java/org/mini/vm/ByteCodeAssembler.java old mode 100755 new mode 100644 similarity index 92% rename from minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeAssembler.java rename to minijvm/java/src/main/java/org/mini/vm/ByteCodeAssembler.java index 0825c3c72..b8b0c68dc --- a/minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeAssembler.java +++ b/minijvm/java/src/main/java/org/mini/vm/ByteCodeAssembler.java @@ -1,134 +1,134 @@ -/* Copyright (c) 2008-2015, Avian Contributors - - Permission to use, copy, modify, and/or distribute this software - for any purpose with or without fee is hereby granted, provided - that the above copyright notice and this permission notice appear - in all copies. - - There is NO WARRANTY for this software. See license.txt for - details. */ -package org.mini.reflect.vm; - -import org.mini.reflect.vm.ByteCodeConstantPool.PoolEntry; - -import java.util.List; -import java.io.OutputStream; -import java.io.IOException; -import static org.mini.reflect.vm.ByteCodeStream.write2; -import static org.mini.reflect.vm.ByteCodeStream.write4; - -public class ByteCodeAssembler { - - public static final int ACC_PUBLIC = 1 << 0; - public static final int ACC_STATIC = 1 << 3; - - public static final int aaload = 0x32; - public static final int aastore = 0x53; - public static final int aload = 0x19; - public static final int aload_0 = 0x2a; - public static final int aload_1 = 0x2b; - public static final int astore_0 = 0x4b; - public static final int anewarray = 0xbd; - public static final int areturn = 0xb0; - public static final int dload = 0x18; - public static final int dreturn = 0xaf; - public static final int dup = 0x59; - public static final int fload = 0x17; - public static final int freturn = 0xae; - public static final int getfield = 0xb4; - public static final int goto_ = 0xa7; - public static final int iload = 0x15; - public static final int invokeinterface = 0xb9; - public static final int invokespecial = 0xb7; - public static final int invokestatic = 0xb8; - public static final int invokevirtual = 0xb6; - public static final int ireturn = 0xac; - public static final int jsr = 0xa8; - public static final int ldc_w = 0x13; - public static final int lload = 0x16; - public static final int lreturn = 0xad; - public static final int new_ = 0xbb; - public static final int pop = 0x57; - public static final int putfield = 0xb5; - public static final int ret = 0xa9; - public static final int return_ = 0xb1; - - public static void writeClass(OutputStream out, - List pool, - int name, - int super_, - int[] interfaces, - FieldData[] fields, - MethodData[] methods) - throws IOException { - int codeAttributeName = ByteCodeConstantPool.addUtf8(pool, "Code"); - - write4(out, 0xCAFEBABE); - write2(out, 0); // minor version - write2(out, 50); // major version - - write2(out, pool.size() + 1); - for (PoolEntry e : pool) { - e.writeTo(out); - } - - write2(out, ACC_PUBLIC); // flags - write2(out, name + 1); - write2(out, super_ + 1); - - write2(out, interfaces.length); - for (int i : interfaces) { - write2(out, i + 1); - } - - write2(out, fields.length); - for (FieldData f : fields) { - write2(out, f.flags); - write2(out, f.nameIndex + 1); - write2(out, f.specIndex + 1); - write2(out, 0); // attribute count - } - - write2(out, methods.length); - for (MethodData m : methods) { - write2(out, m.flags); - write2(out, m.nameIndex + 1); - write2(out, m.specIndex + 1); - - write2(out, 1); // attribute count - write2(out, codeAttributeName + 1); - write4(out, m.code.length); - out.write(m.code); - } - - write2(out, 0); // attribute count - } - - public static class MethodData { - - public final int flags; - public final int nameIndex; - public final int specIndex; - public final byte[] code; - - public MethodData(int flags, int nameIndex, int specIndex, byte[] code) { - this.flags = flags; - this.nameIndex = nameIndex; - this.specIndex = specIndex; - this.code = code; - } - } - - public static class FieldData { - - public final int flags; - public final int nameIndex; - public final int specIndex; - - public FieldData(int flags, int nameIndex, int specIndex) { - this.flags = flags; - this.nameIndex = nameIndex; - this.specIndex = specIndex; - } - } -} +/* Copyright (c) 2008-2015, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ +package org.mini.vm; + +import org.mini.vm.ByteCodeConstantPool.PoolEntry; + +import java.util.List; +import java.io.OutputStream; +import java.io.IOException; +import static org.mini.vm.ByteCodeStream.write2; +import static org.mini.vm.ByteCodeStream.write4; + +public class ByteCodeAssembler { + + public static final int ACC_PUBLIC = 1 << 0; + public static final int ACC_STATIC = 1 << 3; + + public static final int aaload = 0x32; + public static final int aastore = 0x53; + public static final int aload = 0x19; + public static final int aload_0 = 0x2a; + public static final int aload_1 = 0x2b; + public static final int astore_0 = 0x4b; + public static final int anewarray = 0xbd; + public static final int areturn = 0xb0; + public static final int dload = 0x18; + public static final int dreturn = 0xaf; + public static final int dup = 0x59; + public static final int fload = 0x17; + public static final int freturn = 0xae; + public static final int getfield = 0xb4; + public static final int goto_ = 0xa7; + public static final int iload = 0x15; + public static final int invokeinterface = 0xb9; + public static final int invokespecial = 0xb7; + public static final int invokestatic = 0xb8; + public static final int invokevirtual = 0xb6; + public static final int ireturn = 0xac; + public static final int jsr = 0xa8; + public static final int ldc_w = 0x13; + public static final int lload = 0x16; + public static final int lreturn = 0xad; + public static final int new_ = 0xbb; + public static final int pop = 0x57; + public static final int putfield = 0xb5; + public static final int ret = 0xa9; + public static final int return_ = 0xb1; + + public static void writeClass(OutputStream out, + List pool, + int name, + int super_, + int[] interfaces, + FieldData[] fields, + MethodData[] methods) + throws IOException { + int codeAttributeName = ByteCodeConstantPool.addUtf8(pool, "Code"); + + write4(out, 0xCAFEBABE); + write2(out, 0); // minor version + write2(out, 50); // major version + + write2(out, pool.size() + 1); + for (PoolEntry e : pool) { + e.writeTo(out); + } + + write2(out, ACC_PUBLIC); // flags + write2(out, name + 1); + write2(out, super_ + 1); + + write2(out, interfaces.length); + for (int i : interfaces) { + write2(out, i + 1); + } + + write2(out, fields.length); + for (FieldData f : fields) { + write2(out, f.flags); + write2(out, f.nameIndex + 1); + write2(out, f.specIndex + 1); + write2(out, 0); // attribute count + } + + write2(out, methods.length); + for (MethodData m : methods) { + write2(out, m.flags); + write2(out, m.nameIndex + 1); + write2(out, m.specIndex + 1); + + write2(out, 1); // attribute count + write2(out, codeAttributeName + 1); + write4(out, m.code.length); + out.write(m.code); + } + + write2(out, 0); // attribute count + } + + public static class MethodData { + + public final int flags; + public final int nameIndex; + public final int specIndex; + public final byte[] code; + + public MethodData(int flags, int nameIndex, int specIndex, byte[] code) { + this.flags = flags; + this.nameIndex = nameIndex; + this.specIndex = specIndex; + this.code = code; + } + } + + public static class FieldData { + + public final int flags; + public final int nameIndex; + public final int specIndex; + + public FieldData(int flags, int nameIndex, int specIndex) { + this.flags = flags; + this.nameIndex = nameIndex; + this.specIndex = specIndex; + } + } +} diff --git a/minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeConstantPool.java b/minijvm/java/src/main/java/org/mini/vm/ByteCodeConstantPool.java old mode 100755 new mode 100644 similarity index 94% rename from minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeConstantPool.java rename to minijvm/java/src/main/java/org/mini/vm/ByteCodeConstantPool.java index a2fe0d8b7..80a87609c --- a/minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeConstantPool.java +++ b/minijvm/java/src/main/java/org/mini/vm/ByteCodeConstantPool.java @@ -1,279 +1,279 @@ -/* Copyright (c) 2008-2015, Avian Contributors - - Permission to use, copy, modify, and/or distribute this software - for any purpose with or without fee is hereby granted, provided - that the above copyright notice and this permission notice appear - in all copies. - - There is NO WARRANTY for this software. See license.txt for - details. */ -package org.mini.reflect.vm; - -import java.util.List; -import java.io.OutputStream; -import java.io.IOException; -import static org.mini.reflect.vm.ByteCodeStream.write1; -import static org.mini.reflect.vm.ByteCodeStream.write2; -import static org.mini.reflect.vm.ByteCodeStream.write4; - -public class ByteCodeConstantPool { - - private static final int CONSTANT_Integer = 3; - private static final int CONSTANT_Utf8 = 1; - private static final int CONSTANT_String = 8; - private static final int CONSTANT_Class = 7; - private static final int CONSTANT_NameAndType = 12; - private static final int CONSTANT_Fieldref = 9; - private static final int CONSTANT_Methodref = 10; - private static final int CONSTANT_InterfaceMethodref = 11; - - public static int add(List pool, PoolEntry e) { - int i = 0; - for (PoolEntry existing : pool) { - if (existing.equals(e)) { - return i; - } else { - ++i; - } - } - pool.add(e); - return pool.size() - 1; - } - - public static int addInteger(List pool, int value) { - return add(pool, new IntegerPoolEntry(value)); - } - - public static int addUtf8(List pool, String value) { - return add(pool, new Utf8PoolEntry(value)); - } - - public static int addString(List pool, String value) { - return add(pool, new StringPoolEntry(addUtf8(pool, value))); - } - - public static int addClass(List pool, String name) { -// System.out.println("addClass:" + pool + ", " + name); - return add(pool, new ClassPoolEntry(addUtf8(pool, name))); - } - - public static int addNameAndType(List pool, - String name, - String type) { - return add(pool, new NameAndTypePoolEntry(addUtf8(pool, name), - addUtf8(pool, type))); - } - - public static int addFieldRef(List pool, - String className, - String name, - String spec) { - return add(pool, new FieldRefPoolEntry(addClass(pool, className), - addNameAndType(pool, name, spec))); - } - - public static int addMethodRef(List pool, - String className, - String name, - String spec) { - return add(pool, new MethodRefPoolEntry(addClass(pool, className), - addNameAndType(pool, name, spec))); - } - - public static int addInterfaceMethodRef(List pool, - String interfaceName, - String name, - String spec) { - return add(pool, new InterfaceMethodRefPoolEntry(addClass(pool, interfaceName), - addNameAndType(pool, name, spec))); - } - - public interface PoolEntry { - - public void writeTo(OutputStream out) throws IOException; - } - - private static class IntegerPoolEntry implements PoolEntry { - - private final int value; - - public IntegerPoolEntry(int value) { - this.value = value; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_Integer); - write4(out, value); - } - - public boolean equals(Object o) { - return o instanceof IntegerPoolEntry - && ((IntegerPoolEntry) o).value == value; - } - } - - private static class Utf8PoolEntry implements PoolEntry { - - private final String data; - - public Utf8PoolEntry(String data) { - this.data = data; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_Utf8); - byte[] bytes = data.getBytes(); - write2(out, bytes.length); - out.write(bytes); - } - - public boolean equals(Object o) { - return o instanceof Utf8PoolEntry - && ((Utf8PoolEntry) o).data.equals(data); - } - } - - private static class StringPoolEntry implements PoolEntry { - - private final int valueIndex; - - public StringPoolEntry(int valueIndex) { - this.valueIndex = valueIndex; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_String); - write2(out, valueIndex + 1); - } - - public boolean equals(Object o) { - return o instanceof StringPoolEntry - && ((StringPoolEntry) o).valueIndex == valueIndex; - } - } - - private static class ClassPoolEntry implements PoolEntry { - - private final int nameIndex; - - public ClassPoolEntry(int nameIndex) { - this.nameIndex = nameIndex; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_Class); - write2(out, nameIndex + 1); - } - - public boolean equals(Object o) { - return o instanceof ClassPoolEntry - && ((ClassPoolEntry) o).nameIndex == nameIndex; - } - } - - private static class NameAndTypePoolEntry implements PoolEntry { - - private final int nameIndex; - private final int typeIndex; - - public NameAndTypePoolEntry(int nameIndex, int typeIndex) { - this.nameIndex = nameIndex; - this.typeIndex = typeIndex; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_NameAndType); - write2(out, nameIndex + 1); - write2(out, typeIndex + 1); - } - - public boolean equals(Object o) { - if (o instanceof NameAndTypePoolEntry) { - NameAndTypePoolEntry other = (NameAndTypePoolEntry) o; - return other.nameIndex == nameIndex && other.typeIndex == typeIndex; - } else { - return false; - } - } - } - - private static class FieldRefPoolEntry implements PoolEntry { - - private final int classIndex; - private final int nameAndTypeIndex; - - public FieldRefPoolEntry(int classIndex, int nameAndTypeIndex) { - this.classIndex = classIndex; - this.nameAndTypeIndex = nameAndTypeIndex; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_Fieldref); - write2(out, classIndex + 1); - write2(out, nameAndTypeIndex + 1); - } - - public boolean equals(Object o) { - if (o instanceof FieldRefPoolEntry) { - FieldRefPoolEntry other = (FieldRefPoolEntry) o; - return other.classIndex == classIndex && other.nameAndTypeIndex == nameAndTypeIndex; - } else { - return false; - } - } - } - - private static class MethodRefPoolEntry implements PoolEntry { - - private final int classIndex; - private final int nameAndTypeIndex; - - public MethodRefPoolEntry(int classIndex, int nameAndTypeIndex) { - this.classIndex = classIndex; - this.nameAndTypeIndex = nameAndTypeIndex; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_Methodref); - write2(out, classIndex + 1); - write2(out, nameAndTypeIndex + 1); - } - - public boolean equals(Object o) { - if (o instanceof MethodRefPoolEntry) { - MethodRefPoolEntry other = (MethodRefPoolEntry) o; - return other.classIndex == classIndex - && other.nameAndTypeIndex == nameAndTypeIndex; - } else { - return false; - } - } - } - - private static class InterfaceMethodRefPoolEntry implements PoolEntry { - - private final int classIndex; - private final int nameAndTypeIndex; - - public InterfaceMethodRefPoolEntry(int classIndex, int nameAndTypeIndex) { - this.classIndex = classIndex; - this.nameAndTypeIndex = nameAndTypeIndex; - } - - public void writeTo(OutputStream out) throws IOException { - write1(out, CONSTANT_InterfaceMethodref); - write2(out, classIndex + 1); - write2(out, nameAndTypeIndex + 1); - } - - public boolean equals(Object o) { - if (o instanceof InterfaceMethodRefPoolEntry) { - InterfaceMethodRefPoolEntry other = (InterfaceMethodRefPoolEntry) o; - return other.classIndex == classIndex - && other.nameAndTypeIndex == nameAndTypeIndex; - } else { - return false; - } - } - } -} +/* Copyright (c) 2008-2015, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ +package org.mini.vm; + +import java.util.List; +import java.io.OutputStream; +import java.io.IOException; +import static org.mini.vm.ByteCodeStream.write1; +import static org.mini.vm.ByteCodeStream.write2; +import static org.mini.vm.ByteCodeStream.write4; + +public class ByteCodeConstantPool { + + private static final int CONSTANT_Integer = 3; + private static final int CONSTANT_Utf8 = 1; + private static final int CONSTANT_String = 8; + private static final int CONSTANT_Class = 7; + private static final int CONSTANT_NameAndType = 12; + private static final int CONSTANT_Fieldref = 9; + private static final int CONSTANT_Methodref = 10; + private static final int CONSTANT_InterfaceMethodref = 11; + + public static int add(List pool, PoolEntry e) { + int i = 0; + for (PoolEntry existing : pool) { + if (existing.equals(e)) { + return i; + } else { + ++i; + } + } + pool.add(e); + return pool.size() - 1; + } + + public static int addInteger(List pool, int value) { + return add(pool, new IntegerPoolEntry(value)); + } + + public static int addUtf8(List pool, String value) { + return add(pool, new Utf8PoolEntry(value)); + } + + public static int addString(List pool, String value) { + return add(pool, new StringPoolEntry(addUtf8(pool, value))); + } + + public static int addClass(List pool, String name) { +// System.out.println("addClass:" + pool + ", " + name); + return add(pool, new ClassPoolEntry(addUtf8(pool, name))); + } + + public static int addNameAndType(List pool, + String name, + String type) { + return add(pool, new NameAndTypePoolEntry(addUtf8(pool, name), + addUtf8(pool, type))); + } + + public static int addFieldRef(List pool, + String className, + String name, + String spec) { + return add(pool, new FieldRefPoolEntry(addClass(pool, className), + addNameAndType(pool, name, spec))); + } + + public static int addMethodRef(List pool, + String className, + String name, + String spec) { + return add(pool, new MethodRefPoolEntry(addClass(pool, className), + addNameAndType(pool, name, spec))); + } + + public static int addInterfaceMethodRef(List pool, + String interfaceName, + String name, + String spec) { + return add(pool, new InterfaceMethodRefPoolEntry(addClass(pool, interfaceName), + addNameAndType(pool, name, spec))); + } + + public interface PoolEntry { + + public void writeTo(OutputStream out) throws IOException; + } + + private static class IntegerPoolEntry implements PoolEntry { + + private final int value; + + public IntegerPoolEntry(int value) { + this.value = value; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_Integer); + write4(out, value); + } + + public boolean equals(Object o) { + return o instanceof IntegerPoolEntry + && ((IntegerPoolEntry) o).value == value; + } + } + + private static class Utf8PoolEntry implements PoolEntry { + + private final String data; + + public Utf8PoolEntry(String data) { + this.data = data; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_Utf8); + byte[] bytes = data.getBytes(); + write2(out, bytes.length); + out.write(bytes); + } + + public boolean equals(Object o) { + return o instanceof Utf8PoolEntry + && ((Utf8PoolEntry) o).data.equals(data); + } + } + + private static class StringPoolEntry implements PoolEntry { + + private final int valueIndex; + + public StringPoolEntry(int valueIndex) { + this.valueIndex = valueIndex; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_String); + write2(out, valueIndex + 1); + } + + public boolean equals(Object o) { + return o instanceof StringPoolEntry + && ((StringPoolEntry) o).valueIndex == valueIndex; + } + } + + private static class ClassPoolEntry implements PoolEntry { + + private final int nameIndex; + + public ClassPoolEntry(int nameIndex) { + this.nameIndex = nameIndex; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_Class); + write2(out, nameIndex + 1); + } + + public boolean equals(Object o) { + return o instanceof ClassPoolEntry + && ((ClassPoolEntry) o).nameIndex == nameIndex; + } + } + + private static class NameAndTypePoolEntry implements PoolEntry { + + private final int nameIndex; + private final int typeIndex; + + public NameAndTypePoolEntry(int nameIndex, int typeIndex) { + this.nameIndex = nameIndex; + this.typeIndex = typeIndex; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_NameAndType); + write2(out, nameIndex + 1); + write2(out, typeIndex + 1); + } + + public boolean equals(Object o) { + if (o instanceof NameAndTypePoolEntry) { + NameAndTypePoolEntry other = (NameAndTypePoolEntry) o; + return other.nameIndex == nameIndex && other.typeIndex == typeIndex; + } else { + return false; + } + } + } + + private static class FieldRefPoolEntry implements PoolEntry { + + private final int classIndex; + private final int nameAndTypeIndex; + + public FieldRefPoolEntry(int classIndex, int nameAndTypeIndex) { + this.classIndex = classIndex; + this.nameAndTypeIndex = nameAndTypeIndex; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_Fieldref); + write2(out, classIndex + 1); + write2(out, nameAndTypeIndex + 1); + } + + public boolean equals(Object o) { + if (o instanceof FieldRefPoolEntry) { + FieldRefPoolEntry other = (FieldRefPoolEntry) o; + return other.classIndex == classIndex && other.nameAndTypeIndex == nameAndTypeIndex; + } else { + return false; + } + } + } + + private static class MethodRefPoolEntry implements PoolEntry { + + private final int classIndex; + private final int nameAndTypeIndex; + + public MethodRefPoolEntry(int classIndex, int nameAndTypeIndex) { + this.classIndex = classIndex; + this.nameAndTypeIndex = nameAndTypeIndex; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_Methodref); + write2(out, classIndex + 1); + write2(out, nameAndTypeIndex + 1); + } + + public boolean equals(Object o) { + if (o instanceof MethodRefPoolEntry) { + MethodRefPoolEntry other = (MethodRefPoolEntry) o; + return other.classIndex == classIndex + && other.nameAndTypeIndex == nameAndTypeIndex; + } else { + return false; + } + } + } + + private static class InterfaceMethodRefPoolEntry implements PoolEntry { + + private final int classIndex; + private final int nameAndTypeIndex; + + public InterfaceMethodRefPoolEntry(int classIndex, int nameAndTypeIndex) { + this.classIndex = classIndex; + this.nameAndTypeIndex = nameAndTypeIndex; + } + + public void writeTo(OutputStream out) throws IOException { + write1(out, CONSTANT_InterfaceMethodref); + write2(out, classIndex + 1); + write2(out, nameAndTypeIndex + 1); + } + + public boolean equals(Object o) { + if (o instanceof InterfaceMethodRefPoolEntry) { + InterfaceMethodRefPoolEntry other = (InterfaceMethodRefPoolEntry) o; + return other.classIndex == classIndex + && other.nameAndTypeIndex == nameAndTypeIndex; + } else { + return false; + } + } + } +} diff --git a/minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeStream.java b/minijvm/java/src/main/java/org/mini/vm/ByteCodeStream.java old mode 100755 new mode 100644 similarity index 95% rename from minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeStream.java rename to minijvm/java/src/main/java/org/mini/vm/ByteCodeStream.java index 8b5aaeead..cdb137299 --- a/minijvm/java/src/main/java/org/mini/reflect/vm/ByteCodeStream.java +++ b/minijvm/java/src/main/java/org/mini/vm/ByteCodeStream.java @@ -1,86 +1,86 @@ -/* Copyright (c) 2008-2015, Avian Contributors - - Permission to use, copy, modify, and/or distribute this software - for any purpose with or without fee is hereby granted, provided - that the above copyright notice and this permission notice appear - in all copies. - - There is NO WARRANTY for this software. See license.txt for - details. */ -package org.mini.reflect.vm; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; -import java.io.EOFException; - -public abstract class ByteCodeStream { - - public static void write1(OutputStream out, int v) throws IOException { - out.write(v & 0xFF); - } - - public static int read1(InputStream in) throws IOException { - return in.read(); - } - - public static void write2(OutputStream out, int v) throws IOException { - out.write((v >>> 8) & 0xFF); - out.write((v) & 0xFF); - } - - public static int read2(InputStream in) throws IOException { - int b1 = in.read(); - int b2 = in.read(); - if (b2 == -1) { - throw new EOFException(); - } - return ((b1 << 8) | (b2 & 0xFF)); - } - - public static void write4(OutputStream out, int v) throws IOException { - out.write((v >>> 24) & 0xFF); - out.write((v >>> 16) & 0xFF); - out.write((v >>> 8) & 0xFF); - out.write((v) & 0xFF); - } - - public static int read4(InputStream in) throws IOException { - int b1 = in.read(); - int b2 = in.read(); - int b3 = in.read(); - int b4 = in.read(); - if (b4 == -1) { - throw new EOFException(); - } - return ((b1 << 24) | (b2 << 16) | (b3 << 8) | (b4)); - } - - public static void write8(OutputStream out, long v) throws IOException { - write4(out, (int) (v >>> 32) & 0xFFFFFFFF); - write4(out, (int) (v) & 0xFFFFFFFF); - } - - public static long read8(InputStream in) throws IOException { - long b1 = in.read(); - long b2 = in.read(); - long b3 = in.read(); - long b4 = in.read(); - long b5 = in.read(); - long b6 = in.read(); - long b7 = in.read(); - long b8 = in.read(); - if (b8 == -1) { - throw new EOFException(); - } - return ((b1 << 56) | (b2 << 48) | (b3 << 40) | (b4 << 32) - | (b5 << 24) | (b6 << 16) | (b7 << 8) | (b8)); - } - - public static void set4(byte[] array, int offset, int v) { - array[offset] = (byte) ((v >>> 24) & 0xFF); - array[offset + 1] = (byte) ((v >>> 16) & 0xFF); - array[offset + 2] = (byte) ((v >>> 8) & 0xFF); - array[offset + 3] = (byte) ((v) & 0xFF); - } -} +/* Copyright (c) 2008-2015, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ +package org.mini.vm; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; +import java.io.EOFException; + +public abstract class ByteCodeStream { + + public static void write1(OutputStream out, int v) throws IOException { + out.write(v & 0xFF); + } + + public static int read1(InputStream in) throws IOException { + return in.read(); + } + + public static void write2(OutputStream out, int v) throws IOException { + out.write((v >>> 8) & 0xFF); + out.write((v) & 0xFF); + } + + public static int read2(InputStream in) throws IOException { + int b1 = in.read(); + int b2 = in.read(); + if (b2 == -1) { + throw new EOFException(); + } + return ((b1 << 8) | (b2 & 0xFF)); + } + + public static void write4(OutputStream out, int v) throws IOException { + out.write((v >>> 24) & 0xFF); + out.write((v >>> 16) & 0xFF); + out.write((v >>> 8) & 0xFF); + out.write((v) & 0xFF); + } + + public static int read4(InputStream in) throws IOException { + int b1 = in.read(); + int b2 = in.read(); + int b3 = in.read(); + int b4 = in.read(); + if (b4 == -1) { + throw new EOFException(); + } + return ((b1 << 24) | (b2 << 16) | (b3 << 8) | (b4)); + } + + public static void write8(OutputStream out, long v) throws IOException { + write4(out, (int) (v >>> 32) & 0xFFFFFFFF); + write4(out, (int) (v) & 0xFFFFFFFF); + } + + public static long read8(InputStream in) throws IOException { + long b1 = in.read(); + long b2 = in.read(); + long b3 = in.read(); + long b4 = in.read(); + long b5 = in.read(); + long b6 = in.read(); + long b7 = in.read(); + long b8 = in.read(); + if (b8 == -1) { + throw new EOFException(); + } + return ((b1 << 56) | (b2 << 48) | (b3 << 40) | (b4 << 32) + | (b5 << 24) | (b6 << 16) | (b7 << 8) | (b8)); + } + + public static void set4(byte[] array, int offset, int v) { + array[offset] = (byte) ((v >>> 24) & 0xFF); + array[offset + 1] = (byte) ((v >>> 16) & 0xFF); + array[offset + 2] = (byte) ((v >>> 8) & 0xFF); + array[offset + 3] = (byte) ((v) & 0xFF); + } +} diff --git a/minijvm/java/src/main/java/org/mini/reflect/vm/LambdaUtil.java b/minijvm/java/src/main/java/org/mini/vm/LambdaUtil.java similarity index 97% rename from minijvm/java/src/main/java/org/mini/reflect/vm/LambdaUtil.java rename to minijvm/java/src/main/java/org/mini/vm/LambdaUtil.java index 4a545ea5b..3c28a8893 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/vm/LambdaUtil.java +++ b/minijvm/java/src/main/java/org/mini/vm/LambdaUtil.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.mini.reflect.vm; +package org.mini.vm; import org.mini.reflect.ReflectMethod; diff --git a/minijvm/java/src/main/java/org/mini/vm/PrintVersion.java b/minijvm/java/src/main/java/org/mini/vm/PrintVersion.java new file mode 100644 index 000000000..2a83520da --- /dev/null +++ b/minijvm/java/src/main/java/org/mini/vm/PrintVersion.java @@ -0,0 +1,11 @@ +package org.mini.vm; + +public class PrintVersion { + public static void main(String[] args) { + + System.out.println("minijvm version \"" + System.getProperty("java.version") + "\""); + System.out.println("minijvm SE Runtime Environment (" + System.getProperty("java.version") + "-b01)"); + String arch = RefNative.refIdSize() == 8 ? "64" : "32"; + System.out.println("minijvm " + arch + "-Bit Server VM (build 1.0-b01, mixed mode)"); + } +} diff --git a/minijvm/java/src/main/java/org/mini/reflect/vm/RConst.java b/minijvm/java/src/main/java/org/mini/vm/RConst.java similarity index 96% rename from minijvm/java/src/main/java/org/mini/reflect/vm/RConst.java rename to minijvm/java/src/main/java/org/mini/vm/RConst.java index 4bf37aa43..98faae632 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/vm/RConst.java +++ b/minijvm/java/src/main/java/org/mini/vm/RConst.java @@ -1,79 +1,79 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.mini.reflect.vm; - -/** - * - * @author gust - */ -public class RConst { - - static public final int ACC_PUBLIC = 0x0001; - static public final int ACC_PRIVATE = 0x0002; - static public final int ACC_PROTECTED = 0x0004; - static public final int ACC_STATIC = 0x0008; - static public final int ACC_FINAL = 0x0010; - static public final int ACC_SYNCHRONIZED = 0x0020; - static public final int ACC_VOLATILE = 0x0040; - static public final int ACC_TRANSIENT = 0x0080; - static public final int ACC_NATIVE = 0x0100; - static public final int ACC_INTERFACE = 0x0200; - static public final int ACC_ABSTRACT = 0x0400; - static public final int ACC_STRICT = 0x0800; - - public static final byte TAG_ARRAY = 91; // '[' - an array object (objectID size). - public static final byte TAG_BYTE = 66; // 'B' - a byte TAG_value (1 byte). - public static final byte TAG_CHAR = 67; // 'C' - a character value (2 bytes). - public static final byte TAG_OBJECT = 76; // 'L' - an object (objectID size). - public static final byte TAG_FLOAT = 70; // 'F' - a float value (4 bytes). - public static final byte TAG_DOUBLE = 68; // 'D' - a double value (8 bytes). - public static final byte TAG_INT = 73; // 'I' - an int value (4 bytes). - public static final byte TAG_LONG = 74; // 'J' - a long value (8 bytes). - public static final byte TAG_SHORT = 83; // 'S' - a short value (2 bytes). - public static final byte TAG_VOID = 86; // 'V' - a void value (no bytes). - public static final byte TAG_BOOLEAN = 90; // 'Z' - a boolean value (1 byte). - public static final byte TAG_STRING = 115; // 's' - a String object (objectID size). - public static final byte TAG_THREAD = 116; // 't' - a Thread object (objectID size). - public static final byte TAG_THREAD_GROUP = 103; // 'g' - a ThreadGroup object (objectID size). - public static final byte TAG_CLASS_LOADER = 108; // 'l' - a ClassLoader object (objectID size). - public static final byte TAG_CLASS_OBJECT = 99; // 'c' - a class object object (objectID size). - - public static char getBytes(byte type) { - char bytes = '0'; - switch (type) { - case TAG_BYTE: - case TAG_BOOLEAN: - bytes = '1'; - break; - case TAG_SHORT: - case TAG_CHAR: - bytes = '2'; - break; - case TAG_INT: - case TAG_FLOAT: - bytes = '4'; - break; - case TAG_LONG: - case TAG_DOUBLE: - bytes = '8'; - break; - case TAG_ARRAY: - case TAG_OBJECT: - case TAG_STRING: - case TAG_THREAD: - case TAG_THREAD_GROUP: - case TAG_CLASS_LOADER: - case TAG_CLASS_OBJECT: - bytes = 'R'; - break; - case TAG_VOID: - bytes = '0'; - break; - } - return bytes; - - } -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mini.vm; + +/** + * + * @author gust + */ +public class RConst { + + static public final int ACC_PUBLIC = 0x0001; + static public final int ACC_PRIVATE = 0x0002; + static public final int ACC_PROTECTED = 0x0004; + static public final int ACC_STATIC = 0x0008; + static public final int ACC_FINAL = 0x0010; + static public final int ACC_SYNCHRONIZED = 0x0020; + static public final int ACC_VOLATILE = 0x0040; + static public final int ACC_TRANSIENT = 0x0080; + static public final int ACC_NATIVE = 0x0100; + static public final int ACC_INTERFACE = 0x0200; + static public final int ACC_ABSTRACT = 0x0400; + static public final int ACC_STRICT = 0x0800; + + public static final byte TAG_ARRAY = 91; // '[' - an array object (objectID size). + public static final byte TAG_BYTE = 66; // 'B' - a byte TAG_value (1 byte). + public static final byte TAG_CHAR = 67; // 'C' - a character value (2 bytes). + public static final byte TAG_OBJECT = 76; // 'L' - an object (objectID size). + public static final byte TAG_FLOAT = 70; // 'F' - a float value (4 bytes). + public static final byte TAG_DOUBLE = 68; // 'D' - a double value (8 bytes). + public static final byte TAG_INT = 73; // 'I' - an int value (4 bytes). + public static final byte TAG_LONG = 74; // 'J' - a long value (8 bytes). + public static final byte TAG_SHORT = 83; // 'S' - a short value (2 bytes). + public static final byte TAG_VOID = 86; // 'V' - a void value (no bytes). + public static final byte TAG_BOOLEAN = 90; // 'Z' - a boolean value (1 byte). + public static final byte TAG_STRING = 115; // 's' - a String object (objectID size). + public static final byte TAG_THREAD = 116; // 't' - a Thread object (objectID size). + public static final byte TAG_THREAD_GROUP = 103; // 'g' - a ThreadGroup object (objectID size). + public static final byte TAG_CLASS_LOADER = 108; // 'l' - a ClassLoader object (objectID size). + public static final byte TAG_CLASS_OBJECT = 99; // 'c' - a class object object (objectID size). + + public static char getBytes(byte type) { + char bytes = '0'; + switch (type) { + case TAG_BYTE: + case TAG_BOOLEAN: + bytes = '1'; + break; + case TAG_SHORT: + case TAG_CHAR: + bytes = '2'; + break; + case TAG_INT: + case TAG_FLOAT: + bytes = '4'; + break; + case TAG_LONG: + case TAG_DOUBLE: + bytes = '8'; + break; + case TAG_ARRAY: + case TAG_OBJECT: + case TAG_STRING: + case TAG_THREAD: + case TAG_THREAD_GROUP: + case TAG_CLASS_LOADER: + case TAG_CLASS_OBJECT: + bytes = 'R'; + break; + case TAG_VOID: + bytes = '0'; + break; + } + return bytes; + + } +} diff --git a/minijvm/java/src/main/java/org/mini/reflect/vm/RefNative.java b/minijvm/java/src/main/java/org/mini/vm/RefNative.java similarity index 96% rename from minijvm/java/src/main/java/org/mini/reflect/vm/RefNative.java rename to minijvm/java/src/main/java/org/mini/vm/RefNative.java index 10ab35a42..2e17a9df5 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/vm/RefNative.java +++ b/minijvm/java/src/main/java/org/mini/vm/RefNative.java @@ -1,109 +1,109 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.mini.reflect.vm; - -import java.net.URL; - -/** - * @author gust - */ -public class RefNative { - - - public static native int refIdSize(); - - public static native long obj2id(Object o); - - public static native Object id2obj(long objId); - - public static native Class[] getClasses(); - - public static native Class getBootstrapClassByName(String className);//only get bootstrap class, other return null - - public static native int setLocalVal(long frame, int slot, byte type, long value, int bytes); - - public static native int getLocalVal(long frame, int slot, ValueType val); - - public static native Object newWithoutInit(Class cl); - - //thread method - static public native Thread[] getThreads(); - - static public native int getStatus(Thread t); - - static public native int suspendThread(Thread t); - - static public native int resumeThread(Thread t); - - static public native int getSuspendCount(Thread t); - - static public native int getFrameCount(Thread t); - - static public native int stopThread(Thread t, long objid); - - static public native long getStackFrame(Thread t); - - // - public static native int getGarbageMarkCounter(); - - public static native int getGarbageStatus(); - - public static native Class defineClass(ClassLoader cloader, String name, byte[] bytecodes, int offset, int length); - - public static native void addJarToClasspath(String jarFullPath); - - public static native Class findLoadedClass0(ClassLoader loader, String name); - - public static native URL findResource0(ClassLoader loader, String path); - - // - // - public static native long heap_calloc(int capacity); - - public static native void heap_free(long memAddr); - - public static native void heap_put_byte(long memAddr, int byteIndex, byte value); - - public static native byte heap_get_byte(long memAddr, int byteIndex); - - public static native void heap_put_short(long memAddr, int byteIndex, short value); - - public static native short heap_get_short(long memAddr, int byteIndex); - - public static native void heap_put_int(long memAddr, int byteIndex, int value); - - public static native int heap_get_int(long memAddr, int byteIndex); - - public static native void heap_put_long(long memAddr, int byteIndex, long value); - - public static native long heap_get_long(long memAddr, int byteIndex); - - public static native void heap_put_float(long memAddr, int byteIndex, float value); - - public static native float heap_get_float(long memAddr, int byteIndex); - - public static native void heap_put_double(long memAddr, int byteIndex, double value); - - public static native double heap_get_double(long memAddr, int byteIndex); - - public static native void heap_put_ref(long memAddr, int byteIndex, Object value); - - public static native Object heap_get_ref(long memAddr, int byteIndex); - - public static native void heap_copy(long srcMemAddr, int srcPos, long destMemAddr, int destPos, int length); - - public static native int heap_bin_search(long srcMemAddr, int srcLen, long keyMemAddr, int keyLen); - - public static native void heap_fill(long srcMemAddr, int srcLen, long valMemAddr, int valLen); - - public static native int heap_endian(); - - public static native Class getCallerClass(); - - public static native void initNativeClassLoader(ClassLoader cloader, ClassLoader parent); - - public static native void destroyNativeClassLoader(ClassLoader cloader); -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mini.vm; + +import java.net.URL; + +/** + * @author gust + */ +public class RefNative { + + + public static native int refIdSize(); + + public static native long obj2id(Object o); + + public static native Object id2obj(long objId); + + public static native Class[] getClasses(); + + public static native Class getBootstrapClassByName(String className);//only get bootstrap class, other return null + + public static native int setLocalVal(long frame, int slot, byte type, long value, int bytes); + + public static native int getLocalVal(long frame, int slot, ValueType val); + + public static native Object newWithoutInit(Class cl); + + //thread method + static public native Thread[] getThreads(); + + static public native int getStatus(Thread t); + + static public native int suspendThread(Thread t); + + static public native int resumeThread(Thread t); + + static public native int getSuspendCount(Thread t); + + static public native int getFrameCount(Thread t); + + static public native int stopThread(Thread t, long objid); + + static public native long getStackFrame(Thread t); + + // + public static native int getGarbageMarkCounter(); + + public static native int getGarbageStatus(); + + public static native Class defineClass(ClassLoader cloader, String name, byte[] bytecodes, int offset, int length); + + public static native void addJarToClasspath(String jarFullPath); + + public static native Class findLoadedClass0(ClassLoader loader, String name); + + public static native URL findResource0(ClassLoader loader, String path); + + // + // + public static native long heap_calloc(int capacity); + + public static native void heap_free(long memAddr); + + public static native void heap_put_byte(long memAddr, int byteIndex, byte value); + + public static native byte heap_get_byte(long memAddr, int byteIndex); + + public static native void heap_put_short(long memAddr, int byteIndex, short value); + + public static native short heap_get_short(long memAddr, int byteIndex); + + public static native void heap_put_int(long memAddr, int byteIndex, int value); + + public static native int heap_get_int(long memAddr, int byteIndex); + + public static native void heap_put_long(long memAddr, int byteIndex, long value); + + public static native long heap_get_long(long memAddr, int byteIndex); + + public static native void heap_put_float(long memAddr, int byteIndex, float value); + + public static native float heap_get_float(long memAddr, int byteIndex); + + public static native void heap_put_double(long memAddr, int byteIndex, double value); + + public static native double heap_get_double(long memAddr, int byteIndex); + + public static native void heap_put_ref(long memAddr, int byteIndex, Object value); + + public static native Object heap_get_ref(long memAddr, int byteIndex); + + public static native void heap_copy(long srcMemAddr, int srcPos, long destMemAddr, int destPos, int length); + + public static native int heap_bin_search(long srcMemAddr, int srcLen, long keyMemAddr, int keyLen); + + public static native void heap_fill(long srcMemAddr, int srcLen, long valMemAddr, int valLen); + + public static native int heap_endian(); + + public static native Class getCallerClass(); + + public static native void initNativeClassLoader(ClassLoader cloader, ClassLoader parent); + + public static native void destroyNativeClassLoader(ClassLoader cloader); +} diff --git a/minijvm/java/src/main/java/org/mini/reflect/vm/ValueType.java b/minijvm/java/src/main/java/org/mini/vm/ValueType.java similarity index 90% rename from minijvm/java/src/main/java/org/mini/reflect/vm/ValueType.java rename to minijvm/java/src/main/java/org/mini/vm/ValueType.java index bf1717a3a..8e3ea6819 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/vm/ValueType.java +++ b/minijvm/java/src/main/java/org/mini/vm/ValueType.java @@ -1,28 +1,28 @@ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.mini.reflect.vm; - -/** - * - * @author gust - */ -public class ValueType { - - public byte type; - public long value; - public char bytes; - - public ValueType(byte type) { - this.type = type; - bytes = RConst.getBytes(type); - } - - - public String toString() { - return (char) type + "|" + bytes + "|" + Long.toString(value, 16); - } + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mini.vm; + +/** + * + * @author gust + */ +public class ValueType { + + public byte type; + public long value; + public char bytes; + + public ValueType(byte type) { + this.type = type; + bytes = RConst.getBytes(type); + } + + + public String toString() { + return (char) type + "|" + bytes + "|" + Long.toString(value, 16); + } } \ No newline at end of file diff --git a/minijvm/java/src/main/java/org/mini/reflect/Launcher.java b/minijvm/java/src/main/java/sun/misc/Launcher.java similarity index 98% rename from minijvm/java/src/main/java/org/mini/reflect/Launcher.java rename to minijvm/java/src/main/java/sun/misc/Launcher.java index e0643b3ab..5793ba1ed 100644 --- a/minijvm/java/src/main/java/org/mini/reflect/Launcher.java +++ b/minijvm/java/src/main/java/sun/misc/Launcher.java @@ -1,6 +1,6 @@ -package org.mini.reflect; +package sun.misc; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RefNative; import org.mini.zip.Zip; import java.io.File; diff --git a/minijvm/java/src/main/java/sun/misc/Unsafe.java b/minijvm/java/src/main/java/sun/misc/Unsafe.java index 6dad87d96..2ef460492 100755 --- a/minijvm/java/src/main/java/sun/misc/Unsafe.java +++ b/minijvm/java/src/main/java/sun/misc/Unsafe.java @@ -10,8 +10,8 @@ package sun.misc; -import org.mini.reflect.vm.RConst; -import org.mini.reflect.vm.RefNative; +import org.mini.vm.RConst; +import org.mini.vm.RefNative; import java.lang.reflect.Field; diff --git a/minijvm/java/src/main/resource/sys.properties b/minijvm/java/src/main/resource/sys.properties index 91a636f7b..3af707c05 100644 --- a/minijvm/java/src/main/resource/sys.properties +++ b/minijvm/java/src/main/resource/sys.properties @@ -5,7 +5,7 @@ file.encoding=utf-8 java.class.path=jvm_set_value : classpath jvm startup with -cp java.home= java.vendor=org.minijvm -java.vendor.url= +java.vendor.url=https://github.com/digitalgust/miniJVM java.version=1.0 line.separator=jvm_set_value: posix="\n" windows="\r\n" os.arch=