241 242 @SuppressWarnings("try") 243 private boolean shouldDump(StructuredGraph graph, C context) { 244 DebugContext debug = graph.getDebug(); 245 String phaseChange = DebugOptions.DumpOnPhaseChange.getValue(graph.getOptions()); 246 if (phaseChange != null && Pattern.matches(phaseChange, getClass().getSimpleName())) { 247 StructuredGraph graphCopy = (StructuredGraph) graph.copy(graph.getDebug()); 248 GraphChangeListener listener = new GraphChangeListener(graphCopy); 249 try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) { 250 try (DebugContext.Scope s2 = debug.sandbox("GraphChangeListener", null)) { 251 run(graphCopy, context); 252 } catch (Throwable t) { 253 debug.handle(t); 254 } 255 } 256 return listener.changed; 257 } 258 return false; 259 } 260 261 private final class GraphChangeListener implements NodeEventListener { 262 boolean changed; 263 private StructuredGraph graph; 264 private Mark mark; 265 266 GraphChangeListener(StructuredGraph graphCopy) { 267 this.graph = graphCopy; 268 this.mark = graph.getMark(); 269 } 270 271 @Override 272 public void event(NodeEvent e, Node node) { 273 if (!graph.isNew(mark, node) && node.isAlive()) { 274 if (e == NodeEvent.INPUT_CHANGED || e == NodeEvent.ZERO_USAGES) { 275 changed = true; 276 } 277 } 278 } 279 } 280 281 protected CharSequence getName() { 282 return new ClassTypeSequence(BasePhase.this.getClass()); 283 } 284 285 protected abstract void run(StructuredGraph graph, C context); 286 287 @Override 288 public String contractorName() { 289 return getName().toString(); 290 } 291 292 @Override | 241 242 @SuppressWarnings("try") 243 private boolean shouldDump(StructuredGraph graph, C context) { 244 DebugContext debug = graph.getDebug(); 245 String phaseChange = DebugOptions.DumpOnPhaseChange.getValue(graph.getOptions()); 246 if (phaseChange != null && Pattern.matches(phaseChange, getClass().getSimpleName())) { 247 StructuredGraph graphCopy = (StructuredGraph) graph.copy(graph.getDebug()); 248 GraphChangeListener listener = new GraphChangeListener(graphCopy); 249 try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) { 250 try (DebugContext.Scope s2 = debug.sandbox("GraphChangeListener", null)) { 251 run(graphCopy, context); 252 } catch (Throwable t) { 253 debug.handle(t); 254 } 255 } 256 return listener.changed; 257 } 258 return false; 259 } 260 261 private final class GraphChangeListener extends NodeEventListener { 262 boolean changed; 263 private StructuredGraph graph; 264 private Mark mark; 265 266 GraphChangeListener(StructuredGraph graphCopy) { 267 this.graph = graphCopy; 268 this.mark = graph.getMark(); 269 } 270 271 @Override 272 public void changed(NodeEvent e, Node node) { 273 if (!graph.isNew(mark, node) && node.isAlive()) { 274 if (e == NodeEvent.INPUT_CHANGED || e == NodeEvent.ZERO_USAGES) { 275 changed = true; 276 } 277 } 278 } 279 } 280 281 protected CharSequence getName() { 282 return new ClassTypeSequence(BasePhase.this.getClass()); 283 } 284 285 protected abstract void run(StructuredGraph graph, C context); 286 287 @Override 288 public String contractorName() { 289 return getName().toString(); 290 } 291 292 @Override |