Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.graal.snippets/src/com/oracle/graal/replacements/Log.java @ 8415:2361bf148c06
rename packages: *snippets* -> *replacements*
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 20 Mar 2013 22:23:14 +0100 |
parents | graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/Log.java@630ea5001e33 |
children |
comparison
equal
deleted
inserted
replaced
8414:8f274684c123 | 8415:2361bf148c06 |
---|---|
1 /* | |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.graal.replacements; | |
24 | |
25 import java.io.*; | |
26 | |
27 import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; | |
28 import com.oracle.graal.api.meta.*; | |
29 import com.oracle.graal.graph.Node.ConstantNodeParameter; | |
30 import com.oracle.graal.graph.Node.NodeIntrinsic; | |
31 import com.oracle.graal.nodes.extended.*; | |
32 | |
33 //JaCoCo Exclude | |
34 | |
35 /** | |
36 * Provides {@link PrintStream}-like logging facility. This should only be used in | |
37 * {@linkplain Snippet snippets}. | |
38 */ | |
39 public final class Log { | |
40 | |
41 public static final Descriptor LOG_PRIMITIVE = new Descriptor("logPrimitive", false, void.class, int.class, long.class, boolean.class); | |
42 public static final Descriptor LOG_OBJECT = new Descriptor("logObject", false, void.class, Object.class, int.class); | |
43 public static final Descriptor LOG_PRINTF = new Descriptor("logPrintf", false, void.class, Object.class, long.class, long.class, long.class); | |
44 | |
45 // Note: Must be kept in sync with constants in c1_Runtime1.hpp | |
46 private static final int LOG_OBJECT_NEWLINE = 0x01; | |
47 private static final int LOG_OBJECT_STRING = 0x02; | |
48 private static final int LOG_OBJECT_ADDRESS = 0x04; | |
49 | |
50 @NodeIntrinsic(RuntimeCallNode.class) | |
51 private static native void log(@ConstantNodeParameter Descriptor logObject, Object object, int flags); | |
52 | |
53 @NodeIntrinsic(RuntimeCallNode.class) | |
54 private static native void log(@ConstantNodeParameter Descriptor logPrimitive, int typeChar, long value, boolean newline); | |
55 | |
56 @NodeIntrinsic(RuntimeCallNode.class) | |
57 private static native void printf(@ConstantNodeParameter Descriptor logPrintf, String format, long v1, long v2, long v3); | |
58 | |
59 public static void print(boolean value) { | |
60 log(LOG_PRIMITIVE, Kind.Boolean.getTypeChar(), value ? 1L : 0L, false); | |
61 } | |
62 | |
63 public static void print(byte value) { | |
64 log(LOG_PRIMITIVE, Kind.Byte.getTypeChar(), value, false); | |
65 } | |
66 | |
67 public static void print(char value) { | |
68 log(LOG_PRIMITIVE, Kind.Char.getTypeChar(), value, false); | |
69 } | |
70 | |
71 public static void print(short value) { | |
72 log(LOG_PRIMITIVE, Kind.Short.getTypeChar(), value, false); | |
73 } | |
74 | |
75 public static void print(int value) { | |
76 log(LOG_PRIMITIVE, Kind.Int.getTypeChar(), value, false); | |
77 } | |
78 | |
79 public static void print(long value) { | |
80 log(LOG_PRIMITIVE, Kind.Long.getTypeChar(), value, false); | |
81 } | |
82 | |
83 /** | |
84 * Prints a formatted string to the log stream. | |
85 * | |
86 * @param format a C style printf format value that can contain at most one conversion specifier | |
87 * (i.e., a sequence of characters starting with '%'). | |
88 * @param value the value associated with the conversion specifier | |
89 */ | |
90 public static void printf(String format, long value) { | |
91 printf(LOG_PRINTF, format, value, 0L, 0L); | |
92 } | |
93 | |
94 public static void printf(String format, long v1, long v2) { | |
95 printf(LOG_PRINTF, format, v1, v2, 0L); | |
96 } | |
97 | |
98 public static void printf(String format, long v1, long v2, long v3) { | |
99 printf(LOG_PRINTF, format, v1, v2, v3); | |
100 } | |
101 | |
102 public static void print(float value) { | |
103 if (Float.isNaN(value)) { | |
104 print("NaN"); | |
105 } else if (value == Float.POSITIVE_INFINITY) { | |
106 print("Infinity"); | |
107 } else if (value == Float.NEGATIVE_INFINITY) { | |
108 print("-Infinity"); | |
109 } else { | |
110 log(LOG_PRIMITIVE, Kind.Float.getTypeChar(), Float.floatToRawIntBits(value), false); | |
111 } | |
112 } | |
113 | |
114 public static void print(double value) { | |
115 if (Double.isNaN(value)) { | |
116 print("NaN"); | |
117 } else if (value == Double.POSITIVE_INFINITY) { | |
118 print("Infinity"); | |
119 } else if (value == Double.NEGATIVE_INFINITY) { | |
120 print("-Infinity"); | |
121 } else { | |
122 log(LOG_PRIMITIVE, Kind.Double.getTypeChar(), Double.doubleToRawLongBits(value), false); | |
123 } | |
124 } | |
125 | |
126 public static void print(String value) { | |
127 log(LOG_OBJECT, value, LOG_OBJECT_STRING); | |
128 } | |
129 | |
130 public static void printAddress(Object o) { | |
131 log(LOG_OBJECT, o, LOG_OBJECT_ADDRESS); | |
132 } | |
133 | |
134 public static void printObject(Object o) { | |
135 log(LOG_OBJECT, o, 0); | |
136 } | |
137 | |
138 public static void println(boolean value) { | |
139 log(LOG_PRIMITIVE, Kind.Boolean.getTypeChar(), value ? 1L : 0L, true); | |
140 } | |
141 | |
142 public static void println(byte value) { | |
143 log(LOG_PRIMITIVE, Kind.Byte.getTypeChar(), value, true); | |
144 } | |
145 | |
146 public static void println(char value) { | |
147 log(LOG_PRIMITIVE, Kind.Char.getTypeChar(), value, true); | |
148 } | |
149 | |
150 public static void println(short value) { | |
151 log(LOG_PRIMITIVE, Kind.Short.getTypeChar(), value, true); | |
152 } | |
153 | |
154 public static void println(int value) { | |
155 log(LOG_PRIMITIVE, Kind.Int.getTypeChar(), value, true); | |
156 } | |
157 | |
158 public static void println(long value) { | |
159 log(LOG_PRIMITIVE, Kind.Long.getTypeChar(), value, true); | |
160 } | |
161 | |
162 public static void println(float value) { | |
163 if (Float.isNaN(value)) { | |
164 println("NaN"); | |
165 } else if (value == Float.POSITIVE_INFINITY) { | |
166 println("Infinity"); | |
167 } else if (value == Float.NEGATIVE_INFINITY) { | |
168 println("-Infinity"); | |
169 } else { | |
170 log(LOG_PRIMITIVE, Kind.Float.getTypeChar(), Float.floatToRawIntBits(value), true); | |
171 } | |
172 } | |
173 | |
174 public static void println(double value) { | |
175 if (Double.isNaN(value)) { | |
176 println("NaN"); | |
177 } else if (value == Double.POSITIVE_INFINITY) { | |
178 println("Infinity"); | |
179 } else if (value == Double.NEGATIVE_INFINITY) { | |
180 println("-Infinity"); | |
181 } else { | |
182 log(LOG_PRIMITIVE, Kind.Double.getTypeChar(), Double.doubleToRawLongBits(value), true); | |
183 } | |
184 } | |
185 | |
186 public static void println(String value) { | |
187 log(LOG_OBJECT, value, LOG_OBJECT_NEWLINE | LOG_OBJECT_STRING); | |
188 } | |
189 | |
190 public static void printlnAddress(Object o) { | |
191 log(LOG_OBJECT, o, LOG_OBJECT_NEWLINE | LOG_OBJECT_ADDRESS); | |
192 } | |
193 | |
194 public static void printlnObject(Object o) { | |
195 log(LOG_OBJECT, o, LOG_OBJECT_NEWLINE); | |
196 } | |
197 | |
198 public static void println() { | |
199 println(""); | |
200 } | |
201 } |