Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/asm/Disassembler.java @ 6782:5a98bf7d847b
6879063: SA should use hsdis for disassembly
Summary: We should in SA to use hsdis for it like the JVM does to replace the current java based disassembler.
Reviewed-by: twisti, jrose, sla
Contributed-by: yumin.qi@oracle.com
author | minqi |
---|---|
date | Mon, 24 Sep 2012 12:44:00 -0700 |
parents | c18cbe5936b8 |
children | 763705f0fec3 |
rev | line source |
---|---|
0 | 1 /* |
6782 | 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.asm; | |
26 | |
6782 | 27 import java.io.PrintStream; |
28 import java.util.Observer; | |
29 import java.util.Observable; | |
30 import sun.jvm.hotspot.code.CodeBlob; | |
31 import sun.jvm.hotspot.code.NMethod; | |
32 import sun.jvm.hotspot.debugger.Address; | |
33 import sun.jvm.hotspot.runtime.VM; | |
34 | |
35 public class Disassembler { | |
36 private static String options = ""; | |
37 private static long decode_function; | |
0 | 38 |
6782 | 39 protected long startPc; |
40 protected byte[] code; | |
41 private CodeBlob blob; | |
42 private NMethod nmethod; | |
43 | |
44 public static void decode(InstructionVisitor visitor, CodeBlob blob) { | |
45 decode(visitor, blob, blob.codeBegin(), blob.codeEnd()); | |
46 } | |
47 | |
48 public static void decode(InstructionVisitor visitor, CodeBlob blob, Address begin, Address end) { | |
49 int codeSize = (int)end.minus(begin); | |
50 long startPc = VM.getAddressValue(begin); | |
51 byte[] code = new byte[codeSize]; | |
52 for (int i = 0; i < code.length; i++) | |
53 code[i] = begin.getJByteAt(i); | |
54 Disassembler dis = new Disassembler(startPc, code); | |
55 dis.decode(visitor); | |
0 | 56 } |
57 | |
6782 | 58 private Disassembler(long startPc, byte[] code) { |
59 this.startPc = startPc; | |
60 this.code = code; | |
61 | |
62 // Lazily load hsdis | |
63 if (decode_function == 0) { | |
64 StringBuilder path = new StringBuilder(System.getProperty("java.home")); | |
65 String sep = System.getProperty("file.separator"); | |
66 String os = System.getProperty("os.name"); | |
67 String libname = "hsdis"; | |
68 String arch = System.getProperty("os.arch"); | |
69 if (os.lastIndexOf("Windows", 0) != -1) { | |
70 path.append(sep + "bin" + sep); | |
71 libname += ".dll"; | |
72 } else if (os.lastIndexOf("SunOS", 0) != -1) { | |
73 if (arch.equals("x86") || arch.equals("i386")) { | |
74 path.append(sep + "lib" + sep + "i386" + sep); | |
75 libname += "-i386" + ".so"; | |
76 } else if (arch.equals("amd64")) { | |
77 path.append(sep + "lib" + sep + "amd64" + sep); | |
78 libname += "-amd64" + ".so"; | |
79 } else { | |
80 path.append(sep + "lib" + sep + arch + sep); | |
81 libname += "-" + arch + ".so"; | |
82 } | |
83 } else if (os.lastIndexOf("Linux", 0) != -1) { | |
84 if (arch.equals("x86") || arch.equals("i386")) { | |
85 path.append(sep + "lib" + sep + "i386" + sep); | |
86 libname += "-i386.so"; | |
87 } else if (arch.equals("amd64") || arch.equals("x86_64")) { | |
88 path.append(sep + "lib" + sep + "amd64" + sep); | |
89 libname += "-amd64.so"; | |
90 } else { | |
91 path.append(sep + "lib" + sep + arch + sep); | |
92 libname += "-" + arch + ".so"; | |
93 } | |
94 } else if (os.lastIndexOf("Mac OS X", 0) != -1) { | |
95 path.append(sep + "lib" + sep); | |
96 libname += "-amd64" + ".dylib"; // x86_64 => amd64 | |
97 } else { | |
98 path.append(sep + "lib" + sep + "arch" + sep); | |
99 libname += "-" + arch + ".so"; | |
100 } | |
101 decode_function = load_library(path.toString(), libname); | |
102 } | |
0 | 103 } |
104 | |
6782 | 105 private static native long load_library(String installed_jrepath, String hsdis_library_name); |
106 | |
107 private native void decode(InstructionVisitor visitor, long pc, byte[] code, | |
108 String options, long decode_function); | |
109 | |
110 private void decode(InstructionVisitor visitor) { | |
111 visitor.prologue(); | |
112 decode(visitor, startPc, code, options, decode_function); | |
113 visitor.epilogue(); | |
114 } | |
115 | |
116 private boolean match(String event, String tag) { | |
117 if (!event.startsWith(tag)) | |
118 return false; | |
119 int taglen = tag.length(); | |
120 if (taglen == event.length()) return true; | |
121 char delim = event.charAt(taglen); | |
122 return delim == ' ' || delim == '/' || delim == '='; | |
0 | 123 } |
124 | |
6782 | 125 // This is called from the native code to process various markers |
126 // in the dissassembly. | |
127 private long handleEvent(InstructionVisitor visitor, String event, long arg) { | |
128 if (match(event, "insn")) { | |
129 try { | |
130 visitor.beginInstruction(arg); | |
131 } catch (Throwable e) { | |
132 e.printStackTrace(); | |
133 } | |
134 } else if (match(event, "/insn")) { | |
135 try { | |
136 visitor.endInstruction(arg); | |
137 } catch (Throwable e) { | |
138 e.printStackTrace(); | |
139 } | |
140 } else if (match(event, "addr")) { | |
141 if (arg != 0) { | |
142 visitor.printAddress(arg); | |
143 } | |
144 return arg; | |
145 } else if (match(event, "mach")) { | |
146 // output().printf("[Disassembling for mach='%s']\n", arg); | |
147 } else { | |
148 // ignore unrecognized markup | |
149 } | |
150 return 0; | |
151 } | |
152 | |
153 // This called from the native code to perform printing | |
154 private void rawPrint(InstructionVisitor visitor, String s) { | |
155 visitor.print(s); | |
156 } | |
0 | 157 } |