blob: 9df53f436e5950652b26f066ea4c0675103ec278 [file] [log] [blame]
Richard Uhlerb957c892018-07-06 10:20:37 +01001/*
2 * Copyright (C) 2018 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 com.sun.management.HotSpotDiagnosticMXBean;
18import java.io.IOException;
19import java.lang.management.ManagementFactory;
20import javax.management.MBeanServer;
21
22/**
23 * Program used to create an RI heap dump for test purposes.
24 */
25public class Main {
Richard Uhlerefadbcd2018-07-26 12:41:52 +010026 public static DumpedStuff stuff;
Richard Uhlerb957c892018-07-06 10:20:37 +010027
28 public static void main(String[] args) throws IOException {
29 if (args.length < 1) {
30 System.err.println("no output file specified");
31 return;
32 }
33 String file = args[0];
34
Richard Uhlerefadbcd2018-07-26 12:41:52 +010035 stuff = new DumpedStuff();
36
Richard Uhlerb957c892018-07-06 10:20:37 +010037 // Take a heap dump of this process.
38 MBeanServer server = ManagementFactory.getPlatformMBeanServer();
39 HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server,
40 "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
41 bean.dumpHeap(file, false);
42 }
43}