static int initAnnotation() { Class *enum_cls, *map_cls, *anno_inv_cls, *obj_ary_cls; Class *anno_ary_cls, *dbl_anno_ary_cls; enum_cls = findSystemClass("java/lang/Enum"); map_cls = findSystemClass("java/util/HashMap"); anno_inv_cls = findSystemClass("sun/reflect/annotation/Annotation" "InvocationHandler"); obj_ary_cls = findArrayClass("[Ljava/lang/Object;"); anno_ary_cls = findArrayClass("[Ljava/lang/annotation/Annotation;"); dbl_anno_ary_cls = findArrayClass("[[Ljava/lang/annotation/Annotation;"); if(!enum_cls || !map_cls || !anno_inv_cls || !obj_ary_cls || !anno_ary_cls || !dbl_anno_ary_cls) return FALSE; map_init_mb = findMethod(map_cls, SYMBOL(object_init), SYMBOL(___V)); map_put_mb = findMethod(map_cls, SYMBOL(put), newUtf8("(Ljava/lang/Object;Ljava/lang/Object;)" "Ljava/lang/Object;")); anno_create_mb = findMethod(anno_inv_cls, newUtf8("create"), newUtf8("(Ljava/lang/Class;Ljava/util/Map;)" "Ljava/lang/annotation/Annotation;")); enum_valueof_mb = findMethod(enum_cls, newUtf8("valueOf"), newUtf8("(Ljava/lang/Class;Ljava/lang/String;)" "Ljava/lang/Enum;")); if(!map_init_mb || !map_put_mb || !anno_create_mb || !enum_valueof_mb) { /* FindMethod doesn't throw an exception... */ signalException(java_lang_InternalError, "Expected field/method doesn't exist"); return FALSE; } registerStaticClassRefLocked(&enum_class, enum_cls); registerStaticClassRefLocked(&map_class, map_cls); registerStaticClassRefLocked(&anno_inv_class, anno_inv_cls); registerStaticClassRefLocked(&obj_array_class, obj_ary_cls); registerStaticClassRefLocked(&anno_array_class, anno_ary_cls); registerStaticClassRefLocked(&dbl_anno_array_class, dbl_anno_ary_cls); return anno_inited = TRUE; }
int classlibThreadPostInit() { Class *system = findSystemClass(SYMBOL(java_lang_System)); if(system != NULL) { MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass), SYMBOL(___V)); if(init != NULL) { executeStaticMethod(system, init); return !exceptionOccurred(); } } return FALSE; }
void signalChainedExceptionName(char *excep_name, char *message, Object *cause) { if(!inited) { jam_fprintf(stderr, "Exception occurred while VM initialising.\n"); if(message) jam_fprintf(stderr, "%s: %s\n", excep_name, message); else jam_fprintf(stderr, "%s\n", excep_name); exit(1); } else { Class *exception = findSystemClass(excep_name); if(!exceptionOccurred()) signalChainedExceptionClass(exception, message, cause); } }
void exitVM(int status) { main_exited = TRUE; /* Execute System.exit() to run any registered shutdown hooks. In the unlikely event that System.exit() can't be found, or it returns, fall through and exit. */ if(!VMInitialising()) { Class *system = findSystemClass(SYMBOL(java_lang_System)); if(system) { MethodBlock *exit = findMethod(system, SYMBOL(exit), SYMBOL(_I__V)); if(exit) { DummyFrame dummy; executeStaticMethod(&dummy, system, exit, status); } } } jamvm_exit(status); }
int classlibThreadPostInit() { Class *system; #ifdef JSR292 /* Initialise lock used in Method Handle resolution - this must be done before any invokedynamic instruction is executed */ initVMLock(resolve_lock); #endif /* Initialise System class */ system = findSystemClass(SYMBOL(java_lang_System)); if(system != NULL) { MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass), SYMBOL(___V)); if(init != NULL) { executeStaticMethod(system, init); return !exceptionOccurred(); } } return FALSE; }
void initialiseThreadStage2(InitArgs *args) { Object *java_thread; Class *thrdGrp_class; MethodBlock *run, *remove_thread; FieldBlock *group, *priority, *root, *threadId; FieldBlock *vmThread = NULL, *thread = NULL; FieldBlock *vmData, *daemon, *name; /* Load thread class and register reference for compaction threading */ thread_class = findSystemClass0(SYMBOL(java_lang_Thread)); registerStaticClassRef(&thread_class); if(thread_class != NULL) { vmThread = findField(thread_class, SYMBOL(vmThread), SYMBOL(sig_java_lang_VMThread)); daemon = findField(thread_class, SYMBOL(daemon), SYMBOL(Z)); name = findField(thread_class, SYMBOL(name), SYMBOL(sig_java_lang_String)); group = findField(thread_class, SYMBOL(group), SYMBOL(sig_java_lang_ThreadGroup)); priority = findField(thread_class, SYMBOL(priority), SYMBOL(I)); threadId = findField(thread_class, SYMBOL(threadId), SYMBOL(J)); init_mb = findMethod(thread_class, SYMBOL(object_init), SYMBOL(_java_lang_VMThread_java_lang_String_I_Z__V)); run = findMethod(thread_class, SYMBOL(run), SYMBOL(___V)); vmthread_class = findSystemClass0(SYMBOL(java_lang_VMThread)); CLASS_CB(vmthread_class)->flags |= VMTHREAD; /* Register class reference for compaction threading */ registerStaticClassRef(&vmthread_class); if(vmthread_class != NULL) { thread = findField(vmthread_class, SYMBOL(thread), SYMBOL(sig_java_lang_Thread)); vmData = findField(vmthread_class, SYMBOL(vmData), SYMBOL(I)); } } /* findField and findMethod do not throw an exception... */ if((init_mb == NULL) || (vmData == NULL) || (run == NULL) || (daemon == NULL) || (name == NULL) || (group == NULL) || (priority == NULL) || (vmThread == NULL) || (thread == NULL) || (threadId == NULL)) goto error; vmthread_offset = vmThread->offset; thread_offset = thread->offset; vmData_offset = vmData->offset; daemon_offset = daemon->offset; group_offset = group->offset; priority_offset = priority->offset; threadId_offset = threadId->offset; name_offset = name->offset; run_mtbl_idx = run->method_table_index; /* Initialise the Java-level thread objects for the main thread */ java_thread = initJavaThread(&main_thread, FALSE, "main"); /* Main thread is now sufficiently setup to be able to run the thread group initialiser. This is essential to create the root thread group */ thrdGrp_class = findSystemClass(SYMBOL(java_lang_ThreadGroup)); root = findField(thrdGrp_class, SYMBOL(root), SYMBOL(sig_java_lang_ThreadGroup)); addThread_mb = findMethod(thrdGrp_class, SYMBOL(addThread), SYMBOL(_java_lang_Thread_args__void)); remove_thread = findMethod(thrdGrp_class, SYMBOL(removeThread), SYMBOL(_java_lang_Thread_args__void)); /* findField and findMethod do not throw an exception... */ if((root == NULL) || (addThread_mb == NULL) || (remove_thread == NULL)) goto error; rmveThrd_mtbl_idx = remove_thread->method_table_index; /* Add the main thread to the root thread group */ INST_DATA(java_thread)[group_offset] = root->static_value; { DummyFrame dummy; executeMethod(&dummy, ((Object*)root->static_value), addThread_mb, java_thread); } // dyn INST_DATA(java_thread)[vmthread_offset] = 0; /* Setup signal handling. This will be inherited by all threads created within Java */ initialiseSignals(); /* Create the signal handler thread. It is responsible for catching and handling SIGQUIT (thread dump) and SIGINT (user-termination of the VM, e.g. via Ctrl-C). Note it must be a valid Java-level thread as it needs to run the shutdown hooks in the event of user-termination */ createVMThread("Signal Handler", dumpThreadsLoop); return; error: jam_fprintf(stderr, "Error initialising VM (initialiseMainThread)\nCheck " "the README for compatible versions of GNU Classpath\n"); printException(); exitVM(1); }
int classlibInitReflection() { Class *cons_ref_cls, *mthd_ref_cls, *fld_ref_cls; FieldBlock *cons_slot_fb, *cons_class_fb, *cons_param_fb; FieldBlock *mthd_slot_fb, *mthd_class_fb, *mthd_ret_fb, *mthd_param_fb; FieldBlock *fld_slot_fb, *fld_class_fb; cons_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Constructor)); mthd_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Method)); fld_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Field)); if(!cons_ref_cls || !mthd_ref_cls || !fld_ref_cls) return FALSE; cons_slot_fb = findField(cons_ref_cls, SYMBOL(slot), SYMBOL(I)); cons_class_fb = findField(cons_ref_cls, SYMBOL(clazz), SYMBOL(sig_java_lang_Class)); cons_param_fb = findField(cons_ref_cls, SYMBOL(parameterTypes), SYMBOL(array_java_lang_Class)); mthd_slot_fb = findField(mthd_ref_cls, SYMBOL(slot), SYMBOL(I)); mthd_class_fb = findField(mthd_ref_cls, SYMBOL(clazz), SYMBOL(sig_java_lang_Class)); mthd_ret_fb = findField(mthd_ref_cls, SYMBOL(returnType), SYMBOL(sig_java_lang_Class)); mthd_param_fb = findField(mthd_ref_cls, SYMBOL(parameterTypes), SYMBOL(array_java_lang_Class)); fld_slot_fb = findField(fld_ref_cls, SYMBOL(slot), SYMBOL(I)); fld_class_fb = findField(fld_ref_cls, SYMBOL(clazz), SYMBOL(sig_java_lang_Class)); fld_init_mb = findMethod(fld_ref_cls, SYMBOL(object_init), SYMBOL(java_lang_reflect_field_init_sig)); cons_init_mb = findMethod(cons_ref_cls, SYMBOL(object_init), SYMBOL(java_lang_reflect_cons_init_sig)); mthd_init_mb = findMethod(mthd_ref_cls, SYMBOL(object_init), SYMBOL(java_lang_reflect_mthd_init_sig)); mthd_invoke_mb = findMethod(mthd_ref_cls, SYMBOL(invoke), SYMBOL(java_lang_reflect_mthd_invoke_sig)); if(!fld_init_mb || !cons_init_mb || !mthd_init_mb || !cons_slot_fb || !cons_class_fb || !cons_param_fb || !mthd_slot_fb || !mthd_class_fb || !mthd_ret_fb || !mthd_param_fb || !fld_slot_fb || !fld_class_fb || !mthd_invoke_mb) { /* Find Field/Method doesn't throw an exception... */ signalException(java_lang_InternalError, "Expected reflection method/field doesn't exist"); return FALSE; } cons_slot_offset = cons_slot_fb->u.offset; cons_class_offset = cons_class_fb->u.offset; cons_param_offset = cons_param_fb->u.offset; mthd_slot_offset = mthd_slot_fb->u.offset; mthd_class_offset = mthd_class_fb->u.offset; mthd_ret_offset = mthd_ret_fb->u.offset; mthd_param_offset = mthd_param_fb->u.offset; fld_slot_offset = fld_slot_fb->u.offset; fld_class_offset = fld_class_fb->u.offset; registerStaticClassRefLocked(&cons_reflect_class, cons_ref_cls); registerStaticClassRefLocked(&method_reflect_class, mthd_ref_cls); registerStaticClassRefLocked(&field_reflect_class, fld_ref_cls); return TRUE; }
static int initReflection() { Class *cls_ary_cls, *cons_ary_cls, *cons_ref_cls, *mthd_ary_cls; Class *mthd_ref_cls, *fld_ary_cls, *fld_ref_cls, *vm_cons_cls; Class *vm_mthd_cls, *vm_fld_cls; FieldBlock *vm_cons_slot_fb, *vm_cons_class_fb, *vm_cons_param_fb; FieldBlock *vm_cons_cons_fb, *vm_mthd_slot_fb, *vm_mthd_class_fb; FieldBlock *vm_mthd_ret_fb, *vm_mthd_param_fb, *vm_mthd_m_fb; FieldBlock *vm_fld_slot_fb, *vm_fld_class_fb, *vm_fld_type_fb; FieldBlock *vm_fld_f_fb, *cons_cons_fb, *mthd_m_fb, *fld_f_fb; FieldBlock *acc_flag_fb; cls_ary_cls = findArrayClass(SYMBOL(array_java_lang_Class)); cons_ary_cls = findArrayClass(SYMBOL(array_java_lang_reflect_Constructor)); cons_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Constructor)); vm_cons_cls = findSystemClass(SYMBOL(java_lang_reflect_VMConstructor)); mthd_ary_cls = findArrayClass(SYMBOL(array_java_lang_reflect_Method)); mthd_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Method)); vm_mthd_cls = findSystemClass(SYMBOL(java_lang_reflect_VMMethod)); fld_ary_cls = findArrayClass(SYMBOL(array_java_lang_reflect_Field)); fld_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Field)); vm_fld_cls = findSystemClass(SYMBOL(java_lang_reflect_VMField)); if(!cls_ary_cls || !cons_ary_cls || !cons_ref_cls || !mthd_ary_cls || !mthd_ref_cls || !fld_ary_cls || !fld_ref_cls || !vm_cons_cls || !vm_mthd_cls || !vm_fld_cls) return FALSE; vm_cons_slot_fb = findField(vm_cons_cls, SYMBOL(slot), SYMBOL(I)); vm_cons_class_fb = findField(vm_cons_cls, SYMBOL(clazz), SYMBOL(sig_java_lang_Class)); vm_cons_param_fb = findField(vm_cons_cls, SYMBOL(parameterTypes), SYMBOL(array_java_lang_Class)); vm_cons_cons_fb = findField(vm_cons_cls, SYMBOL(cons), SYMBOL(sig_java_lang_reflect_Constructor)); vm_mthd_slot_fb = findField(vm_mthd_cls, SYMBOL(slot), SYMBOL(I)); vm_mthd_class_fb = findField(vm_mthd_cls, SYMBOL(clazz), SYMBOL(sig_java_lang_Class)); vm_mthd_ret_fb = findField(vm_mthd_cls, SYMBOL(returnType), SYMBOL(sig_java_lang_Class)); vm_mthd_param_fb = findField(vm_mthd_cls, SYMBOL(parameterTypes), SYMBOL(array_java_lang_Class)); vm_mthd_m_fb = findField(vm_mthd_cls, SYMBOL(m), SYMBOL(sig_java_lang_reflect_Method)); vm_fld_slot_fb = findField(vm_fld_cls, SYMBOL(slot), SYMBOL(I)); vm_fld_class_fb = findField(vm_fld_cls, SYMBOL(clazz), SYMBOL(sig_java_lang_Class)); vm_fld_type_fb = findField(vm_fld_cls, SYMBOL(type), SYMBOL(sig_java_lang_Class)); vm_fld_f_fb = findField(vm_fld_cls, SYMBOL(f), SYMBOL(sig_java_lang_reflect_Field)); cons_cons_fb = findField(cons_ref_cls, SYMBOL(cons), SYMBOL(sig_java_lang_reflect_VMConstructor)); mthd_m_fb = findField(mthd_ref_cls, SYMBOL(m), SYMBOL(sig_java_lang_reflect_VMMethod)); fld_f_fb = findField(fld_ref_cls, SYMBOL(f), SYMBOL(sig_java_lang_reflect_VMField)); acc_flag_fb = lookupField(cons_ref_cls, SYMBOL(flag), SYMBOL(Z)); if(!vm_cons_slot_fb || !vm_cons_class_fb || !vm_cons_param_fb || !vm_cons_cons_fb || !vm_mthd_slot_fb || !vm_mthd_class_fb || !vm_mthd_ret_fb || !vm_mthd_m_fb || !vm_mthd_param_fb || !vm_fld_slot_fb || !vm_fld_class_fb || !vm_fld_type_fb || !vm_fld_f_fb || !cons_cons_fb || !mthd_m_fb || !fld_f_fb || !acc_flag_fb) { /* Find Field/Method doesn't throw an exception... */ signalException(java_lang_InternalError, "Expected reflection field doesn't exist"); return FALSE; } vm_cons_slot_offset = vm_cons_slot_fb->u.offset; vm_cons_class_offset = vm_cons_class_fb->u.offset; vm_cons_param_offset = vm_cons_param_fb->u.offset; vm_cons_cons_offset = vm_cons_cons_fb->u.offset; vm_mthd_slot_offset = vm_mthd_slot_fb->u.offset; vm_mthd_class_offset = vm_mthd_class_fb->u.offset; vm_mthd_ret_offset = vm_mthd_ret_fb->u.offset; vm_mthd_param_offset = vm_mthd_param_fb->u.offset; vm_mthd_m_offset = vm_mthd_m_fb->u.offset; vm_fld_slot_offset = vm_fld_slot_fb->u.offset; vm_fld_class_offset = vm_fld_class_fb->u.offset; vm_fld_type_offset = vm_fld_type_fb->u.offset; vm_fld_f_offset = vm_fld_f_fb->u.offset; cons_cons_offset = cons_cons_fb->u.offset; mthd_m_offset = mthd_m_fb->u.offset; fld_f_offset = fld_f_fb->u.offset; acc_flag_offset = acc_flag_fb->u.offset; registerStaticClassRefLocked(&class_array_class, cls_ary_cls); registerStaticClassRefLocked(&cons_array_class, cons_ary_cls); registerStaticClassRefLocked(&method_array_class, mthd_ary_cls); registerStaticClassRefLocked(&field_array_class, fld_ary_cls); registerStaticClassRefLocked(&cons_reflect_class, cons_ref_cls); registerStaticClassRefLocked(&vmcons_reflect_class, vm_cons_cls); registerStaticClassRefLocked(&method_reflect_class, mthd_ref_cls); registerStaticClassRefLocked(&vmmethod_reflect_class, vm_mthd_cls); registerStaticClassRefLocked(&field_reflect_class, fld_ref_cls); registerStaticClassRefLocked(&vmfield_reflect_class, vm_fld_cls); return inited = TRUE; }