8149096: Remove unused code in methodComparator
authorstuefe
Thu, 11 Feb 2016 02:39:35 -0800
changeset 36092 b1bf903783b8
parent 36091 fd10d4ee314a
child 36094 bd3e4031b89c
8149096: Remove unused code in methodComparator Summary: Remove unused code in methodComparator Reviewed-by: coleenp, sspitsyn, dholmes
hotspot/src/share/vm/prims/methodComparator.cpp
hotspot/src/share/vm/prims/methodComparator.hpp
--- a/hotspot/src/share/vm/prims/methodComparator.cpp	Thu Feb 11 08:57:00 2016 +0100
+++ b/hotspot/src/share/vm/prims/methodComparator.cpp	Thu Feb 11 02:39:35 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,9 +34,6 @@
 BytecodeStream *MethodComparator::_s_new;
 ConstantPool* MethodComparator::_old_cp;
 ConstantPool* MethodComparator::_new_cp;
-BciMap *MethodComparator::_bci_map;
-bool MethodComparator::_switchable_test;
-GrowableArray<int> *MethodComparator::_fwd_jmps;
 
 bool MethodComparator::methods_EMCP(Method* old_method, Method* new_method) {
   if (old_method->code_size() != new_method->code_size())
@@ -55,7 +52,6 @@
   BytecodeStream s_new(new_method);
   _s_old = &s_old;
   _s_new = &s_new;
-  _switchable_test = false;
   Bytecodes::Code c_old, c_new;
 
   while ((c_old = s_old.next()) >= 0) {
@@ -68,64 +64,6 @@
   return true;
 }
 
-
-bool MethodComparator::methods_switchable(Method* old_method, Method* new_method,
-                                          BciMap &bci_map) {
-  if (old_method->code_size() > new_method->code_size())
-    // Something has definitely been deleted in the new method, compared to the old one.
-    return false;
-
-  if (! check_stack_and_locals_size(old_method, new_method))
-    return false;
-
-  _old_cp = old_method->constants();
-  _new_cp = new_method->constants();
-  BytecodeStream s_old(old_method);
-  BytecodeStream s_new(new_method);
-  _s_old = &s_old;
-  _s_new = &s_new;
-  _bci_map = &bci_map;
-  _switchable_test = true;
-  GrowableArray<int> fwd_jmps(16);
-  _fwd_jmps = &fwd_jmps;
-  Bytecodes::Code c_old, c_new;
-
-  while ((c_old = s_old.next()) >= 0) {
-    if ((c_new = s_new.next()) < 0)
-      return false;
-    if (! (c_old == c_new && args_same(c_old, c_new))) {
-      int old_bci = s_old.bci();
-      int new_st_bci = s_new.bci();
-      bool found_match = false;
-      do {
-        c_new = s_new.next();
-        if (c_new == c_old && args_same(c_old, c_new)) {
-          found_match = true;
-          break;
-        }
-      } while (c_new >= 0);
-      if (! found_match)
-        return false;
-      int new_end_bci = s_new.bci();
-      bci_map.store_fragment_location(old_bci, new_st_bci, new_end_bci);
-    }
-  }
-
-  // Now we can test all forward jumps
-  for (int i = 0; i < fwd_jmps.length() / 2; i++) {
-    if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
-      RC_TRACE(0x00800000,
-        ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
-        fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
-        fwd_jmps.at(i*2+1)));
-      return false;
-    }
-  }
-
-  return true;
-}
-
-
 bool MethodComparator::args_same(Bytecodes::Code c_old, Bytecodes::Code c_new) {
   // BytecodeStream returns the correct standard Java bytecodes for various "fast"
   // bytecode versions, so we don't have to bother about them here..
@@ -275,22 +213,8 @@
   case Bytecodes::_jsr       : {
     int old_ofs = _s_old->bytecode().get_offset_s2(c_old);
     int new_ofs = _s_new->bytecode().get_offset_s2(c_new);
-    if (_switchable_test) {
-      int old_dest = _s_old->bci() + old_ofs;
-      int new_dest = _s_new->bci() + new_ofs;
-      if (old_ofs < 0 && new_ofs < 0) {
-        if (! _bci_map->old_and_new_locations_same(old_dest, new_dest))
-          return false;
-      } else if (old_ofs > 0 && new_ofs > 0) {
-        _fwd_jmps->append(old_dest);
-        _fwd_jmps->append(new_dest);
-      } else {
-        return false;
-      }
-    } else {
-      if (old_ofs != new_ofs)
-        return false;
-    }
+    if (old_ofs != new_ofs)
+      return false;
     break;
   }
 
@@ -312,73 +236,19 @@
   case Bytecodes::_jsr_w  : {
     int old_ofs = _s_old->bytecode().get_offset_s4(c_old);
     int new_ofs = _s_new->bytecode().get_offset_s4(c_new);
-    if (_switchable_test) {
-      int old_dest = _s_old->bci() + old_ofs;
-      int new_dest = _s_new->bci() + new_ofs;
-      if (old_ofs < 0 && new_ofs < 0) {
-        if (! _bci_map->old_and_new_locations_same(old_dest, new_dest))
-          return false;
-      } else if (old_ofs > 0 && new_ofs > 0) {
-        _fwd_jmps->append(old_dest);
-        _fwd_jmps->append(new_dest);
-      } else {
-        return false;
-      }
-    } else {
-      if (old_ofs != new_ofs)
-        return false;
-    }
+    if (old_ofs != new_ofs)
+      return false;
     break;
   }
 
   case Bytecodes::_lookupswitch : // fall through
   case Bytecodes::_tableswitch  : {
-    if (_switchable_test) {
-      address aligned_bcp_old = (address) round_to((intptr_t)_s_old->bcp() + 1, jintSize);
-      address aligned_bcp_new = (address) round_to((intptr_t)_s_new->bcp() + 1, jintSize);
-      int default_old = (int) Bytes::get_Java_u4(aligned_bcp_old);
-      int default_new = (int) Bytes::get_Java_u4(aligned_bcp_new);
-      _fwd_jmps->append(_s_old->bci() + default_old);
-      _fwd_jmps->append(_s_new->bci() + default_new);
-      if (c_old == Bytecodes::_lookupswitch) {
-        int npairs_old = (int) Bytes::get_Java_u4(aligned_bcp_old + jintSize);
-        int npairs_new = (int) Bytes::get_Java_u4(aligned_bcp_new + jintSize);
-        if (npairs_old != npairs_new)
-          return false;
-        for (int i = 0; i < npairs_old; i++) {
-          int match_old = (int) Bytes::get_Java_u4(aligned_bcp_old + (2+2*i)*jintSize);
-          int match_new = (int) Bytes::get_Java_u4(aligned_bcp_new + (2+2*i)*jintSize);
-          if (match_old != match_new)
-            return false;
-          int ofs_old = (int) Bytes::get_Java_u4(aligned_bcp_old + (2+2*i+1)*jintSize);
-          int ofs_new = (int) Bytes::get_Java_u4(aligned_bcp_new + (2+2*i+1)*jintSize);
-          _fwd_jmps->append(_s_old->bci() + ofs_old);
-          _fwd_jmps->append(_s_new->bci() + ofs_new);
-        }
-      } else if (c_old == Bytecodes::_tableswitch) {
-        int lo_old = (int) Bytes::get_Java_u4(aligned_bcp_old + jintSize);
-        int lo_new = (int) Bytes::get_Java_u4(aligned_bcp_new + jintSize);
-        if (lo_old != lo_new)
-          return false;
-        int hi_old = (int) Bytes::get_Java_u4(aligned_bcp_old + 2*jintSize);
-        int hi_new = (int) Bytes::get_Java_u4(aligned_bcp_new + 2*jintSize);
-        if (hi_old != hi_new)
-          return false;
-        for (int i = 0; i < hi_old - lo_old + 1; i++) {
-          int ofs_old = (int) Bytes::get_Java_u4(aligned_bcp_old + (3+i)*jintSize);
-          int ofs_new = (int) Bytes::get_Java_u4(aligned_bcp_new + (3+i)*jintSize);
-          _fwd_jmps->append(_s_old->bci() + ofs_old);
-          _fwd_jmps->append(_s_new->bci() + ofs_new);
-        }
-      }
-    } else { // !_switchable_test, can use fast rough compare
-      int len_old = _s_old->instruction_size();
-      int len_new = _s_new->instruction_size();
-      if (len_old != len_new)
-        return false;
-      if (memcmp(_s_old->bcp(), _s_new->bcp(), len_old) != 0)
-        return false;
-    }
+    int len_old = _s_old->instruction_size();
+    int len_new = _s_new->instruction_size();
+    if (len_old != len_new)
+      return false;
+    if (memcmp(_s_old->bcp(), _s_new->bcp(), len_old) != 0)
+      return false;
     break;
   }
   }
