Skip to content

Commit 4c18ad5

Browse files
author
Christopher Tate
committed
Add a few GC-flexing microbenchmark tests
Added ObjectGc and FinalizingGc to stress single-object allocation and collection with/without the presence of finalizers. Also added GcOp() to the menu of available single-shot tests. Change-Id: I36d3254dfe2e97e504f9e4f77c8addda98ab4f4b
1 parent 33fe4a3 commit 4c18ad5

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/FrameworkPerf/src/com/android/frameworkperf/TestService.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.content.res.XmlResourceParser;
3434
import android.graphics.Bitmap;
3535
import android.graphics.BitmapFactory;
36+
import android.graphics.Paint;
3637
import android.os.Bundle;
3738
import android.os.FileUtils;
3839
import android.os.Handler;
@@ -64,6 +65,9 @@ public class TestService extends Service {
6465
new MethodCallOp(), new ReadFileOp(),
6566
new SchedulerOp(), new SchedulerOp(),
6667
new GcOp(), new NoOp(),
68+
new ObjectGcOp(), new NoOp(),
69+
new FinalizingGcOp(), new NoOp(),
70+
new PaintGcOp(), new NoOp(),
6771
new IpcOp(), new NoOp(),
6872
new IpcOp(), new CpuOp(),
6973
new IpcOp(), new SchedulerOp(),
@@ -111,6 +115,10 @@ public class TestService extends Service {
111115
new CpuOp(),
112116
new SchedulerOp(),
113117
new MethodCallOp(),
118+
new GcOp(),
119+
new ObjectGcOp(),
120+
new FinalizingGcOp(),
121+
new PaintGcOp(),
114122
new IpcOp(),
115123
new CreateFileOp(),
116124
new CreateWriteFileOp(),
@@ -467,6 +475,47 @@ boolean onRun() {
467475
}
468476
}
469477

478+
static class ObjectGcOp extends Op {
479+
ObjectGcOp() {
480+
super("ObjectGc", "Run garbage collector with simple objects");
481+
}
482+
483+
boolean onRun() {
484+
Object obj = new Object();
485+
return true;
486+
}
487+
}
488+
489+
static class FinalizingGcOp extends Op {
490+
class Finalizable {
491+
Finalizable() {}
492+
@Override
493+
protected void finalize() throws Throwable {
494+
super.finalize();
495+
}
496+
}
497+
498+
FinalizingGcOp() {
499+
super("FinalizingGc", "Run garbage collector with finalizable objects");
500+
}
501+
502+
boolean onRun() {
503+
Finalizable obj = new Finalizable();
504+
return true;
505+
}
506+
}
507+
508+
static class PaintGcOp extends Op {
509+
PaintGcOp() {
510+
super("PaintGc", "Run garbage collector with Paint objects");
511+
}
512+
513+
boolean onRun() {
514+
Paint p = new Paint();
515+
return true;
516+
}
517+
}
518+
470519
static class MethodCallOp extends Op {
471520
MethodCallOp() {
472521
super("MethodCall", "Method call");

0 commit comments

Comments
 (0)