annotate graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeUtil.java @ 21556:48c1ebd24120

renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 27 May 2015 00:36:16 +0200
parents graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java@93215cb4a2f9
children f5b549811bac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
7840
c052cfe3cae3 let CodeUtil.getCallingConvention() honour receivers (if any)
Michael Haupt <michael.haupt@oracle.com>
parents: 7838
diff changeset
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21282
diff changeset
23 package com.oracle.jvmci.code;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21282
diff changeset
25 import com.oracle.jvmci.meta.Signature;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21282
diff changeset
26 import com.oracle.jvmci.meta.ResolvedJavaMethod;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21282
diff changeset
27 import com.oracle.jvmci.meta.JavaType;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21282
diff changeset
28 import com.oracle.jvmci.meta.MetaUtil;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 /**
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21282
diff changeset
33 * Miscellaneous collection of utility methods used by {@code com.oracle.jvmci.code} and its
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
34 * clients.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
36 public class CodeUtil {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 public static final String NEW_LINE = String.format("%n");
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 public static final int K = 1024;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 public static final int M = 1024 * 1024;
4547
a3cdfa2be94e Allow to intrinsify an invoke with a deoptimize node. Make debug output more relaxed wrt to null in FrameMap.method
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4484
diff changeset
42
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 public static boolean isOdd(int n) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 return (n & 1) == 1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 public static boolean isEven(int n) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 return (n & 1) == 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 * Checks whether the specified integer is a power of two.
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
53 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 * @param val the value to check
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 * @return {@code true} if the value is a power of two; {@code false} otherwise
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 public static boolean isPowerOf2(int val) {
10038
9645cfaffc62 CodeUtil.isPowerOf2 should not return true for Integer/Long.MIN_VALUE.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9612
diff changeset
58 return val > 0 && (val & val - 1) == 0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 * Checks whether the specified long is a power of two.
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
63 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 * @param val the value to check
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 * @return {@code true} if the value is a power of two; {@code false} otherwise
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 public static boolean isPowerOf2(long val) {
10038
9645cfaffc62 CodeUtil.isPowerOf2 should not return true for Integer/Long.MIN_VALUE.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9612
diff changeset
68 return val > 0 && (val & val - 1) == 0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
72 * Computes the log (base 2) of the specified integer, rounding down. (E.g {@code log2(8) = 3},
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
73 * {@code log2(21) = 4} )
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
74 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 * @param val the value
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 * @return the log base 2 of the value
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 public static int log2(int val) {
10038
9645cfaffc62 CodeUtil.isPowerOf2 should not return true for Integer/Long.MIN_VALUE.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9612
diff changeset
79 assert val > 0;
10960
8aba11322f4e use type.SIZE instead of constant
twisti
parents: 10038
diff changeset
80 return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(val);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
84 * Computes the log (base 2) of the specified long, rounding down. (E.g {@code log2(8) = 3},
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
85 * {@code log2(21) = 4})
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
86 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 * @param val the value
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 * @return the log base 2 of the value
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 public static int log2(long val) {
10038
9645cfaffc62 CodeUtil.isPowerOf2 should not return true for Integer/Long.MIN_VALUE.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9612
diff changeset
91 assert val > 0;
10960
8aba11322f4e use type.SIZE instead of constant
twisti
parents: 10038
diff changeset
92 return (Long.SIZE - 1) - Long.numberOfLeadingZeros(val);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 /**
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
96 * Narrow an integer value to a given bit width, and return the result as a signed long.
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
97 *
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
98 * @param value the value
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
99 * @param resultBits the result bit width
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
100 * @return {@code value} interpreted as {@code resultBits} bit number, encoded as signed long
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
101 */
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
102 public static long narrow(long value, int resultBits) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
103 long ret = value & mask(resultBits);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
104 return signExtend(ret, resultBits);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
105 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
106
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
107 /**
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
108 * Sign extend an integer.
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
109 *
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
110 * @param value the input value
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
111 * @param inputBits the bit width of the input value
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
112 * @return a signed long with the same value as the signed {@code inputBits}-bit number
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
113 * {@code value}
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
114 */
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
115 public static long signExtend(long value, int inputBits) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
116 if (inputBits < 64) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
117 if ((value >>> (inputBits - 1) & 1) == 1) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
118 return value | (-1L << inputBits);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
119 } else {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
120 return value & ~(-1L << inputBits);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
121 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
122 } else {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
123 return value;
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
124 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
125 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
126
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
127 /**
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
128 * Zero extend an integer.
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
129 *
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
130 * @param value the input value
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
131 * @param inputBits the bit width of the input value
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
132 * @return an unsigned long with the same value as the unsigned {@code inputBits}-bit number
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
133 * {@code value}
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
134 */
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
135 public static long zeroExtend(long value, int inputBits) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
136 if (inputBits < 64) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
137 return value & ~(-1L << inputBits);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
138 } else {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
139 return value;
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
140 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
141 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
142
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
143 /**
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
144 * Convert an integer to long.
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
145 *
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
146 * @param value the input value
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
147 * @param inputBits the bit width of the input value
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
148 * @param unsigned whether the values should be interpreted as signed or unsigned
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
149 * @return a long with the same value as the {@code inputBits}-bit number {@code value}
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
150 */
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
151 public static long convert(long value, int inputBits, boolean unsigned) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
152 if (unsigned) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
153 return zeroExtend(value, inputBits);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
154 } else {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
155 return signExtend(value, inputBits);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
156 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
157 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
158
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
159 /**
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
160 * Get a bitmask with the low {@code bits} bit set and the high {@code 64 - bits} bit clear.
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
161 */
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
162 public static long mask(int bits) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
163 assert 0 <= bits && bits <= 64;
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
164 if (bits == 64) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
165 return 0xffffffffffffffffL;
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
166 } else {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
167 return (1L << bits) - 1;
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
168 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
169 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
170
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
171 /**
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
172 * Get the minimum value representable in a {@code bits} bit signed integer.
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
173 */
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
174 public static long minValue(int bits) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
175 assert 0 < bits && bits <= 64;
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
176 return -1L << (bits - 1);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
177 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
178
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
179 /**
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
180 * Get the maximum value representable in a {@code bits} bit signed integer.
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
181 */
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
182 public static long maxValue(int bits) {
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
183 assert 0 < bits && bits <= 64;
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
184 return mask(bits - 1);
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
185 }
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
186
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
187 /**
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188 * Formats the values in a frame as a tabulated string.
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
189 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
190 * @param frame
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 * @return the values in {@code frame} as a tabulated string
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
193 public static String tabulateValues(BytecodeFrame frame) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 int cols = Math.max(frame.numLocals, Math.max(frame.numStack, frame.numLocks));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 assert cols > 0;
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
196 ArrayList<Object> cells = new ArrayList<>();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 cells.add("");
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 for (int i = 0; i < cols; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 cells.add(i);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 cols++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 if (frame.numLocals != 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 cells.add("locals:");
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
204 cells.addAll(Arrays.asList(frame.values).subList(0, frame.numLocals));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 cells.addAll(Collections.nCopies(cols - frame.numLocals - 1, ""));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 if (frame.numStack != 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 cells.add("stack:");
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 cells.addAll(Arrays.asList(frame.values).subList(frame.numLocals, frame.numLocals + frame.numStack));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 cells.addAll(Collections.nCopies(cols - frame.numStack - 1, ""));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 if (frame.numLocks != 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 cells.add("locks:");
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 cells.addAll(Arrays.asList(frame.values).subList(frame.numLocals + frame.numStack, frame.values.length));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
215 cells.addAll(Collections.nCopies(cols - frame.numLocks - 1, ""));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 Object[] cellArray = cells.toArray();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 for (int i = 0; i < cellArray.length; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 if ((i % cols) != 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220 cellArray[i] = "|" + cellArray[i];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 }
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
223 return CodeUtil.tabulate(cellArray, cols, 1, 1);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
225
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
226 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
227 * Formats a given table as a string. The value of each cell is produced by
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
228 * {@link String#valueOf(Object)}.
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
229 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
230 * @param cells the cells of the table in row-major order
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 * @param cols the number of columns per row
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 * @param lpad the number of space padding inserted before each formatted cell value
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
233 * @param rpad the number of space padding inserted after each formatted cell value
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
234 * @return a string with one line per row and each column left-aligned
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
235 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
236 public static String tabulate(Object[] cells, int cols, int lpad, int rpad) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 int rows = (cells.length + (cols - 1)) / cols;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238 int[] colWidths = new int[cols];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 for (int col = 0; col < cols; col++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240 for (int row = 0; row < rows; row++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
241 int index = col + (row * cols);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242 if (index < cells.length) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243 Object cell = cells[index];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
244 colWidths[col] = Math.max(colWidths[col], String.valueOf(cell).length());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
245 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
246 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
247 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 StringBuilder sb = new StringBuilder();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 String nl = NEW_LINE;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
250 for (int row = 0; row < rows; row++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251 for (int col = 0; col < cols; col++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
252 int index = col + (row * cols);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253 if (index < cells.length) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
254 for (int i = 0; i < lpad; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
255 sb.append(' ');
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
256 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
257 Object cell = cells[index];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
258 String s = String.valueOf(cell);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
259 int w = s.length();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
260 sb.append(s);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
261 while (w < colWidths[col]) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
262 sb.append(' ');
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
263 w++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
264 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
265 for (int i = 0; i < rpad; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
266 sb.append(' ');
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
270 sb.append(nl);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
271 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 return sb.toString();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
273 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
274
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
275 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
276 * Appends a formatted code position to a {@link StringBuilder}.
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
277 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
278 * @param sb the {@link StringBuilder} to append to
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
279 * @param pos the code position to format and append to {@code sb}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
280 * @return the value of {@code sb}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
281 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
282 public static StringBuilder append(StringBuilder sb, BytecodePosition pos) {
5719
429accae15aa moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents: 5711
diff changeset
283 MetaUtil.appendLocation(sb.append("at "), pos.getMethod(), pos.getBCI());
5552
69a8969dbf40 Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
284 if (pos.getCaller() != null) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
285 sb.append(NEW_LINE);
5552
69a8969dbf40 Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
286 append(sb, pos.getCaller());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
287 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
288 return sb;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
289 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
290
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
291 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
292 * Appends a formatted frame to a {@link StringBuilder}.
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
293 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
294 * @param sb the {@link StringBuilder} to append to
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
295 * @param frame the frame to format and append to {@code sb}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
296 * @return the value of {@code sb}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
297 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
298 public static StringBuilder append(StringBuilder sb, BytecodeFrame frame) {
5719
429accae15aa moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents: 5711
diff changeset
299 MetaUtil.appendLocation(sb.append("at "), frame.getMethod(), frame.getBCI());
21282
93215cb4a2f9 include duringCall and rethrowException for BytecodeFrames in disassembly comments
Doug Simon <doug.simon@oracle.com>
parents: 17429
diff changeset
300 assert sb.charAt(sb.length() - 1) == ']';
93215cb4a2f9 include duringCall and rethrowException for BytecodeFrames in disassembly comments
Doug Simon <doug.simon@oracle.com>
parents: 17429
diff changeset
301 sb.deleteCharAt(sb.length() - 1);
93215cb4a2f9 include duringCall and rethrowException for BytecodeFrames in disassembly comments
Doug Simon <doug.simon@oracle.com>
parents: 17429
diff changeset
302 sb.append(", duringCall: ").append(frame.duringCall).append(", rethrow: ").append(frame.rethrowException).append(']');
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
303 if (frame.values != null && frame.values.length > 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
304 sb.append(NEW_LINE);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
305 String table = tabulateValues(frame);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
306 String[] rows = table.split(NEW_LINE);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
307 for (int i = 0; i < rows.length; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
308 String row = rows[i];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
309 if (!row.trim().isEmpty()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
310 sb.append(" ").append(row);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
311 if (i != rows.length - 1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
312 sb.append(NEW_LINE);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
313 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
314 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
315 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
316 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
317 if (frame.caller() != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
318 sb.append(NEW_LINE);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
319 append(sb, frame.caller());
5552
69a8969dbf40 Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
320 } else if (frame.getCaller() != null) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
321 sb.append(NEW_LINE);
5552
69a8969dbf40 Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
322 append(sb, frame.getCaller());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
323 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
324 return sb;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
325 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
326
13725
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
327 public interface RefMapFormatter {
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
328
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
329 String formatStackSlot(int frameRefMapIndex);
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
330
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
331 String formatRegister(int regRefMapIndex);
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
332 }
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
333
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
334 /**
17429
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
335 * Formats a location in a register reference map.
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
336 */
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
337 public static class DefaultRegFormatter implements RefMapFormatter {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
338
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
339 private final Register[] registers;
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
340
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
341 public DefaultRegFormatter(Architecture arch) {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
342 registers = new Register[arch.getRegisterReferenceMapSize()];
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
343 for (Register r : arch.getRegisters()) {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
344 if (r.getReferenceMapIndex() >= 0) {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
345 registers[r.getReferenceMapIndex()] = r;
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
346 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
347 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
348 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
349
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
350 public String formatStackSlot(int frameRefMapIndex) {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
351 return null;
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
352 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
353
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
354 public String formatRegister(int regRefMapIndex) {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
355 int i = regRefMapIndex;
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
356 int idx = 0;
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
357 while (registers[i] == null) {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
358 i--;
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
359 idx++;
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
360 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
361 if (idx == 0) {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
362 return registers[i].toString();
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
363 } else {
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
364 return String.format("%s+%d", registers[i].toString(), idx);
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
365 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
366 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
367 }
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
368
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
369 /**
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
370 * Formats a location present in a register or frame reference map.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
371 */
17429
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
372 public static class DefaultRefMapFormatter extends DefaultRegFormatter {
4547
a3cdfa2be94e Allow to intrinsify an invoke with a deoptimize node. Make debug output more relaxed wrt to null in FrameMap.method
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4484
diff changeset
373
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
374 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
375 * The size of a stack slot.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
376 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
377 public final int slotSize;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
378
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
379 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
380 * The register used as the frame pointer.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
381 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
382 public final Register fp;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
383
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
384 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
385 * The offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6582
diff changeset
386 * to bit 0 in the frame reference map.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
387 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
388 public final int refMapToFPOffset;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
389
13725
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
390 public DefaultRefMapFormatter(Architecture arch, int slotSize, Register fp, int refMapToFPOffset) {
17429
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
391 super(arch);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
392 this.slotSize = slotSize;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
393 this.fp = fp;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
394 this.refMapToFPOffset = refMapToFPOffset;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
395 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
396
17429
f609dff05ea0 Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
397 @Override
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
398 public String formatStackSlot(int frameRefMapIndex) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
399 int refMapOffset = frameRefMapIndex * slotSize;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
400 int fpOffset = refMapOffset + refMapToFPOffset;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
401 if (fpOffset >= 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402 return fp + "+" + fpOffset;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
403 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
404 return fp.name + fpOffset;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
405 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
406 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
407
14562
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
408 public static class NumberedRefMapFormatter implements RefMapFormatter {
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
409
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
410 public String formatStackSlot(int frameRefMapIndex) {
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
411 return "s" + frameRefMapIndex;
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
412 }
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
413
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
414 public String formatRegister(int regRefMapIndex) {
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
415 return "r" + regRefMapIndex;
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
416 }
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
417 }
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
418
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
419 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
420 * Appends a formatted debug info to a {@link StringBuilder}.
17196
189479d72dc8 Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
421 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
422 * @param sb the {@link StringBuilder} to append to
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
423 * @param info the debug info to format and append to {@code sb}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
424 * @return the value of {@code sb}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
425 */
14562
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
426 public static StringBuilder append(StringBuilder sb, DebugInfo info, RefMapFormatter formatterArg) {
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
427 RefMapFormatter formatter = formatterArg;
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
428 if (formatter == null) {
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
429 formatter = new NumberedRefMapFormatter();
45812e05cdb3 Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 13725
diff changeset
430 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
431 String nl = NEW_LINE;
13725
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
432 ReferenceMap refMap = info.getReferenceMap();
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
433 if (refMap != null && refMap.hasRegisterRefMap()) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
434 sb.append(" reg-ref-map:");
13725
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
435 refMap.appendRegisterMap(sb, formatter);
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
436 sb.append(nl);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
437 }
13725
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
438 if (refMap != null && refMap.hasFrameRefMap()) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
439 sb.append("frame-ref-map:");
13725
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
440 refMap.appendFrameMap(sb, formatter);
8d8732e14447 Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents: 12050
diff changeset
441 sb.append(nl);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
442 }
9336
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
443 RegisterSaveLayout calleeSaveInfo = info.getCalleeSaveInfo();
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
444 if (calleeSaveInfo != null) {
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
445 sb.append("callee-save-info:").append(nl);
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
446 Map<Integer, Register> map = calleeSaveInfo.slotsToRegisters(true);
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
447 for (Map.Entry<Integer, Register> e : map.entrySet()) {
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
448 sb.append(" ").append(e.getValue()).append(" -> ").append(formatter.formatStackSlot(e.getKey())).append(nl);
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
449 }
47e7933283f1 added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 7840
diff changeset
450 }
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
451 BytecodeFrame frame = info.frame();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
452 if (frame != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
453 append(sb, frame);
5552
69a8969dbf40 Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
454 } else if (info.getBytecodePosition() != null) {
69a8969dbf40 Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
455 append(sb, info.getBytecodePosition());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
456 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
457 return sb;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
458 }
7798
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
459
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
460 /**
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
461 * Create a calling convention from a {@link ResolvedJavaMethod}.
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
462 */
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
463 public static CallingConvention getCallingConvention(CodeCacheProvider codeCache, CallingConvention.Type type, ResolvedJavaMethod method, boolean stackOnly) {
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
464 Signature sig = method.getSignature();
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
465 JavaType retType = sig.getReturnType(null);
9612
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
466 int sigCount = sig.getParameterCount(false);
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
467 JavaType[] argTypes;
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
468 int argIndex = 0;
15311
820c6d353358 added ModifiersProvider as superinterface for ResolvedJava[Method|Field|Type] and implemented all checks against modifiers as default methods
Doug Simon <doug.simon@oracle.com>
parents: 14562
diff changeset
469 if (!method.isStatic()) {
9612
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
470 argTypes = new JavaType[sigCount + 1];
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
471 argTypes[argIndex++] = method.getDeclaringClass();
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
472 } else {
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
473 argTypes = new JavaType[sigCount];
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
474 }
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
475 for (int i = 0; i < sigCount; i++) {
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 9336
diff changeset
476 argTypes[argIndex++] = sig.getParameterType(i, null);
7798
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
477 }
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
478
12050
9584d08f56db rename: lookupRegisterConfig -> getRegisterConfig
Doug Simon <doug.simon@oracle.com>
parents: 10960
diff changeset
479 RegisterConfig registerConfig = codeCache.getRegisterConfig();
7798
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
480 return registerConfig.getCallingConvention(type, retType, argTypes, codeCache.getTarget(), stackOnly);
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
481 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
482 }