annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationStatistics.java @ 21526:1da7aef31a08

created com.oracle.graal.hotspot.jvmci package and moved classes destined for future JVMCI module into it (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 19 May 2015 23:16:07 +0200
parents 3c3cd36a3836
children 93c50cefb9e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
23 package com.oracle.graal.hotspot;
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
25 import static java.lang.Thread.*;
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
26
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import java.io.*;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
28 import java.lang.annotation.*;
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
29 import java.lang.management.*;
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30 import java.lang.reflect.*;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31 import java.util.*;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
32 import java.util.concurrent.*;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33
21526
1da7aef31a08 created com.oracle.graal.hotspot.jvmci package and moved classes destined for future JVMCI module into it (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16483
diff changeset
34 import com.oracle.graal.hotspot.jvmci.*;
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5719
diff changeset
35 import com.oracle.graal.hotspot.meta.*;
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
36 import com.sun.management.ThreadMXBean;
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38 @SuppressWarnings("unused")
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
39 public final class CompilationStatistics {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41 private static final long RESOLUTION = 100000000;
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
42 private static final boolean ENABLED = Boolean.getBoolean("graal.comp.stats");
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
44 private static final CompilationStatistics DUMMY = new CompilationStatistics(null, false);
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
46 private static ConcurrentLinkedDeque<CompilationStatistics> list = new ConcurrentLinkedDeque<>();
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
48 private static final ThreadLocal<Deque<CompilationStatistics>> current = new ThreadLocal<Deque<CompilationStatistics>>() {
7553
d34f5456475f applied eclipseformat
Doug Simon <doug.simon@oracle.com>
parents: 7552
diff changeset
49
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50 @Override
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
51 protected Deque<CompilationStatistics> initialValue() {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
52 return new ArrayDeque<>();
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
53 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54 };
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
55
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
56 @Retention(RetentionPolicy.RUNTIME)
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
57 @Target(ElementType.FIELD)
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
58 private static @interface NotReported {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
59 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
60
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
61 @Retention(RetentionPolicy.RUNTIME)
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
62 @Target(ElementType.FIELD)
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
63 private static @interface TimeValue {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
64 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
65
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
66 private static long zeroTime = System.nanoTime();
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
67
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
68 private static long getThreadAllocatedBytes() {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
69 ThreadMXBean thread = (ThreadMXBean) ManagementFactory.getThreadMXBean();
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
70 return thread.getThreadAllocatedBytes(currentThread().getId());
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
71 }
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
72
7553
d34f5456475f applied eclipseformat
Doug Simon <doug.simon@oracle.com>
parents: 7552
diff changeset
73 @NotReported private final long startTime;
d34f5456475f applied eclipseformat
Doug Simon <doug.simon@oracle.com>
parents: 7552
diff changeset
74 @NotReported private long threadAllocatedBytesStart;
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
75
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
76 private int bytecodeCount;
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
77 private int codeSize;
7553
d34f5456475f applied eclipseformat
Doug Simon <doug.simon@oracle.com>
parents: 7552
diff changeset
78 @TimeValue private long duration;
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
79 private long memoryUsed;
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
80 private final boolean osr;
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
81 private final String holder;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
82 private final String name;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
83 private final String signature;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
84
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
85 private CompilationStatistics(HotSpotResolvedJavaMethod method, boolean osr) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
86 this.osr = osr;
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87 if (method != null) {
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
88 holder = method.getDeclaringClass().getName();
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5719
diff changeset
89 name = method.getName();
16483
3c3cd36a3836 moved signatureToMethodDescriptor(Signature sig) from MetaUtil to be a default method in Signature
Doug Simon <doug.simon@oracle.com>
parents: 14991
diff changeset
90 signature = method.getSignature().toMethodDescriptor();
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
91 startTime = System.nanoTime();
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5719
diff changeset
92 bytecodeCount = method.getCodeSize();
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
93 threadAllocatedBytesStart = getThreadAllocatedBytes();
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
94 } else {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
95 holder = "";
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
96 name = "";
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
97 signature = "";
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
98 startTime = 0;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
99 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
100 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
101
14545
4877b0cb446f removed ResolvedJavaMethod.getCompiledCodeSize()
Doug Simon <doug.simon@oracle.com>
parents: 10639
diff changeset
102 public void finish(HotSpotResolvedJavaMethod method, HotSpotInstalledCode code) {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
103 if (ENABLED) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
104 duration = System.nanoTime() - startTime;
14545
4877b0cb446f removed ResolvedJavaMethod.getCompiledCodeSize()
Doug Simon <doug.simon@oracle.com>
parents: 10639
diff changeset
105 codeSize = (int) code.getCodeSize();
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
106 memoryUsed = getThreadAllocatedBytes() - threadAllocatedBytesStart;
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
107 if (current.get().getLast() != this) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
108 throw new RuntimeException("mismatch in finish()");
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
109 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
110 current.get().removeLast();
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
111 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
112 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
113
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
114 public static CompilationStatistics current() {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
115 return current.get().isEmpty() ? null : current.get().getLast();
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
116 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
117
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
118 public static CompilationStatistics create(HotSpotResolvedJavaMethod method, boolean isOSR) {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
119 if (ENABLED) {
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
120 CompilationStatistics stats = new CompilationStatistics(method, isOSR);
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
121 list.add(stats);
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
122 current.get().addLast(stats);
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
123 return stats;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
124 } else {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
125 return DUMMY;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
126 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
127 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
128
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
129 @SuppressWarnings("deprecation")
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
130 public static void clear(String dumpName) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
131 if (!ENABLED) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
132 return;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
133 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
134 try {
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
135 ConcurrentLinkedDeque<CompilationStatistics> snapshot = list;
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
136 long snapshotZeroTime = zeroTime;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
137
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
138 list = new ConcurrentLinkedDeque<>();
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
139 zeroTime = System.nanoTime();
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
140
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
141 Date now = new Date();
7547
f7ca24d268c4 changed format of files generated by CompilationStatistics to avoid spaces
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
142 String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes();
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
143
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
144 dumpCompilations(snapshot, dumpName, dateString);
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
145
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
146 try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
147
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
148 long[] timeSpent = new long[10000];
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
149 int maxTick = 0;
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
150 for (CompilationStatistics stats : snapshot) {
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
151 long start = stats.startTime - snapshotZeroTime;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
152 long duration = stats.duration;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
153 if (start < 0) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
154 duration -= -start;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
155 start = 0;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
156 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
157
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
158 int tick = (int) (start / RESOLUTION);
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
159 long timeLeft = RESOLUTION - (start % RESOLUTION);
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
160
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
161 while (tick < timeSpent.length && duration > 0) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
162 if (tick > maxTick) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
163 maxTick = tick;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
164 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
165 timeSpent[tick] += Math.min(timeLeft, duration);
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
166 duration -= timeLeft;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
167 tick++;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
168 timeLeft = RESOLUTION;
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
169 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
170 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
171 String timelineName = System.getProperty("stats.timeline.name");
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
172 if (timelineName != null && !timelineName.isEmpty()) {
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
173 out.print(timelineName + "\t");
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
174 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
175 for (int i = 0; i <= maxTick; i++) {
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
176 out.print((timeSpent[i] * 100 / RESOLUTION) + "\t");
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
177 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
178 out.println();
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
179 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
180 } catch (Exception e) {
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
181 throw new RuntimeException(e);
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
182 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
183 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
184
7549
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
185 protected static void dumpCompilations(ConcurrentLinkedDeque<CompilationStatistics> snapshot, String dumpName, String dateString) throws IllegalAccessException, FileNotFoundException {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
186 String fileName = "compilations_" + dateString + "_" + dumpName + ".csv";
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
187 try (PrintStream out = new PrintStream(fileName)) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
188 // output the list of all compilations
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
189
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
190 Field[] declaredFields = CompilationStatistics.class.getDeclaredFields();
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
191 ArrayList<Field> fields = new ArrayList<>();
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
192 for (Field field : declaredFields) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
193 if (!Modifier.isStatic(field.getModifiers()) && !field.isAnnotationPresent(NotReported.class)) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
194 fields.add(field);
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
195 }
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
196 }
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
197 for (Field field : fields) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
198 out.print(field.getName() + "\t");
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
199 }
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
200 out.println();
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
201 for (CompilationStatistics stats : snapshot) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
202 for (Field field : fields) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
203 if (field.isAnnotationPresent(TimeValue.class)) {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
204 double value = field.getLong(stats) / 1000000d;
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
205 out.print(String.format(Locale.ENGLISH, "%.3f", value) + "\t");
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
206 } else {
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
207 out.print(field.get(stats) + "\t");
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
208 }
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
209 }
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
210 out.println();
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
211 }
5512fae3683b added memory usage to CompilationStatistics
Doug Simon <doug.simon@oracle.com>
parents: 7547
diff changeset
212 }
5176
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
213 }
af59b4dfc9e4 compilation queue changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
214 }