src/share/vm/prims/methodComparator.hpp

Print this page


   1 /*
   2  * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 







  25 class BciMap;
  26 
  27 // methodComparator provides an interface for determining if methods of
  28 // different versions of classes are equivalent or switchable
  29 
  30 class MethodComparator {
  31  private:
  32   static BytecodeStream *_s_old, *_s_new;
  33   static constantPoolOop _old_cp, _new_cp;
  34   static BciMap *_bci_map;
  35   static bool _switchable_test;
  36   static GrowableArray<int> *_fwd_jmps;
  37 
  38   static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new);
  39   static int check_stack_and_locals_size(methodOop old_method, methodOop new_method);
  40 
  41  public:
  42   // Check if the new method is equivalent to the old one modulo constant pool (EMCP).
  43   // Intuitive definition: two versions of the same method are EMCP, if they don't differ
  44   // on the source code level. Practically, we check whether the only difference between


 103   }
 104 
 105   int new_bci_for_old(int old_bci) {
 106     if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci;
 107     _pos = 1;
 108     while (_pos < _cur_pos && old_bci >= _old_bci[_pos])
 109       _pos++;
 110     return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]);
 111   }
 112 
 113   // Test if two indexes - one in the old method and another in the new one - correspond
 114   // to the same bytecode
 115   bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) {
 116     if (new_bci_for_old(old_dest_bci) == new_dest_bci)
 117       return true;
 118     else if (_old_bci[_pos-1] == old_dest_bci)
 119       return (new_dest_bci == _new_st_bci[_pos-1]);
 120     else return false;
 121   }
 122 };


   1 /*
   2  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
  26 #define SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
  27 
  28 #include "interpreter/bytecodeStream.hpp"
  29 #include "oops/constantPoolOop.hpp"
  30 #include "oops/methodOop.hpp"
  31 
  32 class BciMap;
  33 
  34 // methodComparator provides an interface for determining if methods of
  35 // different versions of classes are equivalent or switchable
  36 
  37 class MethodComparator {
  38  private:
  39   static BytecodeStream *_s_old, *_s_new;
  40   static constantPoolOop _old_cp, _new_cp;
  41   static BciMap *_bci_map;
  42   static bool _switchable_test;
  43   static GrowableArray<int> *_fwd_jmps;
  44 
  45   static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new);
  46   static int check_stack_and_locals_size(methodOop old_method, methodOop new_method);
  47 
  48  public:
  49   // Check if the new method is equivalent to the old one modulo constant pool (EMCP).
  50   // Intuitive definition: two versions of the same method are EMCP, if they don't differ
  51   // on the source code level. Practically, we check whether the only difference between


 110   }
 111 
 112   int new_bci_for_old(int old_bci) {
 113     if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci;
 114     _pos = 1;
 115     while (_pos < _cur_pos && old_bci >= _old_bci[_pos])
 116       _pos++;
 117     return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]);
 118   }
 119 
 120   // Test if two indexes - one in the old method and another in the new one - correspond
 121   // to the same bytecode
 122   bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) {
 123     if (new_bci_for_old(old_dest_bci) == new_dest_bci)
 124       return true;
 125     else if (_old_bci[_pos-1] == old_dest_bci)
 126       return (new_dest_bci == _new_st_bci[_pos-1]);
 127     else return false;
 128   }
 129 };
 130 
 131 #endif // SHARE_VM_PRIMS_METHODCOMPARATOR_HPP