374 // -XX:SuppressErrorAt=vframe.cpp:XXX (XXX=following line number) 375 assert(false, "invalid bci or invalid scope desc"); 376 } 377 378 // top-frame will be skipped 379 vframeStream::vframeStream(JavaThread* thread, frame top_frame, 380 bool stop_at_java_call_stub) : vframeStreamCommon(thread) { 381 _stop_at_java_call_stub = stop_at_java_call_stub; 382 383 // skip top frame, as it may not be at safepoint 384 _frame = top_frame.sender(&_reg_map); 385 while (!fill_from_frame()) { 386 _frame = _frame.sender(&_reg_map); 387 } 388 } 389 390 391 // Step back n frames, skip any pseudo frames in between. 392 // This function is used in Class.forName, Class.newInstance, Method.Invoke, 393 // AccessController.doPrivileged. 394 // 395 // NOTE that in JDK 1.4 this has been exposed to Java as 396 // sun.reflect.Reflection.getCallerClass(), which can be inlined. 397 // Inlined versions must match this routine's logic. 398 // Native method prefixing logic does not need to match since 399 // the method names don't match and inlining will not occur. 400 // See, for example, 401 // Parse::inline_native_Reflection_getCallerClass in 402 // opto/library_call.cpp. 403 void vframeStreamCommon::security_get_caller_frame(int depth) { 404 bool use_new_reflection = JDK_Version::is_gte_jdk14x_version() && UseNewReflection; 405 406 while (!at_end()) { 407 if (Universe::reflect_invoke_cache()->is_same_method(method())) { 408 // This is Method.invoke() -- skip it 409 } else if (use_new_reflection && 410 method()->method_holder() 411 ->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass())) { 412 // This is an auxilary frame -- skip it 413 } else if (method()->is_method_handle_intrinsic() || 414 method()->is_compiled_lambda_form()) { 415 // This is an internal adapter frame for method handles -- skip it 416 } else { 417 // This is non-excluded frame, we need to count it against the depth 418 if (depth-- <= 0) { 419 // we have reached the desired depth, we are done 420 break; 421 } 422 } 423 if (method()->is_prefixed_native()) { 424 skip_prefixed_method_and_wrappers(); 425 } else { 426 next(); 427 } 428 } 429 } 430 431 432 void vframeStreamCommon::skip_prefixed_method_and_wrappers() { 433 ResourceMark rm; 434 HandleMark hm; 435 436 int method_prefix_count = 0; 437 char** method_prefixes = JvmtiExport::get_all_native_method_prefixes(&method_prefix_count); 438 KlassHandle prefixed_klass(method()->method_holder()); 439 const char* prefixed_name = method()->name()->as_C_string(); 440 size_t prefixed_name_len = strlen(prefixed_name); 441 int prefix_index = method_prefix_count-1; 442 443 while (!at_end()) { 444 next(); 445 if (method()->method_holder() != prefixed_klass()) { 446 break; // classes don't match, can't be a wrapper 447 } 448 const char* name = method()->name()->as_C_string(); | 374 // -XX:SuppressErrorAt=vframe.cpp:XXX (XXX=following line number) 375 assert(false, "invalid bci or invalid scope desc"); 376 } 377 378 // top-frame will be skipped 379 vframeStream::vframeStream(JavaThread* thread, frame top_frame, 380 bool stop_at_java_call_stub) : vframeStreamCommon(thread) { 381 _stop_at_java_call_stub = stop_at_java_call_stub; 382 383 // skip top frame, as it may not be at safepoint 384 _frame = top_frame.sender(&_reg_map); 385 while (!fill_from_frame()) { 386 _frame = _frame.sender(&_reg_map); 387 } 388 } 389 390 391 // Step back n frames, skip any pseudo frames in between. 392 // This function is used in Class.forName, Class.newInstance, Method.Invoke, 393 // AccessController.doPrivileged. 394 void vframeStreamCommon::security_get_caller_frame(int depth) { 395 assert(depth >= 0, err_msg("invalid depth: %d", depth)); 396 for (int n = 0; !at_end(); security_next()) { 397 if (!method()->is_ignored_by_security_stack_walk()) { 398 if (n == depth) { 399 // We have reached the desired depth; return. 400 return; 401 } 402 n++; // this is a non-skipped frame; count it against the depth 403 } 404 } 405 // NOTE: At this point there were not enough frames on the stack 406 // to walk to depth. Callers of this method have to check for at_end. 407 } 408 409 410 void vframeStreamCommon::security_next() { 411 if (method()->is_prefixed_native()) { 412 skip_prefixed_method_and_wrappers(); // calls next() 413 } else { 414 next(); 415 } 416 } 417 418 419 void vframeStreamCommon::skip_prefixed_method_and_wrappers() { 420 ResourceMark rm; 421 HandleMark hm; 422 423 int method_prefix_count = 0; 424 char** method_prefixes = JvmtiExport::get_all_native_method_prefixes(&method_prefix_count); 425 KlassHandle prefixed_klass(method()->method_holder()); 426 const char* prefixed_name = method()->name()->as_C_string(); 427 size_t prefixed_name_len = strlen(prefixed_name); 428 int prefix_index = method_prefix_count-1; 429 430 while (!at_end()) { 431 next(); 432 if (method()->method_holder() != prefixed_klass()) { 433 break; // classes don't match, can't be a wrapper 434 } 435 const char* name = method()->name()->as_C_string(); |