Skip to content

Commit 6969308

Browse files
committed
Revert "Android: Make ThreadChecker optimized away in release builds"
Reason for revert: see #100 This reverts commit 7e8a59c.
1 parent e60c260 commit 6969308

File tree

5 files changed

+11
-33
lines changed

5 files changed

+11
-33
lines changed

base/android/java/src/org/chromium/base/ThreadUtils.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import org.chromium.base.task.PostTask;
1414
import org.chromium.base.task.TaskTraits;
15-
import org.chromium.build.BuildConfig;
1615

1716
import java.util.concurrent.Callable;
1817
import java.util.concurrent.ExecutionException;
@@ -33,8 +32,9 @@ public class ThreadUtils {
3332
* A helper object to ensure that interactions with a particular object only happens on a
3433
* particular thread.
3534
*
36-
* <pre>Example:
37-
*
35+
* Example:
36+
* <pre>
37+
* {@code
3838
* class Foo {
3939
* // Valid thread is set during construction here.
4040
* private final ThreadChecker mThreadChecker = new ThreadChecker();
@@ -43,19 +43,11 @@ public class ThreadUtils {
4343
* mThreadChecker.assertOnValidThread();
4444
* }
4545
* }
46+
* }
4647
* </pre>
4748
*/
48-
// TODO(b/274802355): Add @CheckDiscard once R8 can remove this.
4949
public static class ThreadChecker {
50-
private long mThreadId;
51-
52-
public ThreadChecker() {
53-
resetThreadId();
54-
}
55-
56-
public void resetThreadId() {
57-
mThreadId = BuildConfig.ENABLE_ASSERTS ? Process.myTid() : 0;
58-
}
50+
private final long mThreadId = Process.myTid();
5951

6052
/**
6153
* Asserts that the current thread is the same as the one the ThreadChecker was constructed

base/android/java/src/org/chromium/base/jank_tracker/FrameMetricsStore.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
* This class stores relevant metrics from FrameMetrics between the calls to UMA reporting methods.
1919
*/
2020
public class FrameMetricsStore {
21-
private final ThreadChecker mThreadChecker = new ThreadChecker();
21+
// FrameMetricsStore can only be accessed on the handler thread (from the
22+
// JankReportingScheduler.getOrCreateHandler() method). However construction occurs on a
23+
// separate thread so the ThreadChecker is instead constructed later.
24+
private ThreadChecker mThreadChecker;
2225
// An arbitrary value from which to create a trace event async track. The only risk if this
2326
// clashes with another track is trace events will show up on both potentially looking weird in
2427
// the tracing UI. No other issue will occur.
@@ -85,10 +88,8 @@ public static String scenarioToString(@JankScenario.Type int scenario) {
8588
* checking.
8689
*/
8790
void initialize() {
88-
// FrameMetricsStore can only be accessed on the handler thread (from the
89-
// JankReportingScheduler.getOrCreateHandler() method). However construction occurs on a
90-
// separate thread so the ThreadChecker is instead constructed later.
91-
mThreadChecker.resetThreadId();
91+
assert mThreadChecker == null;
92+
mThreadChecker = new ThreadChecker();
9293
}
9394

9495
/** Records the total draw duration and jankiness for a single frame. */

base/android/proguard/chromium_code.flags

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
<init>();
4444
}
4545

46-
# Required to remove fields until b/274802355 is resolved.
47-
-assumevalues class !cr_allowunused,** {
48-
final org.chromium.base.ThreadUtils$ThreadChecker * return _NONNULL_;
49-
}
50-
5146
# TODO(agrieve): Remove once we start to use Android U SDK.
5247
-dontwarn android.window.BackEvent
5348
-dontwarn android.window.OnBackAnimationCallback

chrome/android/expectations/monochrome_64_32_public_bundle.proguard_flags.expected

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,6 @@
252252
<init>();
253253
}
254254

255-
# Required to remove fields until b/274802355 is resolved.
256-
-assumevalues class !cr_allowunused,** {
257-
final org.chromium.base.ThreadUtils$ThreadChecker * return _NONNULL_;
258-
}
259-
260255
# TODO(agrieve): Remove once we start to use Android U SDK.
261256
-dontwarn android.window.BackEvent
262257
-dontwarn android.window.OnBackAnimationCallback

components/cronet/android/cronet_combined_impl_native_proguard_golden.cfg

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
<init>();
4545
}
4646

47-
# Required to remove fields until b/274802355 is resolved.
48-
-assumevalues class !cr_allowunused,** {
49-
final org.chromium.base.ThreadUtils$ThreadChecker * return _NONNULL_;
50-
}
51-
5247
# TODO(agrieve): Remove once we start to use Android U SDK.
5348
-dontwarn android.window.BackEvent
5449
-dontwarn android.window.OnBackAnimationCallback

0 commit comments

Comments
 (0)