| 32 | } |
| 33 | |
| 34 | void J9WallClock::timerLoop() { |
| 35 | JNIEnv* jni = VM::attachThread("Async-profiler Sampler"); |
| 36 | jvmtiEnv* jvmti = VM::jvmti(); |
| 37 | |
| 38 | int max_frames = _max_stack_depth + MAX_NATIVE_FRAMES + RESERVED_FRAMES; |
| 39 | ASGCT_CallFrame* frames = (ASGCT_CallFrame*)malloc(max_frames * sizeof(ASGCT_CallFrame)); |
| 40 | |
| 41 | while (_running) { |
| 42 | if (!_enabled) { |
| 43 | OS::uninterruptibleSleep(_interval, &_running); |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | jni->PushLocalFrame(64); |
| 48 | |
| 49 | jvmtiStackInfoExtended* stack_infos; |
| 50 | jint thread_count; |
| 51 | if (J9Ext::GetAllStackTracesExtended(_max_stack_depth, (void**)&stack_infos, &thread_count) == 0) { |
| 52 | u64 start_time = TSC::ticks(); |
| 53 | for (int i = 0; i < thread_count; i++) { |
| 54 | jvmtiStackInfoExtended* si = &stack_infos[i]; |
| 55 | for (int j = 0; j < si->frame_count; j++) { |
| 56 | jvmtiFrameInfoExtended* fi = &si->frame_buffer[j]; |
| 57 | frames[j].method_id = fi->method; |
| 58 | frames[j].bci = FrameType::encode(fi->type, fi->location); |
| 59 | } |
| 60 | |
| 61 | int tid = J9Ext::GetOSThreadID(si->thread); |
| 62 | ExecutionEvent event(start_time); |
| 63 | event._thread_state = (si->state & JVMTI_THREAD_STATE_RUNNABLE) ? THREAD_RUNNING : THREAD_SLEEPING; |
| 64 | Profiler::instance()->recordExternalSample(_interval, tid, EXECUTION_SAMPLE, &event, si->frame_count, frames); |
| 65 | } |
| 66 | jvmti->Deallocate((unsigned char*)stack_infos); |
| 67 | } |
| 68 | |
| 69 | jni->PopLocalFrame(NULL); |
| 70 | |
| 71 | OS::uninterruptibleSleep(_interval, &_running); |
| 72 | } |
| 73 | |
| 74 | free(frames); |
| 75 | |
| 76 | VM::detachThread(); |
| 77 | } |
nothing calls this directly
no test coverage detected