/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This file is part of SableVM. * * See the file "LICENSE" for Copyright information and the * * terms and conditions for copying, distribution and * * modification of SableVM. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* ---------------------------------------------------------------------- Java_java_lang_Class_nativeIsInstance ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: nativeIsInstance * Signature: (Ljava/lang/Object;)Z */ JNIEXPORT jboolean JNICALL Java_java_lang_Class_nativeIsInstance (JNIEnv *_env, jobject this, jobject obj) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jboolean result; _svmf_resuming_java (env); { _svmt_type_info *T = _svmf_unwrap_class_instance (env, this); _svmt_type_info *S = (*obj)->vtable->type; result = _svmf_is_assignable_from (env, S, T); } _svmf_stopping_java (env); return result; } /* ---------------------------------------------------------------------- Java_java_lang_Class_getModifiers ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: getModifiers * Signature: ()I */ JNIEXPORT jint JNICALL Java_java_lang_Class_getModifiers (JNIEnv *_env, jobject this) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jint result; _svmf_resuming_java (env); { _svmt_type_info *type = _svmf_unwrap_class_instance (env, this); /* make sure not to return any internal flags */ result = type->access_flags & (SVM_ACC_PUBLIC | SVM_ACC_FINAL | SVM_ACC_SUPER | SVM_ACC_INTERFACE | SVM_ACC_ABSTRACT); } _svmf_stopping_java (env); return result; } /* ---------------------------------------------------------------------- Java_java_lang_Class_isInterface ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: isInterface * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_java_lang_Class_isInterface (JNIEnv *_env, jobject this) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jboolean result; _svmf_resuming_java (env); { _svmt_type_info *type = _svmf_unwrap_class_instance (env, this); if (!(type->is_array) && _svmf_is_set_flag (type->access_flags, SVM_ACC_INTERFACE)) { result = JNI_TRUE; } else { result = JNI_FALSE; } } _svmf_stopping_java (env); return result; } /* ---------------------------------------------------------------------- Java_java_lang_Class_getSuperclass ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: getSuperclass * Signature: ()Ljava/lang/Class; */ JNIEXPORT jclass JNICALL Java_java_lang_Class_getSuperclass (JNIEnv *_env, jobject class) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jclass super = NULL; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_type_info *type = _svmf_unwrap_class_instance (env, class); if (type->is_array) { super = _svmf_get_jni_frame_native_local (env); *super = *(vm->class_loading.boot_loader.classes.jlobject->class_instance); goto end; } if (_svmf_is_set_flag (type->access_flags, SVM_ACC_INTERFACE)) { goto end; } super = _svmf_get_jni_frame_native_local (env); *super = *(_svmf_cast_class (type)->class_instance); } end: _svmf_stopping_java (env); return super; } /* ---------------------------------------------------------------------- Java_java_lang_Class_isAssignableFrom ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: isAssignableFrom * Signature: (Ljava/lang/Class;)Z */ JNIEXPORT jboolean JNICALL Java_java_lang_Class_isAssignableFrom (JNIEnv *_env, jobject this, jclass c) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jboolean is_assignable; _svmf_resuming_java (env); { _svmt_type_info *to = _svmf_unwrap_class_instance (env, this); _svmt_type_info *from = _svmf_unwrap_class_instance (env, this); is_assignable = _svmf_is_assignable_from (env, from, to); } _svmf_stopping_java (env); return is_assignable; } /* ---------------------------------------------------------------------- Java_java_lang_Class_getClassLoader0 ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: getClassLoader0 * Signature: ()Ljava/lang/ClassLoader; */ JNIEXPORT jobject JNICALL Java_java_lang_Class_getClassLoader0 (JNIEnv *_env, jobject this) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jobject class_loader = NULL; _svmf_resuming_java (env); { _svmt_type_info *type = _svmf_unwrap_class_instance (env, this); if (type->class_loader_info->class_loader != NULL) { class_loader = _svmf_get_jni_frame_native_local (env); *class_loader = *(type->class_loader_info->class_loader); } } _svmf_stopping_java (env); return class_loader; } /* ---------------------------------------------------------------------- Java_java_lang_Class_nativeGetDeclaredField ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: nativeGetDeclaredField * Signature: ([BLjava/lang/String;)Ljava/lang/reflect/Field; */ JNIEXPORT jobject JNICALL Java_java_lang_Class_nativeGetDeclaredField (JNIEnv *_env, jclass _class, jbyteArray vmData, jstring _name) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jobject field = NULL; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); _svmt_field_info *field_info; char *name; jbyteArray wrapper; jboolean monitor_acquired = JNI_FALSE; if (_svmf_enter_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } monitor_acquired = JNI_TRUE; if (_svmf_link_class (env, class) != JNI_OK) { goto end; } if (_svmm_galloc_utf_chars (env, _name, name) != JNI_OK) { goto end; } /* this is wrong! We should be looking for the most precise descriptor type, instead of "any"... */ { jint fields_count = class->fields_count; _svmt_field_info *fields = class->fields; jint i; assert (_svmf_is_set_flag (class->state, SVM_TYPE_STATE_PREPARED)); field_info = NULL; for (i = 0; i < fields_count; i++) { _svmt_field_info *current = &fields[i]; if (strcmp (name, DREF (current->name, value)) == 0) { field_info = current; break; } } } _svmm_gfree_utf_chars (name); if (field_info == NULL) { _svmf_error_NoSuchFieldException (env); goto end; } if (field_info->reflection_instance != NULL) { field = _svmf_get_jni_frame_native_local (env); *field = *(field_info->reflection_instance); goto end; } /* wrap it */ wrapper = _svmf_get_jni_frame_native_local_array (env); if (_svmm_local_wrap_pointer (env, field_info, wrapper) != JNI_OK) { goto end; } field = _svmf_get_jni_frame_native_local (env); if (_svmm_new_object_instance (env, vm->class_loading.boot_loader.classes.jlrfield, *field) != JNI_OK) { goto end; } if (_svmm_invoke_nonvirtual_jlrfield_init (env, field, _svmf_cast_jobject (wrapper)) != JNI_OK) { goto end; } if (_svmm_new_native_global (env, field_info->reflection_instance) != JNI_OK) { goto end; } *(field_info->reflection_instance) = *field; end: if (monitor_acquired) { monitor_acquired = JNI_FALSE; if (_svmf_exit_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } } } _svmf_stopping_java (env); return field; } /* ---------------------------------------------------------------------- Java_java_lang_Class_nativeGetMethod ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: nativeGetMethod * Signature: ([BLjava/lang/String;Ljava/lang/String;)Ljava/lang/reflect/Method; */ JNIEXPORT jobject JNICALL Java_java_lang_Class_nativeGetMethod (JNIEnv *_env, jclass _class, jbyteArray vmData, jstring _name, jstring _descriptor) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jobject method = NULL; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); _svmt_method_info *method_info; char *name; char *incomplete_descriptor; jbyteArray wrapper; jboolean monitor_acquired = JNI_FALSE; if (_svmf_enter_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } monitor_acquired = JNI_TRUE; if (_svmf_link_class (env, class) != JNI_OK) { goto end; } if (_svmm_galloc_utf_chars (env, _name, name) != JNI_OK) { goto end; } if (_svmm_galloc_utf_chars (env, _descriptor, incomplete_descriptor) != JNI_OK) { _svmm_gfree_utf_chars (name); goto end; } /* this is wrong! We should be looking for the most precise return type, instead of "any"... */ method_info = _svmf_resolve_incomplete_method (class, name, incomplete_descriptor); _svmm_gfree_utf_chars (name); _svmm_gfree_utf_chars (incomplete_descriptor); if (method_info == NULL) { _svmf_error_NoSuchMethodException (env); goto end; } if (method_info->reflection_instance != NULL) { method = _svmf_get_jni_frame_native_local (env); *method = *(method_info->reflection_instance); goto end; } /* wrap it */ wrapper = _svmf_get_jni_frame_native_local_array (env); if (_svmm_local_wrap_pointer (env, method_info, wrapper) != JNI_OK) { goto end; } method = _svmf_get_jni_frame_native_local (env); if (_svmm_new_object_instance (env, vm->class_loading.boot_loader.classes.jlrmethod, *method) != JNI_OK) { goto end; } if (_svmm_invoke_nonvirtual_jlrmethod_init (env, method, _svmf_cast_jobject (wrapper)) != JNI_OK) { goto end; } if (_svmm_new_native_global (env, method_info->reflection_instance) != JNI_OK) { goto end; } *(method_info->reflection_instance) = *method; end: if (monitor_acquired) { monitor_acquired = JNI_FALSE; if (_svmf_exit_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } } } _svmf_stopping_java (env); return method; } /* ---------------------------------------------------------------------- Java_java_lang_Class_nativeGetDeclaredMethod ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: nativeGetDeclaredMethod * Signature: ([BLjava/lang/String;Ljava/lang/String;)Ljava/lang/reflect/Method; */ JNIEXPORT jobject JNICALL Java_java_lang_Class_nativeGetDeclaredMethod (JNIEnv *_env, jclass _class, jbyteArray vmData, jstring _name, jstring _descriptor) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jobject method = NULL; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); _svmt_method_info *method_info; char *name; char *incomplete_descriptor; jbyteArray wrapper; jboolean monitor_acquired = JNI_FALSE; if (_svmf_enter_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } monitor_acquired = JNI_TRUE; if (_svmf_link_class (env, class) != JNI_OK) { goto end; } if (_svmm_galloc_utf_chars (env, _name, name) != JNI_OK) { goto end; } if (_svmm_galloc_utf_chars (env, _descriptor, incomplete_descriptor) != JNI_OK) { _svmm_gfree_utf_chars (name); goto end; } /* this is wrong! We should be looking for the most precise return type, instead of "any"... */ { jint methods_count = class->methods_count; _svmt_method_info *methods = class->methods; jint i; size_t length = strlen (incomplete_descriptor); assert (_svmf_is_set_flag (class->state, SVM_TYPE_STATE_PREPARED)); assert (name[0] != '<'); method_info = NULL; for (i = 0; i < methods_count; i++) { _svmt_method_info *current = &methods[i]; if (strcmp (name, DREF (current->name, value)) == 0 && strncmp (incomplete_descriptor, DREF (current->descriptor, value), length) == 0) { method_info = current; break; } } } _svmm_gfree_utf_chars (name); _svmm_gfree_utf_chars (incomplete_descriptor); if (method_info == NULL) { _svmf_error_NoSuchMethodException (env); goto end; } if (method_info->reflection_instance != NULL) { method = _svmf_get_jni_frame_native_local (env); *method = *(method_info->reflection_instance); goto end; } /* wrap it */ wrapper = _svmf_get_jni_frame_native_local_array (env); if (_svmm_local_wrap_pointer (env, method_info, wrapper) != JNI_OK) { goto end; } method = _svmf_get_jni_frame_native_local (env); if (_svmm_new_object_instance (env, vm->class_loading.boot_loader.classes.jlrmethod, *method) != JNI_OK) { goto end; } if (_svmm_invoke_nonvirtual_jlrmethod_init (env, method, _svmf_cast_jobject (wrapper)) != JNI_OK) { goto end; } if (_svmm_new_native_global (env, method_info->reflection_instance) != JNI_OK) { goto end; } *(method_info->reflection_instance) = *method; end: if (monitor_acquired) { monitor_acquired = JNI_FALSE; if (_svmf_exit_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } } } _svmf_stopping_java (env); return method; } /* ---------------------------------------------------------------------- Java_java_lang_Class_nativeGetConstructor ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: nativeGetConstructor * Signature: ([BLjava/lang/String;)Ljava/lang/reflect/Constructor; */ JNIEXPORT jobject JNICALL Java_java_lang_Class_nativeGetConstructor (JNIEnv *_env, jclass _class, jbyteArray vmData, jstring _descriptor) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jobject constructor = NULL; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); _svmt_method_info *constructor_info; char *descriptor; jbyteArray wrapper; jboolean monitor_acquired = JNI_FALSE; if (_svmf_enter_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } monitor_acquired = JNI_TRUE; if (_svmf_link_class (env, class) != JNI_OK) { goto end; } if (_svmm_galloc_utf_chars (env, _descriptor, descriptor) != JNI_OK) { goto end; } constructor_info = _svmf_resolve_method (class, "", descriptor); _svmm_gfree_utf_chars (descriptor); if (constructor_info == NULL) { _svmf_error_NoSuchMethodException (env); goto end; } if (constructor_info->reflection_instance != NULL) { constructor = _svmf_get_jni_frame_native_local (env); *constructor = *(constructor_info->reflection_instance); goto end; } /* wrap it */ wrapper = _svmf_get_jni_frame_native_local_array (env); if (_svmm_local_wrap_pointer (env, constructor_info, wrapper) != JNI_OK) { goto end; } constructor = _svmf_get_jni_frame_native_local (env); if (_svmm_new_object_instance (env, vm->class_loading.boot_loader.classes.jlrconstructor, *constructor) != JNI_OK) { goto end; } if (_svmm_invoke_nonvirtual_jlrconstructor_init (env, constructor, _svmf_cast_jobject (wrapper)) != JNI_OK) { goto end; } if (_svmm_new_native_global (env, constructor_info->reflection_instance) != JNI_OK) { goto end; } *(constructor_info->reflection_instance) = *constructor; end: if (monitor_acquired) { monitor_acquired = JNI_FALSE; if (_svmf_exit_object_monitor (env, *(vm->class_loading.boot_loader.classes.virtualmachine-> class_instance)) != JNI_OK) { goto end; } } } _svmf_stopping_java (env); return constructor; } /* ---------------------------------------------------------------------- Java_java_lang_Class_nativeGetName ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: nativeGetName * Signature: ([B)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_java_lang_Class_nativeGetName (JNIEnv *_env, jclass _class, jbyteArray vmData) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jstring name; _svmf_resuming_java (env); { _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); name = _svmf_get_jni_frame_native_local (env); _svmf_get_string (env, class->name, name); } _svmf_stopping_java (env); return name; } /* ---------------------------------------------------------------------- Java_java_lang_Class_isInitialized ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: isInitialized * Signature: ([B)Z */ JNIEXPORT jboolean JNICALL Java_java_lang_Class_isInitialized (JNIEnv *_env, jclass _class, jbyteArray vmData) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jboolean result; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); result = _svmf_is_set_flag (class->state, SVM_TYPE_STATE_INITIALIZED) ? JNI_TRUE : JNI_FALSE; } _svmf_stopping_java (env); return result; } /* ---------------------------------------------------------------------- Java_java_lang_Class_setInitialized ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: setInitialized * Signature: ([B)V */ JNIEXPORT void JNICALL Java_java_lang_Class_setInitialized (JNIEnv *_env, jclass _class, jbyteArray vmData) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); _svmm_set_flag (class->state, SVM_TYPE_STATE_INITIALIZED); } _svmf_stopping_java (env); } /* ---------------------------------------------------------------------- Java_java_lang_Class_step7 ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: step7 * Signature: ([B)V */ JNIEXPORT void JNICALL Java_java_lang_Class_step7 (JNIEnv *_env, jclass _class, jbyteArray vmData) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); /* if not interface, initialize super class */ if (!_svmf_is_interface (class)) { if (CAN_DREF (class->super_class)) { _svmt_class_info *super_class = _svmf_cast_class (DREF (class->super_class, type)); if (_svmf_class_initialization (env, super_class) != JNI_OK) { goto end; } } } } end: _svmf_stopping_java (env); } /* ---------------------------------------------------------------------- Java_java_lang_Class_step8 ---------------------------------------------------------------------- */ /* * Class: java_lang_Class * Method: step8 * Signature: ([B)V */ JNIEXPORT void JNICALL Java_java_lang_Class_step8 (JNIEnv *_env, jclass _class, jbyteArray vmData) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_class_info *class = _svmf_unwrap_pointer (*vmData); _svmt_method_info *clinit; /* initialize constant fields */ if (_svmf_initialize_fields (env, class) != JNI_OK) { goto end; } /* invoke , if it exists */ clinit = _svmf_resolve_method (class, "", "()V"); if (clinit != NULL) { if (_svmm_invoke_specific_static_clinit (env, clinit) != JNI_OK) { goto end; } } } end: _svmf_stopping_java (env); }