0N/A/*
1833N/A * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
1879N/A#define SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
1879N/A
1879N/A#include "interpreter/bytecodeStream.hpp"
1879N/A#include "oops/constantPoolOop.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A
0N/Aclass BciMap;
0N/A
0N/A// methodComparator provides an interface for determining if methods of
0N/A// different versions of classes are equivalent or switchable
0N/A
0N/Aclass MethodComparator {
0N/A private:
0N/A static BytecodeStream *_s_old, *_s_new;
0N/A static constantPoolOop _old_cp, _new_cp;
0N/A static BciMap *_bci_map;
0N/A static bool _switchable_test;
0N/A static GrowableArray<int> *_fwd_jmps;
0N/A
0N/A static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new);
1833N/A static bool pool_constants_same(int cpi_old, int cpi_new);
0N/A static int check_stack_and_locals_size(methodOop old_method, methodOop new_method);
0N/A
0N/A public:
0N/A // Check if the new method is equivalent to the old one modulo constant pool (EMCP).
0N/A // Intuitive definition: two versions of the same method are EMCP, if they don't differ
0N/A // on the source code level. Practically, we check whether the only difference between
0N/A // method versions is some constantpool indices embedded into the bytecodes, and whether
0N/A // these indices eventually point to the same constants for both method versions.
0N/A static bool methods_EMCP(methodOop old_method, methodOop new_method);
0N/A
0N/A static bool methods_switchable(methodOop old_method, methodOop new_method, BciMap &bci_map);
0N/A};
0N/A
0N/A
0N/A// ByteCode Index Map. For two versions of the same method, where the new version may contain
0N/A// fragments not found in the old version, provides a mapping from an index of a bytecode in
0N/A// the old method to the index of the same bytecode in the new method.
0N/A
0N/Aclass BciMap {
0N/A private:
0N/A int *_old_bci, *_new_st_bci, *_new_end_bci;
0N/A int _cur_size, _cur_pos;
0N/A int _pos;
0N/A
0N/A public:
0N/A BciMap() {
0N/A _cur_size = 50;
0N/A _old_bci = (int*) malloc(sizeof(int) * _cur_size);
0N/A _new_st_bci = (int*) malloc(sizeof(int) * _cur_size);
0N/A _new_end_bci = (int*) malloc(sizeof(int) * _cur_size);
0N/A _cur_pos = 0;
0N/A }
0N/A
0N/A ~BciMap() {
0N/A free(_old_bci);
0N/A free(_new_st_bci);
0N/A free(_new_end_bci);
0N/A }
0N/A
0N/A // Store the position of an added fragment, e.g.
0N/A //
0N/A // |<- old_bci
0N/A // -----------------------------------------
0N/A // Old method |invokevirtual 5|aload 1|...
0N/A // -----------------------------------------
0N/A //
0N/A // |<- new_st_bci |<- new_end_bci
0N/A // --------------------------------------------------------------------
0N/A // New method |invokevirual 5|aload 2|invokevirtual 6|aload 1|...
0N/A // --------------------------------------------------------------------
0N/A // ^^^^^^^^^^^^^^^^^^^^^^^^
0N/A // Added fragment
0N/A
0N/A void store_fragment_location(int old_bci, int new_st_bci, int new_end_bci) {
0N/A if (_cur_pos == _cur_size) {
0N/A _cur_size += 10;
0N/A _old_bci = (int*) realloc(_old_bci, sizeof(int) * _cur_size);
0N/A _new_st_bci = (int*) realloc(_new_st_bci, sizeof(int) * _cur_size);
0N/A _new_end_bci = (int*) realloc(_new_end_bci, sizeof(int) * _cur_size);
0N/A }
0N/A _old_bci[_cur_pos] = old_bci;
0N/A _new_st_bci[_cur_pos] = new_st_bci;
0N/A _new_end_bci[_cur_pos] = new_end_bci;
0N/A _cur_pos++;
0N/A }
0N/A
0N/A int new_bci_for_old(int old_bci) {
0N/A if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci;
0N/A _pos = 1;
0N/A while (_pos < _cur_pos && old_bci >= _old_bci[_pos])
0N/A _pos++;
0N/A return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]);
0N/A }
0N/A
0N/A // Test if two indexes - one in the old method and another in the new one - correspond
0N/A // to the same bytecode
0N/A bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) {
0N/A if (new_bci_for_old(old_dest_bci) == new_dest_bci)
0N/A return true;
0N/A else if (_old_bci[_pos-1] == old_dest_bci)
0N/A return (new_dest_bci == _new_st_bci[_pos-1]);
0N/A else return false;
0N/A }
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_PRIMS_METHODCOMPARATOR_HPP