--- a/hotspot/src/share/vm/prims/methodComparator.hpp	Thu Feb 11 08:57:00 2016 +0100
+++ b/hotspot/src/share/vm/prims/methodComparator.hpp	Thu Feb 11 02:39:35 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,8 +29,6 @@
 #include "oops/constantPool.hpp"
 #include "oops/method.hpp"
 
-class BciMap;
-
 // methodComparator provides an interface for determining if methods of
 // different versions of classes are equivalent or switchable
 
@@ -39,9 +37,6 @@
   static BytecodeStream *_s_old, *_s_new;
   static ConstantPool* _old_cp;
   static ConstantPool* _new_cp;
-  static BciMap *_bci_map;
-  static bool _switchable_test;
-  static GrowableArray<int> *_fwd_jmps;
 
   static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new);
   static bool pool_constants_same(int cpi_old, int cpi_new);
@@ -55,79 +50,6 @@
   // these indices eventually point to the same constants for both method versions.
   static bool methods_EMCP(Method* old_method, Method* new_method);
 
-  static bool methods_switchable(Method* old_method, Method* new_method, BciMap &bci_map);
-};
-
-
-// ByteCode Index Map. For two versions of the same method, where the new version may contain
-// fragments not found in the old version, provides a mapping from an index of a bytecode in
-// the old method to the index of the same bytecode in the new method.
-
-class BciMap {
- private:
-  int *_old_bci, *_new_st_bci, *_new_end_bci;
-  int _cur_size, _cur_pos;
-  int _pos;
-
- public:
-  BciMap() {
-    _cur_size = 50;
-    _old_bci = (int*) malloc(sizeof(int) * _cur_size);
-    _new_st_bci = (int*) malloc(sizeof(int) * _cur_size);
-    _new_end_bci = (int*) malloc(sizeof(int) * _cur_size);
-    _cur_pos = 0;
-  }
-
-  ~BciMap() {
-    free(_old_bci);
-    free(_new_st_bci);
-    free(_new_end_bci);
-  }
-
-  // Store the position of an added fragment, e.g.
-  //
-  //                              |<- old_bci
-  // -----------------------------------------
-  // Old method   |invokevirtual 5|aload 1|...
-  // -----------------------------------------
-  //
-  //                                 |<- new_st_bci          |<- new_end_bci
-  // --------------------------------------------------------------------
-  // New method       |invokevirual 5|aload 2|invokevirtual 6|aload 1|...
-  // --------------------------------------------------------------------
-  //                                 ^^^^^^^^^^^^^^^^^^^^^^^^
-  //                                    Added fragment
-
-  void store_fragment_location(int old_bci, int new_st_bci, int new_end_bci) {
-    if (_cur_pos == _cur_size) {
-      _cur_size += 10;
-      _old_bci = (int*) realloc(_old_bci, sizeof(int) * _cur_size);
-      _new_st_bci = (int*) realloc(_new_st_bci, sizeof(int) * _cur_size);
-      _new_end_bci = (int*) realloc(_new_end_bci, sizeof(int) * _cur_size);
-    }
-    _old_bci[_cur_pos] = old_bci;
-    _new_st_bci[_cur_pos] = new_st_bci;
-    _new_end_bci[_cur_pos] = new_end_bci;
-    _cur_pos++;
-  }
-
-  int new_bci_for_old(int old_bci) {
-    if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci;
-    _pos = 1;
-    while (_pos < _cur_pos && old_bci >= _old_bci[_pos])
-      _pos++;
-    return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]);
-  }
-
-  // Test if two indexes - one in the old method and another in the new one - correspond
-  // to the same bytecode
-  bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) {
-    if (new_bci_for_old(old_dest_bci) == new_dest_bci)
-      return true;
-    else if (_old_bci[_pos-1] == old_dest_bci)
-      return (new_dest_bci == _new_st_bci[_pos-1]);
-    else return false;
-  }
 };
 
 #endif // SHARE_VM_PRIMS_METHODCOMPARATOR_HPP