diff --git a/modules/audio_device/android/audio_manager.cc b/modules/audio_device/android/audio_manager.cc index 6f385a3073..fae4ecce0c 100644 --- a/modules/audio_device/android/audio_manager.cc +++ b/modules/audio_device/android/audio_manager.cc @@ -18,6 +18,7 @@ #include "modules/utility/include/helpers_android.h" #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" +#include "rtc_base/platform_thread.h" #define TAG "AudioManager" #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__) @@ -40,11 +41,11 @@ AudioManager::JavaAudioManager::JavaAudioManager( is_device_blacklisted_for_open_sles_usage_( native_reg->GetMethodId("isDeviceBlacklistedForOpenSLESUsage", "()Z")) { - ALOGD("JavaAudioManager::ctor%s", GetThreadInfo().c_str()); + ALOGD("JavaAudioManager::ctor @[tid=%d]", rtc::CurrentThreadId()); } AudioManager::JavaAudioManager::~JavaAudioManager() { - ALOGD("JavaAudioManager::dtor%s", GetThreadInfo().c_str()); + ALOGD("JavaAudioManager::dtor[tid=%d]", rtc::CurrentThreadId()); } bool AudioManager::JavaAudioManager::Init() { @@ -75,7 +76,7 @@ AudioManager::AudioManager() low_latency_playout_(false), low_latency_record_(false), delay_estimate_in_milliseconds_(0) { - ALOGD("ctor%s", GetThreadInfo().c_str()); + ALOGD("ctor[tid=%d]", rtc::CurrentThreadId()); RTC_CHECK(j_environment_); JNINativeMethod native_methods[] = { {"nativeCacheAudioParameters", "(IIIZZZZZZIIJ)V", @@ -90,14 +91,14 @@ AudioManager::AudioManager() } AudioManager::~AudioManager() { - ALOGD("~dtor%s", GetThreadInfo().c_str()); + ALOGD("~dtor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); Close(); } void AudioManager::SetActiveAudioLayer( AudioDeviceModule::AudioLayer audio_layer) { - ALOGD("SetActiveAudioLayer(%d)%s", audio_layer, GetThreadInfo().c_str()); + ALOGD("SetActiveAudioLayer(%d)[tid=%d]", audio_layer, rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(!initialized_); // Store the currently utilized audio layer. @@ -114,7 +115,7 @@ void AudioManager::SetActiveAudioLayer( } SLObjectItf AudioManager::GetOpenSLEngine() { - ALOGD("GetOpenSLEngine%s", GetThreadInfo().c_str()); + ALOGD("GetOpenSLEngine[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); // Only allow usage of OpenSL ES if such an audio layer has been specified. if (audio_layer_ != AudioDeviceModule::kAndroidOpenSLESAudio && @@ -153,7 +154,7 @@ SLObjectItf AudioManager::GetOpenSLEngine() { } bool AudioManager::Init() { - ALOGD("Init%s", GetThreadInfo().c_str()); + ALOGD("Init[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(!initialized_); RTC_DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio); @@ -166,7 +167,7 @@ bool AudioManager::Init() { } bool AudioManager::Close() { - ALOGD("Close%s", GetThreadInfo().c_str()); + ALOGD("Close[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (!initialized_) return true; @@ -271,7 +272,7 @@ void AudioManager::OnCacheAudioParameters(JNIEnv* env, jboolean pro_audio, jint output_buffer_size, jint input_buffer_size) { - ALOGD("OnCacheAudioParameters%s", GetThreadInfo().c_str()); + ALOGD("OnCacheAudioParameters[tid=%d]", rtc::CurrentThreadId()); ALOGD("hardware_aec: %d", hardware_aec); ALOGD("hardware_agc: %d", hardware_agc); ALOGD("hardware_ns: %d", hardware_ns); diff --git a/modules/audio_device/android/audio_record_jni.cc b/modules/audio_device/android/audio_record_jni.cc index edf9e364d2..f0c4a4ec57 100644 --- a/modules/audio_device/android/audio_record_jni.cc +++ b/modules/audio_device/android/audio_record_jni.cc @@ -18,6 +18,7 @@ #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" #include "rtc_base/format_macros.h" +#include "rtc_base/platform_thread.h" #define TAG "AudioRecordJni" #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__) @@ -78,7 +79,7 @@ AudioRecordJni::AudioRecordJni(AudioManager* audio_manager) initialized_(false), recording_(false), audio_device_buffer_(nullptr) { - ALOGD("ctor%s", GetThreadInfo().c_str()); + ALOGD("ctor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(audio_parameters_.is_valid()); RTC_CHECK(j_environment_); JNINativeMethod native_methods[] = { @@ -100,26 +101,26 @@ AudioRecordJni::AudioRecordJni(AudioManager* audio_manager) } AudioRecordJni::~AudioRecordJni() { - ALOGD("~dtor%s", GetThreadInfo().c_str()); + ALOGD("~dtor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); Terminate(); } int32_t AudioRecordJni::Init() { - ALOGD("Init%s", GetThreadInfo().c_str()); + ALOGD("Init[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); return 0; } int32_t AudioRecordJni::Terminate() { - ALOGD("Terminate%s", GetThreadInfo().c_str()); + ALOGD("Terminate[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); StopRecording(); return 0; } int32_t AudioRecordJni::InitRecording() { - ALOGD("InitRecording%s", GetThreadInfo().c_str()); + ALOGD("InitRecording[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(!initialized_); RTC_DCHECK(!recording_); @@ -141,7 +142,7 @@ int32_t AudioRecordJni::InitRecording() { } int32_t AudioRecordJni::StartRecording() { - ALOGD("StartRecording%s", GetThreadInfo().c_str()); + ALOGD("StartRecording[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(initialized_); RTC_DCHECK(!recording_); @@ -154,7 +155,7 @@ int32_t AudioRecordJni::StartRecording() { } int32_t AudioRecordJni::StopRecording() { - ALOGD("StopRecording%s", GetThreadInfo().c_str()); + ALOGD("StopRecording[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (!initialized_ || !recording_) { return 0; @@ -190,7 +191,7 @@ void AudioRecordJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { } int32_t AudioRecordJni::EnableBuiltInAEC(bool enable) { - ALOGD("EnableBuiltInAEC%s", GetThreadInfo().c_str()); + ALOGD("EnableBuiltInAEC[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); return j_audio_record_->EnableBuiltInAEC(enable) ? 0 : -1; } @@ -202,7 +203,7 @@ int32_t AudioRecordJni::EnableBuiltInAGC(bool enable) { } int32_t AudioRecordJni::EnableBuiltInNS(bool enable) { - ALOGD("EnableBuiltInNS%s", GetThreadInfo().c_str()); + ALOGD("EnableBuiltInNS[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); return j_audio_record_->EnableBuiltInNS(enable) ? 0 : -1; } diff --git a/modules/audio_device/android/audio_track_jni.cc b/modules/audio_device/android/audio_track_jni.cc index 89d4af0508..eca225f305 100644 --- a/modules/audio_device/android/audio_track_jni.cc +++ b/modules/audio_device/android/audio_track_jni.cc @@ -18,6 +18,7 @@ #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" #include "rtc_base/format_macros.h" +#include "rtc_base/platform_thread.h" #define TAG "AudioTrackJni" #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__) @@ -77,7 +78,7 @@ AudioTrackJni::AudioTrackJni(AudioManager* audio_manager) initialized_(false), playing_(false), audio_device_buffer_(nullptr) { - ALOGD("ctor%s", GetThreadInfo().c_str()); + ALOGD("ctor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(audio_parameters_.is_valid()); RTC_CHECK(j_environment_); JNINativeMethod native_methods[] = { @@ -99,26 +100,26 @@ AudioTrackJni::AudioTrackJni(AudioManager* audio_manager) } AudioTrackJni::~AudioTrackJni() { - ALOGD("~dtor%s", GetThreadInfo().c_str()); + ALOGD("~dtor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); Terminate(); } int32_t AudioTrackJni::Init() { - ALOGD("Init%s", GetThreadInfo().c_str()); + ALOGD("Init[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); return 0; } int32_t AudioTrackJni::Terminate() { - ALOGD("Terminate%s", GetThreadInfo().c_str()); + ALOGD("Terminate[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); StopPlayout(); return 0; } int32_t AudioTrackJni::InitPlayout() { - ALOGD("InitPlayout%s", GetThreadInfo().c_str()); + ALOGD("InitPlayout[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(!initialized_); RTC_DCHECK(!playing_); @@ -132,7 +133,7 @@ int32_t AudioTrackJni::InitPlayout() { } int32_t AudioTrackJni::StartPlayout() { - ALOGD("StartPlayout%s", GetThreadInfo().c_str()); + ALOGD("StartPlayout[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(initialized_); RTC_DCHECK(!playing_); @@ -145,7 +146,7 @@ int32_t AudioTrackJni::StartPlayout() { } int32_t AudioTrackJni::StopPlayout() { - ALOGD("StopPlayout%s", GetThreadInfo().c_str()); + ALOGD("StopPlayout[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (!initialized_ || !playing_) { return 0; @@ -170,27 +171,27 @@ int AudioTrackJni::SpeakerVolumeIsAvailable(bool& available) { } int AudioTrackJni::SetSpeakerVolume(uint32_t volume) { - ALOGD("SetSpeakerVolume(%d)%s", volume, GetThreadInfo().c_str()); + ALOGD("SetSpeakerVolume(%d)[tid=%d]", volume, rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); return j_audio_track_->SetStreamVolume(volume) ? 0 : -1; } int AudioTrackJni::MaxSpeakerVolume(uint32_t& max_volume) const { - ALOGD("MaxSpeakerVolume%s", GetThreadInfo().c_str()); + ALOGD("MaxSpeakerVolume[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); max_volume = j_audio_track_->GetStreamMaxVolume(); return 0; } int AudioTrackJni::MinSpeakerVolume(uint32_t& min_volume) const { - ALOGD("MaxSpeakerVolume%s", GetThreadInfo().c_str()); + ALOGD("MaxSpeakerVolume[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); min_volume = 0; return 0; } int AudioTrackJni::SpeakerVolume(uint32_t& volume) const { - ALOGD("SpeakerVolume%s", GetThreadInfo().c_str()); + ALOGD("SpeakerVolume[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); volume = j_audio_track_->GetStreamVolume(); return 0; @@ -198,7 +199,7 @@ int AudioTrackJni::SpeakerVolume(uint32_t& volume) const { // TODO(henrika): possibly add stereo support. void AudioTrackJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { - ALOGD("AttachAudioBuffer%s", GetThreadInfo().c_str()); + ALOGD("AttachAudioBuffer[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); audio_device_buffer_ = audioBuffer; const int sample_rate_hz = audio_parameters_.sample_rate(); diff --git a/modules/audio_device/android/opensles_player.cc b/modules/audio_device/android/opensles_player.cc index 7ac691236b..2732f99b82 100644 --- a/modules/audio_device/android/opensles_player.cc +++ b/modules/audio_device/android/opensles_player.cc @@ -19,6 +19,7 @@ #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" #include "rtc_base/format_macros.h" +#include "rtc_base/platform_thread.h" #include "rtc_base/timeutils.h" #define TAG "OpenSLESPlayer" @@ -51,7 +52,7 @@ OpenSLESPlayer::OpenSLESPlayer(AudioManager* audio_manager) simple_buffer_queue_(nullptr), volume_(nullptr), last_play_time_(0) { - ALOGD("ctor%s", GetThreadInfo().c_str()); + ALOGD("ctor[tid=%d]", rtc::CurrentThreadId()); // Use native audio output parameters provided by the audio manager and // define the PCM format structure. pcm_format_ = CreatePCMConfiguration(audio_parameters_.channels(), @@ -63,7 +64,7 @@ OpenSLESPlayer::OpenSLESPlayer(AudioManager* audio_manager) } OpenSLESPlayer::~OpenSLESPlayer() { - ALOGD("dtor%s", GetThreadInfo().c_str()); + ALOGD("dtor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); Terminate(); DestroyAudioPlayer(); @@ -77,7 +78,7 @@ OpenSLESPlayer::~OpenSLESPlayer() { } int OpenSLESPlayer::Init() { - ALOGD("Init%s", GetThreadInfo().c_str()); + ALOGD("Init[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (audio_parameters_.channels() == 2) { // TODO(henrika): FineAudioBuffer needs more work to support stereo. @@ -88,14 +89,14 @@ int OpenSLESPlayer::Init() { } int OpenSLESPlayer::Terminate() { - ALOGD("Terminate%s", GetThreadInfo().c_str()); + ALOGD("Terminate[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); StopPlayout(); return 0; } int OpenSLESPlayer::InitPlayout() { - ALOGD("InitPlayout%s", GetThreadInfo().c_str()); + ALOGD("InitPlayout[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(!initialized_); RTC_DCHECK(!playing_); @@ -110,7 +111,7 @@ int OpenSLESPlayer::InitPlayout() { } int OpenSLESPlayer::StartPlayout() { - ALOGD("StartPlayout%s", GetThreadInfo().c_str()); + ALOGD("StartPlayout[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(initialized_); RTC_DCHECK(!playing_); @@ -138,7 +139,7 @@ int OpenSLESPlayer::StartPlayout() { } int OpenSLESPlayer::StopPlayout() { - ALOGD("StopPlayout%s", GetThreadInfo().c_str()); + ALOGD("StopPlayout[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (!initialized_ || !playing_) { return 0; diff --git a/modules/audio_device/android/opensles_recorder.cc b/modules/audio_device/android/opensles_recorder.cc index 123406889c..919486ba70 100644 --- a/modules/audio_device/android/opensles_recorder.cc +++ b/modules/audio_device/android/opensles_recorder.cc @@ -19,6 +19,7 @@ #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" #include "rtc_base/format_macros.h" +#include "rtc_base/platform_thread.h" #include "rtc_base/timeutils.h" #define TAG "OpenSLESRecorder" @@ -51,7 +52,7 @@ OpenSLESRecorder::OpenSLESRecorder(AudioManager* audio_manager) simple_buffer_queue_(nullptr), buffer_index_(0), last_rec_time_(0) { - ALOGD("ctor%s", GetThreadInfo().c_str()); + ALOGD("ctor[tid=%d]", rtc::CurrentThreadId()); // Detach from this thread since we want to use the checker to verify calls // from the internal audio thread. thread_checker_opensles_.DetachFromThread(); @@ -63,7 +64,7 @@ OpenSLESRecorder::OpenSLESRecorder(AudioManager* audio_manager) } OpenSLESRecorder::~OpenSLESRecorder() { - ALOGD("dtor%s", GetThreadInfo().c_str()); + ALOGD("dtor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); Terminate(); DestroyAudioRecorder(); @@ -74,7 +75,7 @@ OpenSLESRecorder::~OpenSLESRecorder() { } int OpenSLESRecorder::Init() { - ALOGD("Init%s", GetThreadInfo().c_str()); + ALOGD("Init[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (audio_parameters_.channels() == 2) { // TODO(henrika): FineAudioBuffer needs more work to support stereo. @@ -85,14 +86,14 @@ int OpenSLESRecorder::Init() { } int OpenSLESRecorder::Terminate() { - ALOGD("Terminate%s", GetThreadInfo().c_str()); + ALOGD("Terminate[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); StopRecording(); return 0; } int OpenSLESRecorder::InitRecording() { - ALOGD("InitRecording%s", GetThreadInfo().c_str()); + ALOGD("InitRecording[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(!initialized_); RTC_DCHECK(!recording_); @@ -107,7 +108,7 @@ int OpenSLESRecorder::InitRecording() { } int OpenSLESRecorder::StartRecording() { - ALOGD("StartRecording%s", GetThreadInfo().c_str()); + ALOGD("StartRecording[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(initialized_); RTC_DCHECK(!recording_); @@ -144,7 +145,7 @@ int OpenSLESRecorder::StartRecording() { } int OpenSLESRecorder::StopRecording() { - ALOGD("StopRecording%s", GetThreadInfo().c_str()); + ALOGD("StopRecording[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (!initialized_ || !recording_) { return 0; diff --git a/modules/utility/include/helpers_android.h b/modules/utility/include/helpers_android.h index 1d23653d5d..2ee577ceea 100644 --- a/modules/utility/include/helpers_android.h +++ b/modules/utility/include/helpers_android.h @@ -45,12 +45,6 @@ jobject NewGlobalRef(JNIEnv* jni, jobject o); void DeleteGlobalRef(JNIEnv* jni, jobject o); -// Return thread ID as a string. -std::string GetThreadId(); - -// Return thread ID as string suitable for debug logging. -std::string GetThreadInfo(); - // Attach thread to JVM if necessary and detach at scope end if originally // attached. class AttachThreadScoped { diff --git a/modules/utility/source/helpers_android.cc b/modules/utility/source/helpers_android.cc index c5a91235e3..5e760b4c03 100644 --- a/modules/utility/source/helpers_android.cc +++ b/modules/utility/source/helpers_android.cc @@ -9,7 +9,6 @@ */ #include "modules/utility/include/helpers_android.h" -#include "rtc_base/checks.h" #include #include @@ -17,6 +16,9 @@ #include #include +#include "rtc_base/checks.h" +#include "rtc_base/platform_thread.h" + #define TAG "HelpersAndroid" #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) @@ -82,19 +84,6 @@ void DeleteGlobalRef(JNIEnv* jni, jobject o) { CHECK_EXCEPTION(jni) << "Error during DeleteGlobalRef"; } -std::string GetThreadId() { - char buf[21]; // Big enough to hold a kuint64max plus terminating NULL. - int thread_id = gettid(); - RTC_CHECK_LT(snprintf(buf, sizeof(buf), "%i", thread_id), - static_cast(sizeof(buf))) - << "Thread id is bigger than uint64??"; - return std::string(buf); -} - -std::string GetThreadInfo() { - return "@[tid=" + GetThreadId() + "]"; -} - AttachThreadScoped::AttachThreadScoped(JavaVM* jvm) : attached_(false), jvm_(jvm), env_(NULL) { env_ = GetEnv(jvm); @@ -102,7 +91,7 @@ AttachThreadScoped::AttachThreadScoped(JavaVM* jvm) // Adding debug log here so we can track down potential leaks and figure // out why we sometimes see "Native thread exiting without having called // DetachCurrentThread" in logcat outputs. - ALOGD("Attaching thread to JVM%s", GetThreadInfo().c_str()); + ALOGD("Attaching thread to JVM[tid=%d]", rtc::CurrentThreadId()); jint res = jvm->AttachCurrentThread(&env_, NULL); attached_ = (res == JNI_OK); RTC_CHECK(attached_) << "AttachCurrentThread failed: " << res; @@ -111,7 +100,7 @@ AttachThreadScoped::AttachThreadScoped(JavaVM* jvm) AttachThreadScoped::~AttachThreadScoped() { if (attached_) { - ALOGD("Detaching thread from JVM%s", GetThreadInfo().c_str()); + ALOGD("Detaching thread from JVM[tid=%d]", rtc::CurrentThreadId()); jint res = jvm_->DetachCurrentThread(); RTC_CHECK(res == JNI_OK) << "DetachCurrentThread failed: " << res; RTC_CHECK(!GetEnv(jvm_)); diff --git a/modules/utility/source/jvm_android.cc b/modules/utility/source/jvm_android.cc index 8c27624947..fc0739caf8 100644 --- a/modules/utility/source/jvm_android.cc +++ b/modules/utility/source/jvm_android.cc @@ -15,6 +15,7 @@ #include "modules/utility/include/jvm_android.h" #include "rtc_base/checks.h" +#include "rtc_base/platform_thread.h" #define TAG "JVM" #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) @@ -72,7 +73,7 @@ jclass LookUpClass(const char* name) { // AttachCurrentThreadIfNeeded implementation. AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded() : attached_(false) { - ALOGD("AttachCurrentThreadIfNeeded::ctor%s", GetThreadInfo().c_str()); + ALOGD("AttachCurrentThreadIfNeeded::ctor[tid=%d]", rtc::CurrentThreadId()); JavaVM* jvm = JVM::GetInstance()->jvm(); RTC_CHECK(jvm); JNIEnv* jni = GetEnv(jvm); @@ -85,7 +86,7 @@ AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded() } AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() { - ALOGD("AttachCurrentThreadIfNeeded::dtor%s", GetThreadInfo().c_str()); + ALOGD("AttachCurrentThreadIfNeeded::dtor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (attached_) { ALOGD("Detaching thread from JVM"); @@ -97,11 +98,11 @@ AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() { // GlobalRef implementation. GlobalRef::GlobalRef(JNIEnv* jni, jobject object) : jni_(jni), j_object_(NewGlobalRef(jni, object)) { - ALOGD("GlobalRef::ctor%s", GetThreadInfo().c_str()); + ALOGD("GlobalRef::ctor[tid=%d]", rtc::CurrentThreadId()); } GlobalRef::~GlobalRef() { - ALOGD("GlobalRef::dtor%s", GetThreadInfo().c_str()); + ALOGD("GlobalRef::dtor[tid=%d]", rtc::CurrentThreadId()); DeleteGlobalRef(jni_, j_object_); } @@ -134,18 +135,18 @@ void GlobalRef::CallVoidMethod(jmethodID methodID, ...) { // NativeRegistration implementation. NativeRegistration::NativeRegistration(JNIEnv* jni, jclass clazz) : JavaClass(jni, clazz), jni_(jni) { - ALOGD("NativeRegistration::ctor%s", GetThreadInfo().c_str()); + ALOGD("NativeRegistration::ctor[tid=%d]", rtc::CurrentThreadId()); } NativeRegistration::~NativeRegistration() { - ALOGD("NativeRegistration::dtor%s", GetThreadInfo().c_str()); + ALOGD("NativeRegistration::dtor[tid=%d]", rtc::CurrentThreadId()); jni_->UnregisterNatives(j_class_); CHECK_EXCEPTION(jni_) << "Error during UnregisterNatives"; } std::unique_ptr NativeRegistration::NewObject( const char* name, const char* signature, ...) { - ALOGD("NativeRegistration::NewObject%s", GetThreadInfo().c_str()); + ALOGD("NativeRegistration::NewObject[tid=%d]", rtc::CurrentThreadId()); va_list args; va_start(args, signature); jobject obj = jni_->NewObjectV(j_class_, @@ -185,11 +186,11 @@ jint JavaClass::CallStaticIntMethod(jmethodID methodID, ...) { // JNIEnvironment implementation. JNIEnvironment::JNIEnvironment(JNIEnv* jni) : jni_(jni) { - ALOGD("JNIEnvironment::ctor%s", GetThreadInfo().c_str()); + ALOGD("JNIEnvironment::ctor[tid=%d]", rtc::CurrentThreadId()); } JNIEnvironment::~JNIEnvironment() { - ALOGD("JNIEnvironment::dtor%s", GetThreadInfo().c_str()); + ALOGD("JNIEnvironment::dtor[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); } @@ -218,7 +219,7 @@ std::string JNIEnvironment::JavaToStdString(const jstring& j_string) { // static void JVM::Initialize(JavaVM* jvm) { - ALOGD("JVM::Initialize%s", GetThreadInfo().c_str()); + ALOGD("JVM::Initialize[tid=%d]", rtc::CurrentThreadId()); RTC_CHECK(!g_jvm); g_jvm = new JVM(jvm); } @@ -236,7 +237,7 @@ void JVM::Initialize(JavaVM* jvm, jobject context) { // static void JVM::Uninitialize() { - ALOGD("JVM::Uninitialize%s", GetThreadInfo().c_str()); + ALOGD("JVM::Uninitialize[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(g_jvm); delete g_jvm; g_jvm = nullptr; @@ -249,19 +250,19 @@ JVM* JVM::GetInstance() { } JVM::JVM(JavaVM* jvm) : jvm_(jvm) { - ALOGD("JVM::JVM%s", GetThreadInfo().c_str()); + ALOGD("JVM::JVM[tid=%d]", rtc::CurrentThreadId()); RTC_CHECK(jni()) << "AttachCurrentThread() must be called on this thread."; LoadClasses(jni()); } JVM::~JVM() { - ALOGD("JVM::~JVM%s", GetThreadInfo().c_str()); + ALOGD("JVM::~JVM[tid=%d]", rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); FreeClassReferences(jni()); } std::unique_ptr JVM::environment() { - ALOGD("JVM::environment%s", GetThreadInfo().c_str()); + ALOGD("JVM::environment[tid=%d]", rtc::CurrentThreadId()); // The JNIEnv is used for thread-local storage. For this reason, we cannot // share a JNIEnv between threads. If a piece of code has no other way to get // its JNIEnv, we should share the JavaVM, and use GetEnv to discover the @@ -276,7 +277,7 @@ std::unique_ptr JVM::environment() { } JavaClass JVM::GetClass(const char* name) { - ALOGD("JVM::GetClass(%s)%s", name, GetThreadInfo().c_str()); + ALOGD("JVM::GetClass(%s)[tid=%d]", name, rtc::CurrentThreadId()); RTC_DCHECK(thread_checker_.CalledOnValidThread()); return JavaClass(jni(), LookUpClass(name)); }