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