321 if (!next() || addr() >= begin) break;
322 }
323 assert(addrCheck == NULL || addrCheck == backup_addr, "must have matched addrCheck");
324 assert(infoCheck == NULL || infoCheck == backup, "must have matched infoCheck");
325 // At this point, either we are at the first matching record,
326 // or else there is no such record, and !has_current().
327 // In either case, revert to the immediatly preceding state.
328 _current = backup;
329 _addr = backup_addr;
330 set_has_current(false);
331 }
332 }
333
334
335 void RelocIterator::set_limit(address limit) {
336 address code_end = (address)code() + code()->size();
337 assert(limit == NULL || limit <= code_end, "in bounds");
338 _limit = limit;
339 }
340
341
342 void PatchingRelocIterator:: prepass() {
343 // turn breakpoints off during patching
344 _init_state = (*this); // save cursor
345 while (next()) {
346 if (type() == relocInfo::breakpoint_type) {
347 breakpoint_reloc()->set_active(false);
348 }
349 }
350 (RelocIterator&)(*this) = _init_state; // reset cursor for client
351 }
352
353
354 void PatchingRelocIterator:: postpass() {
355 // turn breakpoints back on after patching
356 (RelocIterator&)(*this) = _init_state; // reset cursor again
357 while (next()) {
358 if (type() == relocInfo::breakpoint_type) {
359 breakpoint_Relocation* bpt = breakpoint_reloc();
360 bpt->set_active(bpt->enabled());
361 }
362 }
363 }
364
365
366 // All the strange bit-encodings are in here.
367 // The idea is to encode relocation data which are small integers
368 // very efficiently (a single extra halfword). Larger chunks of
369 // relocation data need a halfword header to hold their size.
370 void RelocIterator::advance_over_prefix() {
371 if (_current->is_datalen()) {
372 _data = (short*) _current->data();
373 _datalen = _current->datalen();
374 _current += _datalen + 1; // skip the embedded data & header
375 } else {
376 _databuf = _current->immediate();
377 _data = &_databuf;
378 _datalen = 1;
379 _current++; // skip the header
380 }
381 // The client will see the following relocInfo, whatever that is.
382 // It is the reloc to which the preceding data applies.
383 }
384
385
687 }
688
689
690 void internal_word_Relocation::unpack_data() {
691 jint x0 = unpack_1_int();
692 _target = x0==0? NULL: address_from_scaled_offset(x0, addr());
693 _section = CodeBuffer::SECT_NONE;
694 }
695
696
697 void section_word_Relocation::unpack_data() {
698 jint x = unpack_1_int();
699 jint offset = (x >> section_width);
700 int sindex = (x & ((1<<section_width)-1));
701 address base = binding()->section_start(sindex);
702
703 _section = sindex;
704 _target = address_from_scaled_offset(offset, base);
705 }
706
707
708 void breakpoint_Relocation::pack_data_to(CodeSection* dest) {
709 short* p = (short*) dest->locs_end();
710 address point = dest->locs_point();
711
712 *p++ = _bits;
713
714 assert(_target != NULL, "sanity");
715
716 if (internal()) normalize_address(_target, dest);
717
718 jint target_bits =
719 (jint)( internal() ? scaled_offset (_target, point)
720 : runtime_address_to_index(_target) );
721 if (settable()) {
722 // save space for set_target later
723 p = add_jint(p, target_bits);
724 } else {
725 p = add_var_int(p, target_bits);
726 }
727
728 for (int i = 0; i < instrlen(); i++) {
729 // put placeholder words until bytes can be saved
730 p = add_short(p, (short)0x7777);
731 }
732
733 dest->set_locs_end((relocInfo*) p);
734 }
735
736
737 void breakpoint_Relocation::unpack_data() {
738 _bits = live_bits();
739
740 int targetlen = datalen() - 1 - instrlen();
741 jint target_bits = 0;
742 if (targetlen == 0) target_bits = 0;
743 else if (targetlen == 1) target_bits = *(data()+1);
744 else if (targetlen == 2) target_bits = relocInfo::jint_from_data(data()+1);
745 else { ShouldNotReachHere(); }
746
747 _target = internal() ? address_from_scaled_offset(target_bits, addr())
748 : index_to_runtime_address (target_bits);
749 }
750
751
752 //// miscellaneous methods
753 oop* oop_Relocation::oop_addr() {
754 int n = _oop_index;
755 if (n == 0) {
756 // oop is stored in the code stream
757 return (oop*) pd_address_in_code();
758 } else {
759 // oop is stored in table at nmethod::oops_begin
760 return code()->oop_addr_at(n);
761 }
762 }
763
764
765 oop oop_Relocation::oop_value() {
766 oop v = *oop_addr();
767 // clean inline caches store a special pseudo-null
768 if (v == (oop)Universe::non_oop_word()) v = NULL;
769 return v;
770 }
771
915 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
916 address target = _target;
917 if (target == NULL) {
918 if (addr_in_const()) {
919 target = new_addr_for(*(address*)addr(), src, dest);
920 } else {
921 target = new_addr_for(pd_get_address_from_code(), src, dest);
922 }
923 }
924 set_value(target);
925 }
926
927
928 address internal_word_Relocation::target() {
929 address target = _target;
930 if (target == NULL) {
931 target = pd_get_address_from_code();
932 }
933 return target;
934 }
935
936
937 breakpoint_Relocation::breakpoint_Relocation(int kind, address target, bool internal) {
938 bool active = false;
939 bool enabled = (kind == initialization);
940 bool removable = (kind != safepoint);
941 bool settable = (target == NULL);
942
943 int bits = kind;
944 if (enabled) bits |= enabled_state;
945 if (internal) bits |= internal_attr;
946 if (removable) bits |= removable_attr;
947 if (settable) bits |= settable_attr;
948
949 _bits = bits | high_bit;
950 _target = target;
951
952 assert(this->kind() == kind, "kind encoded");
953 assert(this->enabled() == enabled, "enabled encoded");
954 assert(this->active() == active, "active encoded");
955 assert(this->internal() == internal, "internal encoded");
956 assert(this->removable() == removable, "removable encoded");
957 assert(this->settable() == settable, "settable encoded");
958 }
959
960
961 address breakpoint_Relocation::target() const {
962 return _target;
963 }
964
965
966 void breakpoint_Relocation::set_target(address x) {
967 assert(settable(), "must be settable");
968 jint target_bits =
969 (jint)(internal() ? scaled_offset (x, addr())
970 : runtime_address_to_index(x));
971 short* p = &live_bits() + 1;
972 p = add_jint(p, target_bits);
973 assert(p == instrs(), "new target must fit");
974 _target = x;
975 }
976
977
978 void breakpoint_Relocation::set_enabled(bool b) {
979 if (enabled() == b) return;
980
981 if (b) {
982 set_bits(bits() | enabled_state);
983 } else {
984 set_active(false); // remove the actual breakpoint insn, if any
985 set_bits(bits() & ~enabled_state);
986 }
987 }
988
989
990 void breakpoint_Relocation::set_active(bool b) {
991 assert(!b || enabled(), "cannot activate a disabled breakpoint");
992
993 if (active() == b) return;
994
995 // %%% should probably seize a lock here (might not be the right lock)
996 //MutexLockerEx ml_patch(Patching_lock, true);
997 //if (active() == b) return; // recheck state after locking
998
999 if (b) {
1000 set_bits(bits() | active_state);
1001 if (instrlen() == 0)
1002 fatal("breakpoints in original code must be undoable");
1003 pd_swap_in_breakpoint (addr(), instrs(), instrlen());
1004 } else {
1005 set_bits(bits() & ~active_state);
1006 pd_swap_out_breakpoint(addr(), instrs(), instrlen());
1007 }
1008 }
1009
1010
1011 //---------------------------------------------------------------------------------
1012 // Non-product code
1013
1014 #ifndef PRODUCT
1015
1016 static const char* reloc_type_string(relocInfo::relocType t) {
1017 switch (t) {
1018 #define EACH_CASE(name) \
1019 case relocInfo::name##_type: \
1020 return #name;
1021
1022 APPLY_TO_RELOCATIONS(EACH_CASE);
1023 #undef EACH_CASE
1024
1025 case relocInfo::none:
1026 return "none";
1027 case relocInfo::data_prefix_tag:
1028 return "prefix";
1029 default:
|
321 if (!next() || addr() >= begin) break;
322 }
323 assert(addrCheck == NULL || addrCheck == backup_addr, "must have matched addrCheck");
324 assert(infoCheck == NULL || infoCheck == backup, "must have matched infoCheck");
325 // At this point, either we are at the first matching record,
326 // or else there is no such record, and !has_current().
327 // In either case, revert to the immediatly preceding state.
328 _current = backup;
329 _addr = backup_addr;
330 set_has_current(false);
331 }
332 }
333
334
335 void RelocIterator::set_limit(address limit) {
336 address code_end = (address)code() + code()->size();
337 assert(limit == NULL || limit <= code_end, "in bounds");
338 _limit = limit;
339 }
340
341 // All the strange bit-encodings are in here.
342 // The idea is to encode relocation data which are small integers
343 // very efficiently (a single extra halfword). Larger chunks of
344 // relocation data need a halfword header to hold their size.
345 void RelocIterator::advance_over_prefix() {
346 if (_current->is_datalen()) {
347 _data = (short*) _current->data();
348 _datalen = _current->datalen();
349 _current += _datalen + 1; // skip the embedded data & header
350 } else {
351 _databuf = _current->immediate();
352 _data = &_databuf;
353 _datalen = 1;
354 _current++; // skip the header
355 }
356 // The client will see the following relocInfo, whatever that is.
357 // It is the reloc to which the preceding data applies.
358 }
359
360
662 }
663
664
665 void internal_word_Relocation::unpack_data() {
666 jint x0 = unpack_1_int();
667 _target = x0==0? NULL: address_from_scaled_offset(x0, addr());
668 _section = CodeBuffer::SECT_NONE;
669 }
670
671
672 void section_word_Relocation::unpack_data() {
673 jint x = unpack_1_int();
674 jint offset = (x >> section_width);
675 int sindex = (x & ((1<<section_width)-1));
676 address base = binding()->section_start(sindex);
677
678 _section = sindex;
679 _target = address_from_scaled_offset(offset, base);
680 }
681
682 //// miscellaneous methods
683 oop* oop_Relocation::oop_addr() {
684 int n = _oop_index;
685 if (n == 0) {
686 // oop is stored in the code stream
687 return (oop*) pd_address_in_code();
688 } else {
689 // oop is stored in table at nmethod::oops_begin
690 return code()->oop_addr_at(n);
691 }
692 }
693
694
695 oop oop_Relocation::oop_value() {
696 oop v = *oop_addr();
697 // clean inline caches store a special pseudo-null
698 if (v == (oop)Universe::non_oop_word()) v = NULL;
699 return v;
700 }
701
845 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
846 address target = _target;
847 if (target == NULL) {
848 if (addr_in_const()) {
849 target = new_addr_for(*(address*)addr(), src, dest);
850 } else {
851 target = new_addr_for(pd_get_address_from_code(), src, dest);
852 }
853 }
854 set_value(target);
855 }
856
857
858 address internal_word_Relocation::target() {
859 address target = _target;
860 if (target == NULL) {
861 target = pd_get_address_from_code();
862 }
863 return target;
864 }
865
866 //---------------------------------------------------------------------------------
867 // Non-product code
868
869 #ifndef PRODUCT
870
871 static const char* reloc_type_string(relocInfo::relocType t) {
872 switch (t) {
873 #define EACH_CASE(name) \
874 case relocInfo::name##_type: \
875 return #name;
876
877 APPLY_TO_RELOCATIONS(EACH_CASE);
878 #undef EACH_CASE
879
880 case relocInfo::none:
881 return "none";
882 case relocInfo::data_prefix_tag:
883 return "prefix";
884 default:
|