comparison graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java @ 5134:4eb9895d9afe

Refactoring of the debug framework. Move compiler thread implementation to its own file.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 21 Mar 2012 12:07:41 +0100
parents e808627bd16f
children 55bf72fafc41
comparison
equal deleted inserted replaced
5102:09f638813477 5134:4eb9895d9afe
39 39
40 private Object[] context; 40 private Object[] context;
41 41
42 private DebugValueMap valueMap; 42 private DebugValueMap valueMap;
43 private String qualifiedName; 43 private String qualifiedName;
44 private String name;
45 44
46 private static final char SCOPE_SEP = '.'; 45 private static final char SCOPE_SEP = '.';
47 46
48 private boolean logEnabled; 47 private boolean logEnabled;
49 private boolean meterEnabled; 48 private boolean meterEnabled;
65 public static DebugConfig getConfig() { 64 public static DebugConfig getConfig() {
66 return configTL.get(); 65 return configTL.get();
67 } 66 }
68 67
69 private DebugScope(String name, String qualifiedName, DebugScope parent, Object... context) { 68 private DebugScope(String name, String qualifiedName, DebugScope parent, Object... context) {
70 this.name = name;
71 this.parent = parent; 69 this.parent = parent;
72 this.context = context; 70 this.context = context;
73 this.qualifiedName = qualifiedName; 71 this.qualifiedName = qualifiedName;
74 assert context != null; 72 assert context != null;
73
74 if (parent != null) {
75 for (DebugValueMap child : parent.getValueMap().getChildren()) {
76 if (child.getName().equals(name)) {
77 this.valueMap = child;
78 return;
79 }
80 }
81 this.valueMap = new DebugValueMap(name);
82 parent.getValueMap().addChild(this.valueMap);
83 } else {
84 this.valueMap = new DebugValueMap(name);
85 }
75 } 86 }
76 87
77 public boolean isDumpEnabled() { 88 public boolean isDumpEnabled() {
78 return dumpEnabled; 89 return dumpEnabled;
79 } 90 }
121 instanceTL.set(newChild); 132 instanceTL.set(newChild);
122 newChild.updateFlags(); 133 newChild.updateFlags();
123 try (TimerCloseable a = scopeTime.start()) { 134 try (TimerCloseable a = scopeTime.start()) {
124 return executeScope(runnable, callable); 135 return executeScope(runnable, callable);
125 } finally { 136 } finally {
126 if (!sandbox && newChild.hasValueMap()) {
127 getValueMap().addChild(newChild.getValueMap());
128 }
129 newChild.context = null; 137 newChild.context = null;
130 instanceTL.set(oldContext); 138 instanceTL.set(oldContext);
131 setConfig(oldConfig); 139 setConfig(oldConfig);
132 } 140 }
133 } 141 }
134 142
135 private <T> T executeScope(Runnable runnable, Callable<T> callable) { 143 private <T> T executeScope(Runnable runnable, Callable<T> callable) {
144
136 try { 145 try {
137 if (runnable != null) { 146 if (runnable != null) {
138 runnable.run(); 147 runnable.run();
139 } 148 }
140 if (callable != null) { 149 if (callable != null) {
189 } 198 }
190 return null; 199 return null;
191 } 200 }
192 201
193 private DebugValueMap getValueMap() { 202 private DebugValueMap getValueMap() {
194 if (valueMap == null) {
195 valueMap = new DebugValueMap(name);
196 }
197 return valueMap; 203 return valueMap;
198 }
199
200 private boolean hasValueMap() {
201 return valueMap != null;
202 } 204 }
203 205
204 long getCurrentValue(int index) { 206 long getCurrentValue(int index) {
205 return getValueMap().getCurrentValue(index); 207 return getValueMap().getCurrentValue(index);
206 } 208 }