comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/Logger.java @ 1422:3483ec571caf

* using reflected objects instead of oops * removed scratch from allocatable registers * instanceof xir snippet * arraylength xir snippet * exceptionobject xir snippet * VMEntries and VMExits as interfaces * calls to VMEntries and VMExits are routet through logging proxies
author Lukas Stadler <lukas.stadler@oracle.com>
date Mon, 02 Aug 2010 15:44:38 -0700
parents
children
comparison
equal deleted inserted replaced
1421:6223633ce7dd 1422:3483ec571caf
1 package com.sun.hotspot.c1x;
2
3 import java.lang.reflect.*;
4 import java.util.*;
5
6 public class Logger {
7
8 private static final boolean ENABLED = true;
9 private static final int SPACING = 2;
10 private static Deque<Boolean> openStack = new LinkedList<Boolean>();
11 private static boolean open = false;
12 private static int level = 0;
13
14 public static void log(String message) {
15 if (ENABLED) {
16 if (open) {
17 System.out.println("...");
18 open = false;
19 }
20 System.out.print(space(level));
21 System.out.println(message);
22 }
23 }
24
25 public static void startScope(String message) {
26 if (ENABLED) {
27 if (open) {
28 System.out.println("...");
29 open = false;
30 }
31 System.out.print(space(level));
32 System.out.print(message);
33 openStack.push(open);
34 open = true;
35 level++;
36 }
37 }
38
39 public static void endScope(String message) {
40 if (ENABLED) {
41 level--;
42 if (open)
43 System.out.println(message);
44 else
45 System.out.println(space(level) + "..." + message);
46 open = openStack.pop();
47 }
48 }
49
50 private static String[] spaces = new String[50];
51
52 private static String space(int count) {
53 assert count >= 0;
54 String result;
55 if (count >= spaces.length || spaces[count] == null) {
56 StringBuilder str = new StringBuilder();
57 for (int i = 0; i < count * SPACING; i++)
58 str.append(' ');
59 result = str.toString();
60 if (count < spaces.length)
61 spaces[count] = result;
62 } else {
63 result = spaces[count];
64 }
65 return result;
66 }
67
68 public static String pretty(Object value) {
69 if (value instanceof Method) {
70 return "method \"" + ((Method) value).getName() + "\"";
71 } else if (value instanceof Class<?>) {
72 return "class \"" + ((Class<?>) value).getSimpleName() + "\"";
73 } else if (value instanceof Void) {
74 return "void";
75 } else if (value instanceof Integer) {
76 if ((Integer) value < 10)
77 return value.toString();
78 return value + " (0x" + Integer.toHexString((Integer) value) + ")";
79 } else if (value instanceof Long) {
80 if ((Long) value < 10)
81 return value + "l";
82 return value + "l (0x" + Long.toHexString((Long) value) + "l)";
83 }
84 return value == null ? "null" : value.toString();
85 }
86 }