author | prappo |
Thu, 11 Oct 2018 14:10:13 +0100 | |
changeset 52095 | c459186b9584 |
parent 49382 | 3875d7b926a8 |
permissions | -rw-r--r-- |
13873 | 1 |
/* |
49382
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
13873 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "sun_jvm_hotspot_asm_Disassembler.h" |
|
26 |
||
27 |
/* |
|
28 |
* This file implements a binding between Java and the hsdis |
|
52095
c459186b9584
8212001: Verify exported symbols in java.base (libjava)
prappo
parents:
49382
diff
changeset
|
29 |
* disassembler. It should compile on Linux/Solaris and Windows. |
13873 | 30 |
* The only platform dependent pieces of the code for doing |
31 |
* dlopen/dlsym to find the entry point in hsdis. All the rest is |
|
32 |
* standard JNI code. |
|
33 |
*/ |
|
34 |
||
35 |
#ifdef _WINDOWS |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
36 |
// Disable CRT security warning against _snprintf |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
37 |
#pragma warning (disable : 4996) |
13873 | 38 |
|
39 |
#define snprintf _snprintf |
|
40 |
#define vsnprintf _vsnprintf |
|
41 |
||
42 |
#include <windows.h> |
|
43 |
#include <sys/types.h> |
|
44 |
#include <sys/stat.h> |
|
45 |
#ifdef _DEBUG |
|
46 |
#include <crtdbg.h> |
|
47 |
#endif |
|
48 |
||
49 |
#else |
|
50 |
||
13959
bcadb9151203
8000332: SA ClassDump throws exception after permgen removal
minqi
parents:
13873
diff
changeset
|
51 |
#include <string.h> |
13873 | 52 |
#include <dlfcn.h> |
16351 | 53 |
|
54 |
#ifndef __APPLE__ |
|
13873 | 55 |
#include <link.h> |
16351 | 56 |
#endif |
13873 | 57 |
|
58 |
#endif |
|
59 |
||
60 |
#include <limits.h> |
|
61 |
#include <stdio.h> |
|
62 |
#include <stdarg.h> |
|
63 |
#include <stdlib.h> |
|
64 |
#include <errno.h> |
|
65 |
||
66 |
#ifdef _WINDOWS |
|
49382
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
67 |
#define JVM_MAXPATHLEN _MAX_PATH |
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
68 |
#else |
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
69 |
#include <sys/param.h> |
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
70 |
#define JVM_MAXPATHLEN MAXPATHLEN |
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
71 |
#endif |
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
72 |
|
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
73 |
|
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
74 |
#ifdef _WINDOWS |
13873 | 75 |
static int getLastErrorString(char *buf, size_t len) |
76 |
{ |
|
77 |
long errval; |
|
78 |
||
79 |
if ((errval = GetLastError()) != 0) |
|
80 |
{ |
|
81 |
/* DOS error */ |
|
82 |
size_t n = (size_t)FormatMessage( |
|
83 |
FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, |
|
84 |
NULL, |
|
85 |
errval, |
|
86 |
0, |
|
87 |
buf, |
|
88 |
(DWORD)len, |
|
89 |
NULL); |
|
90 |
if (n > 3) { |
|
91 |
/* Drop final '.', CR, LF */ |
|
92 |
if (buf[n - 1] == '\n') n--; |
|
93 |
if (buf[n - 1] == '\r') n--; |
|
94 |
if (buf[n - 1] == '.') n--; |
|
95 |
buf[n] = '\0'; |
|
96 |
} |
|
97 |
return (int)n; |
|
98 |
} |
|
99 |
||
100 |
if (errno != 0) |
|
101 |
{ |
|
102 |
/* C runtime error that has no corresponding DOS error code */ |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
103 |
strerror_s(buf, len, errno); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
104 |
return strlen(buf); |
13873 | 105 |
} |
106 |
return 0; |
|
107 |
} |
|
108 |
#endif /* _WINDOWS */ |
|
109 |
||
110 |
/* |
|
111 |
* Class: sun_jvm_hotspot_asm_Disassembler |
|
112 |
* Method: load_library |
|
113 |
* Signature: (Ljava/lang/String;)L |
|
114 |
*/ |
|
115 |
JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_asm_Disassembler_load_1library(JNIEnv * env, |
|
116 |
jclass disclass, |
|
117 |
jstring jrepath_s, |
|
118 |
jstring libname_s) { |
|
119 |
uintptr_t func = 0; |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
120 |
const char *error_message = NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
121 |
const char *jrepath = NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
122 |
const char *libname = NULL; |
49382
3875d7b926a8
8199323: hsdis could not be loaded which are located on long path
ysuenaga
parents:
47216
diff
changeset
|
123 |
char buffer[JVM_MAXPATHLEN]; |
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
124 |
|
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
125 |
#ifdef _WINDOWS |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
126 |
HINSTANCE hsdis_handle = (HINSTANCE) NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
127 |
#else |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
128 |
void* hsdis_handle = NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
129 |
#endif |
13873 | 130 |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
131 |
jrepath = (*env)->GetStringUTFChars(env, jrepath_s, NULL); // like $JAVA_HOME/jre/lib/sparc/ |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
132 |
if (jrepath == NULL || (*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
133 |
return 0; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
134 |
} |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
135 |
|
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
136 |
libname = (*env)->GetStringUTFChars(env, libname_s, NULL); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
137 |
if (libname == NULL || (*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
138 |
(*env)->ReleaseStringUTFChars(env, jrepath_s, jrepath); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
139 |
return 0; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
140 |
} |
13873 | 141 |
|
142 |
/* Load the hsdis library */ |
|
143 |
#ifdef _WINDOWS |
|
144 |
hsdis_handle = LoadLibrary(libname); |
|
145 |
if (hsdis_handle == NULL) { |
|
146 |
snprintf(buffer, sizeof(buffer), "%s%s", jrepath, libname); |
|
147 |
hsdis_handle = LoadLibrary(buffer); |
|
148 |
} |
|
149 |
if (hsdis_handle != NULL) { |
|
150 |
func = (uintptr_t)GetProcAddress(hsdis_handle, "decode_instructions_virtual"); |
|
151 |
} |
|
152 |
if (func == 0) { |
|
153 |
getLastErrorString(buffer, sizeof(buffer)); |
|
154 |
error_message = buffer; |
|
155 |
} |
|
156 |
#else |
|
157 |
hsdis_handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL); |
|
158 |
if (hsdis_handle == NULL) { |
|
159 |
snprintf(buffer, sizeof(buffer), "%s%s", jrepath, libname); |
|
160 |
hsdis_handle = dlopen(buffer, RTLD_LAZY | RTLD_GLOBAL); |
|
161 |
} |
|
162 |
if (hsdis_handle != NULL) { |
|
163 |
func = (uintptr_t)dlsym(hsdis_handle, "decode_instructions_virtual"); |
|
164 |
} |
|
165 |
if (func == 0) { |
|
166 |
error_message = dlerror(); |
|
167 |
} |
|
168 |
#endif |
|
169 |
||
170 |
(*env)->ReleaseStringUTFChars(env, libname_s, libname); |
|
171 |
(*env)->ReleaseStringUTFChars(env, jrepath_s, jrepath); |
|
172 |
||
173 |
if (func == 0) { |
|
174 |
/* Couldn't find entry point. error_message should contain some |
|
175 |
* platform dependent error message. |
|
176 |
*/ |
|
177 |
jclass eclass = (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"); |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
178 |
if ((*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
179 |
/* Can't throw exception, probably OOM, so silently return 0 */ |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
180 |
return (jlong) 0; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
181 |
} |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
182 |
|
13873 | 183 |
(*env)->ThrowNew(env, eclass, error_message); |
184 |
} |
|
185 |
return (jlong)func; |
|
186 |
} |
|
187 |
||
188 |
/* signature of decode_instructions_virtual from hsdis.h */ |
|
189 |
typedef void* (*decode_func)(uintptr_t start_va, uintptr_t end_va, |
|
190 |
unsigned char* start, uintptr_t length, |
|
191 |
void* (*event_callback)(void*, const char*, void*), |
|
192 |
void* event_stream, |
|
193 |
int (*printf_callback)(void*, const char*, ...), |
|
194 |
void* printf_stream, |
|
16351 | 195 |
const char* options, |
196 |
int newline); |
|
13873 | 197 |
|
198 |
/* container for call back state when decoding instructions */ |
|
199 |
typedef struct { |
|
200 |
JNIEnv* env; |
|
201 |
jobject dis; |
|
202 |
jobject visitor; |
|
203 |
jmethodID handle_event; |
|
204 |
jmethodID raw_print; |
|
205 |
char buffer[4096]; |
|
206 |
} decode_env; |
|
207 |
||
208 |
||
209 |
/* event callback binding to Disassembler.handleEvent */ |
|
210 |
static void* event_to_env(void* env_pv, const char* event, void* arg) { |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
211 |
jlong result = 0; |
13873 | 212 |
decode_env* denv = (decode_env*)env_pv; |
213 |
JNIEnv* env = denv->env; |
|
214 |
jstring event_string = (*env)->NewStringUTF(env, event); |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
215 |
if ((*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
216 |
return NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
217 |
} |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
218 |
|
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
219 |
result = (*env)->CallLongMethod(env, denv->dis, denv->handle_event, denv->visitor, |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
220 |
event_string, (jlong) (uintptr_t)arg); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
221 |
if ((*env)->ExceptionOccurred(env)) { |
13873 | 222 |
/* ignore exceptions for now */ |
223 |
(*env)->ExceptionClear(env); |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
224 |
return NULL; |
13873 | 225 |
} |
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
226 |
|
13873 | 227 |
return (void*)(uintptr_t)result; |
228 |
} |
|
229 |
||
230 |
/* printing callback binding to Disassembler.rawPrint */ |
|
231 |
static int printf_to_env(void* env_pv, const char* format, ...) { |
|
232 |
jstring output; |
|
233 |
va_list ap; |
|
234 |
int cnt; |
|
235 |
decode_env* denv = (decode_env*)env_pv; |
|
236 |
JNIEnv* env = denv->env; |
|
237 |
size_t flen = strlen(format); |
|
238 |
const char* raw = NULL; |
|
239 |
||
240 |
if (flen == 0) return 0; |
|
241 |
if (flen < 2 || |
|
242 |
strchr(format, '%') == NULL) { |
|
243 |
raw = format; |
|
244 |
} else if (format[0] == '%' && format[1] == '%' && |
|
245 |
strchr(format+2, '%') == NULL) { |
|
246 |
// happens a lot on machines with names like %foo |
|
247 |
flen--; |
|
248 |
raw = format+1; |
|
249 |
} |
|
250 |
if (raw != NULL) { |
|
251 |
jstring output = (*env)->NewStringUTF(env, raw); |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
252 |
if (!(*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
253 |
/* make sure that UTF allocation doesn't cause OOM */ |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
254 |
(*env)->CallVoidMethod(env, denv->dis, denv->raw_print, denv->visitor, output); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
255 |
} |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
256 |
if ((*env)->ExceptionOccurred(env)) { |
13873 | 257 |
/* ignore exceptions for now */ |
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
258 |
(*env)->ExceptionClear(env); |
13873 | 259 |
} |
260 |
return (int) flen; |
|
261 |
} |
|
262 |
va_start(ap, format); |
|
263 |
cnt = vsnprintf(denv->buffer, sizeof(denv->buffer), format, ap); |
|
264 |
va_end(ap); |
|
265 |
||
266 |
output = (*env)->NewStringUTF(env, denv->buffer); |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
267 |
if (!(*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
268 |
/* make sure that UTF allocation doesn't cause OOM */ |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
269 |
(*env)->CallVoidMethod(env, denv->dis, denv->raw_print, denv->visitor, output); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
270 |
} |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
271 |
|
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
272 |
if ((*env)->ExceptionOccurred(env)) { |
13873 | 273 |
/* ignore exceptions for now */ |
274 |
(*env)->ExceptionClear(env); |
|
275 |
} |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
276 |
|
13873 | 277 |
return cnt; |
278 |
} |
|
279 |
||
280 |
/* |
|
281 |
* Class: sun_jvm_hotspot_asm_Disassembler |
|
282 |
* Method: decode |
|
283 |
* Signature: (Lsun/jvm/hotspot/asm/InstructionVisitor;J[BLjava/lang/String;J)V |
|
284 |
*/ |
|
285 |
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_asm_Disassembler_decode(JNIEnv * env, |
|
286 |
jobject dis, |
|
287 |
jobject visitor, |
|
288 |
jlong startPc, |
|
289 |
jbyteArray code, |
|
290 |
jstring options_s, |
|
291 |
jlong decode_instructions_virtual) { |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
292 |
jbyte *start = NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
293 |
jbyte *end = NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
294 |
jclass disclass = NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
295 |
const char *options = NULL; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
296 |
decode_env denv; |
13873 | 297 |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
298 |
start = (*env)->GetByteArrayElements(env, code, NULL); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
299 |
if ((*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
300 |
return; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
301 |
} |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
302 |
end = start + (*env)->GetArrayLength(env, code); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
303 |
options = (*env)->GetStringUTFChars(env, options_s, NULL); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
304 |
if ((*env)->ExceptionOccurred(env)) { |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
305 |
(*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
306 |
return; |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
307 |
} |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
308 |
disclass = (*env)->GetObjectClass(env, dis); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
309 |
|
13873 | 310 |
denv.env = env; |
311 |
denv.dis = dis; |
|
312 |
denv.visitor = visitor; |
|
313 |
||
314 |
/* find Disassembler.handleEvent callback */ |
|
315 |
denv.handle_event = (*env)->GetMethodID(env, disclass, "handleEvent", |
|
316 |
"(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;J)J"); |
|
317 |
if ((*env)->ExceptionOccurred(env)) { |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
318 |
(*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
319 |
(*env)->ReleaseStringUTFChars(env, options_s, options); |
13873 | 320 |
return; |
321 |
} |
|
322 |
||
323 |
/* find Disassembler.rawPrint callback */ |
|
324 |
denv.raw_print = (*env)->GetMethodID(env, disclass, "rawPrint", |
|
325 |
"(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;)V"); |
|
326 |
if ((*env)->ExceptionOccurred(env)) { |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
327 |
(*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT); |
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
328 |
(*env)->ReleaseStringUTFChars(env, options_s, options); |
13873 | 329 |
return; |
330 |
} |
|
331 |
||
332 |
/* decode the buffer */ |
|
28162
cf13d6e8e46f
8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents:
16351
diff
changeset
|
333 |
(*(decode_func)(uintptr_t)decode_instructions_virtual)((uintptr_t) startPc, |
13873 | 334 |
startPc + end - start, |
335 |
(unsigned char*)start, |
|
336 |
end - start, |
|
337 |
&event_to_env, (void*) &denv, |
|
338 |
&printf_to_env, (void*) &denv, |
|
16351 | 339 |
options, 0 /* newline */); |
13873 | 340 |
|
341 |
/* cleanup */ |
|
342 |
(*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT); |
|
343 |
(*env)->ReleaseStringUTFChars(env, options_s, options); |
|
344 |
} |