src/share/vm/prims/methodComparator.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
aoqi@0 26 #define SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
aoqi@0 27
aoqi@0 28 #include "interpreter/bytecodeStream.hpp"
aoqi@0 29 #include "oops/constantPool.hpp"
aoqi@0 30 #include "oops/method.hpp"
aoqi@0 31
aoqi@0 32 class BciMap;
aoqi@0 33
aoqi@0 34 // methodComparator provides an interface for determining if methods of
aoqi@0 35 // different versions of classes are equivalent or switchable
aoqi@0 36
aoqi@0 37 class MethodComparator {
aoqi@0 38 private:
aoqi@0 39 static BytecodeStream *_s_old, *_s_new;
aoqi@0 40 static ConstantPool* _old_cp;
aoqi@0 41 static ConstantPool* _new_cp;
aoqi@0 42 static BciMap *_bci_map;
aoqi@0 43 static bool _switchable_test;
aoqi@0 44 static GrowableArray<int> *_fwd_jmps;
aoqi@0 45
aoqi@0 46 static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new);
aoqi@0 47 static bool pool_constants_same(int cpi_old, int cpi_new);
aoqi@0 48 static int check_stack_and_locals_size(Method* old_method, Method* new_method);
aoqi@0 49
aoqi@0 50 public:
aoqi@0 51 // Check if the new method is equivalent to the old one modulo constant pool (EMCP).
aoqi@0 52 // Intuitive definition: two versions of the same method are EMCP, if they don't differ
aoqi@0 53 // on the source code level. Practically, we check whether the only difference between
aoqi@0 54 // method versions is some constantpool indices embedded into the bytecodes, and whether
aoqi@0 55 // these indices eventually point to the same constants for both method versions.
aoqi@0 56 static bool methods_EMCP(Method* old_method, Method* new_method);
aoqi@0 57
aoqi@0 58 static bool methods_switchable(Method* old_method, Method* new_method, BciMap &bci_map);
aoqi@0 59 };
aoqi@0 60
aoqi@0 61
aoqi@0 62 // ByteCode Index Map. For two versions of the same method, where the new version may contain
aoqi@0 63 // fragments not found in the old version, provides a mapping from an index of a bytecode in
aoqi@0 64 // the old method to the index of the same bytecode in the new method.
aoqi@0 65
aoqi@0 66 class BciMap {
aoqi@0 67 private:
aoqi@0 68 int *_old_bci, *_new_st_bci, *_new_end_bci;
aoqi@0 69 int _cur_size, _cur_pos;
aoqi@0 70 int _pos;
aoqi@0 71
aoqi@0 72 public:
aoqi@0 73 BciMap() {
aoqi@0 74 _cur_size = 50;
aoqi@0 75 _old_bci = (int*) malloc(sizeof(int) * _cur_size);
aoqi@0 76 _new_st_bci = (int*) malloc(sizeof(int) * _cur_size);
aoqi@0 77 _new_end_bci = (int*) malloc(sizeof(int) * _cur_size);
aoqi@0 78 _cur_pos = 0;
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 ~BciMap() {
aoqi@0 82 free(_old_bci);
aoqi@0 83 free(_new_st_bci);
aoqi@0 84 free(_new_end_bci);
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 // Store the position of an added fragment, e.g.
aoqi@0 88 //
aoqi@0 89 // |<- old_bci
aoqi@0 90 // -----------------------------------------
aoqi@0 91 // Old method |invokevirtual 5|aload 1|...
aoqi@0 92 // -----------------------------------------
aoqi@0 93 //
aoqi@0 94 // |<- new_st_bci |<- new_end_bci
aoqi@0 95 // --------------------------------------------------------------------
aoqi@0 96 // New method |invokevirual 5|aload 2|invokevirtual 6|aload 1|...
aoqi@0 97 // --------------------------------------------------------------------
aoqi@0 98 // ^^^^^^^^^^^^^^^^^^^^^^^^
aoqi@0 99 // Added fragment
aoqi@0 100
aoqi@0 101 void store_fragment_location(int old_bci, int new_st_bci, int new_end_bci) {
aoqi@0 102 if (_cur_pos == _cur_size) {
aoqi@0 103 _cur_size += 10;
aoqi@0 104 _old_bci = (int*) realloc(_old_bci, sizeof(int) * _cur_size);
aoqi@0 105 _new_st_bci = (int*) realloc(_new_st_bci, sizeof(int) * _cur_size);
aoqi@0 106 _new_end_bci = (int*) realloc(_new_end_bci, sizeof(int) * _cur_size);
aoqi@0 107 }
aoqi@0 108 _old_bci[_cur_pos] = old_bci;
aoqi@0 109 _new_st_bci[_cur_pos] = new_st_bci;
aoqi@0 110 _new_end_bci[_cur_pos] = new_end_bci;
aoqi@0 111 _cur_pos++;
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 int new_bci_for_old(int old_bci) {
aoqi@0 115 if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci;
aoqi@0 116 _pos = 1;
aoqi@0 117 while (_pos < _cur_pos && old_bci >= _old_bci[_pos])
aoqi@0 118 _pos++;
aoqi@0 119 return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]);
aoqi@0 120 }
aoqi@0 121
aoqi@0 122 // Test if two indexes - one in the old method and another in the new one - correspond
aoqi@0 123 // to the same bytecode
aoqi@0 124 bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) {
aoqi@0 125 if (new_bci_for_old(old_dest_bci) == new_dest_bci)
aoqi@0 126 return true;
aoqi@0 127 else if (_old_bci[_pos-1] == old_dest_bci)
aoqi@0 128 return (new_dest_bci == _new_st_bci[_pos-1]);
aoqi@0 129 else return false;
aoqi@0 130 }
aoqi@0 131 };
aoqi@0 132
aoqi@0 133 #endif // SHARE_VM_PRIMS_METHODCOMPARATOR_HPP

mercurial