annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/jvmci/logging/Logger.java @ 21546:7306a4dba8ce

removed dependency from JVMCI class HotSpotResolvedJavaMethodImpl to non-JVMCI class StructuredGraph (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 00:40:36 +0200
parents 07b088d61d5d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21526
diff changeset
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21526
diff changeset
23 package com.oracle.graal.hotspot.jvmci.logging;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.io.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 import java.lang.reflect.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
29 import com.oracle.graal.debug.*;
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: 16006
diff changeset
30 import com.oracle.graal.hotspot.jvmci.*;
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
31
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 /**
16006
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents: 9146
diff changeset
33 * Scoped logging class used to display the call hierarchy of {@link CompilerToVM} calls.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 public class Logger {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 public static final boolean ENABLED = Boolean.valueOf(System.getProperty("graal.debug"));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 private static final int SPACING = 4;
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
39 private static final ThreadLocal<Logger> loggerTL;
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
40
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
41 private Deque<Boolean> openStack = new LinkedList<>();
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
42 private boolean open = false;
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
43 private int level = 0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 private static final PrintStream out;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 static {
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
48 if (ENABLED) {
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
49 loggerTL = new ThreadLocal<Logger>() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 5278
diff changeset
50
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
51 @Override
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
52 protected Logger initialValue() {
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
53 return new Logger();
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
54 }
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
55 };
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
56 } else {
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
57 loggerTL = null;
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
58 }
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
59
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 PrintStream ps = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 String filename = System.getProperty("graal.info_file");
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 if (filename != null && !"".equals(filename)) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 try {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 ps = new PrintStream(new FileOutputStream(filename));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 } catch (FileNotFoundException e) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 e.printStackTrace();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 ps = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 out = ps;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 if (out != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 out.println("start: " + new Date());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 public static void info(String message) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 if (ENABLED) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 log(message);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 } else {
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
80 TTY.println(message);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 if (out != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 out.println(message);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 out.flush();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 public static void log(String message) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 if (ENABLED) {
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
90 Logger logger = loggerTL.get();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 for (String line : message.split("\n")) {
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
92 if (logger.open) {
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
93 TTY.println("...");
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
94 logger.open = false;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 }
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
96 TTY.print(space(logger.level));
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
97 TTY.println(line);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 public static void startScope(String message) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 if (ENABLED) {
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
104 Logger logger = loggerTL.get();
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
105 if (logger.open) {
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
106 TTY.println("...");
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
107 logger.open = false;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 }
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
109 TTY.print(space(logger.level));
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
110 TTY.print(message);
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
111 logger.openStack.push(logger.open);
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
112 logger.open = true;
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
113 logger.level++;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 public static void endScope(String message) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 if (ENABLED) {
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
119 Logger logger = loggerTL.get();
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
120 logger.level--;
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
121 if (logger.open) {
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
122 TTY.println(message);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 } else {
9146
febfb532ed2f Removed several instances of System.out.print.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
124 TTY.println(space(logger.level) + "..." + message);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
125 }
5185
db2286df9149 made Logger thread-safe by using a ThreadLocal
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
126 logger.open = logger.openStack.pop();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 private static String[] spaces = new String[50];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 private static String space(int count) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 assert count >= 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 String result;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 if (count >= spaces.length || spaces[count] == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 StringBuilder str = new StringBuilder();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 for (int i = 0; i < count * SPACING; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 str.append(' ');
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 result = str.toString();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 if (count < spaces.length) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 spaces[count] = result;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 result = spaces[count];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147 return result;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 public static String pretty(Object value) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 if (value == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 return "null";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 Class<?> klass = value.getClass();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 if (value instanceof Void) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 return "void";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
158 } else if (value instanceof String) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 return "\"" + value + "\"";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 } else if (value instanceof Method) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 return "method \"" + ((Method) value).getName() + "\"";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 } else if (value instanceof Class<?>) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 return "class \"" + ((Class<?>) value).getSimpleName() + "\"";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 } else if (value instanceof Integer) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 if ((Integer) value < 10) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 return value.toString();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 return value + " (0x" + Integer.toHexString((Integer) value) + ")";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 } else if (value instanceof Long) {
5186
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
170 if ((Long) value < 10 && (Long) value > -10) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171 return value + "l";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 return value + "l (0x" + Long.toHexString((Long) value) + "l)";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 } else if (klass.isArray()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 StringBuilder str = new StringBuilder();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 int dimensions = 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 while (klass.isArray()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 dimensions++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 klass = klass.getComponentType();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 }
5186
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
181 int length = Array.getLength(value);
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
182 str.append(klass.getSimpleName()).append('[').append(length).append(']');
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 for (int i = 1; i < dimensions; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 str.append("[]");
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 }
5186
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
186 str.append(" {");
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
187 for (int i = 0; i < length; i++) {
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
188 str.append(pretty(Array.get(value, i)));
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
189 if (i < length - 1) {
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
190 str.append(", ");
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
191 }
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
192 }
b00e56aa159d added printing of HotSpot config if graal.printconfig system property is true
Doug Simon <doug.simon@oracle.com>
parents: 5185
diff changeset
193 str.append('}');
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 return str.toString();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 return value.toString();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 }