Bug 1469495 - Java Sampler never stops profiling. r?njn
Since GeckoJavaSampler::Stop() isn't called from locked_profiler_stop, Java
sampler is never stopped after stopping profiler.
And when calling GeckoJavaSampler::Stop(), it causes dead lock since stop()
is acquiring lock. So when calling join method, we should release this lock.
MozReview-Commit-ID: BLREo0lH6DS
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoJavaSampler.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoJavaSampler.java
@@ -182,24 +182,28 @@ public class GeckoJavaSampler {
public static void unpause() {
synchronized (GeckoJavaSampler.class) {
sSamplingRunnable.mPauseSampler = false;
}
}
@WrapForJNI
public static void stop() {
+ Thread samplingThread;
+
synchronized (GeckoJavaSampler.class) {
if (sSamplingThread == null) {
return;
}
sSamplingRunnable.mStopSampler = true;
- try {
- sSamplingThread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ samplingThread = sSamplingThread;
sSamplingThread = null;
sSamplingRunnable = null;
}
+
+ try {
+ samplingThread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -3089,16 +3089,22 @@ locked_profiler_stop(PSLockRef aLock)
{
LOG("locked_profiler_stop");
MOZ_RELEASE_ASSERT(CorePS::Exists() && ActivePS::Exists(aLock));
// At the very start, clear RacyFeatures.
RacyFeatures::SetInactive();
+#if defined(GP_OS_android)
+ if (ActivePS::FeatureJava(aLock)) {
+ java::GeckoJavaSampler::Stop();
+ }
+#endif
+
#ifdef MOZ_TASK_TRACER
if (ActivePS::FeatureTaskTracer(aLock)) {
tasktracer::StopLogging();
}
#endif
// Stop sampling live threads.
int tid = Thread::GetCurrentId();