434 if (k_mirror == nullptr) {
435 return JVMTI_ERROR_INVALID_CLASS;
436 }
437 if (!k_mirror->is_a(vmClasses::Class_klass())) {
438 return JVMTI_ERROR_INVALID_CLASS;
439 }
440
441 if (!VM_RedefineClasses::is_modifiable_class(k_mirror)) {
442 return JVMTI_ERROR_UNMODIFIABLE_CLASS;
443 }
444
445 Klass* klass = java_lang_Class::as_Klass(k_mirror);
446
447 jint status = klass->jvmti_class_status();
448 if (status & (JVMTI_CLASS_STATUS_ERROR)) {
449 return JVMTI_ERROR_INVALID_CLASS;
450 }
451
452 InstanceKlass* ik = InstanceKlass::cast(klass);
453 if (ik->get_cached_class_file_bytes() == nullptr) {
454 // Not cached, we need to reconstitute the class file from the
455 // VM representation. We don't attach the reconstituted class
456 // bytes to the InstanceKlass here because they have not been
457 // validated and we're not at a safepoint.
458 JvmtiClassFileReconstituter reconstituter(ik);
459 if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
460 return reconstituter.get_error();
461 }
462
463 class_definitions[index].class_byte_count = (jint)reconstituter.class_file_size();
464 class_definitions[index].class_bytes = (unsigned char*)
465 reconstituter.class_file_bytes();
466 } else {
467 // it is cached, get it from the cache
468 class_definitions[index].class_byte_count = ik->get_cached_class_file_len();
469 class_definitions[index].class_bytes = ik->get_cached_class_file_bytes();
470 }
471 class_definitions[index].klass = jcls;
472 }
473 EventRetransformClasses event;
3411 jvmti_table[i].generic_signature = gen_sig_buf;
3412 jvmti_table[i].slot = slot;
3413 }
3414 }
3415
3416 // set results
3417 (*entry_count_ptr) = num_entries;
3418 (*table_ptr) = jvmti_table;
3419
3420 return JVMTI_ERROR_NONE;
3421 } /* end GetLocalVariableTable */
3422
3423
3424 // method - pre-checked for validity, but may be null meaning obsolete method
3425 // bytecode_count_ptr - pre-checked for null
3426 // bytecodes_ptr - pre-checked for null
3427 jvmtiError
3428 JvmtiEnv::GetBytecodes(Method* method, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr) {
3429 NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID);
3430
3431 methodHandle mh(Thread::current(), method);
3432 jint size = (jint)mh->code_size();
3433 jvmtiError err = allocate(size, bytecodes_ptr);
3434 if (err != JVMTI_ERROR_NONE) {
3435 return err;
3436 }
3437
3438 (*bytecode_count_ptr) = size;
3439 // get byte codes
3440 JvmtiClassFileReconstituter::copy_bytecodes(mh, *bytecodes_ptr);
3441
3442 return JVMTI_ERROR_NONE;
3443 } /* end GetBytecodes */
3444
3445
3446 // method - pre-checked for validity, but may be null meaning obsolete method
3447 // is_native_ptr - pre-checked for null
3448 jvmtiError
3449 JvmtiEnv::IsMethodNative(Method* method, jboolean* is_native_ptr) {
3450 NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID);
3451 (*is_native_ptr) = method->is_native();
3452 return JVMTI_ERROR_NONE;
3453 } /* end IsMethodNative */
3454
3455
3456 // method - pre-checked for validity, but may be null meaning obsolete method
3457 // is_synthetic_ptr - pre-checked for null
3458 jvmtiError
3459 JvmtiEnv::IsMethodSynthetic(Method* method, jboolean* is_synthetic_ptr) {
|
434 if (k_mirror == nullptr) {
435 return JVMTI_ERROR_INVALID_CLASS;
436 }
437 if (!k_mirror->is_a(vmClasses::Class_klass())) {
438 return JVMTI_ERROR_INVALID_CLASS;
439 }
440
441 if (!VM_RedefineClasses::is_modifiable_class(k_mirror)) {
442 return JVMTI_ERROR_UNMODIFIABLE_CLASS;
443 }
444
445 Klass* klass = java_lang_Class::as_Klass(k_mirror);
446
447 jint status = klass->jvmti_class_status();
448 if (status & (JVMTI_CLASS_STATUS_ERROR)) {
449 return JVMTI_ERROR_INVALID_CLASS;
450 }
451
452 InstanceKlass* ik = InstanceKlass::cast(klass);
453 if (ik->get_cached_class_file_bytes() == nullptr) {
454 // Link the class to avoid races with the rewriter. This will call the verifier also
455 // on the class. Linking is also done in VM_RedefineClasses below, but we need
456 // to keep that for other VM_RedefineClasses callers.
457 JavaThread* THREAD = current_thread;
458 ik->link_class(THREAD);
459 if (HAS_PENDING_EXCEPTION) {
460 // Retransform/JVMTI swallows error messages. Using this class will rerun the verifier in a context
461 // that propagates the VerifyError, if thrown.
462 CLEAR_PENDING_EXCEPTION;
463 return JVMTI_ERROR_INVALID_CLASS;
464 }
465
466 // Not cached, we need to reconstitute the class file from the
467 // VM representation. We don't attach the reconstituted class
468 // bytes to the InstanceKlass here because they have not been
469 // validated and we're not at a safepoint.
470 JvmtiClassFileReconstituter reconstituter(ik);
471 if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
472 return reconstituter.get_error();
473 }
474
475 class_definitions[index].class_byte_count = (jint)reconstituter.class_file_size();
476 class_definitions[index].class_bytes = (unsigned char*)
477 reconstituter.class_file_bytes();
478 } else {
479 // it is cached, get it from the cache
480 class_definitions[index].class_byte_count = ik->get_cached_class_file_len();
481 class_definitions[index].class_bytes = ik->get_cached_class_file_bytes();
482 }
483 class_definitions[index].klass = jcls;
484 }
485 EventRetransformClasses event;
3423 jvmti_table[i].generic_signature = gen_sig_buf;
3424 jvmti_table[i].slot = slot;
3425 }
3426 }
3427
3428 // set results
3429 (*entry_count_ptr) = num_entries;
3430 (*table_ptr) = jvmti_table;
3431
3432 return JVMTI_ERROR_NONE;
3433 } /* end GetLocalVariableTable */
3434
3435
3436 // method - pre-checked for validity, but may be null meaning obsolete method
3437 // bytecode_count_ptr - pre-checked for null
3438 // bytecodes_ptr - pre-checked for null
3439 jvmtiError
3440 JvmtiEnv::GetBytecodes(Method* method, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr) {
3441 NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID);
3442
3443 JavaThread* current_thread = JavaThread::current();
3444 methodHandle mh(current_thread, method);
3445 jint size = (jint)mh->code_size();
3446 jvmtiError err = allocate(size, bytecodes_ptr);
3447 if (err != JVMTI_ERROR_NONE) {
3448 return err;
3449 }
3450
3451 (*bytecode_count_ptr) = size;
3452 // get byte codes
3453 // Make sure the class is verified and rewritten first.
3454 JavaThread* THREAD = current_thread;
3455 mh->method_holder()->link_class(THREAD);
3456 if (HAS_PENDING_EXCEPTION) {
3457 CLEAR_PENDING_EXCEPTION;
3458 return JVMTI_ERROR_INVALID_CLASS;
3459 }
3460 JvmtiClassFileReconstituter::copy_bytecodes(mh, *bytecodes_ptr);
3461
3462 return JVMTI_ERROR_NONE;
3463 } /* end GetBytecodes */
3464
3465
3466 // method - pre-checked for validity, but may be null meaning obsolete method
3467 // is_native_ptr - pre-checked for null
3468 jvmtiError
3469 JvmtiEnv::IsMethodNative(Method* method, jboolean* is_native_ptr) {
3470 NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID);
3471 (*is_native_ptr) = method->is_native();
3472 return JVMTI_ERROR_NONE;
3473 } /* end IsMethodNative */
3474
3475
3476 // method - pre-checked for validity, but may be null meaning obsolete method
3477 // is_synthetic_ptr - pre-checked for null
3478 jvmtiError
3479 JvmtiEnv::IsMethodSynthetic(Method* method, jboolean* is_synthetic_ptr) {
|