annotate src/share/vm/prims/methodComparator.cpp @ 13052:3cb736f232c7

8185301: [MVT] Add JVM support for -Dvalhalla.mangleClassInfo Summary: Introduction of JVM_CONSTANT_Value to support MVT's name mangling specification for value types Reviewed-by: acorn, dsimms
author lfoltan
date Tue, 25 Jul 2017 16:57:58 -0400
parents 0e3de00effac
children bc075a2f87ad
rev   line source
duke@0 1 /*
lfoltan@13052 2 * Copyright (c) 2000, 2017, 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
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "oops/oop.inline.hpp"
coleenp@2062 27 #include "oops/symbol.hpp"
stefank@1879 28 #include "prims/methodComparator.hpp"
stefank@1879 29 #include "runtime/handles.inline.hpp"
stefank@1879 30 #include "utilities/globalDefinitions.hpp"
duke@0 31
duke@0 32 BytecodeStream *MethodComparator::_s_old;
duke@0 33 BytecodeStream *MethodComparator::_s_new;
coleenp@3602 34 ConstantPool* MethodComparator::_old_cp;
coleenp@3602 35 ConstantPool* MethodComparator::_new_cp;
duke@0 36
coleenp@3602 37 bool MethodComparator::methods_EMCP(Method* old_method, Method* new_method) {
duke@0 38 if (old_method->code_size() != new_method->code_size())
duke@0 39 return false;
duke@0 40 if (check_stack_and_locals_size(old_method, new_method) != 0) {
rehn@11205 41 if (log_is_enabled(Debug, redefine, class, methodcomparator)) {
rehn@11205 42 ResourceMark rm;
rehn@11205 43 log_debug(redefine, class, methodcomparator)
rehn@11205 44 ("Methods %s non-comparable with diagnosis %d",
rehn@11205 45 old_method->name()->as_C_string(), check_stack_and_locals_size(old_method, new_method));
rehn@11205 46 }
duke@0 47 return false;
duke@0 48 }
duke@0 49
duke@0 50 _old_cp = old_method->constants();
duke@0 51 _new_cp = new_method->constants();
duke@0 52 BytecodeStream s_old(old_method);
duke@0 53 BytecodeStream s_new(new_method);
duke@0 54 _s_old = &s_old;
duke@0 55 _s_new = &s_new;
duke@0 56 Bytecodes::Code c_old, c_new;
duke@0 57
duke@0 58 while ((c_old = s_old.next()) >= 0) {
duke@0 59 if ((c_new = s_new.next()) < 0 || c_old != c_new)
duke@0 60 return false;
duke@0 61
duke@0 62 if (! args_same(c_old, c_new))
duke@0 63 return false;
duke@0 64 }
duke@0 65 return true;
duke@0 66 }
duke@0 67
duke@0 68 bool MethodComparator::args_same(Bytecodes::Code c_old, Bytecodes::Code c_new) {
duke@0 69 // BytecodeStream returns the correct standard Java bytecodes for various "fast"
duke@0 70 // bytecode versions, so we don't have to bother about them here..
duke@0 71 switch (c_old) {
duke@0 72 case Bytecodes::_new : // fall through
duke@0 73 case Bytecodes::_anewarray : // fall through
duke@0 74 case Bytecodes::_multianewarray : // fall through
duke@0 75 case Bytecodes::_checkcast : // fall through
duke@0 76 case Bytecodes::_instanceof : {
jrose@1485 77 u2 cpi_old = _s_old->get_index_u2();
jrose@1485 78 u2 cpi_new = _s_new->get_index_u2();
duke@0 79 if ((_old_cp->klass_at_noresolve(cpi_old) != _new_cp->klass_at_noresolve(cpi_new)))
duke@0 80 return false;
duke@0 81 if (c_old == Bytecodes::_multianewarray &&
duke@0 82 *(jbyte*)(_s_old->bcp() + 3) != *(jbyte*)(_s_new->bcp() + 3))
duke@0 83 return false;
duke@0 84 break;
duke@0 85 }
duke@0 86
duke@0 87 case Bytecodes::_getstatic : // fall through
duke@0 88 case Bytecodes::_putstatic : // fall through
duke@0 89 case Bytecodes::_getfield : // fall through
duke@0 90 case Bytecodes::_putfield : // fall through
duke@0 91 case Bytecodes::_invokevirtual : // fall through
duke@0 92 case Bytecodes::_invokespecial : // fall through
duke@0 93 case Bytecodes::_invokestatic : // fall through
duke@0 94 case Bytecodes::_invokeinterface : {
jrose@1833 95 int cpci_old = _s_old->get_index_u2_cpcache();
jrose@1833 96 int cpci_new = _s_new->get_index_u2_cpcache();
duke@0 97 // Check if the names of classes, field/method names and signatures at these indexes
duke@0 98 // are the same. Indices which are really into constantpool cache (rather than constant
duke@0 99 // pool itself) are accepted by the constantpool query routines below.
duke@0 100 if ((_old_cp->klass_ref_at_noresolve(cpci_old) != _new_cp->klass_ref_at_noresolve(cpci_new)) ||
duke@0 101 (_old_cp->name_ref_at(cpci_old) != _new_cp->name_ref_at(cpci_new)) ||
duke@0 102 (_old_cp->signature_ref_at(cpci_old) != _new_cp->signature_ref_at(cpci_new)))
duke@0 103 return false;
duke@0 104 break;
duke@0 105 }
jrose@1833 106 case Bytecodes::_invokedynamic: {
jrose@1833 107 int cpci_old = _s_old->get_index_u4();
jrose@1833 108 int cpci_new = _s_new->get_index_u4();
coleenp@3602 109
jrose@1833 110 // Check if the names of classes, field/method names and signatures at these indexes
jrose@1833 111 // are the same. Indices which are really into constantpool cache (rather than constant
jrose@1833 112 // pool itself) are accepted by the constantpool query routines below.
jrose@1833 113 if ((_old_cp->name_ref_at(cpci_old) != _new_cp->name_ref_at(cpci_new)) ||
jrose@1833 114 (_old_cp->signature_ref_at(cpci_old) != _new_cp->signature_ref_at(cpci_new)))
jrose@1833 115 return false;
coleenp@3602 116
coleenp@3602 117 // Translate object indexes to constant pool cache indexes.
coleenp@3602 118 cpci_old = _old_cp->invokedynamic_cp_cache_index(cpci_old);
coleenp@3602 119 cpci_new = _new_cp->invokedynamic_cp_cache_index(cpci_new);
coleenp@3602 120
coleenp@3602 121 int cpi_old = _old_cp->cache()->entry_at(cpci_old)->constant_pool_index();
coleenp@3602 122 int cpi_new = _new_cp->cache()->entry_at(cpci_new)->constant_pool_index();
jrose@1833 123 int bsm_old = _old_cp->invoke_dynamic_bootstrap_method_ref_index_at(cpi_old);
jrose@1833 124 int bsm_new = _new_cp->invoke_dynamic_bootstrap_method_ref_index_at(cpi_new);
jrose@1833 125 if (!pool_constants_same(bsm_old, bsm_new))
jrose@1833 126 return false;
jrose@1833 127 int cnt_old = _old_cp->invoke_dynamic_argument_count_at(cpi_old);
jrose@1833 128 int cnt_new = _new_cp->invoke_dynamic_argument_count_at(cpi_new);
jrose@1833 129 if (cnt_old != cnt_new)
jrose@1833 130 return false;
jrose@1833 131 for (int arg_i = 0; arg_i < cnt_old; arg_i++) {
jrose@1833 132 int idx_old = _old_cp->invoke_dynamic_argument_index_at(cpi_old, arg_i);
jrose@1833 133 int idx_new = _new_cp->invoke_dynamic_argument_index_at(cpi_new, arg_i);
jrose@1833 134 if (!pool_constants_same(idx_old, idx_new))
jrose@1833 135 return false;
jrose@1833 136 }
jrose@1833 137 break;
jrose@1833 138 }
duke@0 139
duke@0 140 case Bytecodes::_ldc : // fall through
duke@0 141 case Bytecodes::_ldc_w : {
never@2027 142 Bytecode_loadconstant ldc_old(_s_old->method(), _s_old->bci());
never@2027 143 Bytecode_loadconstant ldc_new(_s_new->method(), _s_new->bci());
never@2027 144 int cpi_old = ldc_old.pool_index();
never@2027 145 int cpi_new = ldc_new.pool_index();
jrose@1833 146 if (!pool_constants_same(cpi_old, cpi_new))
jrose@1833 147 return false;
duke@0 148 break;
duke@0 149 }
duke@0 150
duke@0 151 case Bytecodes::_ldc2_w : {
jrose@1485 152 u2 cpi_old = _s_old->get_index_u2();
jrose@1485 153 u2 cpi_new = _s_new->get_index_u2();
duke@0 154 constantTag tag_old = _old_cp->tag_at(cpi_old);
duke@0 155 constantTag tag_new = _new_cp->tag_at(cpi_new);
duke@0 156 if (tag_old.value() != tag_new.value())
duke@0 157 return false;
duke@0 158 if (tag_old.is_long()) {
duke@0 159 if (_old_cp->long_at(cpi_old) != _new_cp->long_at(cpi_new))
duke@0 160 return false;
duke@0 161 } else {
jrose@1494 162 // Use jlong_cast to compare the bits rather than numerical values.
jrose@1494 163 // This makes a difference for NaN constants.
jrose@1494 164 if (jlong_cast(_old_cp->double_at(cpi_old)) != jlong_cast(_new_cp->double_at(cpi_new)))
duke@0 165 return false;
duke@0 166 }
duke@0 167 break;
duke@0 168 }
duke@0 169
duke@0 170 case Bytecodes::_bipush :
duke@0 171 if (_s_old->bcp()[1] != _s_new->bcp()[1])
duke@0 172 return false;
duke@0 173 break;
duke@0 174
duke@0 175 case Bytecodes::_sipush :
jrose@1485 176 if (_s_old->get_index_u2() != _s_new->get_index_u2())
duke@0 177 return false;
duke@0 178 break;
duke@0 179
duke@0 180 case Bytecodes::_aload : // fall through
duke@0 181 case Bytecodes::_astore : // fall through
duke@0 182 case Bytecodes::_dload : // fall through
duke@0 183 case Bytecodes::_dstore : // fall through
duke@0 184 case Bytecodes::_fload : // fall through
duke@0 185 case Bytecodes::_fstore : // fall through
duke@0 186 case Bytecodes::_iload : // fall through
duke@0 187 case Bytecodes::_istore : // fall through
duke@0 188 case Bytecodes::_lload : // fall through
duke@0 189 case Bytecodes::_lstore : // fall through
duke@0 190 case Bytecodes::_ret :
duke@0 191 if (_s_old->is_wide() != _s_new->is_wide())
duke@0 192 return false;
duke@0 193 if (_s_old->get_index() != _s_new->get_index())
duke@0 194 return false;
duke@0 195 break;
duke@0 196
duke@0 197 case Bytecodes::_goto : // fall through
duke@0 198 case Bytecodes::_if_acmpeq : // fall through
duke@0 199 case Bytecodes::_if_acmpne : // fall through
duke@0 200 case Bytecodes::_if_icmpeq : // fall through
duke@0 201 case Bytecodes::_if_icmpne : // fall through
duke@0 202 case Bytecodes::_if_icmplt : // fall through
duke@0 203 case Bytecodes::_if_icmpge : // fall through
duke@0 204 case Bytecodes::_if_icmpgt : // fall through
duke@0 205 case Bytecodes::_if_icmple : // fall through
duke@0 206 case Bytecodes::_ifeq : // fall through
duke@0 207 case Bytecodes::_ifne : // fall through
duke@0 208 case Bytecodes::_iflt : // fall through
duke@0 209 case Bytecodes::_ifge : // fall through
duke@0 210 case Bytecodes::_ifgt : // fall through
duke@0 211 case Bytecodes::_ifle : // fall through
duke@0 212 case Bytecodes::_ifnonnull : // fall through
duke@0 213 case Bytecodes::_ifnull : // fall through
duke@0 214 case Bytecodes::_jsr : {
never@2027 215 int old_ofs = _s_old->bytecode().get_offset_s2(c_old);
never@2027 216 int new_ofs = _s_new->bytecode().get_offset_s2(c_new);
stuefe@10254 217 if (old_ofs != new_ofs)
stuefe@10254 218 return false;
duke@0 219 break;
duke@0 220 }
duke@0 221
duke@0 222 case Bytecodes::_iinc :
duke@0 223 if (_s_old->is_wide() != _s_new->is_wide())
duke@0 224 return false;
duke@0 225 if (! _s_old->is_wide()) {
jrose@1485 226 // We could use get_index_u1 and get_constant_u1, but it's simpler to grab both bytes at once:
jrose@1485 227 if (Bytes::get_Java_u2(_s_old->bcp() + 1) != Bytes::get_Java_u2(_s_new->bcp() + 1))
duke@0 228 return false;
duke@0 229 } else {
jrose@1485 230 // We could use get_index_u2 and get_constant_u2, but it's simpler to grab all four bytes at once:
duke@0 231 if (Bytes::get_Java_u4(_s_old->bcp() + 1) != Bytes::get_Java_u4(_s_new->bcp() + 1))
duke@0 232 return false;
duke@0 233 }
duke@0 234 break;
duke@0 235
duke@0 236 case Bytecodes::_goto_w : // fall through
duke@0 237 case Bytecodes::_jsr_w : {
never@2027 238 int old_ofs = _s_old->bytecode().get_offset_s4(c_old);
never@2027 239 int new_ofs = _s_new->bytecode().get_offset_s4(c_new);
stuefe@10254 240 if (old_ofs != new_ofs)
stuefe@10254 241 return false;
duke@0 242 break;
duke@0 243 }
duke@0 244
duke@0 245 case Bytecodes::_lookupswitch : // fall through
duke@0 246 case Bytecodes::_tableswitch : {
stuefe@10254 247 int len_old = _s_old->instruction_size();
stuefe@10254 248 int len_new = _s_new->instruction_size();
stuefe@10254 249 if (len_old != len_new)
stuefe@10254 250 return false;
stuefe@10254 251 if (memcmp(_s_old->bcp(), _s_new->bcp(), len_old) != 0)
stuefe@10254 252 return false;
duke@0 253 break;
duke@0 254 }
duke@0 255 }
duke@0 256
duke@0 257 return true;
duke@0 258 }
duke@0 259
jrose@1833 260 bool MethodComparator::pool_constants_same(int cpi_old, int cpi_new) {
jrose@1833 261 constantTag tag_old = _old_cp->tag_at(cpi_old);
jrose@1833 262 constantTag tag_new = _new_cp->tag_at(cpi_new);
jrose@1833 263 if (tag_old.is_int() || tag_old.is_float()) {
jrose@1833 264 if (tag_old.value() != tag_new.value())
jrose@1833 265 return false;
jrose@1833 266 if (tag_old.is_int()) {
jrose@1833 267 if (_old_cp->int_at(cpi_old) != _new_cp->int_at(cpi_new))
jrose@1833 268 return false;
jrose@1833 269 } else {
jrose@1833 270 // Use jint_cast to compare the bits rather than numerical values.
jrose@1833 271 // This makes a difference for NaN constants.
jrose@1833 272 if (jint_cast(_old_cp->float_at(cpi_old)) != jint_cast(_new_cp->float_at(cpi_new)))
jrose@1833 273 return false;
jrose@1833 274 }
coleenp@3602 275 } else if (tag_old.is_string() && tag_new.is_string()) {
jrose@1833 276 if (strcmp(_old_cp->string_at_noresolve(cpi_old),
jrose@1833 277 _new_cp->string_at_noresolve(cpi_new)) != 0)
jrose@1833 278 return false;
sspitsyn@7769 279 if (_old_cp->is_pseudo_string_at(cpi_old) || _new_cp->is_pseudo_string_at(cpi_new))
sspitsyn@7769 280 return (_old_cp->is_pseudo_string_at(cpi_old) == _new_cp->is_pseudo_string_at(cpi_new));
lfoltan@13052 281 } else if (tag_old.is_klass() || tag_old.is_unresolved_klass() ||
lfoltan@13052 282 tag_old.is_value_type() || tag_old.is_unresolved_value_type()) {
jrose@1833 283 // tag_old should be klass - 4881222
lfoltan@13052 284 if (! (tag_new.is_unresolved_klass() || tag_new.is_klass() ||
lfoltan@13052 285 tag_new.is_unresolved_value_type() || tag_new.is_value_type()))
jrose@1833 286 return false;
jrose@1833 287 if (_old_cp->klass_at_noresolve(cpi_old) !=
jrose@1833 288 _new_cp->klass_at_noresolve(cpi_new))
jrose@1833 289 return false;
jrose@1833 290 } else if (tag_old.is_method_type() && tag_new.is_method_type()) {
jrose@1833 291 int mti_old = _old_cp->method_type_index_at(cpi_old);
jrose@1833 292 int mti_new = _new_cp->method_type_index_at(cpi_new);
jrose@1833 293 if ((_old_cp->symbol_at(mti_old) != _new_cp->symbol_at(mti_new)))
jrose@1833 294 return false;
jrose@1833 295 } else if (tag_old.is_method_handle() && tag_new.is_method_handle()) {
jrose@1833 296 if (_old_cp->method_handle_ref_kind_at(cpi_old) !=
jrose@1833 297 _new_cp->method_handle_ref_kind_at(cpi_new))
jrose@1833 298 return false;
jrose@1833 299 int mhi_old = _old_cp->method_handle_index_at(cpi_old);
jrose@1833 300 int mhi_new = _new_cp->method_handle_index_at(cpi_new);
jrose@1833 301 if ((_old_cp->uncached_klass_ref_at_noresolve(mhi_old) != _new_cp->uncached_klass_ref_at_noresolve(mhi_new)) ||
jrose@1833 302 (_old_cp->uncached_name_ref_at(mhi_old) != _new_cp->uncached_name_ref_at(mhi_new)) ||
jrose@1833 303 (_old_cp->uncached_signature_ref_at(mhi_old) != _new_cp->uncached_signature_ref_at(mhi_new)))
jrose@1833 304 return false;
jrose@1833 305 } else {
jrose@1833 306 return false; // unknown tag
jrose@1833 307 }
jrose@1833 308 return true;
jrose@1833 309 }
jrose@1833 310
duke@0 311
coleenp@3602 312 int MethodComparator::check_stack_and_locals_size(Method* old_method, Method* new_method) {
duke@0 313 if (old_method->max_stack() != new_method->max_stack()) {
duke@0 314 return 1;
duke@0 315 } else if (old_method->max_locals() != new_method->max_locals()) {
duke@0 316 return 2;
duke@0 317 } else if (old_method->size_of_parameters() != new_method->size_of_parameters()) {
duke@0 318 return 3;
duke@0 319 } else return 0;
duke@0 320 }