# HG changeset patch # User Doug Simon # Date 1341479892 -7200 # Node ID 25e37b01b92aa6669851eed55b1bee270f71920e # Parent 8635406a0c33d722e3a6dd636431e6ad7fe609e1 moved SnippetCounter and DirectObjectStoreNode into graal.snippets project as they are not HotSpot specific diff -r 8635406a0c33 -r 25e37b01b92a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java Thu Jul 05 10:31:30 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java Thu Jul 05 11:18:12 2012 +0200 @@ -30,6 +30,7 @@ import com.oracle.graal.snippets.*; import com.oracle.graal.snippets.Snippet.ConstantParameter; import com.oracle.graal.snippets.Snippet.Fold; +import com.oracle.graal.snippets.nodes.*; @SuppressWarnings("unused") diff -r 8635406a0c33 -r 25e37b01b92a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/DirectObjectStoreNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/DirectObjectStoreNode.java Thu Jul 05 10:31:30 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.snippets; - -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; -import com.oracle.graal.snippets.*; - -/** - * A special purpose store node that differs from {@link UnsafeStoreNode} in that - * it is not a {@link StateSplit} and does not include a write barrier. - */ -class DirectObjectStoreNode extends FixedWithNextNode implements Lowerable { - @Input private ValueNode object; - @Input private ValueNode value; - @Input private ValueNode offset; - private final int displacement; - - public DirectObjectStoreNode(ValueNode object, int displacement, ValueNode offset, ValueNode value) { - super(StampFactory.forVoid()); - this.object = object; - this.value = value; - this.offset = offset; - this.displacement = displacement; - } - - @SuppressWarnings("unused") - @NodeIntrinsic - public static void storeObject(Object obj, @ConstantNodeParameter int displacement, long offset, Object value) { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unused") - @NodeIntrinsic - public static void storeLong(Object obj, @ConstantNodeParameter int displacement, long offset, long value) { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unused") - @NodeIntrinsic - public static void storeWord(Object obj, @ConstantNodeParameter int displacement, long offset, Word value) { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unused") - @NodeIntrinsic - public static void storeInt(Object obj, @ConstantNodeParameter int displacement, long offset, int value) { - throw new UnsupportedOperationException(); - } - - @Override - public void lower(LoweringTool tool) { - StructuredGraph graph = (StructuredGraph) this.graph(); - IndexedLocationNode location = IndexedLocationNode.create(LocationNode.ANY_LOCATION, value.kind(), displacement, offset, graph, false); - WriteNode write = graph.add(new WriteNode(object, value, location)); - graph.replaceFixedWithFixed(this, write); - } -} diff -r 8635406a0c33 -r 25e37b01b92a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Thu Jul 05 10:31:30 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Thu Jul 05 11:18:12 2012 +0200 @@ -24,9 +24,9 @@ import static com.oracle.graal.hotspot.nodes.CastFromHub.*; import static com.oracle.graal.hotspot.nodes.RegisterNode.*; -import static com.oracle.graal.hotspot.snippets.DirectObjectStoreNode.*; import static com.oracle.graal.nodes.extended.UnsafeLoadNode.*; import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*; +import static com.oracle.graal.snippets.nodes.DirectObjectStoreNode.*; import static com.oracle.graal.snippets.nodes.ExplodeLoopNode.*; import static com.oracle.max.asm.target.amd64.AMD64.*; import static com.oracle.max.criutils.UnsignedMath.*; diff -r 8635406a0c33 -r 25e37b01b92a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SnippetCounter.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SnippetCounter.java Thu Jul 05 10:31:30 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.snippets; - -import java.io.*; -import java.util.*; - -import sun.misc.*; - -import com.oracle.graal.graph.*; -import com.oracle.graal.snippets.Snippet.Fold; - -/** - * A counter that can be safely {@linkplain #inc() incremented} from within a - * snippet for gathering snippet specific metrics. - */ -public class SnippetCounter implements Comparable { - - /** - * A group of related counters. - */ - public static class Group { - final String name; - final List counters; - - public Group(String name) { - this.name = name; - this.counters = new ArrayList<>(); - } - - @Override - public synchronized String toString() { - Collections.sort(counters); - - long total = 0; - for (SnippetCounter c : counters) { - total += c.value; - } - - StringBuilder buf = new StringBuilder(String.format("Counters: %s%n", name)); - - for (SnippetCounter c : counters) { - double percent = total == 0D ? 0D : ((double) (c.value * 100)) / total; - buf.append(String.format("%16s: %5.2f%%%10d // %s%n", c.name, percent, c.value, c.description)); - } - return buf.toString(); - } - } - - /** - * Sorts counters in descending order of their {@linkplain #value() values}. - */ - @Override - public int compareTo(SnippetCounter o) { - if (value > o.value) { - return -1; - } else if (o.value < value) { - return 1; - } - return 0; - } - - private static final List groups = new ArrayList<>(); - - private final Group group; - private final int index; - private final String name; - private final String description; - private long value; - - @Fold - private static int countOffset() { - try { - return (int) Unsafe.getUnsafe().objectFieldOffset(SnippetCounter.class.getDeclaredField("value")); - } catch (Exception e) { - throw new GraalInternalError(e); - } - } - - /** - * Creates a counter. - * - * @param group the group to which the counter belongs. If this is null, the newly created counter is disabled and - * {@linkplain #inc() incrementing} is a no-op. - * @param name the name of the counter - * @param description a brief comment describing the metric represented by the counter - */ - public SnippetCounter(Group group, String name, String description) { - this.group = group; - this.name = name; - this.description = description; - if (group != null) { - List counters = group.counters; - this.index = counters.size(); - counters.add(this); - if (index == 0) { - groups.add(group); - } - } else { - this.index = -1; - } - } - - /** - * Increments the value of this counter. This method can be safely used in a snippet - * if it is invoked on a compile-time constant {@link SnippetCounter} object. - */ - public void inc() { - if (group != null) { - DirectObjectStoreNode.storeLong(this, countOffset(), 0, value + 1); - } - } - - /** - * Gets the value of this counter. - */ - public long value() { - return value; - } - - /** - * Prints all the counter groups to a given stream. - */ - public static void printGroups(PrintStream out) { - for (Group group : groups) { - out.println(group); - } - } -} diff -r 8635406a0c33 -r 25e37b01b92a graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetCounter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetCounter.java Thu Jul 05 11:18:12 2012 +0200 @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.snippets; + +import java.io.*; +import java.util.*; + +import sun.misc.*; + +import com.oracle.graal.graph.*; +import com.oracle.graal.snippets.Snippet.Fold; +import com.oracle.graal.snippets.nodes.*; + +/** + * A counter that can be safely {@linkplain #inc() incremented} from within a + * snippet for gathering snippet specific metrics. + */ +public class SnippetCounter implements Comparable { + + /** + * A group of related counters. + */ + public static class Group { + final String name; + final List counters; + + public Group(String name) { + this.name = name; + this.counters = new ArrayList<>(); + } + + @Override + public synchronized String toString() { + Collections.sort(counters); + + long total = 0; + for (SnippetCounter c : counters) { + total += c.value; + } + + StringBuilder buf = new StringBuilder(String.format("Counters: %s%n", name)); + + for (SnippetCounter c : counters) { + double percent = total == 0D ? 0D : ((double) (c.value * 100)) / total; + buf.append(String.format("%16s: %5.2f%%%10d // %s%n", c.name, percent, c.value, c.description)); + } + return buf.toString(); + } + } + + /** + * Sorts counters in descending order of their {@linkplain #value() values}. + */ + @Override + public int compareTo(SnippetCounter o) { + if (value > o.value) { + return -1; + } else if (o.value < value) { + return 1; + } + return 0; + } + + private static final List groups = new ArrayList<>(); + + private final Group group; + private final int index; + private final String name; + private final String description; + private long value; + + @Fold + private static int countOffset() { + try { + return (int) Unsafe.getUnsafe().objectFieldOffset(SnippetCounter.class.getDeclaredField("value")); + } catch (Exception e) { + throw new GraalInternalError(e); + } + } + + /** + * Creates a counter. + * + * @param group the group to which the counter belongs. If this is null, the newly created counter is disabled and + * {@linkplain #inc() incrementing} is a no-op. + * @param name the name of the counter + * @param description a brief comment describing the metric represented by the counter + */ + public SnippetCounter(Group group, String name, String description) { + this.group = group; + this.name = name; + this.description = description; + if (group != null) { + List counters = group.counters; + this.index = counters.size(); + counters.add(this); + if (index == 0) { + groups.add(group); + } + } else { + this.index = -1; + } + } + + /** + * Increments the value of this counter. This method can be safely used in a snippet + * if it is invoked on a compile-time constant {@link SnippetCounter} object. + */ + public void inc() { + if (group != null) { + DirectObjectStoreNode.storeLong(this, countOffset(), 0, value + 1); + } + } + + /** + * Gets the value of this counter. + */ + public long value() { + return value; + } + + /** + * Prints all the counter groups to a given stream. + */ + public static void printGroups(PrintStream out) { + for (Group group : groups) { + out.println(group); + } + } +} diff -r 8635406a0c33 -r 25e37b01b92a graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/DirectObjectStoreNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/DirectObjectStoreNode.java Thu Jul 05 11:18:12 2012 +0200 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.snippets.nodes; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; +import com.oracle.graal.snippets.*; + +/** + * A special purpose store node that differs from {@link UnsafeStoreNode} in that + * it is not a {@link StateSplit} and does not include a write barrier. + */ +public class DirectObjectStoreNode extends FixedWithNextNode implements Lowerable { + @Input private ValueNode object; + @Input private ValueNode value; + @Input private ValueNode offset; + private final int displacement; + + public DirectObjectStoreNode(ValueNode object, int displacement, ValueNode offset, ValueNode value) { + super(StampFactory.forVoid()); + this.object = object; + this.value = value; + this.offset = offset; + this.displacement = displacement; + } + + @SuppressWarnings("unused") + @NodeIntrinsic + public static void storeObject(Object obj, @ConstantNodeParameter int displacement, long offset, Object value) { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unused") + @NodeIntrinsic + public static void storeLong(Object obj, @ConstantNodeParameter int displacement, long offset, long value) { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unused") + @NodeIntrinsic + public static void storeWord(Object obj, @ConstantNodeParameter int displacement, long offset, Word value) { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unused") + @NodeIntrinsic + public static void storeInt(Object obj, @ConstantNodeParameter int displacement, long offset, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void lower(LoweringTool tool) { + StructuredGraph graph = (StructuredGraph) this.graph(); + IndexedLocationNode location = IndexedLocationNode.create(LocationNode.ANY_LOCATION, value.kind(), displacement, offset, graph, false); + WriteNode write = graph.add(new WriteNode(object, value, location)); + graph.replaceFixedWithFixed(this, write); + } +}