15a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray/*
25a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * Copyright (C) 2015 The Android Open Source Project
35a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray *
45a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
55a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * you may not use this file except in compliance with the License.
65a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * You may obtain a copy of the License at
75a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray *
85a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
95a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray *
105a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
115a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
125a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * See the License for the specific language governing permissions and
145a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray * limitations under the License.
155a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray */
165a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
175a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.io.File;
185a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.io.IOException;
195a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.lang.reflect.Method;
205a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.concurrent.ConcurrentSkipListMap;
215a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.HashMap;
225a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.HashSet;
235a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.LinkedHashMap;
245a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.LinkedHashSet;
255a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.Map;
265a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.Set;
275a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.TreeMap;
285a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffrayimport java.util.TreeSet;
295a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
305a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffraypublic class Main {
315a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    private static final String TEMP_FILE_NAME_PREFIX = "test";
325a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    private static final String TEMP_FILE_NAME_SUFFIX = ".trace";
335a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    private static File file;
345a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
355a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    public static void main(String[] args) throws Exception {
365a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        String name = System.getProperty("java.vm.name");
375a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        if (!"Dalvik".equals(name)) {
385a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            System.out.println("This test is not supported on " + name);
395a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            return;
405a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        }
415a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        file = createTempFile();
425a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        try {
435a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            new Main().ensureCaller(true, 0);
445a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            new Main().ensureCaller(false, 0);
455a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        } finally {
465a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            if (file != null) {
475a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray              file.delete();
485a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            }
495a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        }
505a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    }
515a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
525a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    private static File createTempFile() throws Exception {
535a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        try {
545a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            return  File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX);
555a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        } catch (IOException e) {
565a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            System.setProperty("java.io.tmpdir", "/data/local/tmp");
575a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            try {
585a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX);
595a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            } catch (IOException e2) {
605a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                System.setProperty("java.io.tmpdir", "/sdcard");
615a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX);
625a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            }
635a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        }
645a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    }
655a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
665a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // We make sure 'doLoadsOfStuff' has a caller, because it is this caller that will be
675a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // pushed in the side instrumentation frame.
685a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    public void ensureCaller(boolean warmup, int invocationCount) throws Exception {
695a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        doLoadsOfStuff(warmup, invocationCount);
705a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    }
715a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
725a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // The number of recursive calls we are going to do in 'doLoadsOfStuff' to ensure
735a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // the JIT sees it hot.
745a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    static final int NUMBER_OF_INVOCATIONS = 5;
755a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
765a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    public void doLoadsOfStuff(boolean warmup, int invocationCount) throws Exception {
775a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        // Warmup is to make sure the JIT gets a chance to compile 'doLoadsOfStuff'.
785a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        if (warmup) {
795a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            if (invocationCount < NUMBER_OF_INVOCATIONS) {
805a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                doLoadsOfStuff(warmup, ++invocationCount);
815a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            } else {
825a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                // Give the JIT a chance to compiler.
835a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                Thread.sleep(1000);
845a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            }
855a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        } else {
865a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            if (invocationCount == 0) {
8741f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray                // When running the trace in trace mode, there is already a trace running.
8841f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray                if (VMDebug.getMethodTracingMode() != 0) {
8941f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray                    VMDebug.stopMethodTracing();
9041f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray                }
915a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                VMDebug.startMethodTracing(file.getPath(), 0, 0, false, 0);
925a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            }
935a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            fillJit();
945a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            if (invocationCount < NUMBER_OF_INVOCATIONS) {
955a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                doLoadsOfStuff(warmup, ++invocationCount);
965a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            } else {
975a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                VMDebug.stopMethodTracing();
985a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            }
995a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        }
1005a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    }
1015a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
1025a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // This method creates enough profiling data to fill the code cache and trigger
1035a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // a collection in debug mode (at the time of the test 10KB of data space). We
1045a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // used to crash by not looking at the instrumentation stack and deleting JIT code
1055a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    // that will be later restored by the instrumentation.
1065a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    public static void fillJit() throws Exception {
1075a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        Map map = new HashMap();
1085a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("foo", "bar");
1095a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.clear();
1105a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsKey("foo");
1115a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsValue("foo");
1125a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.entrySet();
1135a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.equals(map);
1145a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.hashCode();
1155a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.isEmpty();
1165a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.keySet();
1175a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.putAll(map);
1185a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.remove("foo");
1195a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.size();
1205a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("bar", "foo");
1215a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.values();
1225a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
1235a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map = new LinkedHashMap();
1245a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("foo", "bar");
1255a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.clear();
1265a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsKey("foo");
1275a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsValue("foo");
1285a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.entrySet();
1295a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.equals(map);
1305a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.hashCode();
1315a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.isEmpty();
1325a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.keySet();
1335a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.putAll(map);
1345a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.remove("foo");
1355a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.size();
1365a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("bar", "foo");
1375a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.values();
1385a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
1395a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map = new TreeMap();
1405a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("foo", "bar");
1415a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.clear();
1425a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsKey("foo");
1435a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsValue("foo");
1445a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.entrySet();
1455a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.equals(map);
1465a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.hashCode();
1475a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.isEmpty();
1485a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.keySet();
1495a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.putAll(map);
1505a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.remove("foo");
1515a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.size();
1525a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("bar", "foo");
1535a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.values();
1545a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
1555a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map = new ConcurrentSkipListMap();
1565a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("foo", "bar");
1575a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.clear();
1585a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsKey("foo");
1595a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.containsValue("foo");
1605a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.entrySet();
1615a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.equals(map);
1625a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.hashCode();
1635a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.isEmpty();
1645a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.keySet();
1655a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.putAll(map);
1665a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.remove("foo");
1675a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.size();
1685a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.put("bar", "foo");
1695a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        map.values();
1705a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
1715a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        Set set = new HashSet();
1725a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.add("foo");
1735a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.addAll(set);
1745a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.clear();
1755a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.contains("foo");
1765a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.containsAll(set);
1775a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.equals(set);
1785a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.hashCode();
1795a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.isEmpty();
1805a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.iterator();
1815a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.remove("foo");
1825a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.removeAll(set);
1835a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.retainAll(set);
1845a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.size();
1855a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.add("foo");
1865a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.toArray();
1875a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
1885a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set = new LinkedHashSet();
1895a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.add("foo");
1905a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.addAll(set);
1915a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.clear();
1925a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.contains("foo");
1935a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.containsAll(set);
1945a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.equals(set);
1955a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.hashCode();
1965a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.isEmpty();
1975a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.iterator();
1985a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.remove("foo");
1995a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.removeAll(set);
2005a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.retainAll(set);
2015a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.size();
2025a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.add("foo");
2035a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.toArray();
2045a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
2055a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set = new TreeSet();
2065a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.add("foo");
2075a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.addAll(set);
2085a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.clear();
2095a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.contains("foo");
2105a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.containsAll(set);
2115a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.equals(set);
2125a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.hashCode();
2135a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.isEmpty();
2145a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.iterator();
2155a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.remove("foo");
2165a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.removeAll(set);
2175a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.retainAll(set);
2185a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.size();
2195a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.add("foo");
2205a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        set.toArray();
2215a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    }
2225a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
2235a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    private static class VMDebug {
2245a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        private static final Method startMethodTracingMethod;
2255a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        private static final Method stopMethodTracingMethod;
22641f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray        private static final Method getMethodTracingModeMethod;
2275a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        static {
2285a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            try {
2295a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                Class c = Class.forName("dalvik.system.VMDebug");
2305a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                startMethodTracingMethod = c.getDeclaredMethod("startMethodTracing", String.class,
2315a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                        Integer.TYPE, Integer.TYPE, Boolean.TYPE, Integer.TYPE);
2325a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                stopMethodTracingMethod = c.getDeclaredMethod("stopMethodTracing");
23341f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray                getMethodTracingModeMethod = c.getDeclaredMethod("getMethodTracingMode");
2345a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            } catch (Exception e) {
2355a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                throw new RuntimeException(e);
2365a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            }
2375a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        }
2385a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray
2395a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        public static void startMethodTracing(String filename, int bufferSize, int flags,
2405a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                boolean samplingEnabled, int intervalUs) throws Exception {
2415a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            startMethodTracingMethod.invoke(null, filename, bufferSize, flags, samplingEnabled,
2425a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray                    intervalUs);
2435a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        }
2445a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        public static void stopMethodTracing() throws Exception {
2455a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray            stopMethodTracingMethod.invoke(null);
2465a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray        }
24741f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray        public static int getMethodTracingMode() throws Exception {
24841f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray            return (int) getMethodTracingModeMethod.invoke(null);
24941f10bcea6b1e7ebc8c18f8fc880c0ad8711e407Nicolas Geoffray        }
2505a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray    }
2515a23d2ea6e0d89112ff11ec765e676c03818b7c2Nicolas Geoffray}
252