Mercurial > hg > truffle
annotate graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java @ 17196:189479d72dc8
Move bit manipulation methods to CodeUtil class.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Fri, 19 Sep 2014 11:00:46 +0200 |
parents | 820c6d353358 |
children | f609dff05ea0 |
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 */ |
5510
426c605c9d3c
Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
23 package com.oracle.graal.api.code; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 import java.util.*; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5506
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
30 * Miscellaneous collection of utility methods used by {@code com.oracle.graal.api.code} and its |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
31 * clients. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
33 public class CodeUtil { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 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
|
36 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 public static final int K = 1024; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 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
|
39 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 public static boolean isOdd(int n) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 return (n & 1) == 1; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 public static boolean isEven(int n) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 return (n & 1) == 0; |
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 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 * 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
|
50 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 * @param val the value to check |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 * @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
|
53 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 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
|
55 return val > 0 && (val & val - 1) == 0; |
3733
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 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 * 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
|
60 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 * @param val the value to check |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 * @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
|
63 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 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
|
65 return val > 0 && (val & val - 1) == 0; |
3733
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 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
69 * 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
|
70 * {@code log2(21) = 4} ) |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
71 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 * @param val the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 * @return the log base 2 of the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 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
|
76 assert val > 0; |
10960 | 77 return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(val); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
81 * 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
|
82 * {@code log2(21) = 4}) |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
83 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 * @param val the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 * @return the log base 2 of the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 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
|
88 assert val > 0; |
10960 | 89 return (Long.SIZE - 1) - Long.numberOfLeadingZeros(val); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 /** |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
93 * 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
|
94 * |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
95 * @param value the value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
96 * @param resultBits the result bit width |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
97 * @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
|
98 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
99 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
|
100 long ret = value & mask(resultBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
101 return signExtend(ret, resultBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
102 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
103 |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
104 /** |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
105 * Sign extend an integer. |
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 * @param value the input value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
108 * @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
|
109 * @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
|
110 * {@code value} |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
111 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
112 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
|
113 if (inputBits < 64) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
114 if ((value >>> (inputBits - 1) & 1) == 1) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
115 return value | (-1L << inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
116 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
117 return value & ~(-1L << inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
118 } |
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; |
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 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
123 |
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 * Zero extend an integer. |
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 * @param value the input value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
128 * @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
|
129 * @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
|
130 * {@code value} |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
131 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
132 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
|
133 if (inputBits < 64) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
134 return value & ~(-1L << inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
135 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
136 return value; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
137 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
138 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
139 |
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 * Convert an integer to long. |
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 * @param value the input value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
144 * @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
|
145 * @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
|
146 * @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
|
147 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
148 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
|
149 if (unsigned) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
150 return zeroExtend(value, inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
151 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
152 return signExtend(value, inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
153 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
154 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
155 |
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 * 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
|
158 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
159 public static long mask(int bits) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
160 assert 0 <= bits && bits <= 64; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
161 if (bits == 64) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
162 return 0xffffffffffffffffL; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
163 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
164 return (1L << bits) - 1; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
165 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
166 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
167 |
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 * 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
|
170 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
171 public static long minValue(int bits) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
172 assert 0 < bits && bits <= 64; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
173 return -1L << (bits - 1); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
174 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
175 |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
176 /** |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
177 * 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
|
178 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
179 public static long maxValue(int bits) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
180 assert 0 < bits && bits <= 64; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
181 return mask(bits - 1); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
182 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
183 |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
184 /** |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
185 * 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
|
186 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
187 * @param frame |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
188 * @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
|
189 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
190 public static String tabulateValues(BytecodeFrame frame) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
191 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
|
192 assert cols > 0; |
4142
bc8527f3071c
Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3733
diff
changeset
|
193 ArrayList<Object> cells = new ArrayList<>(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
194 cells.add(""); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
195 for (int i = 0; i < cols; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
196 cells.add(i); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
197 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
198 cols++; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
199 if (frame.numLocals != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
200 cells.add("locals:"); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
201 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
|
202 cells.addAll(Collections.nCopies(cols - frame.numLocals - 1, "")); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
203 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
204 if (frame.numStack != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
205 cells.add("stack:"); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
206 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
|
207 cells.addAll(Collections.nCopies(cols - frame.numStack - 1, "")); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
208 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
209 if (frame.numLocks != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
210 cells.add("locks:"); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
211 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
|
212 cells.addAll(Collections.nCopies(cols - frame.numLocks - 1, "")); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
213 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
214 Object[] cellArray = cells.toArray(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
215 for (int i = 0; i < cellArray.length; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
216 if ((i % cols) != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
217 cellArray[i] = "|" + cellArray[i]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
218 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
219 } |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
220 return CodeUtil.tabulate(cellArray, cols, 1, 1); |
3733
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 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
224 * 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
|
225 * {@link String#valueOf(Object)}. |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
226 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
227 * @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
|
228 * @param cols the number of columns per row |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
229 * @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
|
230 * @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
|
231 * @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
|
232 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
233 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
|
234 int rows = (cells.length + (cols - 1)) / cols; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
235 int[] colWidths = new int[cols]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
236 for (int col = 0; col < cols; col++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
237 for (int row = 0; row < rows; row++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
238 int index = col + (row * cols); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
239 if (index < cells.length) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
240 Object cell = cells[index]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
241 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
|
242 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
243 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
244 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
245 StringBuilder sb = new StringBuilder(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
246 String nl = NEW_LINE; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
247 for (int row = 0; row < rows; row++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
248 for (int col = 0; col < cols; col++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
249 int index = col + (row * cols); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
250 if (index < cells.length) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
251 for (int i = 0; i < lpad; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
252 sb.append(' '); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
253 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
254 Object cell = cells[index]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
255 String s = String.valueOf(cell); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
256 int w = s.length(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
257 sb.append(s); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
258 while (w < colWidths[col]) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
259 sb.append(' '); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
260 w++; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
261 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
262 for (int i = 0; i < rpad; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
263 sb.append(' '); |
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 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
266 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
267 sb.append(nl); |
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 return sb.toString(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
270 } |
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 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
273 * 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
|
274 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
275 * @param sb the {@link StringBuilder} to append to |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
276 * @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
|
277 * @return the value of {@code sb} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
278 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
279 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
|
280 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
|
281 if (pos.getCaller() != null) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
282 sb.append(NEW_LINE); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
283 append(sb, pos.getCaller()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
284 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
285 return sb; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
286 } |
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 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
289 * 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
|
290 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
291 * @param sb the {@link StringBuilder} to append to |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
292 * @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
|
293 * @return the value of {@code sb} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
294 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
295 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
|
296 MetaUtil.appendLocation(sb.append("at "), frame.getMethod(), frame.getBCI()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
297 if (frame.values != null && frame.values.length > 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
298 sb.append(NEW_LINE); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
299 String table = tabulateValues(frame); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
300 String[] rows = table.split(NEW_LINE); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
301 for (int i = 0; i < rows.length; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
302 String row = rows[i]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
303 if (!row.trim().isEmpty()) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
304 sb.append(" ").append(row); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
305 if (i != rows.length - 1) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
306 sb.append(NEW_LINE); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
307 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
308 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
309 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
310 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
311 if (frame.caller() != null) { |
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 append(sb, frame.caller()); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
314 } else if (frame.getCaller() != null) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
315 sb.append(NEW_LINE); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
316 append(sb, frame.getCaller()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
317 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
318 return sb; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
319 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
320 |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
321 public interface RefMapFormatter { |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
322 |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
323 String formatStackSlot(int frameRefMapIndex); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
324 |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
325 String formatRegister(int regRefMapIndex); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
326 } |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
327 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
328 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
329 * 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
|
330 */ |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
331 public static class DefaultRefMapFormatter implements RefMapFormatter { |
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
|
332 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
333 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
334 * The size of a stack slot. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
335 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
336 public final int slotSize; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
337 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
338 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
339 * The register used as the frame pointer. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
340 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
341 public final Register fp; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
342 |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
343 public final Architecture arch; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
344 |
6582
cc32ce37eddc
deleted Architecture.twoOperandMode() and encapsulated all public fields in Architecture with getters
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
345 private final Register[] registers; |
cc32ce37eddc
deleted Architecture.twoOperandMode() and encapsulated all public fields in Architecture with getters
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
346 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
347 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
348 * 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
|
349 * 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
|
350 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
351 public final int refMapToFPOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
352 |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
353 public DefaultRefMapFormatter(Architecture arch, int slotSize, Register fp, int refMapToFPOffset) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
354 this.arch = arch; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
355 this.slotSize = slotSize; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
356 this.fp = fp; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
357 this.refMapToFPOffset = refMapToFPOffset; |
6582
cc32ce37eddc
deleted Architecture.twoOperandMode() and encapsulated all public fields in Architecture with getters
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
358 this.registers = arch.getRegisters(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
359 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
360 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
361 public String formatStackSlot(int frameRefMapIndex) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
362 int refMapOffset = frameRefMapIndex * slotSize; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
363 int fpOffset = refMapOffset + refMapToFPOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
364 if (fpOffset >= 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
365 return fp + "+" + fpOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
366 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
367 return fp.name + fpOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
368 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
369 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
370 public String formatRegister(int regRefMapIndex) { |
6582
cc32ce37eddc
deleted Architecture.twoOperandMode() and encapsulated all public fields in Architecture with getters
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
371 return registers[regRefMapIndex].toString(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
372 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
373 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
374 |
14562
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
375 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
|
376 |
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
377 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
|
378 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
|
379 } |
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
380 |
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
381 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
|
382 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
|
383 } |
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
384 } |
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
385 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
386 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
387 * 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
|
388 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
389 * @param sb the {@link StringBuilder} to append to |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
390 * @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
|
391 * @return the value of {@code sb} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
392 */ |
14562
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 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
|
397 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
398 String nl = NEW_LINE; |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
399 ReferenceMap refMap = info.getReferenceMap(); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
400 if (refMap != null && refMap.hasRegisterRefMap()) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
401 sb.append(" reg-ref-map:"); |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
402 refMap.appendRegisterMap(sb, formatter); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
403 sb.append(nl); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
404 } |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
405 if (refMap != null && refMap.hasFrameRefMap()) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
406 sb.append("frame-ref-map:"); |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
407 refMap.appendFrameMap(sb, formatter); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
408 sb.append(nl); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
409 } |
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
7840
diff
changeset
|
410 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
|
411 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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
7840
diff
changeset
|
417 } |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
418 BytecodeFrame frame = info.frame(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
419 if (frame != null) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
420 append(sb, frame); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
421 } else if (info.getBytecodePosition() != null) { |
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
422 append(sb, info.getBytecodePosition()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
423 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
424 return sb; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
425 } |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
426 |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
427 /** |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
428 * Create a calling convention from a {@link ResolvedJavaMethod}. |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
429 */ |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
430 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
|
431 Signature sig = method.getSignature(); |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 } 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
|
440 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
|
441 } |
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
|
442 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
|
443 argTypes[argIndex++] = sig.getParameterType(i, null); |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
444 } |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
445 |
12050
9584d08f56db
rename: lookupRegisterConfig -> getRegisterConfig
Doug Simon <doug.simon@oracle.com>
parents:
10960
diff
changeset
|
446 RegisterConfig registerConfig = codeCache.getRegisterConfig(); |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
447 return registerConfig.getCallingConvention(type, retType, argTypes, codeCache.getTarget(), stackOnly); |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
448 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
449 } |