blob: 2cc9c3aafddc4d19c3b81d9eb80cee15f0148247 [file] [log] [blame]
Andreas Gampe8da6d032016-10-31 19:31:03 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import java.util.ArrayList;
18
19public class Main {
20 public static void main(String[] args) throws Exception {
21 System.loadLibrary(args[1]);
22
23 doTest();
24 }
25
26 public static void doTest() throws Exception {
27 setupGcCallback();
28
29 enableGcTracking(true);
30 run();
31 enableGcTracking(false);
32 }
33
34 private static void run() {
Andreas Gampeef3ace02016-11-01 13:58:14 -070035 clearStats();
Andreas Gampe8da6d032016-10-31 19:31:03 -070036 printStats();
37 forceGarbageCollection();
38 printStats();
39 }
40
Andreas Gampeef3ace02016-11-01 13:58:14 -070041 private static void clearStats() {
42 getGcStarts();
43 getGcFinishes();
44 }
45
Andreas Gampe8da6d032016-10-31 19:31:03 -070046 private static void printStats() {
47 System.out.println("---");
48 int s = getGcStarts();
49 int f = getGcFinishes();
50 System.out.println((s > 0) + " " + (f > 0));
51 }
52
53 private static native void setupGcCallback();
54 private static native void enableGcTracking(boolean enable);
55 private static native int getGcStarts();
56 private static native int getGcFinishes();
57 private static native void forceGarbageCollection();
58}