alibaba / alibaba/AndFix

被替换的方法循环执行5000次后,报错:W/dalvikvm(27735): ReferenceTable overflow (max=4096)

Open
#103 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
7k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

我是在做一个性能测试,下面代码是官方的代码,我略微修改了一下:

``` java

/**
* sample activity
*
* @author luohou
* @author sanping.li@alipay.com
*
*/
public class MainActivity extends Activity {
private static final String TAG = "euler";

private TextView mTv;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mTv = (TextView) findViewById(R.id.txt);
long start = System.currentTimeMillis();
for (int i = 0; i < 5000; i++) {
test();
}

System.out.println("===>used time: " + (System.currentTimeMillis() - start));
}

private void test() {
String s = "good"; // 我只想修改这里
Fix.a(s);
mTv.setText(s);
// Log.e(TAG, Fix.a("good"));
// Log.e(TAG, "" + new Fix().b("s1", "s2"));

// Log.e(TAG, "" + new Fix());
// Log.e(TAG, A.a("good"));
// Log.e(TAG, "" + new A().b("s1", "s2"));
// Log.e(TAG, "" + new A().getI());
}

@Override
protected void onDestroy() {
super.onDestroy();
android.os.Process.killProcess(android.os.Process.myPid());
}

}

```

上面是正常的运行的,我没有做任何替换,也就是andFix还没有开始工作,没有执行方法替换操作。
我修改了test()方法中的s变量值为"xxxx",然后使用apkpatch工具生成out.apatch文件,并放置到SD卡,然后kill应用,测试方法被替换后的结果,但是出现了以下异常,应用闪退:
10-30 15:00:48.059: E/dalvikvm(27735): threadid=1: unable to add 0x4163de40 to internal ref table
10-30 15:00:48.059: W/dalvikvm(27735): ReferenceTable overflow (max=4096)

将onCreate()方法中的for循环次数改为4000是正常的。
**如果应用中被替换的方法出现在一个for循环中,而且循环次数比较多,那么这就是一个坑。**

我测试的机型:MOTO G XT1032 ,系统:android 4.4.4 DVM。

--EOF--

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce from MainActivity.onCreate(), the test() loop, and Fix.a(s), comparing 5,000 and 4,000 iterations on Android 4.4.4 Dalvik. Then trace the apkpatch-generated replacement path and the reported ReferenceTable overflow; done means the 5,000-iteration case no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.