267 #endif // PRODUCT 268 269 static BasicType constant_pool_type(methodOop method, int index) { 270 constantTag tag = method->constants()->tag_at(index); 271 if (tag.is_int ()) return T_INT; 272 else if (tag.is_float ()) return T_FLOAT; 273 else if (tag.is_long ()) return T_LONG; 274 else if (tag.is_double ()) return T_DOUBLE; 275 else if (tag.is_string ()) return T_OBJECT; 276 else if (tag.is_unresolved_string()) return T_OBJECT; 277 else if (tag.is_klass ()) return T_OBJECT; 278 else if (tag.is_unresolved_klass ()) return T_OBJECT; 279 ShouldNotReachHere(); 280 return T_ILLEGAL; 281 } 282 283 284 //------------------------------------------------------------------------------------------------------------------------ 285 // Deoptimization support 286 287 // If deoptimization happens, this method returns the point where to continue in 288 // interpreter. For calls (invokexxxx, newxxxx) the continuation is at next 289 // bci and the top of stack is in eax/edx/FPU tos. 290 // For putfield/getfield, put/getstatic, the continuation is at the same 291 // bci and the TOS is on stack. 292 293 // Note: deopt_entry(type, 0) means reexecute bytecode 294 // deopt_entry(type, length) means continue at next bytecode 295 296 address AbstractInterpreter::continuation_for(methodOop method, address bcp, int callee_parameters, bool is_top_frame, bool& use_next_mdp) { 297 assert(method->contains(bcp), "just checkin'"); 298 Bytecodes::Code code = Bytecodes::java_code_at(bcp); 299 int bci = method->bci_from(bcp); 300 int length = -1; // initial value for debugging 301 // compute continuation length 302 length = Bytecodes::length_at(bcp); 303 // compute result type 304 BasicType type = T_ILLEGAL; 305 // when continuing after a compiler safepoint, re-execute the bytecode 306 // (an invoke is continued after the safepoint) 307 use_next_mdp = true; 308 switch (code) { 309 case Bytecodes::_lookupswitch: 310 case Bytecodes::_tableswitch: 311 case Bytecodes::_fast_binaryswitch: 312 case Bytecodes::_fast_linearswitch: 313 // recompute condtional expression folded into _if<cond> 314 case Bytecodes::_lcmp : 315 case Bytecodes::_fcmpl : 316 case Bytecodes::_fcmpg : 317 case Bytecodes::_dcmpl : 318 case Bytecodes::_dcmpg : 319 case Bytecodes::_ifnull : 320 case Bytecodes::_ifnonnull : 321 case Bytecodes::_goto : 322 case Bytecodes::_goto_w : 323 case Bytecodes::_ifeq : 324 case Bytecodes::_ifne : 325 case Bytecodes::_iflt : 326 case Bytecodes::_ifge : 327 case Bytecodes::_ifgt : 328 case Bytecodes::_ifle : 329 case Bytecodes::_if_icmpeq : 330 case Bytecodes::_if_icmpne : 331 case Bytecodes::_if_icmplt : 332 case Bytecodes::_if_icmpge : 333 case Bytecodes::_if_icmpgt : 334 case Bytecodes::_if_icmple : 335 case Bytecodes::_if_acmpeq : 336 case Bytecodes::_if_acmpne : 337 // special cases 338 case Bytecodes::_getfield : 339 case Bytecodes::_putfield : 340 case Bytecodes::_getstatic : 341 case Bytecodes::_putstatic : 342 case Bytecodes::_aastore : 343 // reexecute the operation and TOS value is on stack 344 assert(is_top_frame, "must be top frame"); 345 use_next_mdp = false; 346 return Interpreter::deopt_entry(vtos, 0); 347 break; 348 349 #ifdef COMPILER1 350 case Bytecodes::_athrow : 351 assert(is_top_frame, "must be top frame"); 352 use_next_mdp = false; 353 return Interpreter::rethrow_exception_entry(); 354 break; 355 #endif /* COMPILER1 */ 356 357 case Bytecodes::_invokevirtual : 358 case Bytecodes::_invokespecial : 359 case Bytecodes::_invokestatic : 360 case Bytecodes::_invokeinterface: { 361 Thread *thread = Thread::current(); 362 ResourceMark rm(thread); 363 methodHandle mh(thread, method); 364 type = Bytecode_invoke_at(mh, bci)->result_type(thread); 365 // since the cache entry might not be initialized: 366 // (NOT needed for the old calling convension) 367 if (!is_top_frame) { 368 int index = Bytes::get_native_u2(bcp+1); 369 method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters); 370 } 371 break; 372 } 373 374 case Bytecodes::_ldc : 375 type = constant_pool_type( method, *(bcp+1) ); 376 break; 377 378 case Bytecodes::_ldc_w : // fall through 379 case Bytecodes::_ldc2_w: 380 type = constant_pool_type( method, Bytes::get_Java_u2(bcp+1) ); 381 break; 382 383 default: 384 type = Bytecodes::result_type(code); 385 break; 386 } 387 388 // return entry point for computed continuation state & bytecode length 389 return 390 is_top_frame 391 ? Interpreter::deopt_entry (as_TosState(type), length) 392 : Interpreter::return_entry(as_TosState(type), length); 393 } 394 395 void AbstractInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { 396 // Quick & dirty stack overflow checking: bang the stack & handle trap. 397 // Note that we do the banging after the frame is setup, since the exception 398 // handling code expects to find a valid interpreter frame on the stack. 399 // Doing the banging earlier fails if the caller frame is not an interpreter 400 // frame. 401 // (Also, the exception throwing code expects to unlock any synchronized 402 // method receiever, so do the banging after locking the receiver.) 403 404 // Bang each page in the shadow zone. We can't assume it's been done for 405 // an interpreter frame with greater than a page of locals, so each page 406 // needs to be checked. Only true for non-native. 407 if (UseStackBanging) { 408 const int start_page = native_call ? StackShadowPages : 1; 409 const int page_size = os::vm_page_size(); 410 for (int pages = start_page; pages <= StackShadowPages ; pages++) { 411 __ bang_stack_with_offset(pages*page_size); 412 } | 267 #endif // PRODUCT 268 269 static BasicType constant_pool_type(methodOop method, int index) { 270 constantTag tag = method->constants()->tag_at(index); 271 if (tag.is_int ()) return T_INT; 272 else if (tag.is_float ()) return T_FLOAT; 273 else if (tag.is_long ()) return T_LONG; 274 else if (tag.is_double ()) return T_DOUBLE; 275 else if (tag.is_string ()) return T_OBJECT; 276 else if (tag.is_unresolved_string()) return T_OBJECT; 277 else if (tag.is_klass ()) return T_OBJECT; 278 else if (tag.is_unresolved_klass ()) return T_OBJECT; 279 ShouldNotReachHere(); 280 return T_ILLEGAL; 281 } 282 283 284 //------------------------------------------------------------------------------------------------------------------------ 285 // Deoptimization support 286 287 // If deoptimization happens, this function returns the point of next bytecode to continue execution 288 address AbstractInterpreter::deopt_continue_after_entry(methodOop method, address bcp, int callee_parameters, bool is_top_frame) { 289 assert(method->contains(bcp), "just checkin'"); 290 Bytecodes::Code code = Bytecodes::java_code_at(bcp); 291 assert(!Interpreter::bytecode_should_reexecute(code), "should not reexecute"); 292 int bci = method->bci_from(bcp); 293 int length = -1; // initial value for debugging 294 // compute continuation length 295 length = Bytecodes::length_at(bcp); 296 // compute result type 297 BasicType type = T_ILLEGAL; 298 299 switch (code) { 300 case Bytecodes::_invokevirtual : 301 case Bytecodes::_invokespecial : 302 case Bytecodes::_invokestatic : 303 case Bytecodes::_invokeinterface: { 304 Thread *thread = Thread::current(); 305 ResourceMark rm(thread); 306 methodHandle mh(thread, method); 307 type = Bytecode_invoke_at(mh, bci)->result_type(thread); 308 // since the cache entry might not be initialized: 309 // (NOT needed for the old calling convension) 310 if (!is_top_frame) { 311 int index = Bytes::get_native_u2(bcp+1); 312 method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters); 313 } 314 break; 315 } 316 317 case Bytecodes::_ldc : 318 type = constant_pool_type( method, *(bcp+1) ); 319 break; 320 321 case Bytecodes::_ldc_w : // fall through 322 case Bytecodes::_ldc2_w: 323 type = constant_pool_type( method, Bytes::get_Java_u2(bcp+1) ); 324 break; 325 326 default: 327 type = Bytecodes::result_type(code); 328 break; 329 } 330 331 // return entry point for computed continuation state & bytecode length 332 return 333 is_top_frame 334 ? Interpreter::deopt_entry (as_TosState(type), length) 335 : Interpreter::return_entry(as_TosState(type), length); 336 } 337 338 // If deoptimization happens, this function returns the point where the interpreter reexecutes 339 // the bytecode. 340 // Note: Bytecodes::_athrow is a special case in that it does not return 341 // Interpreter::deopt_entry(vtos, 0) like others 342 address AbstractInterpreter::deopt_reexecute_entry(methodOop method, address bcp) { 343 assert(method->contains(bcp), "just checkin'"); 344 Bytecodes::Code code = Bytecodes::java_code_at(bcp); 345 #ifdef COMPILER1 346 if(code == Bytecodes::_athrow ) { 347 return Interpreter::rethrow_exception_entry(); 348 } 349 #endif /* COMPILER1 */ 350 return Interpreter::deopt_entry(vtos, 0); 351 } 352 353 // If deoptimization happens, the interpreter should reexecute these bytecodes. 354 // This function mainly helps the compilers to set up the reexecute bit. 355 bool AbstractInterpreter::bytecode_should_reexecute(Bytecodes::Code code) { 356 switch (code) { 357 case Bytecodes::_lookupswitch: 358 case Bytecodes::_tableswitch: 359 case Bytecodes::_fast_binaryswitch: 360 case Bytecodes::_fast_linearswitch: 361 // recompute condtional expression folded into _if<cond> 362 case Bytecodes::_lcmp : 363 case Bytecodes::_fcmpl : 364 case Bytecodes::_fcmpg : 365 case Bytecodes::_dcmpl : 366 case Bytecodes::_dcmpg : 367 case Bytecodes::_ifnull : 368 case Bytecodes::_ifnonnull : 369 case Bytecodes::_goto : 370 case Bytecodes::_goto_w : 371 case Bytecodes::_ifeq : 372 case Bytecodes::_ifne : 373 case Bytecodes::_iflt : 374 case Bytecodes::_ifge : 375 case Bytecodes::_ifgt : 376 case Bytecodes::_ifle : 377 case Bytecodes::_if_icmpeq : 378 case Bytecodes::_if_icmpne : 379 case Bytecodes::_if_icmplt : 380 case Bytecodes::_if_icmpge : 381 case Bytecodes::_if_icmpgt : 382 case Bytecodes::_if_icmple : 383 case Bytecodes::_if_acmpeq : 384 case Bytecodes::_if_acmpne : 385 // special cases 386 case Bytecodes::_getfield : 387 case Bytecodes::_putfield : 388 case Bytecodes::_getstatic : 389 case Bytecodes::_putstatic : 390 case Bytecodes::_aastore : 391 #ifdef COMPILER1 392 //special case of reexecution 393 case Bytecodes::_athrow : 394 #endif 395 return true; 396 397 default: 398 return false; 399 } 400 } 401 402 void AbstractInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { 403 // Quick & dirty stack overflow checking: bang the stack & handle trap. 404 // Note that we do the banging after the frame is setup, since the exception 405 // handling code expects to find a valid interpreter frame on the stack. 406 // Doing the banging earlier fails if the caller frame is not an interpreter 407 // frame. 408 // (Also, the exception throwing code expects to unlock any synchronized 409 // method receiever, so do the banging after locking the receiver.) 410 411 // Bang each page in the shadow zone. We can't assume it's been done for 412 // an interpreter frame with greater than a page of locals, so each page 413 // needs to be checked. Only true for non-native. 414 if (UseStackBanging) { 415 const int start_page = native_call ? StackShadowPages : 1; 416 const int page_size = os::vm_page_size(); 417 for (int pages = start_page; pages <= StackShadowPages ; pages++) { 418 __ bang_stack_with_offset(pages*page_size); 419 } |