Mercurial > hg > truffle
annotate test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java @ 13370:3e67710a6d08
SchedulePhase: remove old memory aware scheudling
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Tue, 17 Dec 2013 21:39:01 +0100 |
parents | 8ef918538e22 |
children |
rev | line source |
---|---|
12820
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
1 /* |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
4 * |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
8 * |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
13 * accompanied this code). |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
14 * |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
18 * |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
21 * questions. |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
22 */ |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
23 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
24 import java.lang.management.ManagementFactory; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
25 import java.lang.management.RuntimeMXBean; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
26 import java.lang.reflect.Field; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
27 import java.lang.reflect.Method; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
28 import java.util.ArrayList; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
29 import java.util.List; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
30 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
31 import sun.management.VMManagement; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
32 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
33 public class JMapHProfLargeHeapProc { |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
34 private static final List<byte[]> heapGarbage = new ArrayList<>(); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
35 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
36 public static void main(String[] args) throws Exception { |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
37 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
38 buildLargeHeap(args); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
39 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
40 // Print our pid on stdout |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
41 System.out.println("PID[" + getProcessId() + "]"); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
42 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
43 // Wait for input before termination |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
44 System.in.read(); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
45 } |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
46 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
47 private static void buildLargeHeap(String[] args) { |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
48 for (long i = 0; i < Integer.parseInt(args[0]); i++) { |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
49 heapGarbage.add(new byte[1024]); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
50 } |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
51 } |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
52 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
53 public static int getProcessId() throws Exception { |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
54 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
55 // Get the current process id using a reflection hack |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
56 RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
57 Field jvm = runtime.getClass().getDeclaredField("jvm"); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
58 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
59 jvm.setAccessible(true); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
60 VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
61 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
62 Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId"); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
63 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
64 pid_method.setAccessible(true); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
65 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
66 int pid = (Integer) pid_method.invoke(mgmt); |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
67 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
68 return pid; |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
69 } |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
70 |
8ef918538e22
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
diff
changeset
|
71 } |