| 390 | } |
| 391 | |
| 392 | u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Event* event) { |
| 393 | atomicInc(_total_samples); |
| 394 | |
| 395 | int tid = OS::threadId(); |
| 396 | u32 lock_index = getLockIndex(tid); |
| 397 | if (!_locks[lock_index].tryLock() && |
| 398 | !_locks[lock_index = (lock_index + 1) % CONCURRENCY_LEVEL].tryLock() && |
| 399 | !_locks[lock_index = (lock_index + 2) % CONCURRENCY_LEVEL].tryLock()) |
| 400 | { |
| 401 | // Too many concurrent signals already |
| 402 | atomicInc(_failures[-ticks_skipped]); |
| 403 | |
| 404 | if (event_type == PERF_SAMPLE) { |
| 405 | // Need to reset PerfEvents ring buffer, even though we discard the collected trace |
| 406 | PerfEvents::resetBuffer(tid); |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | u64 stack_walk_begin = _features.stats ? OS::nanotime() : 0; |
| 412 | |
| 413 | ASGCT_CallFrame* frames = _calltrace_buffer[lock_index]->_asgct_frames; |
| 414 | jvmtiFrameInfo* jvmti_frames = _calltrace_buffer[lock_index]->_jvmti_frames; |
| 415 | |
| 416 | int num_frames = 0; |
| 417 | if (_add_event_frame && event_type >= ALLOC_SAMPLE && event_type <= PARK_SAMPLE) { |
| 418 | u32 class_id = ((EventWithClassId*)event)->_class_id; |
| 419 | if (class_id != 0) { |
| 420 | // Convert event_type to frame_type, e.g. ALLOC_SAMPLE -> BCI_ALLOC |
| 421 | jint frame_type = BCI_ALLOC - (event_type - ALLOC_SAMPLE); |
| 422 | num_frames = makeFrame(frames, frame_type, class_id); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | u64 cpu = 0; |
| 427 | if (hasNativeStack(event_type)) { |
| 428 | if (_features.pc_addr && event_type <= WALL_CLOCK_SAMPLE) { |
| 429 | num_frames += makeFrame(frames + num_frames, BCI_ADDRESS, StackFrame(ucontext).pc()); |
| 430 | } |
| 431 | if (_cstack != CSTACK_NO) { |
| 432 | num_frames += getNativeTrace(ucontext, frames + num_frames, event_type, tid, &cpu); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (_features.mixed) { |
| 437 | num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, _features, event_type); |
| 438 | } else if (event_type <= MALLOC_SAMPLE) { |
| 439 | if (_cstack == CSTACK_VM) { |
| 440 | num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, _features, event_type); |
| 441 | } else { |
| 442 | num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth); |
| 443 | } |
| 444 | } else if (event_type >= ALLOC_SAMPLE && event_type <= ALLOC_OUTSIDE_TLAB && _alloc_engine == &alloc_tracer) { |
| 445 | if (VMStructs::hasStackStructs()) { |
| 446 | StackWalkFeatures no_features{}; |
| 447 | num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, no_features, event_type); |
| 448 | } else { |
| 449 | num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth); |
no test coverage detected