src/share/vm/prims/methodComparator.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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 #include "precompiled.hpp"
aoqi@0 26 #include "oops/oop.inline.hpp"
aoqi@0 27 #include "oops/symbol.hpp"
aoqi@0 28 #include "prims/jvmtiRedefineClassesTrace.hpp"
aoqi@0 29 #include "prims/methodComparator.hpp"
aoqi@0 30 #include "runtime/handles.inline.hpp"
aoqi@0 31 #include "utilities/globalDefinitions.hpp"
aoqi@0 32
aoqi@0 33 BytecodeStream *MethodComparator::_s_old;
aoqi@0 34 BytecodeStream *MethodComparator::_s_new;
aoqi@0 35 ConstantPool* MethodComparator::_old_cp;
aoqi@0 36 ConstantPool* MethodComparator::_new_cp;
aoqi@0 37 BciMap *MethodComparator::_bci_map;
aoqi@0 38 bool MethodComparator::_switchable_test;
aoqi@0 39 GrowableArray<int> *MethodComparator::_fwd_jmps;
aoqi@0 40
aoqi@0 41 bool MethodComparator::methods_EMCP(Method* old_method, Method* new_method) {
aoqi@0 42 if (old_method->code_size() != new_method->code_size())
aoqi@0 43 return false;
aoqi@0 44 if (check_stack_and_locals_size(old_method, new_method) != 0) {
aoqi@0 45 // RC_TRACE macro has an embedded ResourceMark
aoqi@0 46 RC_TRACE(0x00800000, ("Methods %s non-comparable with diagnosis %d",
aoqi@0 47 old_method->name()->as_C_string(),
aoqi@0 48 check_stack_and_locals_size(old_method, new_method)));
aoqi@0 49 return false;
aoqi@0 50 }
aoqi@0 51
aoqi@0 52 _old_cp = old_method->constants();
aoqi@0 53 _new_cp = new_method->constants();
aoqi@0 54 BytecodeStream s_old(old_method);
aoqi@0 55 BytecodeStream s_new(new_method);
aoqi@0 56 _s_old = &s_old;
aoqi@0 57 _s_new = &s_new;
aoqi@0 58 _switchable_test = false;
aoqi@0 59 Bytecodes::Code c_old, c_new;
aoqi@0 60
aoqi@0 61 while ((c_old = s_old.next()) >= 0) {
aoqi@0 62 if ((c_new = s_new.next()) < 0 || c_old != c_new)
aoqi@0 63 return false;
aoqi@0 64
aoqi@0 65 if (! args_same(c_old, c_new))
aoqi@0 66 return false;
aoqi@0 67 }
aoqi@0 68 return true;
aoqi@0 69 }
aoqi@0 70
aoqi@0 71
aoqi@0 72 bool MethodComparator::methods_switchable(Method* old_method, Method* new_method,
aoqi@0 73 BciMap &bci_map) {
aoqi@0 74 if (old_method->code_size() > new_method->code_size())
aoqi@0 75 // Something has definitely been deleted in the new method, compared to the old one.
aoqi@0 76 return false;
aoqi@0 77
aoqi@0 78 if (! check_stack_and_locals_size(old_method, new_method))
aoqi@0 79 return false;
aoqi@0 80
aoqi@0 81 _old_cp = old_method->constants();
aoqi@0 82 _new_cp = new_method->constants();
aoqi@0 83 BytecodeStream s_old(old_method);
aoqi@0 84 BytecodeStream s_new(new_method);
aoqi@0 85 _s_old = &s_old;
aoqi@0 86 _s_new = &s_new;
aoqi@0 87 _bci_map = &bci_map;
aoqi@0 88 _switchable_test = true;
aoqi@0 89 GrowableArray<int> fwd_jmps(16);
aoqi@0 90 _fwd_jmps = &fwd_jmps;
aoqi@0 91 Bytecodes::Code c_old, c_new;
aoqi@0 92
aoqi@0 93 while ((c_old = s_old.next()) >= 0) {
aoqi@0 94 if ((c_new = s_new.next()) < 0)
aoqi@0 95 return false;
aoqi@0 96 if (! (c_old == c_new && args_same(c_old, c_new))) {
aoqi@0 97 int old_bci = s_old.bci();
aoqi@0 98 int new_st_bci = s_new.bci();
aoqi@0 99 bool found_match = false;
aoqi@0 100 do {
aoqi@0 101 c_new = s_new.next();
aoqi@0 102 if (c_new == c_old && args_same(c_old, c_new)) {
aoqi@0 103 found_match = true;
aoqi@0 104 break;
aoqi@0 105 }
aoqi@0 106 } while (c_new >= 0);
aoqi@0 107 if (! found_match)
aoqi@0 108 return false;
aoqi@0 109 int new_end_bci = s_new.bci();
aoqi@0 110 bci_map.store_fragment_location(old_bci, new_st_bci, new_end_bci);
aoqi@0 111 }
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 // Now we can test all forward jumps
aoqi@0 115 for (int i = 0; i < fwd_jmps.length() / 2; i++) {
aoqi@0 116 if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
aoqi@0 117 RC_TRACE(0x00800000,
aoqi@0 118 ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
aoqi@0 119 fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
aoqi@0 120 fwd_jmps.at(i*2+1)));
aoqi@0 121 return false;
aoqi@0 122 }
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 return true;
aoqi@0 126 }
aoqi@0 127
aoqi@0 128
aoqi@0 129 bool MethodComparator::args_same(Bytecodes::Code c_old, Bytecodes::Code c_new) {
aoqi@0 130 // BytecodeStream returns the correct standard Java bytecodes for various "fast"
aoqi@0 131 // bytecode versions, so we don't have to bother about them here..
aoqi@0 132 switch (c_old) {
aoqi@0 133 case Bytecodes::_new : // fall through
aoqi@0 134 case Bytecodes::_anewarray : // fall through
aoqi@0 135 case Bytecodes::_multianewarray : // fall through
aoqi@0 136 case Bytecodes::_checkcast : // fall through
aoqi@0 137 case Bytecodes::_instanceof : {
aoqi@0 138 u2 cpi_old = _s_old->get_index_u2();
aoqi@0 139 u2 cpi_new = _s_new->get_index_u2();
aoqi@0 140 if ((_old_cp->klass_at_noresolve(cpi_old) != _new_cp->klass_at_noresolve(cpi_new)))
aoqi@0 141 return false;
aoqi@0 142 if (c_old == Bytecodes::_multianewarray &&
aoqi@0 143 *(jbyte*)(_s_old->bcp() + 3) != *(jbyte*)(_s_new->bcp() + 3))
aoqi@0 144 return false;
aoqi@0 145 break;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 case Bytecodes::_getstatic : // fall through
aoqi@0 149 case Bytecodes::_putstatic : // fall through
aoqi@0 150 case Bytecodes::_getfield : // fall through
aoqi@0 151 case Bytecodes::_putfield : // fall through
aoqi@0 152 case Bytecodes::_invokevirtual : // fall through
aoqi@0 153 case Bytecodes::_invokespecial : // fall through
aoqi@0 154 case Bytecodes::_invokestatic : // fall through
aoqi@0 155 case Bytecodes::_invokeinterface : {
aoqi@0 156 int cpci_old = _s_old->get_index_u2_cpcache();
aoqi@0 157 int cpci_new = _s_new->get_index_u2_cpcache();
aoqi@0 158 // Check if the names of classes, field/method names and signatures at these indexes
aoqi@0 159 // are the same. Indices which are really into constantpool cache (rather than constant
aoqi@0 160 // pool itself) are accepted by the constantpool query routines below.
aoqi@0 161 if ((_old_cp->klass_ref_at_noresolve(cpci_old) != _new_cp->klass_ref_at_noresolve(cpci_new)) ||
aoqi@0 162 (_old_cp->name_ref_at(cpci_old) != _new_cp->name_ref_at(cpci_new)) ||
aoqi@0 163 (_old_cp->signature_ref_at(cpci_old) != _new_cp->signature_ref_at(cpci_new)))
aoqi@0 164 return false;
aoqi@0 165 break;
aoqi@0 166 }
aoqi@0 167 case Bytecodes::_invokedynamic: {
aoqi@0 168 int cpci_old = _s_old->get_index_u4();
aoqi@0 169 int cpci_new = _s_new->get_index_u4();
aoqi@0 170
aoqi@0 171 // Check if the names of classes, field/method names and signatures at these indexes
aoqi@0 172 // are the same. Indices which are really into constantpool cache (rather than constant
aoqi@0 173 // pool itself) are accepted by the constantpool query routines below.
aoqi@0 174 if ((_old_cp->name_ref_at(cpci_old) != _new_cp->name_ref_at(cpci_new)) ||
aoqi@0 175 (_old_cp->signature_ref_at(cpci_old) != _new_cp->signature_ref_at(cpci_new)))
aoqi@0 176 return false;
aoqi@0 177
aoqi@0 178 // Translate object indexes to constant pool cache indexes.
aoqi@0 179 cpci_old = _old_cp->invokedynamic_cp_cache_index(cpci_old);
aoqi@0 180 cpci_new = _new_cp->invokedynamic_cp_cache_index(cpci_new);
aoqi@0 181
aoqi@0 182 int cpi_old = _old_cp->cache()->entry_at(cpci_old)->constant_pool_index();
aoqi@0 183 int cpi_new = _new_cp->cache()->entry_at(cpci_new)->constant_pool_index();
aoqi@0 184 int bsm_old = _old_cp->invoke_dynamic_bootstrap_method_ref_index_at(cpi_old);
aoqi@0 185 int bsm_new = _new_cp->invoke_dynamic_bootstrap_method_ref_index_at(cpi_new);
aoqi@0 186 if (!pool_constants_same(bsm_old, bsm_new))
aoqi@0 187 return false;
aoqi@0 188 int cnt_old = _old_cp->invoke_dynamic_argument_count_at(cpi_old);
aoqi@0 189 int cnt_new = _new_cp->invoke_dynamic_argument_count_at(cpi_new);
aoqi@0 190 if (cnt_old != cnt_new)
aoqi@0 191 return false;
aoqi@0 192 for (int arg_i = 0; arg_i < cnt_old; arg_i++) {
aoqi@0 193 int idx_old = _old_cp->invoke_dynamic_argument_index_at(cpi_old, arg_i);
aoqi@0 194 int idx_new = _new_cp->invoke_dynamic_argument_index_at(cpi_new, arg_i);
aoqi@0 195 if (!pool_constants_same(idx_old, idx_new))
aoqi@0 196 return false;
aoqi@0 197 }
aoqi@0 198 break;
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 case Bytecodes::_ldc : // fall through
aoqi@0 202 case Bytecodes::_ldc_w : {
aoqi@0 203 Bytecode_loadconstant ldc_old(_s_old->method(), _s_old->bci());
aoqi@0 204 Bytecode_loadconstant ldc_new(_s_new->method(), _s_new->bci());
aoqi@0 205 int cpi_old = ldc_old.pool_index();
aoqi@0 206 int cpi_new = ldc_new.pool_index();
aoqi@0 207 if (!pool_constants_same(cpi_old, cpi_new))
aoqi@0 208 return false;
aoqi@0 209 break;
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 case Bytecodes::_ldc2_w : {
aoqi@0 213 u2 cpi_old = _s_old->get_index_u2();
aoqi@0 214 u2 cpi_new = _s_new->get_index_u2();
aoqi@0 215 constantTag tag_old = _old_cp->tag_at(cpi_old);
aoqi@0 216 constantTag tag_new = _new_cp->tag_at(cpi_new);
aoqi@0 217 if (tag_old.value() != tag_new.value())
aoqi@0 218 return false;
aoqi@0 219 if (tag_old.is_long()) {
aoqi@0 220 if (_old_cp->long_at(cpi_old) != _new_cp->long_at(cpi_new))
aoqi@0 221 return false;
aoqi@0 222 } else {
aoqi@0 223 // Use jlong_cast to compare the bits rather than numerical values.
aoqi@0 224 // This makes a difference for NaN constants.
aoqi@0 225 if (jlong_cast(_old_cp->double_at(cpi_old)) != jlong_cast(_new_cp->double_at(cpi_new)))
aoqi@0 226 return false;
aoqi@0 227 }
aoqi@0 228 break;
aoqi@0 229 }
aoqi@0 230
aoqi@0 231 case Bytecodes::_bipush :
aoqi@0 232 if (_s_old->bcp()[1] != _s_new->bcp()[1])
aoqi@0 233 return false;
aoqi@0 234 break;
aoqi@0 235
aoqi@0 236 case Bytecodes::_sipush :
aoqi@0 237 if (_s_old->get_index_u2() != _s_new->get_index_u2())
aoqi@0 238 return false;
aoqi@0 239 break;
aoqi@0 240
aoqi@0 241 case Bytecodes::_aload : // fall through
aoqi@0 242 case Bytecodes::_astore : // fall through
aoqi@0 243 case Bytecodes::_dload : // fall through
aoqi@0 244 case Bytecodes::_dstore : // fall through
aoqi@0 245 case Bytecodes::_fload : // fall through
aoqi@0 246 case Bytecodes::_fstore : // fall through
aoqi@0 247 case Bytecodes::_iload : // fall through
aoqi@0 248 case Bytecodes::_istore : // fall through
aoqi@0 249 case Bytecodes::_lload : // fall through
aoqi@0 250 case Bytecodes::_lstore : // fall through
aoqi@0 251 case Bytecodes::_ret :
aoqi@0 252 if (_s_old->is_wide() != _s_new->is_wide())
aoqi@0 253 return false;
aoqi@0 254 if (_s_old->get_index() != _s_new->get_index())
aoqi@0 255 return false;
aoqi@0 256 break;
aoqi@0 257
aoqi@0 258 case Bytecodes::_goto : // fall through
aoqi@0 259 case Bytecodes::_if_acmpeq : // fall through
aoqi@0 260 case Bytecodes::_if_acmpne : // fall through
aoqi@0 261 case Bytecodes::_if_icmpeq : // fall through
aoqi@0 262 case Bytecodes::_if_icmpne : // fall through
aoqi@0 263 case Bytecodes::_if_icmplt : // fall through
aoqi@0 264 case Bytecodes::_if_icmpge : // fall through
aoqi@0 265 case Bytecodes::_if_icmpgt : // fall through
aoqi@0 266 case Bytecodes::_if_icmple : // fall through
aoqi@0 267 case Bytecodes::_ifeq : // fall through
aoqi@0 268 case Bytecodes::_ifne : // fall through
aoqi@0 269 case Bytecodes::_iflt : // fall through
aoqi@0 270 case Bytecodes::_ifge : // fall through
aoqi@0 271 case Bytecodes::_ifgt : // fall through
aoqi@0 272 case Bytecodes::_ifle : // fall through
aoqi@0 273 case Bytecodes::_ifnonnull : // fall through
aoqi@0 274 case Bytecodes::_ifnull : // fall through
aoqi@0 275 case Bytecodes::_jsr : {
aoqi@0 276 int old_ofs = _s_old->bytecode().get_offset_s2(c_old);
aoqi@0 277 int new_ofs = _s_new->bytecode().get_offset_s2(c_new);
aoqi@0 278 if (_switchable_test) {
aoqi@0 279 int old_dest = _s_old->bci() + old_ofs;
aoqi@0 280 int new_dest = _s_new->bci() + new_ofs;
aoqi@0 281 if (old_ofs < 0 && new_ofs < 0) {
aoqi@0 282 if (! _bci_map->old_and_new_locations_same(old_dest, new_dest))
aoqi@0 283 return false;
aoqi@0 284 } else if (old_ofs > 0 && new_ofs > 0) {
aoqi@0 285 _fwd_jmps->append(old_dest);
aoqi@0 286 _fwd_jmps->append(new_dest);
aoqi@0 287 } else {
aoqi@0 288 return false;
aoqi@0 289 }
aoqi@0 290 } else {
aoqi@0 291 if (old_ofs != new_ofs)
aoqi@0 292 return false;
aoqi@0 293 }
aoqi@0 294 break;
aoqi@0 295 }
aoqi@0 296
aoqi@0 297 case Bytecodes::_iinc :
aoqi@0 298 if (_s_old->is_wide() != _s_new->is_wide())
aoqi@0 299 return false;
aoqi@0 300 if (! _s_old->is_wide()) {
aoqi@0 301 // We could use get_index_u1 and get_constant_u1, but it's simpler to grab both bytes at once:
aoqi@0 302 if (Bytes::get_Java_u2(_s_old->bcp() + 1) != Bytes::get_Java_u2(_s_new->bcp() + 1))
aoqi@0 303 return false;
aoqi@0 304 } else {
aoqi@0 305 // We could use get_index_u2 and get_constant_u2, but it's simpler to grab all four bytes at once:
aoqi@0 306 if (Bytes::get_Java_u4(_s_old->bcp() + 1) != Bytes::get_Java_u4(_s_new->bcp() + 1))
aoqi@0 307 return false;
aoqi@0 308 }
aoqi@0 309 break;
aoqi@0 310
aoqi@0 311 case Bytecodes::_goto_w : // fall through
aoqi@0 312 case Bytecodes::_jsr_w : {
aoqi@0 313 int old_ofs = _s_old->bytecode().get_offset_s4(c_old);
aoqi@0 314 int new_ofs = _s_new->bytecode().get_offset_s4(c_new);
aoqi@0 315 if (_switchable_test) {
aoqi@0 316 int old_dest = _s_old->bci() + old_ofs;
aoqi@0 317 int new_dest = _s_new->bci() + new_ofs;
aoqi@0 318 if (old_ofs < 0 && new_ofs < 0) {
aoqi@0 319 if (! _bci_map->old_and_new_locations_same(old_dest, new_dest))
aoqi@0 320 return false;
aoqi@0 321 } else if (old_ofs > 0 && new_ofs > 0) {
aoqi@0 322 _fwd_jmps->append(old_dest);
aoqi@0 323 _fwd_jmps->append(new_dest);
aoqi@0 324 } else {
aoqi@0 325 return false;
aoqi@0 326 }
aoqi@0 327 } else {
aoqi@0 328 if (old_ofs != new_ofs)
aoqi@0 329 return false;
aoqi@0 330 }
aoqi@0 331 break;
aoqi@0 332 }
aoqi@0 333
aoqi@0 334 case Bytecodes::_lookupswitch : // fall through
aoqi@0 335 case Bytecodes::_tableswitch : {
aoqi@0 336 if (_switchable_test) {
aoqi@0 337 address aligned_bcp_old = (address) round_to((intptr_t)_s_old->bcp() + 1, jintSize);
aoqi@0 338 address aligned_bcp_new = (address) round_to((intptr_t)_s_new->bcp() + 1, jintSize);
aoqi@0 339 int default_old = (int) Bytes::get_Java_u4(aligned_bcp_old);
aoqi@0 340 int default_new = (int) Bytes::get_Java_u4(aligned_bcp_new);
aoqi@0 341 _fwd_jmps->append(_s_old->bci() + default_old);
aoqi@0 342 _fwd_jmps->append(_s_new->bci() + default_new);
aoqi@0 343 if (c_old == Bytecodes::_lookupswitch) {
aoqi@0 344 int npairs_old = (int) Bytes::get_Java_u4(aligned_bcp_old + jintSize);
aoqi@0 345 int npairs_new = (int) Bytes::get_Java_u4(aligned_bcp_new + jintSize);
aoqi@0 346 if (npairs_old != npairs_new)
aoqi@0 347 return false;
aoqi@0 348 for (int i = 0; i < npairs_old; i++) {
aoqi@0 349 int match_old = (int) Bytes::get_Java_u4(aligned_bcp_old + (2+2*i)*jintSize);
aoqi@0 350 int match_new = (int) Bytes::get_Java_u4(aligned_bcp_new + (2+2*i)*jintSize);
aoqi@0 351 if (match_old != match_new)
aoqi@0 352 return false;
aoqi@0 353 int ofs_old = (int) Bytes::get_Java_u4(aligned_bcp_old + (2+2*i+1)*jintSize);
aoqi@0 354 int ofs_new = (int) Bytes::get_Java_u4(aligned_bcp_new + (2+2*i+1)*jintSize);
aoqi@0 355 _fwd_jmps->append(_s_old->bci() + ofs_old);
aoqi@0 356 _fwd_jmps->append(_s_new->bci() + ofs_new);
aoqi@0 357 }
aoqi@0 358 } else if (c_old == Bytecodes::_tableswitch) {
aoqi@0 359 int lo_old = (int) Bytes::get_Java_u4(aligned_bcp_old + jintSize);
aoqi@0 360 int lo_new = (int) Bytes::get_Java_u4(aligned_bcp_new + jintSize);
aoqi@0 361 if (lo_old != lo_new)
aoqi@0 362 return false;
aoqi@0 363 int hi_old = (int) Bytes::get_Java_u4(aligned_bcp_old + 2*jintSize);
aoqi@0 364 int hi_new = (int) Bytes::get_Java_u4(aligned_bcp_new + 2*jintSize);
aoqi@0 365 if (hi_old != hi_new)
aoqi@0 366 return false;
aoqi@0 367 for (int i = 0; i < hi_old - lo_old + 1; i++) {
aoqi@0 368 int ofs_old = (int) Bytes::get_Java_u4(aligned_bcp_old + (3+i)*jintSize);
aoqi@0 369 int ofs_new = (int) Bytes::get_Java_u4(aligned_bcp_new + (3+i)*jintSize);
aoqi@0 370 _fwd_jmps->append(_s_old->bci() + ofs_old);
aoqi@0 371 _fwd_jmps->append(_s_new->bci() + ofs_new);
aoqi@0 372 }
aoqi@0 373 }
aoqi@0 374 } else { // !_switchable_test, can use fast rough compare
aoqi@0 375 int len_old = _s_old->instruction_size();
aoqi@0 376 int len_new = _s_new->instruction_size();
aoqi@0 377 if (len_old != len_new)
aoqi@0 378 return false;
aoqi@0 379 if (memcmp(_s_old->bcp(), _s_new->bcp(), len_old) != 0)
aoqi@0 380 return false;
aoqi@0 381 }
aoqi@0 382 break;
aoqi@0 383 }
aoqi@0 384 }
aoqi@0 385
aoqi@0 386 return true;
aoqi@0 387 }
aoqi@0 388
aoqi@0 389 bool MethodComparator::pool_constants_same(int cpi_old, int cpi_new) {
aoqi@0 390 constantTag tag_old = _old_cp->tag_at(cpi_old);
aoqi@0 391 constantTag tag_new = _new_cp->tag_at(cpi_new);
aoqi@0 392 if (tag_old.is_int() || tag_old.is_float()) {
aoqi@0 393 if (tag_old.value() != tag_new.value())
aoqi@0 394 return false;
aoqi@0 395 if (tag_old.is_int()) {
aoqi@0 396 if (_old_cp->int_at(cpi_old) != _new_cp->int_at(cpi_new))
aoqi@0 397 return false;
aoqi@0 398 } else {
aoqi@0 399 // Use jint_cast to compare the bits rather than numerical values.
aoqi@0 400 // This makes a difference for NaN constants.
aoqi@0 401 if (jint_cast(_old_cp->float_at(cpi_old)) != jint_cast(_new_cp->float_at(cpi_new)))
aoqi@0 402 return false;
aoqi@0 403 }
aoqi@0 404 } else if (tag_old.is_string() && tag_new.is_string()) {
aoqi@0 405 if (strcmp(_old_cp->string_at_noresolve(cpi_old),
aoqi@0 406 _new_cp->string_at_noresolve(cpi_new)) != 0)
aoqi@0 407 return false;
aoqi@0 408 } else if (tag_old.is_klass() || tag_old.is_unresolved_klass()) {
aoqi@0 409 // tag_old should be klass - 4881222
aoqi@0 410 if (! (tag_new.is_unresolved_klass() || tag_new.is_klass()))
aoqi@0 411 return false;
aoqi@0 412 if (_old_cp->klass_at_noresolve(cpi_old) !=
aoqi@0 413 _new_cp->klass_at_noresolve(cpi_new))
aoqi@0 414 return false;
aoqi@0 415 } else if (tag_old.is_method_type() && tag_new.is_method_type()) {
aoqi@0 416 int mti_old = _old_cp->method_type_index_at(cpi_old);
aoqi@0 417 int mti_new = _new_cp->method_type_index_at(cpi_new);
aoqi@0 418 if ((_old_cp->symbol_at(mti_old) != _new_cp->symbol_at(mti_new)))
aoqi@0 419 return false;
aoqi@0 420 } else if (tag_old.is_method_handle() && tag_new.is_method_handle()) {
aoqi@0 421 if (_old_cp->method_handle_ref_kind_at(cpi_old) !=
aoqi@0 422 _new_cp->method_handle_ref_kind_at(cpi_new))
aoqi@0 423 return false;
aoqi@0 424 int mhi_old = _old_cp->method_handle_index_at(cpi_old);
aoqi@0 425 int mhi_new = _new_cp->method_handle_index_at(cpi_new);
aoqi@0 426 if ((_old_cp->uncached_klass_ref_at_noresolve(mhi_old) != _new_cp->uncached_klass_ref_at_noresolve(mhi_new)) ||
aoqi@0 427 (_old_cp->uncached_name_ref_at(mhi_old) != _new_cp->uncached_name_ref_at(mhi_new)) ||
aoqi@0 428 (_old_cp->uncached_signature_ref_at(mhi_old) != _new_cp->uncached_signature_ref_at(mhi_new)))
aoqi@0 429 return false;
aoqi@0 430 } else {
aoqi@0 431 return false; // unknown tag
aoqi@0 432 }
aoqi@0 433 return true;
aoqi@0 434 }
aoqi@0 435
aoqi@0 436
aoqi@0 437 int MethodComparator::check_stack_and_locals_size(Method* old_method, Method* new_method) {
aoqi@0 438 if (old_method->max_stack() != new_method->max_stack()) {
aoqi@0 439 return 1;
aoqi@0 440 } else if (old_method->max_locals() != new_method->max_locals()) {
aoqi@0 441 return 2;
aoqi@0 442 } else if (old_method->size_of_parameters() != new_method->size_of_parameters()) {
aoqi@0 443 return 3;
aoqi@0 444 } else return 0;
aoqi@0 445 }

mercurial