annotate src/share/vm/prims/methodComparator.hpp @ 1838:3b2dea75431e

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