comparison src/share/vm/interpreter/interpreter.cpp @ 2142:8012aa3ccede

4926272: methodOopDesc::method_from_bcp is unsafe Reviewed-by: coleenp, jrose, kvn, dcubed
author never
date Thu, 13 Jan 2011 22:15:41 -0800
parents f95d63e2154a
children 3582bf76420e
comparison
equal deleted inserted replaced
2130:34d64ad817f4 2142:8012aa3ccede
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
235 235
236 236
237 // Return true if the interpreter can prove that the given bytecode has 237 // Return true if the interpreter can prove that the given bytecode has
238 // not yet been executed (in Java semantics, not in actual operation). 238 // not yet been executed (in Java semantics, not in actual operation).
239 bool AbstractInterpreter::is_not_reached(methodHandle method, int bci) { 239 bool AbstractInterpreter::is_not_reached(methodHandle method, int bci) {
240 address bcp = method->bcp_from(bci); 240 Bytecodes::Code code = method()->code_at(bci);
241 Bytecodes::Code code = Bytecodes::code_at(bcp, method()); 241
242 242 if (!Bytecodes::must_rewrite(code)) {
243 if (!Bytecode_at(bcp)->must_rewrite(code)) {
244 // might have been reached 243 // might have been reached
245 return false; 244 return false;
246 } 245 }
247 246
248 // the bytecode might not be rewritten if the method is an accessor, etc. 247 // the bytecode might not be rewritten if the method is an accessor, etc.
284 // Deoptimization support 283 // Deoptimization support
285 284
286 // If deoptimization happens, this function returns the point of next bytecode to continue execution 285 // If deoptimization happens, this function returns the point of next bytecode to continue execution
287 address AbstractInterpreter::deopt_continue_after_entry(methodOop method, address bcp, int callee_parameters, bool is_top_frame) { 286 address AbstractInterpreter::deopt_continue_after_entry(methodOop method, address bcp, int callee_parameters, bool is_top_frame) {
288 assert(method->contains(bcp), "just checkin'"); 287 assert(method->contains(bcp), "just checkin'");
289 Bytecodes::Code code = Bytecodes::java_code_at(bcp); 288 Bytecodes::Code code = Bytecodes::java_code_at(method, bcp);
290 assert(!Interpreter::bytecode_should_reexecute(code), "should not reexecute"); 289 assert(!Interpreter::bytecode_should_reexecute(code), "should not reexecute");
291 int bci = method->bci_from(bcp); 290 int bci = method->bci_from(bcp);
292 int length = -1; // initial value for debugging 291 int length = -1; // initial value for debugging
293 // compute continuation length 292 // compute continuation length
294 length = Bytecodes::length_at(bcp); 293 length = Bytecodes::length_at(method, bcp);
295 // compute result type 294 // compute result type
296 BasicType type = T_ILLEGAL; 295 BasicType type = T_ILLEGAL;
297 296
298 switch (code) { 297 switch (code) {
299 case Bytecodes::_invokevirtual : 298 case Bytecodes::_invokevirtual :
301 case Bytecodes::_invokestatic : 300 case Bytecodes::_invokestatic :
302 case Bytecodes::_invokeinterface: { 301 case Bytecodes::_invokeinterface: {
303 Thread *thread = Thread::current(); 302 Thread *thread = Thread::current();
304 ResourceMark rm(thread); 303 ResourceMark rm(thread);
305 methodHandle mh(thread, method); 304 methodHandle mh(thread, method);
306 type = Bytecode_invoke_at(mh, bci)->result_type(thread); 305 type = Bytecode_invoke(mh, bci).result_type(thread);
307 // since the cache entry might not be initialized: 306 // since the cache entry might not be initialized:
308 // (NOT needed for the old calling convension) 307 // (NOT needed for the old calling convension)
309 if (!is_top_frame) { 308 if (!is_top_frame) {
310 int index = Bytes::get_native_u2(bcp+1); 309 int index = Bytes::get_native_u2(bcp+1);
311 method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters); 310 method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters);
315 314
316 case Bytecodes::_invokedynamic: { 315 case Bytecodes::_invokedynamic: {
317 Thread *thread = Thread::current(); 316 Thread *thread = Thread::current();
318 ResourceMark rm(thread); 317 ResourceMark rm(thread);
319 methodHandle mh(thread, method); 318 methodHandle mh(thread, method);
320 type = Bytecode_invoke_at(mh, bci)->result_type(thread); 319 type = Bytecode_invoke(mh, bci).result_type(thread);
321 // since the cache entry might not be initialized: 320 // since the cache entry might not be initialized:
322 // (NOT needed for the old calling convension) 321 // (NOT needed for the old calling convension)
323 if (!is_top_frame) { 322 if (!is_top_frame) {
324 int index = Bytes::get_native_u4(bcp+1); 323 int index = Bytes::get_native_u4(bcp+1);
325 method->constants()->cache()->secondary_entry_at(index)->set_parameter_size(callee_parameters); 324 method->constants()->cache()->secondary_entry_at(index)->set_parameter_size(callee_parameters);
332 case Bytecodes::_ldc2_w: 331 case Bytecodes::_ldc2_w:
333 { 332 {
334 Thread *thread = Thread::current(); 333 Thread *thread = Thread::current();
335 ResourceMark rm(thread); 334 ResourceMark rm(thread);
336 methodHandle mh(thread, method); 335 methodHandle mh(thread, method);
337 type = Bytecode_loadconstant_at(mh, bci)->result_type(); 336 type = Bytecode_loadconstant(mh, bci).result_type();
338 break; 337 break;
339 } 338 }
340 339
341 default: 340 default:
342 type = Bytecodes::result_type(code); 341 type = Bytecodes::result_type(code);
354 // the bytecode. 353 // the bytecode.
355 // Note: Bytecodes::_athrow is a special case in that it does not return 354 // Note: Bytecodes::_athrow is a special case in that it does not return
356 // Interpreter::deopt_entry(vtos, 0) like others 355 // Interpreter::deopt_entry(vtos, 0) like others
357 address AbstractInterpreter::deopt_reexecute_entry(methodOop method, address bcp) { 356 address AbstractInterpreter::deopt_reexecute_entry(methodOop method, address bcp) {
358 assert(method->contains(bcp), "just checkin'"); 357 assert(method->contains(bcp), "just checkin'");
359 Bytecodes::Code code = Bytecodes::java_code_at(bcp); 358 Bytecodes::Code code = Bytecodes::java_code_at(method, bcp);
360 #ifdef COMPILER1 359 #ifdef COMPILER1
361 if(code == Bytecodes::_athrow ) { 360 if(code == Bytecodes::_athrow ) {
362 return Interpreter::rethrow_exception_entry(); 361 return Interpreter::rethrow_exception_entry();
363 } 362 }
364 #endif /* COMPILER1 */ 363 #endif /* COMPILER1 */