annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java @ 2903:eb3a82946429

Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 17:26:22 +0200
parents 434d71eec7a9
children 9d80049e76bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
23 package com.oracle.max.graal.compiler.phases;
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
24
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
25 import com.oracle.max.graal.compiler.*;
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
26 import com.oracle.max.graal.graph.Graph;
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
27
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
28 public abstract class Phase {
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
29
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
30 private final String name;
2902
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
31 private static final ThreadLocal<Phase> currentPhase = new ThreadLocal<Phase>();
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
32
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
33 public Phase() {
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
34 this.name = this.getClass().getSimpleName();
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
35 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
36
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
37 public Phase(String name) {
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
38 this.name = name;
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
39 }
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
40
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
41 public final void apply(Graph graph) {
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
42 assert graph != null;
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
43
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
44 int startDeletedNodeCount = graph.getDeletedNodeCount();
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
45 int startNodeCount = graph.getNodeCount();
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
46 Phase oldCurrentPhase = null;
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
47 if (GraalOptions.Time) {
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
48 oldCurrentPhase = currentPhase.get();
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
49 currentPhase.set(this);
2902
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
50 if (oldCurrentPhase != null) {
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
51 GraalTimers.get(oldCurrentPhase.getName()).stop();
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
52 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
53 GraalTimers.get(getName()).start();
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
54 }
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
55 run(graph);
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
56 if (GraalOptions.Time) {
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
57 GraalTimers.get(getName()).stop();
2902
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
58 if (oldCurrentPhase != null) {
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
59 GraalTimers.get(oldCurrentPhase.getName()).start();
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
60 }
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
61 currentPhase.set(oldCurrentPhase);
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
62 }
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
63 if (GraalOptions.Meter) {
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
64 int deletedNodeCount = graph.getDeletedNodeCount() - startDeletedNodeCount;
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
65 int createdNodeCount = graph.getNodeCount() - startNodeCount;
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
66 GraalMetrics.get(getName().concat(".executed")).increment();
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
67 GraalMetrics.get(getName().concat(".deletedNodes")).increment(deletedNodeCount);
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
68 GraalMetrics.get(getName().concat(".createdNodes")).increment(createdNodeCount);
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
69 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
70
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
71 // (Item|Graph|Phase|Value)
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
72 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
73
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
74 public final String getName() {
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
75 return name;
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
76 }
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
77
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78 protected abstract void run(Graph graph);
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
79 }