1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/prims/methodComparator.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,122 @@ 1.4 +/* 1.5 + * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +class BciMap; 1.29 + 1.30 +// methodComparator provides an interface for determining if methods of 1.31 +// different versions of classes are equivalent or switchable 1.32 + 1.33 +class MethodComparator { 1.34 + private: 1.35 + static BytecodeStream *_s_old, *_s_new; 1.36 + static constantPoolOop _old_cp, _new_cp; 1.37 + static BciMap *_bci_map; 1.38 + static bool _switchable_test; 1.39 + static GrowableArray<int> *_fwd_jmps; 1.40 + 1.41 + static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new); 1.42 + static int check_stack_and_locals_size(methodOop old_method, methodOop new_method); 1.43 + 1.44 + public: 1.45 + // Check if the new method is equivalent to the old one modulo constant pool (EMCP). 1.46 + // Intuitive definition: two versions of the same method are EMCP, if they don't differ 1.47 + // on the source code level. Practically, we check whether the only difference between 1.48 + // method versions is some constantpool indices embedded into the bytecodes, and whether 1.49 + // these indices eventually point to the same constants for both method versions. 1.50 + static bool methods_EMCP(methodOop old_method, methodOop new_method); 1.51 + 1.52 + static bool methods_switchable(methodOop old_method, methodOop new_method, BciMap &bci_map); 1.53 +}; 1.54 + 1.55 + 1.56 +// ByteCode Index Map. For two versions of the same method, where the new version may contain 1.57 +// fragments not found in the old version, provides a mapping from an index of a bytecode in 1.58 +// the old method to the index of the same bytecode in the new method. 1.59 + 1.60 +class BciMap { 1.61 + private: 1.62 + int *_old_bci, *_new_st_bci, *_new_end_bci; 1.63 + int _cur_size, _cur_pos; 1.64 + int _pos; 1.65 + 1.66 + public: 1.67 + BciMap() { 1.68 + _cur_size = 50; 1.69 + _old_bci = (int*) malloc(sizeof(int) * _cur_size); 1.70 + _new_st_bci = (int*) malloc(sizeof(int) * _cur_size); 1.71 + _new_end_bci = (int*) malloc(sizeof(int) * _cur_size); 1.72 + _cur_pos = 0; 1.73 + } 1.74 + 1.75 + ~BciMap() { 1.76 + free(_old_bci); 1.77 + free(_new_st_bci); 1.78 + free(_new_end_bci); 1.79 + } 1.80 + 1.81 + // Store the position of an added fragment, e.g. 1.82 + // 1.83 + // |<- old_bci 1.84 + // ----------------------------------------- 1.85 + // Old method |invokevirtual 5|aload 1|... 1.86 + // ----------------------------------------- 1.87 + // 1.88 + // |<- new_st_bci |<- new_end_bci 1.89 + // -------------------------------------------------------------------- 1.90 + // New method |invokevirual 5|aload 2|invokevirtual 6|aload 1|... 1.91 + // -------------------------------------------------------------------- 1.92 + // ^^^^^^^^^^^^^^^^^^^^^^^^ 1.93 + // Added fragment 1.94 + 1.95 + void store_fragment_location(int old_bci, int new_st_bci, int new_end_bci) { 1.96 + if (_cur_pos == _cur_size) { 1.97 + _cur_size += 10; 1.98 + _old_bci = (int*) realloc(_old_bci, sizeof(int) * _cur_size); 1.99 + _new_st_bci = (int*) realloc(_new_st_bci, sizeof(int) * _cur_size); 1.100 + _new_end_bci = (int*) realloc(_new_end_bci, sizeof(int) * _cur_size); 1.101 + } 1.102 + _old_bci[_cur_pos] = old_bci; 1.103 + _new_st_bci[_cur_pos] = new_st_bci; 1.104 + _new_end_bci[_cur_pos] = new_end_bci; 1.105 + _cur_pos++; 1.106 + } 1.107 + 1.108 + int new_bci_for_old(int old_bci) { 1.109 + if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci; 1.110 + _pos = 1; 1.111 + while (_pos < _cur_pos && old_bci >= _old_bci[_pos]) 1.112 + _pos++; 1.113 + return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]); 1.114 + } 1.115 + 1.116 + // Test if two indexes - one in the old method and another in the new one - correspond 1.117 + // to the same bytecode 1.118 + bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) { 1.119 + if (new_bci_for_old(old_dest_bci) == new_dest_bci) 1.120 + return true; 1.121 + else if (_old_bci[_pos-1] == old_dest_bci) 1.122 + return (new_dest_bci == _new_st_bci[_pos-1]); 1.123 + else return false; 1.124 + } 1.125 +};