comparison paraspace/dex_deptracker.py @ 139:0704e23009e4

Fix bug of not dealing encoded method indices. - Becase space optimization, DEX ecnode value for method indices in _DEX_Method. - _deoptimize_classdata() was called at beginning of build_dependencies(). - _optimize_classdata() was called at end of restore_dependencies().
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 10 Aug 2011 20:05:14 +0800
parents 987fead83ce3
children d4e794249b0f
comparison
equal deleted inserted replaced
138:372009418896 139:0704e23009e4
803 raise TypeError, 'invalid depend type %s' % (repr(dep_type)) 803 raise TypeError, 'invalid depend type %s' % (repr(dep_type))
804 pass 804 pass
805 pass 805 pass
806 806
807 807
808 ## \brief Deoptimize methods of classdatas.
809 #
810 # This function must be called at beginning of build_dependencies().
811 # For space optimization reason, values of method index in _DEX_Method
812 # are related previous item, except first one. For convenient,
813 # this function replcae them with absolute ones. It should be reversed
814 # to relative one when running restore_dependencies().
815 #
816 def _deoptimize_classdata(dexroot):
817 for classdata in dexroot.classDatas.items:
818 methods = classdata.directMethods.items
819 if len(methods) > 1:
820 firstmethod = methods[0]
821 lastidx = firstmethod.methodIdx
822 for method in methods[1:]:
823 lastidx = lastidx + method.methodIdx
824 method.methodIdx = lastidx
825 pass
826 pass
827
828 methods = classdata.virtualMethods.items
829 if len(methods) > 1:
830 firstmethod = methods[0]
831 lastidx = firstmethod.methodIdx
832 for method in methods[1:]:
833 lastidx = lastidx + method.methodIdx
834 method.methodIdx = lastidx
835 pass
836 pass
837 pass
838 pass
839
840
841 ## \biref Optimize methods of classdatas.
842 #
843 # \see _deoptimize_classdata
844 #
845 def _optimize_classdata(dexroot):
846 for classdata in dexroot.classDatas.items:
847 methods = classdata.directMethods.items
848 if len(methods) > 1:
849 firstmethod = methods[0]
850 lastidx = firstmethod.methodIdx
851 for method in methods[1:]:
852 save_idx = method.methodIdx
853 method.methodIdx = method.methodIdx - lastidx
854 lastidx = save_idx
855 pass
856 pass
857
858 methods = classdata.virtualMethods.items
859 if len(methods) > 1:
860 firstmethod = methods[0]
861 lastidx = firstmethod.methodIdx
862 for method in methods[1:]:
863 save_idx = method.methodIdx
864 method.methodIdx = method.methodIdx - lastidx
865 lastidx = save_idx
866 pass
867 pass
868 pass
869 pass
870
871
808 def build_dependencies(dexroot, all_dep_decls): 872 def build_dependencies(dexroot, all_dep_decls):
873 _deoptimize_classdata(dexroot)
809 _build_associations(dexroot) 874 _build_associations(dexroot)
810 _build_refs(dexroot) 875 _build_refs(dexroot)
811 _link_dependencies(dexroot, all_dep_decls) 876 _link_dependencies(dexroot, all_dep_decls)
812 pass 877 pass
813 878
1068 else: 1133 else:
1069 raise TypeError, 'invalid depend type %s' % (repr(dep_type)) 1134 raise TypeError, 'invalid depend type %s' % (repr(dep_type))
1070 pass 1135 pass
1071 1136
1072 _sync_DEXFile_fields(dexroot) 1137 _sync_DEXFile_fields(dexroot)
1138 _optimize_classdata(dexroot)
1073 pass 1139 pass
1074 1140
1075 1141
1076 ## \brief Prepare and return dependency declares. 1142 ## \brief Prepare and return dependency declares.
1077 def prepare_dep_decls(): 1143 def prepare_dep_decls():