< prev index next >

src/hotspot/share/prims/jvmtiEnv.cpp

Print this page

2427     return JVMTI_ERROR_NONE;
2428   }
2429 
2430 
2431   InstanceKlass* ik = InstanceKlass::cast(k);
2432 
2433   int result_count = 0;
2434   // First, count the fields.
2435   FilteredFieldStream flds(ik, true, true);
2436   result_count = flds.field_count();
2437 
2438   // Allocate the result and fill it in
2439   jfieldID* result_list = (jfieldID*) jvmtiMalloc(result_count * sizeof(jfieldID));
2440   // The JVMTI spec requires fields in the order they occur in the class file,
2441   // this is the reverse order of what FieldStream hands out.
2442   int id_index = (result_count - 1);
2443 
2444   for (FilteredFieldStream src_st(ik, true, true); !src_st.eos(); src_st.next()) {
2445     result_list[id_index--] = jfieldIDWorkaround::to_jfieldID(
2446                                             ik, src_st.offset(),
2447                                             src_st.access_flags().is_static());

2448   }
2449   assert(id_index == -1, "just checking");
2450   // Fill in the results
2451   *field_count_ptr = result_count;
2452   *fields_ptr = result_list;
2453 
2454   return JVMTI_ERROR_NONE;
2455 } /* end GetClassFields */
2456 
2457 
2458 // k_mirror - may be primitive, this must be checked
2459 // interface_count_ptr - pre-checked for NULL
2460 // interfaces_ptr - pre-checked for NULL
2461 jvmtiError
2462 JvmtiEnv::GetImplementedInterfaces(oop k_mirror, jint* interface_count_ptr, jclass** interfaces_ptr) {
2463   {
2464     if (java_lang_Class::is_primitive(k_mirror)) {
2465       *interface_count_ptr = 0;
2466       *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass));
2467       return JVMTI_ERROR_NONE;
2468     }
2469     JavaThread* current_thread = JavaThread::current();
2470     HandleMark hm(current_thread);
2471     Klass* k = java_lang_Class::as_Klass(k_mirror);
2472     NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
2473 
2474     // Return CLASS_NOT_PREPARED error as per JVMTI spec.
2475     if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) ))
2476       return JVMTI_ERROR_CLASS_NOT_PREPARED;
2477 
2478     if (!k->is_instance_klass()) {
2479       *interface_count_ptr = 0;
2480       *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass));
2481       return JVMTI_ERROR_NONE;
2482     }
2483 
2484     Array<InstanceKlass*>* interface_list = InstanceKlass::cast(k)->local_interfaces();
2485     const int result_length = (interface_list == NULL ? 0 : interface_list->length());

2486     jclass* result_list = (jclass*) jvmtiMalloc(result_length * sizeof(jclass));
2487     for (int i_index = 0; i_index < result_length; i_index += 1) {
2488       InstanceKlass* klass_at = interface_list->at(i_index);
2489       assert(klass_at->is_klass(), "interfaces must be Klass*s");
2490       assert(klass_at->is_interface(), "interfaces must be interfaces");
2491       oop mirror_at = klass_at->java_mirror();
2492       Handle handle_at = Handle(current_thread, mirror_at);
2493       result_list[i_index] = (jclass) jni_reference(handle_at);
2494     }
2495     *interface_count_ptr = result_length;
2496     *interfaces_ptr = result_list;
2497   }
2498 
2499   return JVMTI_ERROR_NONE;
2500 } /* end GetImplementedInterfaces */
2501 
2502 
2503 // k_mirror - may be primitive, this must be checked
2504 // minor_version_ptr - pre-checked for NULL
2505 // major_version_ptr - pre-checked for NULL

2427     return JVMTI_ERROR_NONE;
2428   }
2429 
2430 
2431   InstanceKlass* ik = InstanceKlass::cast(k);
2432 
2433   int result_count = 0;
2434   // First, count the fields.
2435   FilteredFieldStream flds(ik, true, true);
2436   result_count = flds.field_count();
2437 
2438   // Allocate the result and fill it in
2439   jfieldID* result_list = (jfieldID*) jvmtiMalloc(result_count * sizeof(jfieldID));
2440   // The JVMTI spec requires fields in the order they occur in the class file,
2441   // this is the reverse order of what FieldStream hands out.
2442   int id_index = (result_count - 1);
2443 
2444   for (FilteredFieldStream src_st(ik, true, true); !src_st.eos(); src_st.next()) {
2445     result_list[id_index--] = jfieldIDWorkaround::to_jfieldID(
2446                                             ik, src_st.offset(),
2447                                             src_st.access_flags().is_static(),
2448                                             src_st.field_descriptor().is_inlined());
2449   }
2450   assert(id_index == -1, "just checking");
2451   // Fill in the results
2452   *field_count_ptr = result_count;
2453   *fields_ptr = result_list;
2454 
2455   return JVMTI_ERROR_NONE;
2456 } /* end GetClassFields */
2457 
2458 
2459 // k_mirror - may be primitive, this must be checked
2460 // interface_count_ptr - pre-checked for NULL
2461 // interfaces_ptr - pre-checked for NULL
2462 jvmtiError
2463 JvmtiEnv::GetImplementedInterfaces(oop k_mirror, jint* interface_count_ptr, jclass** interfaces_ptr) {
2464   {
2465     if (java_lang_Class::is_primitive(k_mirror)) {
2466       *interface_count_ptr = 0;
2467       *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass));
2468       return JVMTI_ERROR_NONE;
2469     }
2470     JavaThread* current_thread = JavaThread::current();
2471     HandleMark hm(current_thread);
2472     Klass* k = java_lang_Class::as_Klass(k_mirror);
2473     NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
2474 
2475     // Return CLASS_NOT_PREPARED error as per JVMTI spec.
2476     if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) ))
2477       return JVMTI_ERROR_CLASS_NOT_PREPARED;
2478 
2479     if (!k->is_instance_klass()) {
2480       *interface_count_ptr = 0;
2481       *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass));
2482       return JVMTI_ERROR_NONE;
2483     }
2484 
2485     InstanceKlass* ik = InstanceKlass::cast(k);
2486     Array<InstanceKlass*>* interface_list = ik->local_interfaces();
2487     int result_length = (interface_list == NULL ? 0 : interface_list->length());
2488     jclass* result_list = (jclass*) jvmtiMalloc(result_length * sizeof(jclass));
2489     for (int i_index = 0; i_index < result_length; i_index += 1) {
2490       InstanceKlass* klass_at = interface_list->at(i_index);
2491       assert(klass_at->is_klass(), "interfaces must be Klass*s");
2492       assert(klass_at->is_interface(), "interfaces must be interfaces");
2493       oop mirror_at = klass_at->java_mirror();
2494       Handle handle_at = Handle(current_thread, mirror_at);
2495       result_list[i_index] = (jclass) jni_reference(handle_at);
2496     }
2497     *interface_count_ptr = result_length;
2498     *interfaces_ptr = result_list;
2499   }
2500 
2501   return JVMTI_ERROR_NONE;
2502 } /* end GetImplementedInterfaces */
2503 
2504 
2505 // k_mirror - may be primitive, this must be checked
2506 // minor_version_ptr - pre-checked for NULL
2507 // major_version_ptr - pre-checked for NULL
< prev index next >