1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/prims/methodComparator.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,133 @@ 1.4 +/* 1.5 + * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_PRIMS_METHODCOMPARATOR_HPP 1.29 +#define SHARE_VM_PRIMS_METHODCOMPARATOR_HPP 1.30 + 1.31 +#include "interpreter/bytecodeStream.hpp" 1.32 +#include "oops/constantPool.hpp" 1.33 +#include "oops/method.hpp" 1.34 + 1.35 +class BciMap; 1.36 + 1.37 +// methodComparator provides an interface for determining if methods of 1.38 +// different versions of classes are equivalent or switchable 1.39 + 1.40 +class MethodComparator { 1.41 + private: 1.42 + static BytecodeStream *_s_old, *_s_new; 1.43 + static ConstantPool* _old_cp; 1.44 + static ConstantPool* _new_cp; 1.45 + static BciMap *_bci_map; 1.46 + static bool _switchable_test; 1.47 + static GrowableArray<int> *_fwd_jmps; 1.48 + 1.49 + static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new); 1.50 + static bool pool_constants_same(int cpi_old, int cpi_new); 1.51 + static int check_stack_and_locals_size(Method* old_method, Method* new_method); 1.52 + 1.53 + public: 1.54 + // Check if the new method is equivalent to the old one modulo constant pool (EMCP). 1.55 + // Intuitive definition: two versions of the same method are EMCP, if they don't differ 1.56 + // on the source code level. Practically, we check whether the only difference between 1.57 + // method versions is some constantpool indices embedded into the bytecodes, and whether 1.58 + // these indices eventually point to the same constants for both method versions. 1.59 + static bool methods_EMCP(Method* old_method, Method* new_method); 1.60 + 1.61 + static bool methods_switchable(Method* old_method, Method* new_method, BciMap &bci_map); 1.62 +}; 1.63 + 1.64 + 1.65 +// ByteCode Index Map. For two versions of the same method, where the new version may contain 1.66 +// fragments not found in the old version, provides a mapping from an index of a bytecode in 1.67 +// the old method to the index of the same bytecode in the new method. 1.68 + 1.69 +class BciMap { 1.70 + private: 1.71 + int *_old_bci, *_new_st_bci, *_new_end_bci; 1.72 + int _cur_size, _cur_pos; 1.73 + int _pos; 1.74 + 1.75 + public: 1.76 + BciMap() { 1.77 + _cur_size = 50; 1.78 + _old_bci = (int*) malloc(sizeof(int) * _cur_size); 1.79 + _new_st_bci = (int*) malloc(sizeof(int) * _cur_size); 1.80 + _new_end_bci = (int*) malloc(sizeof(int) * _cur_size); 1.81 + _cur_pos = 0; 1.82 + } 1.83 + 1.84 + ~BciMap() { 1.85 + free(_old_bci); 1.86 + free(_new_st_bci); 1.87 + free(_new_end_bci); 1.88 + } 1.89 + 1.90 + // Store the position of an added fragment, e.g. 1.91 + // 1.92 + // |<- old_bci 1.93 + // ----------------------------------------- 1.94 + // Old method |invokevirtual 5|aload 1|... 1.95 + // ----------------------------------------- 1.96 + // 1.97 + // |<- new_st_bci |<- new_end_bci 1.98 + // -------------------------------------------------------------------- 1.99 + // New method |invokevirual 5|aload 2|invokevirtual 6|aload 1|... 1.100 + // -------------------------------------------------------------------- 1.101 + // ^^^^^^^^^^^^^^^^^^^^^^^^ 1.102 + // Added fragment 1.103 + 1.104 + void store_fragment_location(int old_bci, int new_st_bci, int new_end_bci) { 1.105 + if (_cur_pos == _cur_size) { 1.106 + _cur_size += 10; 1.107 + _old_bci = (int*) realloc(_old_bci, sizeof(int) * _cur_size); 1.108 + _new_st_bci = (int*) realloc(_new_st_bci, sizeof(int) * _cur_size); 1.109 + _new_end_bci = (int*) realloc(_new_end_bci, sizeof(int) * _cur_size); 1.110 + } 1.111 + _old_bci[_cur_pos] = old_bci; 1.112 + _new_st_bci[_cur_pos] = new_st_bci; 1.113 + _new_end_bci[_cur_pos] = new_end_bci; 1.114 + _cur_pos++; 1.115 + } 1.116 + 1.117 + int new_bci_for_old(int old_bci) { 1.118 + if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci; 1.119 + _pos = 1; 1.120 + while (_pos < _cur_pos && old_bci >= _old_bci[_pos]) 1.121 + _pos++; 1.122 + return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]); 1.123 + } 1.124 + 1.125 + // Test if two indexes - one in the old method and another in the new one - correspond 1.126 + // to the same bytecode 1.127 + bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) { 1.128 + if (new_bci_for_old(old_dest_bci) == new_dest_bci) 1.129 + return true; 1.130 + else if (_old_bci[_pos-1] == old_dest_bci) 1.131 + return (new_dest_bci == _new_st_bci[_pos-1]); 1.132 + else return false; 1.133 + } 1.134 +}; 1.135 + 1.136 +#endif // SHARE_VM_PRIMS_METHODCOMPARATOR_HPP