1 /* 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 17 import com.sun.management.HotSpotDiagnosticMXBean; 18 import java.io.IOException; 19 import java.lang.management.ManagementFactory; 20 import javax.management.MBeanServer; 21 22 /** 23 * Program used to create an RI heap dump for test purposes. 24 */ 25 public class Main { 26 public static DumpedStuff stuff; 27 main(String[] args)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 35 stuff = new DumpedStuff(); 36 37 // 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 } 44