< prev index next >

src/share/vm/prims/methodComparator.cpp

Print this page
rev 10160 : 8149096: Remove unused code in methodComparator
Reviewed-by:
   1 /*
   2  * Copyright (c) 2000, 2015, 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  *


  50   }
  51 
  52   _old_cp = old_method->constants();
  53   _new_cp = new_method->constants();
  54   BytecodeStream s_old(old_method);
  55   BytecodeStream s_new(new_method);
  56   _s_old = &s_old;
  57   _s_new = &s_new;
  58   _switchable_test = false;
  59   Bytecodes::Code c_old, c_new;
  60 
  61   while ((c_old = s_old.next()) >= 0) {
  62     if ((c_new = s_new.next()) < 0 || c_old != c_new)
  63       return false;
  64 
  65     if (! args_same(c_old, c_new))
  66       return false;
  67   }
  68   return true;
  69 }
  70 
  71 
  72 bool MethodComparator::methods_switchable(Method* old_method, Method* new_method,
  73                                           BciMap &bci_map) {
  74   if (old_method->code_size() > new_method->code_size())
  75     // Something has definitely been deleted in the new method, compared to the old one.
  76     return false;
  77 
  78   if (! check_stack_and_locals_size(old_method, new_method))
  79     return false;
  80 
  81   _old_cp = old_method->constants();
  82   _new_cp = new_method->constants();
  83   BytecodeStream s_old(old_method);
  84   BytecodeStream s_new(new_method);
  85   _s_old = &s_old;
  86   _s_new = &s_new;
  87   _bci_map = &bci_map;
  88   _switchable_test = true;
  89   GrowableArray<int> fwd_jmps(16);
  90   _fwd_jmps = &fwd_jmps;
  91   Bytecodes::Code c_old, c_new;
  92 
  93   while ((c_old = s_old.next()) >= 0) {
  94     if ((c_new = s_new.next()) < 0)
  95       return false;
  96     if (! (c_old == c_new && args_same(c_old, c_new))) {
  97       int old_bci = s_old.bci();
  98       int new_st_bci = s_new.bci();
  99       bool found_match = false;
 100       do {
 101         c_new = s_new.next();
 102         if (c_new == c_old && args_same(c_old, c_new)) {
 103           found_match = true;
 104           break;
 105         }
 106       } while (c_new >= 0);
 107       if (! found_match)
 108         return false;
 109       int new_end_bci = s_new.bci();
 110       bci_map.store_fragment_location(old_bci, new_st_bci, new_end_bci);
 111     }
 112   }
 113 
 114   // Now we can test all forward jumps
 115   for (int i = 0; i < fwd_jmps.length() / 2; i++) {
 116     if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
 117       RC_TRACE(0x00800000,
 118         ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
 119         fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
 120         fwd_jmps.at(i*2+1)));
 121       return false;
 122     }
 123   }
 124 
 125   return true;
 126 }
 127 
 128 
 129 bool MethodComparator::args_same(Bytecodes::Code c_old, Bytecodes::Code c_new) {
 130   // BytecodeStream returns the correct standard Java bytecodes for various "fast"
 131   // bytecode versions, so we don't have to bother about them here..
 132   switch (c_old) {
 133   case Bytecodes::_new            : // fall through
 134   case Bytecodes::_anewarray      : // fall through
 135   case Bytecodes::_multianewarray : // fall through
 136   case Bytecodes::_checkcast      : // fall through
 137   case Bytecodes::_instanceof     : {
 138     u2 cpi_old = _s_old->get_index_u2();
 139     u2 cpi_new = _s_new->get_index_u2();
 140     if ((_old_cp->klass_at_noresolve(cpi_old) != _new_cp->klass_at_noresolve(cpi_new)))
 141         return false;
 142     if (c_old == Bytecodes::_multianewarray &&
 143         *(jbyte*)(_s_old->bcp() + 3) != *(jbyte*)(_s_new->bcp() + 3))
 144       return false;
 145     break;
 146   }
 147 


   1 /*
   2  * Copyright (c) 2000, 2016, 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  *


  50   }
  51 
  52   _old_cp = old_method->constants();
  53   _new_cp = new_method->constants();
  54   BytecodeStream s_old(old_method);
  55   BytecodeStream s_new(new_method);
  56   _s_old = &s_old;
  57   _s_new = &s_new;
  58   _switchable_test = false;
  59   Bytecodes::Code c_old, c_new;
  60 
  61   while ((c_old = s_old.next()) >= 0) {
  62     if ((c_new = s_new.next()) < 0 || c_old != c_new)
  63       return false;
  64 
  65     if (! args_same(c_old, c_new))
  66       return false;
  67   }
  68   return true;
  69 }


























































  70 
  71 bool MethodComparator::args_same(Bytecodes::Code c_old, Bytecodes::Code c_new) {
  72   // BytecodeStream returns the correct standard Java bytecodes for various "fast"
  73   // bytecode versions, so we don't have to bother about them here..
  74   switch (c_old) {
  75   case Bytecodes::_new            : // fall through
  76   case Bytecodes::_anewarray      : // fall through
  77   case Bytecodes::_multianewarray : // fall through
  78   case Bytecodes::_checkcast      : // fall through
  79   case Bytecodes::_instanceof     : {
  80     u2 cpi_old = _s_old->get_index_u2();
  81     u2 cpi_new = _s_new->get_index_u2();
  82     if ((_old_cp->klass_at_noresolve(cpi_old) != _new_cp->klass_at_noresolve(cpi_new)))
  83         return false;
  84     if (c_old == Bytecodes::_multianewarray &&
  85         *(jbyte*)(_s_old->bcp() + 3) != *(jbyte*)(_s_new->bcp() + 3))
  86       return false;
  87     break;
  88   }
  89 


< prev index next >