Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/ShapeProfiler.java @ 21716:2f9e4d984d16
Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 04 Jun 2015 08:08:05 +0200 |
parents | 2c3666f44855 |
children |
rev | line source |
---|---|
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1 /* |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
4 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
8 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
14 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
18 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
21 * questions. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
22 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
23 package com.oracle.truffle.object.debug; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
24 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
25 import java.io.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
26 import java.text.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
27 import java.util.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
28 import java.util.concurrent.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
29 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.object.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
31 import com.oracle.truffle.object.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
32 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
33 public class ShapeProfiler { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
34 private static final String LINE_SEPARATOR = "***********************************************"; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
35 private static final String BULLET = "* "; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
36 private static final String TOKEN_SEPARATOR = "\t"; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
37 private final ConcurrentLinkedQueue<DynamicObject> queue; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
38 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
39 public ShapeProfiler() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
40 queue = new ConcurrentLinkedQueue<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
41 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
43 public void track(DynamicObject obj) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 queue.add(obj); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
45 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
46 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
47 public void dump(PrintWriter out) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
48 ShapeStats globalStats = new ShapeStats("Cumulative results for all shapes"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
49 for (DynamicObject obj : queue) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
50 Shape shape = obj.getShape(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
51 globalStats.profile(shape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
52 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
53 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
54 globalStats.dump(out); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
55 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
56 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
57 public void dump(PrintWriter out, int topResults) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
58 if (topResults > 0) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
59 IdentityHashMap<Shape, ShapeStats> shapeMap = new IdentityHashMap<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
60 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
61 for (DynamicObject obj : queue) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
62 Shape shape = obj.getShape(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
63 ShapeStats stats = shapeMap.get(shape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
64 if (stats == null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
65 shapeMap.put(shape, stats = new ShapeStats(createLabel(shape))); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
66 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
67 stats.profile(shape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
68 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
69 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
70 List<ShapeStats> allStats = new ArrayList<>(shapeMap.values()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
71 Collections.sort(allStats, new Comparator<ShapeStats>() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
72 public int compare(ShapeStats a, ShapeStats b) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
73 return Long.compare(b.jsObjects, a.jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
74 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
75 }); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
76 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
77 ShapeStats avgStats = new ShapeStats("Cumulative results for top " + topResults + " shapes"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
78 for (int i = 0; i < topResults; i++) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
79 ShapeStats stats = allStats.get(i); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
80 stats.setLabel("Shape " + (i + 1) + ": " + stats.getLabel()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
81 stats.dump(out); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
82 avgStats.add(stats); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
83 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
84 avgStats.dump(out); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
85 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
86 // Dump also cumulative results. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
87 dump(out); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
88 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
89 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
90 private static String createLabel(Shape shape) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
91 String label = shape.toString(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
92 return label.substring(label.indexOf('{') + 1, label.lastIndexOf('}')); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
93 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
94 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
95 private static class ShapeStats { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
96 private String label; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
97 private long jsObjects; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
98 private long oac; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
99 private long oas; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
100 private long ofs; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
101 private long pac; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
102 private long pas; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
103 private long pfs; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
104 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
105 public ShapeStats(String label) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
106 this.label = label; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
107 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
108 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
109 public String getLabel() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
110 return label; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
111 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
112 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
113 public void setLabel(String label) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
114 this.label = label; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
115 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
116 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
117 public void profile(Shape shape) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
118 jsObjects++; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
119 oac += shape.getObjectArrayCapacity(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
120 oas += shape.getObjectArraySize(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
121 ofs += shape.getObjectFieldSize(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
122 pac += shape.getPrimitiveArrayCapacity(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
123 pas += shape.getPrimitiveArraySize(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
124 pfs += shape.getPrimitiveFieldSize(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
125 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
126 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
127 public void add(ShapeStats stats) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
128 jsObjects += stats.jsObjects; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
129 oac += stats.oac; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
130 oas += stats.oas; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
131 ofs += stats.ofs; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
132 oac += stats.oac; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
133 oas += stats.oas; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
134 ofs += stats.ofs; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
135 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
136 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
137 public void dump(PrintWriter out) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
138 DecimalFormat format = new DecimalFormat("###.####"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
139 out.println(LINE_SEPARATOR); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
140 out.println(BULLET + label); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
141 out.println(LINE_SEPARATOR); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
142 out.println(BULLET + "Allocated objects:\t" + jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
143 out.println(BULLET + "Total object array capacity:\t" + oac); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
144 out.println(BULLET + "Total object array size:\t" + oas); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
145 out.println(BULLET + "Total object field size:\t" + ofs); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
146 out.println(BULLET + "Average object array capacity:\t" + avgOAC(format)); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
147 out.println(BULLET + "Average object array size:\t" + avgOAS(format)); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
148 out.println(BULLET + "Average object field size:\t" + avgOFS(format)); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
149 out.println(LINE_SEPARATOR); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
150 out.println(BULLET + "Total primitive array capacity:\t" + pac); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
151 out.println(BULLET + "Total primitive array size:\t" + pas); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
152 out.println(BULLET + "Total primitive field size:\t" + pfs); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
153 out.println(BULLET + "Average primitive array capacity:\t" + avgPAC(format)); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
154 out.println(BULLET + "Average primitive array size:\t" + avgPAS(format)); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
155 out.println(BULLET + "Average primitive field size:\t" + avgPFS(format)); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
156 out.println(LINE_SEPARATOR); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
157 out.println(BULLET + toString()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
158 out.println(LINE_SEPARATOR + "\n"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
159 out.flush(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
160 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
161 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
162 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
163 public String toString() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
164 DecimalFormat format = new DecimalFormat("###.####"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
165 // @formatter:off |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
166 return "{" + label + "}" + TOKEN_SEPARATOR |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
167 + jsObjects + TOKEN_SEPARATOR |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
168 + avgOAC(format) + TOKEN_SEPARATOR |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
169 + avgOAS(format) + TOKEN_SEPARATOR |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
170 + avgOFS(format) + TOKEN_SEPARATOR |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
171 + avgPAC(format) + TOKEN_SEPARATOR |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
172 + avgPAS(format) + TOKEN_SEPARATOR |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
173 + avgPFS(format); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
174 // @formatter:on |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
175 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
176 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
177 private String avgOAC(DecimalFormat format) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
178 return format.format((double) oac / jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
179 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
180 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
181 private String avgOAS(DecimalFormat format) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
182 return format.format((double) oas / jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
183 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
184 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
185 private String avgOFS(DecimalFormat format) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
186 return format.format((double) ofs / jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
187 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
188 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
189 private String avgPAC(DecimalFormat format) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
190 return format.format((double) pac / jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
191 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
192 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
193 private String avgPAS(DecimalFormat format) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
194 return format.format((double) pas / jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
195 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
196 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
197 private String avgPFS(DecimalFormat format) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
198 return format.format((double) pfs / jsObjects); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
199 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
200 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
201 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
202 public static ShapeProfiler getInstance() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
203 return shapeProf; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
204 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
205 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
206 private static final ShapeProfiler shapeProf; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
207 static { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
208 if (ObjectStorageOptions.Profile) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
209 shapeProf = new ShapeProfiler(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
210 Runtime.getRuntime().addShutdownHook(new Thread() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
211 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
212 public void run() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
213 getInstance().dump(new PrintWriter(System.out), ObjectStorageOptions.ProfileTopResults); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
214 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
215 }); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
216 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
217 shapeProf = null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
218 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
219 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
220 } |