78 _method_handle_invokers.at_grow(length, 0); |
78 _method_handle_invokers.at_grow(length, 0); |
79 } |
79 } |
80 } |
80 } |
81 |
81 |
82 // Unrewrite the bytecodes if an error occurs. |
82 // Unrewrite the bytecodes if an error occurs. |
83 void Rewriter::restore_bytecodes() { |
83 void Rewriter::restore_bytecodes(Thread* thread) { |
84 int len = _methods->length(); |
84 int len = _methods->length(); |
85 bool invokespecial_error = false; |
85 bool invokespecial_error = false; |
86 |
86 |
87 for (int i = len-1; i >= 0; i--) { |
87 for (int i = len-1; i >= 0; i--) { |
88 Method* method = _methods->at(i); |
88 Method* method = _methods->at(i); |
89 scan_method(method, true, &invokespecial_error); |
89 scan_method(thread, method, true, &invokespecial_error); |
90 assert(!invokespecial_error, "reversing should not get an invokespecial error"); |
90 assert(!invokespecial_error, "reversing should not get an invokespecial error"); |
91 } |
91 } |
92 } |
92 } |
93 |
93 |
94 // Creates a constant pool cache given a CPC map |
94 // Creates a constant pool cache given a CPC map |
437 // |
437 // |
438 // The check is performed after verification and only if verification has |
438 // The check is performed after verification and only if verification has |
439 // succeeded. Therefore, the class is guaranteed to be well-formed. |
439 // succeeded. Therefore, the class is guaranteed to be well-formed. |
440 InstanceKlass* klass = method->method_holder(); |
440 InstanceKlass* klass = method->method_holder(); |
441 u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1); |
441 u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1); |
442 constantPoolHandle cp(method->constants()); |
442 constantPoolHandle cp(thread, method->constants()); |
443 Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index)); |
443 Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index)); |
444 |
444 |
445 if (klass->name() == ref_class_name) { |
445 if (klass->name() == ref_class_name) { |
446 Symbol* field_name = cp->name_ref_at(bc_index); |
446 Symbol* field_name = cp->name_ref_at(bc_index); |
447 Symbol* field_sig = cp->signature_ref_at(bc_index); |
447 Symbol* field_sig = cp->signature_ref_at(bc_index); |
546 int len = _methods->length(); |
546 int len = _methods->length(); |
547 bool invokespecial_error = false; |
547 bool invokespecial_error = false; |
548 |
548 |
549 for (int i = len-1; i >= 0; i--) { |
549 for (int i = len-1; i >= 0; i--) { |
550 Method* method = _methods->at(i); |
550 Method* method = _methods->at(i); |
551 scan_method(method, false, &invokespecial_error); |
551 scan_method(THREAD, method, false, &invokespecial_error); |
552 if (invokespecial_error) { |
552 if (invokespecial_error) { |
553 // If you get an error here, there is no reversing bytecodes |
553 // If you get an error here, there is no reversing bytecodes |
554 // This exception is stored for this class and no further attempt is |
554 // This exception is stored for this class and no further attempt is |
555 // made at verifying or rewriting. |
555 // made at verifying or rewriting. |
556 THROW_MSG(vmSymbols::java_lang_InternalError(), |
556 THROW_MSG(vmSymbols::java_lang_InternalError(), |
568 void Rewriter::rewrite(InstanceKlass* klass, TRAPS) { |
568 void Rewriter::rewrite(InstanceKlass* klass, TRAPS) { |
569 if (!DumpSharedSpaces) { |
569 if (!DumpSharedSpaces) { |
570 assert(!klass->is_shared(), "archive methods must not be rewritten at run time"); |
570 assert(!klass->is_shared(), "archive methods must not be rewritten at run time"); |
571 } |
571 } |
572 ResourceMark rm(THREAD); |
572 ResourceMark rm(THREAD); |
573 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK); |
573 constantPoolHandle cpool(THREAD, klass->constants()); |
|
574 Rewriter rw(klass, cpool, klass->methods(), CHECK); |
574 // (That's all, folks.) |
575 // (That's all, folks.) |
575 } |
576 } |
576 |
577 |
577 Rewriter::Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS) |
578 Rewriter::Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS) |
578 : _klass(klass), |
579 : _klass(klass), |
590 // Rewrite bytecodes - exception here exits. |
591 // Rewrite bytecodes - exception here exits. |
591 rewrite_bytecodes(CHECK); |
592 rewrite_bytecodes(CHECK); |
592 |
593 |
593 // Stress restoring bytecodes |
594 // Stress restoring bytecodes |
594 if (StressRewriter) { |
595 if (StressRewriter) { |
595 restore_bytecodes(); |
596 restore_bytecodes(THREAD); |
596 rewrite_bytecodes(CHECK); |
597 rewrite_bytecodes(CHECK); |
597 } |
598 } |
598 |
599 |
599 // allocate constant pool cache, now that we've seen all the bytecodes |
600 // allocate constant pool cache, now that we've seen all the bytecodes |
600 make_constant_pool_cache(THREAD); |
601 make_constant_pool_cache(THREAD); |
601 |
602 |
602 // Restore bytecodes to their unrewritten state if there are exceptions |
603 // Restore bytecodes to their unrewritten state if there are exceptions |
603 // rewriting bytecodes or allocating the cpCache |
604 // rewriting bytecodes or allocating the cpCache |
604 if (HAS_PENDING_EXCEPTION) { |
605 if (HAS_PENDING_EXCEPTION) { |
605 restore_bytecodes(); |
606 restore_bytecodes(THREAD); |
606 return; |
607 return; |
607 } |
608 } |
608 |
609 |
609 // Relocate after everything, but still do this under the is_rewritten flag, |
610 // Relocate after everything, but still do this under the is_rewritten flag, |
610 // so methods with jsrs in custom class lists in aren't attempted to be |
611 // so methods with jsrs in custom class lists in aren't attempted to be |
618 m = rewrite_jsrs(m, THREAD); |
619 m = rewrite_jsrs(m, THREAD); |
619 // Restore bytecodes to their unrewritten state if there are exceptions |
620 // Restore bytecodes to their unrewritten state if there are exceptions |
620 // relocating bytecodes. If some are relocated, that is ok because that |
621 // relocating bytecodes. If some are relocated, that is ok because that |
621 // doesn't affect constant pool to cpCache rewriting. |
622 // doesn't affect constant pool to cpCache rewriting. |
622 if (HAS_PENDING_EXCEPTION) { |
623 if (HAS_PENDING_EXCEPTION) { |
623 restore_bytecodes(); |
624 restore_bytecodes(THREAD); |
624 return; |
625 return; |
625 } |
626 } |
626 // Method might have gotten rewritten. |
627 // Method might have gotten rewritten. |
627 methods->at_put(i, m()); |
628 methods->at_put(i, m()); |
628 } |
629 } |