Mercurial > hg > truffle
annotate graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CodeUtil.java @ 21582:b72a5d25ad43
Fix wrong free in ~OptionsTable
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Fri, 29 May 2015 10:35:51 +0200 |
parents | f5b549811bac |
children | b9f9b8af17ff |
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 /** |
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
|
32 * 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
|
33 * clients. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
35 public class CodeUtil { |
3733
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 String NEW_LINE = String.format("%n"); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 public static final int K = 1024; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 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
|
41 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 public static boolean isOdd(int n) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 return (n & 1) == 1; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 } |
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 public static boolean isEven(int n) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 return (n & 1) == 0; |
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 |
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 * 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
|
52 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 * @param val the value to check |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 * @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
|
55 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 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
|
57 return val > 0 && (val & val - 1) == 0; |
3733
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 |
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 * 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
|
62 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 * @param val the value to check |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 * @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
|
65 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 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
|
67 return val > 0 && (val & val - 1) == 0; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 } |
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 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
71 * 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
|
72 * {@code log2(21) = 4} ) |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
73 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 * @param val the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 * @return the log base 2 of the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 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
|
78 assert val > 0; |
10960 | 79 return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(val); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 } |
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 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
83 * 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
|
84 * {@code log2(21) = 4}) |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
85 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 * @param val the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 * @return the log base 2 of the value |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 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
|
90 assert val > 0; |
10960 | 91 return (Long.SIZE - 1) - Long.numberOfLeadingZeros(val); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 } |
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 /** |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
95 * 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
|
96 * |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
97 * @param value the value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
98 * @param resultBits the result bit width |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
99 * @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
|
100 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
101 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
|
102 long ret = value & mask(resultBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
103 return signExtend(ret, resultBits); |
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 |
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 * Sign extend an integer. |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
108 * |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
109 * @param value the input value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
110 * @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
|
111 * @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
|
112 * {@code value} |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
113 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
114 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
|
115 if (inputBits < 64) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
116 if ((value >>> (inputBits - 1) & 1) == 1) { |
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 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
119 return value & ~(-1L << inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
120 } |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
121 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
122 return value; |
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 |
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 * Zero extend an integer. |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
128 * |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
129 * @param value the input value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
130 * @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
|
131 * @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
|
132 * {@code value} |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
133 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
134 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
|
135 if (inputBits < 64) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
136 return value & ~(-1L << inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
137 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
138 return value; |
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 |
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 * Convert an integer to long. |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
144 * |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
145 * @param value the input value |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
146 * @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
|
147 * @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
|
148 * @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
|
149 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
150 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
|
151 if (unsigned) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
152 return zeroExtend(value, inputBits); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
153 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
154 return signExtend(value, inputBits); |
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 |
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 * 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
|
160 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
161 public static long mask(int bits) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
162 assert 0 <= bits && bits <= 64; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
163 if (bits == 64) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
164 return 0xffffffffffffffffL; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
165 } else { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
166 return (1L << bits) - 1; |
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 |
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 * 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
|
172 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
173 public static long minValue(int bits) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
174 assert 0 < bits && bits <= 64; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
175 return -1L << (bits - 1); |
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 |
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 * 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
|
180 */ |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
181 public static long maxValue(int bits) { |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
182 assert 0 < bits && bits <= 64; |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
183 return mask(bits - 1); |
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
184 } |
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 /** |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
187 * 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
|
188 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
189 * @param frame |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
190 * @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
|
191 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
192 public static String tabulateValues(BytecodeFrame frame) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
193 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
|
194 assert cols > 0; |
4142
bc8527f3071c
Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3733
diff
changeset
|
195 ArrayList<Object> cells = new ArrayList<>(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
196 cells.add(""); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
197 for (int i = 0; i < cols; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
198 cells.add(i); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
199 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
200 cols++; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
201 if (frame.numLocals != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
202 cells.add("locals:"); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
203 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
|
204 cells.addAll(Collections.nCopies(cols - frame.numLocals - 1, "")); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
205 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
206 if (frame.numStack != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
207 cells.add("stack:"); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
208 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
|
209 cells.addAll(Collections.nCopies(cols - frame.numStack - 1, "")); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
210 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
211 if (frame.numLocks != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
212 cells.add("locks:"); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
213 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
|
214 cells.addAll(Collections.nCopies(cols - frame.numLocks - 1, "")); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
215 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
216 Object[] cellArray = cells.toArray(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
217 for (int i = 0; i < cellArray.length; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
218 if ((i % cols) != 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
219 cellArray[i] = "|" + cellArray[i]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
220 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
221 } |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
222 return CodeUtil.tabulate(cellArray, cols, 1, 1); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 } |
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 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
226 * 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
|
227 * {@link String#valueOf(Object)}. |
17196
189479d72dc8
Move bit manipulation methods to CodeUtil class.
Roland Schatz <roland.schatz@oracle.com>
parents:
15311
diff
changeset
|
228 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
229 * @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
|
230 * @param cols the number of columns per row |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
231 * @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
|
232 * @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
|
233 * @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
|
234 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
235 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
|
236 int rows = (cells.length + (cols - 1)) / cols; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
237 int[] colWidths = new int[cols]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
238 for (int col = 0; col < cols; col++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
239 for (int row = 0; row < rows; row++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
240 int index = col + (row * cols); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
241 if (index < cells.length) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
242 Object cell = cells[index]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
243 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
|
244 } |
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 StringBuilder sb = new StringBuilder(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
248 String nl = NEW_LINE; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
249 for (int row = 0; row < rows; row++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
250 for (int col = 0; col < cols; col++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
251 int index = col + (row * cols); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
252 if (index < cells.length) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
253 for (int i = 0; i < lpad; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
254 sb.append(' '); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
255 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
256 Object cell = cells[index]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
257 String s = String.valueOf(cell); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
258 int w = s.length(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
259 sb.append(s); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
260 while (w < colWidths[col]) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
261 sb.append(' '); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
262 w++; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
263 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
264 for (int i = 0; i < rpad; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
265 sb.append(' '); |
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 } |
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 sb.append(nl); |
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 return sb.toString(); |
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 |
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 * 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
|
276 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
277 * @param sb the {@link StringBuilder} to append to |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
278 * @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
|
279 * @return the value of {@code sb} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
280 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
281 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
|
282 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
|
283 if (pos.getCaller() != null) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
284 sb.append(NEW_LINE); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
285 append(sb, pos.getCaller()); |
3733
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 return sb; |
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 |
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 * 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
|
292 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
293 * @param sb the {@link StringBuilder} to append to |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
294 * @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
|
295 * @return the value of {@code sb} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
296 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 if (frame.values != null && frame.values.length > 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
303 sb.append(NEW_LINE); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
304 String table = tabulateValues(frame); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
305 String[] rows = table.split(NEW_LINE); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
306 for (int i = 0; i < rows.length; i++) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
307 String row = rows[i]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
308 if (!row.trim().isEmpty()) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
309 sb.append(" ").append(row); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
310 if (i != rows.length - 1) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
311 sb.append(NEW_LINE); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
312 } |
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 if (frame.caller() != null) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
317 sb.append(NEW_LINE); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
318 append(sb, frame.caller()); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
319 } else if (frame.getCaller() != null) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
320 sb.append(NEW_LINE); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
321 append(sb, frame.getCaller()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
322 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
323 return sb; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
324 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
325 |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
326 public interface RefMapFormatter { |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
327 |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
328 String formatStackSlot(int frameRefMapIndex); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
329 |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
330 String formatRegister(int regRefMapIndex); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
331 } |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
332 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
333 /** |
17429
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
334 * 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
|
335 */ |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
336 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
|
337 |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
338 private final Register[] registers; |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
339 |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
340 public DefaultRegFormatter(Architecture arch) { |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
341 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
|
342 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
|
343 if (r.getReferenceMapIndex() >= 0) { |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
344 registers[r.getReferenceMapIndex()] = r; |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
345 } |
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 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
|
350 return null; |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
351 } |
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 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
|
354 int i = regRefMapIndex; |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
355 int idx = 0; |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
356 while (registers[i] == null) { |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
357 i--; |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
358 idx++; |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
359 } |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
360 if (idx == 0) { |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
361 return registers[i].toString(); |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
362 } else { |
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
363 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
|
364 } |
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 /** |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
369 * 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
|
370 */ |
17429
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
371 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
|
372 |
3733
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 * The size of a stack slot. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
375 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
376 public final int slotSize; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
377 |
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 * The register used as the frame pointer. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
380 */ |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
381 public final Register fp; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
382 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
383 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6582
diff
changeset
|
384 * 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
|
385 * 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
|
386 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
387 public final int refMapToFPOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
388 |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
389 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
|
390 super(arch); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
391 this.slotSize = slotSize; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
392 this.fp = fp; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
393 this.refMapToFPOffset = refMapToFPOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
394 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
395 |
17429
f609dff05ea0
Output correct register names in register maps in CFGPrinter.
Roland Schatz <roland.schatz@oracle.com>
parents:
17196
diff
changeset
|
396 @Override |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
397 public String formatStackSlot(int frameRefMapIndex) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
398 int refMapOffset = frameRefMapIndex * slotSize; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
399 int fpOffset = refMapOffset + refMapToFPOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
400 if (fpOffset >= 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
401 return fp + "+" + fpOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
402 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
403 return fp.name + fpOffset; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
404 } |
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 |
14562
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
407 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
|
408 |
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
409 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
|
410 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
|
411 } |
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 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
|
414 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
|
415 } |
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 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
418 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
419 * 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
|
420 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
421 * @param sb the {@link StringBuilder} to append to |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
422 * @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
|
423 * @return the value of {@code sb} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
424 */ |
14562
45812e05cdb3
Move narrow oop handling in reference maps to hotspot specific code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13725
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 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
|
429 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
430 String nl = NEW_LINE; |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
431 ReferenceMap refMap = info.getReferenceMap(); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
432 if (refMap != null && refMap.hasRegisterRefMap()) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
433 sb.append(" reg-ref-map:"); |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
434 refMap.appendRegisterMap(sb, formatter); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
435 sb.append(nl); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
436 } |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
437 if (refMap != null && refMap.hasFrameRefMap()) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
438 sb.append("frame-ref-map:"); |
13725
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
439 refMap.appendFrameMap(sb, formatter); |
8d8732e14447
Refactor reference maps.
Roland Schatz <roland.schatz@oracle.com>
parents:
12050
diff
changeset
|
440 sb.append(nl); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
441 } |
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
7840
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
7840
diff
changeset
|
449 } |
5547
b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5542
diff
changeset
|
450 BytecodeFrame frame = info.frame(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
451 if (frame != null) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
452 append(sb, frame); |
5552
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
453 } else if (info.getBytecodePosition() != null) { |
69a8969dbf40
Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5547
diff
changeset
|
454 append(sb, info.getBytecodePosition()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
455 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
456 return sb; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
457 } |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
458 |
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 * Create a calling convention from a {@link ResolvedJavaMethod}. |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
461 */ |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
462 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
|
463 Signature sig = method.getSignature(); |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 } 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
|
472 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
|
473 } |
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 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
|
475 argTypes[argIndex++] = sig.getParameterType(i, null); |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
476 } |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
477 |
12050
9584d08f56db
rename: lookupRegisterConfig -> getRegisterConfig
Doug Simon <doug.simon@oracle.com>
parents:
10960
diff
changeset
|
478 RegisterConfig registerConfig = codeCache.getRegisterConfig(); |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
479 return registerConfig.getCallingConvention(type, retType, argTypes, codeCache.getTarget(), stackOnly); |
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7530
diff
changeset
|
480 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
481 } |