/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This source file is part of SableVM. * * * * See the file "LICENSE" for the copyright information and for * * the terms and conditions for copying, distribution and * * modification of this source file. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* ---------------------------------------------------------------------- Java_gnu_classpath_VMStackWalker_getClassContext ---------------------------------------------------------------------- */ /* * Class: gnu_classpath_VMStackWalker * Method: getClassContext * Signature: ()[Ljava/lang/Class; */ JNIEXPORT static jobjectArray JNICALL Java_gnu_classpath_VMStackWalker_getClassContext (JNIEnv *_env, jclass class SVM_UNUSED) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jobjectArray classes = NULL; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_stack_frame *frame = env->stack.current_frame; _svmt_method_info *method = frame->method; jint class_count = 0; _svmt_array_info *array; while (method != &vm->stack_bottom_method && method != &vm->vm_initiated_call_method) { if (_svmf_is_set_flag (method->access_flags, SVM_ACC_INTERNAL)) { goto next_frame1; } if (strcmp (DREF (method->name, value), "getClassContext") == 0) { if ((strcmp (method->class_info->name, "gnu/classpath/VMStackWalker") == 0) || (strcmp (method->class_info->name, "gnu/classpath/StackWalker") == 0)) { goto next_frame1; } } if (strcmp (DREF (method->name, value), "invoke") == 0) { if (strcmp (method->class_info->name, "java/lang/Method") == 0) { goto next_frame1; } } /* we do not check descriptor, should not be necessary */ class_count++; next_frame1: frame = (_svmt_stack_frame *) (void *) (((char *) frame) - frame->previous_offset); method = frame->method; } if (_svmm_create_array (env, vm->class_loading.boot_loader.class_loader_info, "[Ljava/lang/Class;", array) != JNI_OK) { goto end; } if (_svmf_link_array (env, array) != JNI_OK) { goto end; } classes = _svmf_get_jni_frame_native_local_array (env); if (_svmm_new_array_instance (env, array, class_count, *classes) != JNI_OK) { goto end; } class_count = 0; frame = env->stack.current_frame; method = frame->method; while (method != &vm->stack_bottom_method && method != &vm->vm_initiated_call_method) { if (_svmf_is_set_flag (method->access_flags, SVM_ACC_INTERNAL)) { goto next_frame2; } if (strcmp (DREF (method->name, value), "getClassContext") == 0) { if ((strcmp (method->class_info->name, "gnu/classpath/VMStackWalker") == 0) || (strcmp (method->class_info->name, "gnu/classpath/StackWalker") == 0)) { goto next_frame2; } } if (strcmp (DREF (method->name, value), "invoke") == 0) { if (strcmp (method->class_info->name, "java/lang/Method") == 0) { goto next_frame2; } } /* we ignore the cast result, as it will always succeed */ _svmf_set_reference_array_element_no_exception (env, *classes, class_count++, *(method->class_info->class_instance)); next_frame2: frame = (_svmt_stack_frame *) (void *) (((char *) frame) - frame->previous_offset); method = frame->method; } } end: _svmf_stopping_java (env); return classes; } /* ---------------------------------------------------------------------- Java_gnu_classpath_VMStackWalker_getClassFromClassContext ---------------------------------------------------------------------- */ /* * Class: gnu_classpath_VMStackWalker * Method: getClassFromClassContext * Signature: (I)Ljava/lang/Class; */ JNIEXPORT static jclass JNICALL Java_gnu_classpath_VMStackWalker_getClassFromClassContext (JNIEnv *_env, jclass class SVM_UNUSED, jint index) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); jclass result = NULL; _svmf_resuming_java (env); { _svmt_JavaVM *vm = env->vm; _svmt_stack_frame *frame = env->stack.current_frame; _svmt_method_info *method = frame->method; jint class_count = 0; while (method != &vm->stack_bottom_method && method != &vm->vm_initiated_call_method) { if (_svmf_is_set_flag (method->access_flags, SVM_ACC_INTERNAL)) { goto next_frame1; } if (strcmp (DREF (method->name, value), "getClassFromClassContext") == 0) { if ((strcmp (method->class_info->name, "gnu/classpath/VMStackWalker") == 0) || (strcmp (method->class_info->name, "gnu/classpath/StackWalker") == 0)) { goto next_frame1; } } if (strcmp (DREF (method->name, value), "invoke") == 0) { if (strcmp (method->class_info->name, "java/lang/Method") == 0) { goto next_frame1; } } /* we do not check descriptor, should not be necessary */ if (class_count == index) { /* return class */ result = _svmf_get_jni_frame_native_local (env); *result = *(method->class_info->class_instance); break; } class_count++; next_frame1: frame = (_svmt_stack_frame *) (void *) (((char *) frame) - frame->previous_offset); method = frame->method; } } _svmf_stopping_java (env); return result; }