Skip to content

Commit 1dcbab8

Browse files
jddukeCommit bot
authored andcommitted
Revert of [Android] Mark posted UI thread tasks as asynchronous (patchset #4 id:60001 of https://codereview.chromium.org/512333002/)
Reason for revert: This patch was purely experimental, and the experiment has expired. Original issue's description: > [Android] Mark posted UI thread tasks as asynchronous > > Chromium shares a message loop with Android on the browser UI thread. > This can cause problems when the associated Looper has a sync barrier, > preventing posted Chromium tasks from being dispatched until the > barrier is removed. Make this sharing more fair by marking all Chromium > Message tasks as asynchronous, avoiding stalls when there is a sync > barrier. > > Note: This change is for gathering data about the perf impact and we'll > revert it before cutting a release branch. > > BUG=407149,380781,407133 > > Committed: https://crrev.com/feabeebb3ac5810f896ac8303a77ee695acaf9d4 > Cr-Commit-Position: refs/heads/master@{#292551} [email protected],[email protected],[email protected],[email protected],[email protected] NOTREECHECKS=true NOTRY=true BUG=407149,380781,407133 Review URL: https://codereview.chromium.org/564373005 Cr-Commit-Position: refs/heads/master@{#294875}
1 parent 168a502 commit 1dcbab8

File tree

1 file changed

+2
-49
lines changed

1 file changed

+2
-49
lines changed

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

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,18 @@
66

77
import android.os.Handler;
88
import android.os.Message;
9-
import android.util.Log;
10-
11-
import java.lang.reflect.InvocationTargetException;
12-
import java.lang.reflect.Method;
139

1410
class SystemMessageHandler extends Handler {
1511

16-
private static final String TAG = "SystemMessageHandler";
17-
1812
private static final int SCHEDULED_WORK = 1;
1913
private static final int DELAYED_SCHEDULED_WORK = 2;
2014

21-
// Reflected API for marking a message as asynchronous. This is a workaround
22-
// to provide *fair* Chromium task dispatch when served by the Android UI
23-
// thread's Looper, avoiding stalls when the Looper has a sync barrier.
24-
// Note: Use of this API is experimental and demonstrative, and is likely
25-
// to be removed in the near future.
26-
private Method mMessageMethodSetAsynchonous;
27-
2815
// Native class pointer set by the constructor of the SharedClient native class.
2916
private long mMessagePumpDelegateNative = 0;
3017
private long mDelayedScheduledTimeTicks = 0;
3118

3219
private SystemMessageHandler(long messagePumpDelegateNative) {
3320
mMessagePumpDelegateNative = messagePumpDelegateNative;
34-
35-
try {
36-
Class<?> messageClass = Class.forName("android.os.Message");
37-
mMessageMethodSetAsynchonous = messageClass.getMethod(
38-
"setAsynchronous", new Class[]{boolean.class});
39-
} catch (ClassNotFoundException e) {
40-
Log.e(TAG, "Failed to find android.os.Message class:" + e);
41-
} catch (NoSuchMethodException e) {
42-
Log.e(TAG, "Failed to load Message.setAsynchronous method:" + e);
43-
} catch (RuntimeException e) {
44-
Log.e(TAG, "Exception while loading Message.setAsynchronous method: " + e);
45-
}
4621
}
4722

4823
@Override
@@ -56,7 +31,7 @@ public void handleMessage(Message msg) {
5631
@SuppressWarnings("unused")
5732
@CalledByNative
5833
private void scheduleWork() {
59-
sendMessage(obtainAsyncMessage(SCHEDULED_WORK));
34+
sendEmptyMessage(SCHEDULED_WORK);
6035
}
6136

6237
@SuppressWarnings("unused")
@@ -66,7 +41,7 @@ private void scheduleDelayedWork(long delayedTimeTicks, long millis) {
6641
removeMessages(DELAYED_SCHEDULED_WORK);
6742
}
6843
mDelayedScheduledTimeTicks = delayedTimeTicks;
69-
sendMessageDelayed(obtainAsyncMessage(DELAYED_SCHEDULED_WORK), millis);
44+
sendEmptyMessageDelayed(DELAYED_SCHEDULED_WORK, millis);
7045
}
7146

7247
@SuppressWarnings("unused")
@@ -76,28 +51,6 @@ private void removeAllPendingMessages() {
7651
removeMessages(DELAYED_SCHEDULED_WORK);
7752
}
7853

79-
private Message obtainAsyncMessage(int what) {
80-
Message msg = Message.obtain();
81-
msg.what = what;
82-
if (mMessageMethodSetAsynchonous != null) {
83-
// If invocation fails, assume this is indicative of future
84-
// failures, and avoid log spam by nulling the reflected method.
85-
try {
86-
mMessageMethodSetAsynchonous.invoke(msg, true);
87-
} catch (IllegalAccessException e) {
88-
Log.e(TAG, "Illegal access to asynchronous message creation, disabling.");
89-
mMessageMethodSetAsynchonous = null;
90-
} catch (IllegalArgumentException e) {
91-
Log.e(TAG, "Illegal argument for asynchronous message creation, disabling.");
92-
mMessageMethodSetAsynchonous = null;
93-
} catch (InvocationTargetException e) {
94-
Log.e(TAG, "Invocation exception during asynchronous message creation, disabling.");
95-
mMessageMethodSetAsynchonous = null;
96-
}
97-
}
98-
return msg;
99-
}
100-
10154
@CalledByNative
10255
private static SystemMessageHandler create(long messagePumpDelegateNative) {
10356
return new SystemMessageHandler(messagePumpDelegateNative);

0 commit comments

Comments
 (0)