Andreas Gampe | 8da6d03 | 2016-10-31 19:31:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | import java.util.ArrayList; |
| 18 | |
| 19 | public 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 Gampe | ef3ace0 | 2016-11-01 13:58:14 -0700 | [diff] [blame^] | 35 | clearStats(); |
Andreas Gampe | 8da6d03 | 2016-10-31 19:31:03 -0700 | [diff] [blame] | 36 | printStats(); |
| 37 | forceGarbageCollection(); |
| 38 | printStats(); |
| 39 | } |
| 40 | |
Andreas Gampe | ef3ace0 | 2016-11-01 13:58:14 -0700 | [diff] [blame^] | 41 | private static void clearStats() { |
| 42 | getGcStarts(); |
| 43 | getGcFinishes(); |
| 44 | } |
| 45 | |
Andreas Gampe | 8da6d03 | 2016-10-31 19:31:03 -0700 | [diff] [blame] | 46 | 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 | } |