Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java @ 22548:6b76a24fffbd default tip
Use all variables: a, b, u,v and x, y
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 14 Jan 2016 14:20:57 +0100 |
parents | a647534602a6 |
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; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
24 |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
25 import java.io.File; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
26 import java.io.FileNotFoundException; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
27 import java.io.PrintWriter; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
28 import java.io.UnsupportedEncodingException; |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
29 import java.nio.file.Paths; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
30 import java.util.Collection; |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
31 import java.util.List; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
32 import java.util.concurrent.ConcurrentLinkedQueue; |
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
33 |
22357
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
34 import com.oracle.truffle.api.nodes.GraphPrintVisitor; |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
35 import com.oracle.truffle.api.object.DynamicObject; |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
36 import com.oracle.truffle.api.object.Property; |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
37 import com.oracle.truffle.object.debug.GraphvizShapeVisitor; |
22357
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
38 import com.oracle.truffle.object.debug.IGVShapeVisitor; |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
39 import com.oracle.truffle.object.debug.JSONShapeVisitor; |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
40 import com.oracle.truffle.object.debug.ShapeProfiler; |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
41 |
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 class Debug { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
43 private static Collection<ShapeImpl> allShapes; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
45 static void trackShape(ShapeImpl newShape) { |
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
46 allShapes.add(newShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
47 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
48 |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
49 static void trackObject(DynamicObject obj) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
50 ShapeProfiler.getInstance().track(obj); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
51 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
52 |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
53 static Iterable<ShapeImpl> getAllShapes() { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
54 return allShapes; |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
55 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
56 |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
57 static String dumpObject(DynamicObject object, int level, int levelStop) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
58 List<Property> properties = object.getShape().getPropertyListInternal(true); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
59 StringBuilder sb = new StringBuilder(properties.size() * 10); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
60 sb.append("{\n"); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
61 for (Property property : properties) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
62 indent(sb, level + 1); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
63 |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
64 sb.append(property.getKey()); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
65 sb.append('[').append(property.getLocation()).append(']'); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
66 Object value = property.get(object, false); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
67 if (value instanceof DynamicObject) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
68 if (level < levelStop) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
69 value = dumpObject((DynamicObject) value, level + 1, levelStop); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
70 } else { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
71 value = value.toString(); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
72 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
73 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
74 sb.append(": "); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
75 sb.append(value); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
76 if (property != properties.get(properties.size() - 1)) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
77 sb.append(","); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
78 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
79 sb.append("\n"); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
80 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
81 indent(sb, level); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
82 sb.append("}"); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
83 return sb.toString(); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
84 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
85 |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
86 private static StringBuilder indent(StringBuilder sb, int level) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
87 for (int i = 0; i < level; i++) { |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
88 sb.append(' '); |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
89 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
90 return sb; |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
91 } |
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
92 |
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
93 static { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
94 if (ObjectStorageOptions.DumpShapes) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
95 allShapes = new ConcurrentLinkedQueue<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
96 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
97 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
98 if (ObjectStorageOptions.DumpShapes) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
99 Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
100 public void run() { |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
101 try { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
102 if (ObjectStorageOptions.DumpShapesDOT) { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
103 dumpDOT(); |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
104 } |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
105 if (ObjectStorageOptions.DumpShapesJSON) { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
106 dumpJSON(); |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
107 } |
22357
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
108 if (ObjectStorageOptions.DumpShapesIGV) { |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
109 dumpIGV(); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
110 } |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
111 } catch (FileNotFoundException | UnsupportedEncodingException e) { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
112 throw new RuntimeException(e); |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
113 } |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
114 } |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
115 |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
116 private void dumpDOT() throws FileNotFoundException, UnsupportedEncodingException { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
117 try (PrintWriter out = new PrintWriter(getOutputFile("dot"), "UTF-8")) { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
118 GraphvizShapeVisitor visitor = new GraphvizShapeVisitor(); |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
119 for (ShapeImpl shape : getAllShapes()) { |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
120 shape.accept(visitor); |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
121 } |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
122 out.println(visitor); |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
123 } |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
124 } |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
125 |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
126 private void dumpJSON() throws FileNotFoundException, UnsupportedEncodingException { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
127 try (PrintWriter out = new PrintWriter(getOutputFile("json"), "UTF-8")) { |
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
128 out.println("{\"shapes\": ["); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
129 boolean first = true; |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
130 for (ShapeImpl shape : getAllShapes()) { |
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
131 if (!first) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
132 out.println(","); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
133 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
134 first = false; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
135 out.print(shape.accept(new JSONShapeVisitor())); |
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 if (!first) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
138 out.println(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
139 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
140 out.println("]}"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
141 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
142 } |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
143 |
22357
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
144 private void dumpIGV() { |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
145 GraphPrintVisitor printer = new GraphPrintVisitor(); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
146 printer.beginGroup("shapes"); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
147 IGVShapeVisitor visitor = new IGVShapeVisitor(printer); |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
148 for (ShapeImpl shape : getAllShapes()) { |
22357
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
149 if (isRootShape(shape)) { |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
150 printer.beginGraph(DebugShapeVisitor.getId(shape)); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
151 shape.accept(visitor); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
152 printer.endGraph(); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
153 } |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
154 } |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
155 printer.beginGraph("all shapes"); |
22358
a647534602a6
minor debug code cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
22357
diff
changeset
|
156 for (ShapeImpl shape : getAllShapes()) { |
22357
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
157 if (isRootShape(shape)) { |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
158 shape.accept(visitor); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
159 } |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
160 } |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
161 printer.endGraph(); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
162 printer.endGroup(); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
163 printer.printToNetwork(false); |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
164 } |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
165 |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
166 private boolean isRootShape(ShapeImpl shape) { |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
167 return shape.getParent() == null; |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
168 } |
9c1d40221bf9
add option for dumping shapes to IGV
Andreas Woess <andreas.woess@oracle.com>
parents:
22356
diff
changeset
|
169 |
22356
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
170 private File getOutputFile(String extension) { |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
171 return Paths.get(ObjectStorageOptions.DumpShapesPath, "shapes." + extension).toFile(); |
364bab1763c9
add option for dumping shapes to a DOT file
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
172 } |
18408
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
173 })); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
174 } |
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 } |