annotate src/os/solaris/dtrace/libjvm_db.c @ 2426:1d1603768966

7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: ohair
author trims
date Tue, 05 Apr 2011 14:12:31 -0700
parents 8a3f8defe568
children 2fe087c3e814
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2344
diff changeset
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1123
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1123
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: 1123
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include <stdio.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include <stdlib.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
27 #include <string.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #include <errno.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
29 #include <gelf.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #include "libjvm_db.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #include "JvmOffsets.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #define LIBJVM_SO "libjvm.so"
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 #if defined(i386) || defined(__i386) || defined(__amd64)
a61af66fc99e Initial load
duke
parents:
diff changeset
37 #ifdef COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #define X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
39 #endif /* COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #endif /* i386 */
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 typedef struct {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 short vf_cnt; /* number of recognized java vframes */
a61af66fc99e Initial load
duke
parents:
diff changeset
44 short bci; /* current frame method byte code index */
a61af66fc99e Initial load
duke
parents:
diff changeset
45 int line; /* current frame method source line */
a61af66fc99e Initial load
duke
parents:
diff changeset
46 uint64_t new_fp; /* fp for the next frame */
a61af66fc99e Initial load
duke
parents:
diff changeset
47 uint64_t new_pc; /* pc for the next frame */
a61af66fc99e Initial load
duke
parents:
diff changeset
48 uint64_t new_sp; /* "raw" sp for the next frame (includes extension by interpreter/adapter */
a61af66fc99e Initial load
duke
parents:
diff changeset
49 char locinf; /* indicates there is valid location info */
a61af66fc99e Initial load
duke
parents:
diff changeset
50 } Jframe_t;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 int Jlookup_by_regs(jvm_agent_t* J, const prgregset_t regs, char *name,
a61af66fc99e Initial load
duke
parents:
diff changeset
53 size_t size, Jframe_t *jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 int main(int arg) { return arg; }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 static int debug = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static void failed(int err, const char * file, int line) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 fprintf(stderr, "failed %d at %s:%d\n", err, file, line);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 static void warn(const char * file, int line, const char * msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 fprintf(stderr, "warning: %s at %s:%d\n", msg, file, line);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 static void warn1(const char * file, int line, const char * msg, intptr_t arg1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 fprintf(stderr, "warning: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
74 fprintf(stderr, msg, arg1);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 fprintf(stderr, " at %s:%d\n", file, line);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 #define CHECK_FAIL(err) \
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (err != PS_OK) { failed(err, __FILE__, __LINE__); goto fail; }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 #define WARN(msg) warn(__FILE__, __LINE__, msg)
a61af66fc99e Initial load
duke
parents:
diff changeset
82 #define WARN1(msg, arg1) warn1(__FILE__, __LINE__, msg, arg1)
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 typedef struct VMStructEntry {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 const char * typeName; /* The type name containing the given field (example: "Klass") */
a61af66fc99e Initial load
duke
parents:
diff changeset
86 const char * fieldName; /* The field name within the type (example: "_name") */
a61af66fc99e Initial load
duke
parents:
diff changeset
87 uint64_t address; /* Address of field; only used for static fields */
a61af66fc99e Initial load
duke
parents:
diff changeset
88 /* ("offset" can not be reused because of apparent SparcWorks compiler bug */
a61af66fc99e Initial load
duke
parents:
diff changeset
89 /* in generation of initializer data) */
a61af66fc99e Initial load
duke
parents:
diff changeset
90 } VMStructEntry;
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 /* Prototyping inlined methods */
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 int sprintf(char *s, const char *format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 #define SZ16 sizeof(int16_t)
a61af66fc99e Initial load
duke
parents:
diff changeset
97 #define SZ32 sizeof(int32_t)
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 #define COMP_METHOD_SIGN '*'
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 #define MAX_VFRAMES_CNT 256
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 typedef struct vframe {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 uint64_t methodOop;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int32_t sender_decode_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int32_t methodIdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 int32_t bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 int32_t line;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } Vframe_t;
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 typedef struct frame {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 uintptr_t fp;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 uintptr_t pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 uintptr_t sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 uintptr_t sender_sp; // The unextended sp of the caller
a61af66fc99e Initial load
duke
parents:
diff changeset
116 } Frame_t;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 typedef struct Nmethod_t {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 struct jvm_agent* J;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 Jframe_t *jframe;
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 uint64_t nm; /* _nmethod */
a61af66fc99e Initial load
duke
parents:
diff changeset
123 uint64_t pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 uint64_t pc_desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 int32_t orig_pc_offset; /* _orig_pc_offset */
1748
3e8fbc61cee8 6978355: renaming for 6961697
twisti
parents: 1579
diff changeset
127 int32_t instrs_beg; /* _code_offset */
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128 int32_t instrs_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 int32_t deopt_beg; /* _deoptimize_offset */
a61af66fc99e Initial load
duke
parents:
diff changeset
130 int32_t scopes_data_beg; /* _scopes_data_offset */
a61af66fc99e Initial load
duke
parents:
diff changeset
131 int32_t scopes_data_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 int32_t oops_beg; /* _oops_offset */
1563
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1123
diff changeset
133 int32_t oops_end;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int32_t scopes_pcs_beg; /* _scopes_pcs_offset */
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int32_t scopes_pcs_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 int vf_cnt;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Vframe_t vframes[MAX_VFRAMES_CNT];
a61af66fc99e Initial load
duke
parents:
diff changeset
139 } Nmethod_t;
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 struct jvm_agent {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 struct ps_prochandle* P;
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 uint64_t nmethod_vtbl;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 uint64_t CodeBlob_vtbl;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 uint64_t BufferBlob_vtbl;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 uint64_t RuntimeStub_vtbl;
a61af66fc99e Initial load
duke
parents:
diff changeset
148
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
149 uint64_t Use_Compressed_Oops_address;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
150 uint64_t Universe_methodKlassObj_address;
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
151 uint64_t Universe_narrow_oop_base_address;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
152 uint64_t Universe_narrow_oop_shift_address;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
153 uint64_t CodeCache_heap_address;
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 /* Volatiles */
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
156 uint8_t Use_Compressed_Oops;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
157 uint64_t Universe_methodKlassObj;
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
158 uint64_t Universe_narrow_oop_base;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
159 uint32_t Universe_narrow_oop_shift;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
160 uint64_t CodeCache_low;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 uint64_t CodeCache_high;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 uint64_t CodeCache_segmap_low;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 uint64_t CodeCache_segmap_high;
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 int32_t SIZE_CodeCache_log2_segment;
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 uint64_t methodOopPtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 uint64_t bcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 Nmethod_t *N; /*Inlined methods support */
a61af66fc99e Initial load
duke
parents:
diff changeset
171 Frame_t prev_fr;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 Frame_t curr_fr;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 };
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
176 read_string(struct ps_prochandle *P,
a61af66fc99e Initial load
duke
parents:
diff changeset
177 char *buf, /* caller's buffer */
a61af66fc99e Initial load
duke
parents:
diff changeset
178 size_t size, /* upper limit on bytes to read */
a61af66fc99e Initial load
duke
parents:
diff changeset
179 uintptr_t addr) /* address in process */
a61af66fc99e Initial load
duke
parents:
diff changeset
180 {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 int err = PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 while (size-- > 1 && err == PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 err = ps_pread(P, addr, buf, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (*buf == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 addr += 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 buf += 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
193 static int read_compressed_pointer(jvm_agent_t* J, uint64_t base, uint32_t *ptr) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
194 int err = -1;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
195 uint32_t ptr32;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
196 err = ps_pread(J->P, base, &ptr32, sizeof(uint32_t));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
197 *ptr = ptr32;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
198 return err;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
199 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
200
0
a61af66fc99e Initial load
duke
parents:
diff changeset
201 static int read_pointer(jvm_agent_t* J, uint64_t base, uint64_t* ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 int err = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 uint32_t ptr32;
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 switch (DATA_MODEL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 case PR_MODEL_LP64:
a61af66fc99e Initial load
duke
parents:
diff changeset
207 err = ps_pread(J->P, base, ptr, sizeof(uint64_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
208 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 case PR_MODEL_ILP32:
a61af66fc99e Initial load
duke
parents:
diff changeset
210 err = ps_pread(J->P, base, &ptr32, sizeof(uint32_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
211 *ptr = ptr32;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 static int read_string_pointer(jvm_agent_t* J, uint64_t base, const char ** stringp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 uint64_t ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 int err;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 char buffer[1024];
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 *stringp = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 err = read_pointer(J, base, &ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 if (ptr != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 err = read_string(J->P, buffer, sizeof(buffer), ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 *stringp = strdup(buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
234 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 static int parse_vmstruct_entry(jvm_agent_t* J, uint64_t base, VMStructEntry* vmp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 uint64_t ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 int err;
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 err = read_string_pointer(J, base + OFFSET_VMStructEntrytypeName, &vmp->typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 err = read_string_pointer(J, base + OFFSET_VMStructEntryfieldName, &vmp->fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 err = read_pointer(J, base + OFFSET_VMStructEntryaddress, &vmp->address);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
251 if (vmp->typeName != NULL) free((void*)vmp->typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if (vmp->fieldName != NULL) free((void*)vmp->fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 static int parse_vmstructs(jvm_agent_t* J) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 VMStructEntry vmVar;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 VMStructEntry* vmp = &vmVar;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 uint64_t gHotSpotVMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 psaddr_t sym_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 uint64_t base;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 int err;
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 err = ps_pglobal_lookup(J->P, LIBJVM_SO, "gHotSpotVMStructs", &sym_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
265 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 err = read_pointer(J, sym_addr, &gHotSpotVMStructs);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 base = gHotSpotVMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 err = PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 while (err == PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 memset(vmp, 0, sizeof(VMStructEntry));
a61af66fc99e Initial load
duke
parents:
diff changeset
273 err = parse_vmstruct_entry(J, base, vmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (err != PS_OK || vmp->typeName == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (vmp->typeName[0] == 'C' && strcmp("CodeCache", vmp->typeName) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (strcmp("_heap", vmp->fieldName) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 err = read_pointer(J, vmp->address, &J->CodeCache_heap_address);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 } else if (vmp->typeName[0] == 'U' && strcmp("Universe", vmp->typeName) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (strcmp("_methodKlassObj", vmp->fieldName) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 J->Universe_methodKlassObj_address = vmp->address;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
286 if (strcmp("_narrow_oop._base", vmp->fieldName) == 0) {
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
287 J->Universe_narrow_oop_base_address = vmp->address;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
288 }
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
289 if (strcmp("_narrow_oop._shift", vmp->fieldName) == 0) {
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
290 J->Universe_narrow_oop_shift_address = vmp->address;
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
291 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 base += SIZE_VMStructEntry;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (vmp->typeName != NULL) free((void*)vmp->typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if (vmp->fieldName != NULL) free((void*)vmp->fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
303 if (vmp->typeName != NULL) free((void*)vmp->typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (vmp->fieldName != NULL) free((void*)vmp->fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
308 static int find_symbol(jvm_agent_t* J, const char *name, uint64_t* valuep) {
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
309 psaddr_t sym_addr;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
310 int err;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
311
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
312 err = ps_pglobal_lookup(J->P, LIBJVM_SO, name, &sym_addr);
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
313 if (err != PS_OK) goto fail;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
314 *valuep = sym_addr;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
315 return PS_OK;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
316
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
317 fail:
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
318 return err;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
319 }
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
320
0
a61af66fc99e Initial load
duke
parents:
diff changeset
321 static int read_volatiles(jvm_agent_t* J) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 uint64_t ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
323 int err;
a61af66fc99e Initial load
duke
parents:
diff changeset
324
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
325 err = find_symbol(J, "UseCompressedOops", &J->Use_Compressed_Oops_address);
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
326 if (err == PS_OK) {
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
327 err = ps_pread(J->P, J->Use_Compressed_Oops_address, &J->Use_Compressed_Oops, sizeof(uint8_t));
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
328 CHECK_FAIL(err);
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
329 } else {
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
330 J->Use_Compressed_Oops = 0;
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
331 }
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
332
0
a61af66fc99e Initial load
duke
parents:
diff changeset
333 err = read_pointer(J, J->Universe_methodKlassObj_address, &J->Universe_methodKlassObj);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 CHECK_FAIL(err);
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
335
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
336 err = read_pointer(J, J->Universe_narrow_oop_base_address, &J->Universe_narrow_oop_base);
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
337 CHECK_FAIL(err);
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
338 err = ps_pread(J->P, J->Universe_narrow_oop_shift_address, &J->Universe_narrow_oop_shift, sizeof(uint32_t));
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
339 CHECK_FAIL(err);
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
340
0
a61af66fc99e Initial load
duke
parents:
diff changeset
341 err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_memory +
a61af66fc99e Initial load
duke
parents:
diff changeset
342 OFFSET_VirtualSpace_low, &J->CodeCache_low);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_memory +
a61af66fc99e Initial load
duke
parents:
diff changeset
345 OFFSET_VirtualSpace_high, &J->CodeCache_high);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
347 err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_segmap +
a61af66fc99e Initial load
duke
parents:
diff changeset
348 OFFSET_VirtualSpace_low, &J->CodeCache_segmap_low);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 err = read_pointer(J, J->CodeCache_heap_address + OFFSET_CodeHeap_segmap +
a61af66fc99e Initial load
duke
parents:
diff changeset
351 OFFSET_VirtualSpace_high, &J->CodeCache_segmap_high);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 err = ps_pread(J->P, J->CodeCache_heap_address + OFFSET_CodeHeap_log2_segment_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
355 &J->SIZE_CodeCache_log2_segment, sizeof(J->SIZE_CodeCache_log2_segment));
a61af66fc99e Initial load
duke
parents:
diff changeset
356 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 static int codecache_contains(jvm_agent_t* J, uint64_t ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 /* make sure the code cache is up to date */
a61af66fc99e Initial load
duke
parents:
diff changeset
367 return (J->CodeCache_low <= ptr && ptr < J->CodeCache_high);
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 static uint64_t segment_for(jvm_agent_t* J, uint64_t p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 return (p - J->CodeCache_low) >> J->SIZE_CodeCache_log2_segment;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 static uint64_t block_at(jvm_agent_t* J, int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 return J->CodeCache_low + (i << J->SIZE_CodeCache_log2_segment);
a61af66fc99e Initial load
duke
parents:
diff changeset
376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 static int find_start(jvm_agent_t* J, uint64_t ptr, uint64_t *startp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 int err;
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 *startp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 if (J->CodeCache_low <= ptr && ptr < J->CodeCache_high) {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 int32_t used;
a61af66fc99e Initial load
duke
parents:
diff changeset
384 uint64_t segment = segment_for(J, ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 uint64_t block = J->CodeCache_segmap_low;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 uint8_t tag;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 err = ps_pread(J->P, block + segment, &tag, sizeof(tag));
a61af66fc99e Initial load
duke
parents:
diff changeset
388 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
389 if (tag == 0xff)
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 while (tag > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 err = ps_pread(J->P, block + segment, &tag, sizeof(tag));
a61af66fc99e Initial load
duke
parents:
diff changeset
393 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 segment -= tag;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 block = block_at(J, segment);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 err = ps_pread(J->P, block + OFFSET_HeapBlockHeader_used, &used, sizeof(used));
a61af66fc99e Initial load
duke
parents:
diff changeset
398 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 if (used) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 *startp = block + SIZE_HeapBlockHeader;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
406 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 static int find_jlong_constant(jvm_agent_t* J, const char *name, uint64_t* valuep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 psaddr_t sym_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 int err = ps_pglobal_lookup(J->P, LIBJVM_SO, name, &sym_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
412 if (err == PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 err = ps_pread(J->P, sym_addr, valuep, sizeof(uint64_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
414 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416 *valuep = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
417 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 jvm_agent_t *Jagent_create(struct ps_prochandle *P, int vers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 jvm_agent_t* J;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 int err;
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if (vers != JVM_DB_VERSION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 errno = ENOTSUP;
a61af66fc99e Initial load
duke
parents:
diff changeset
426 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 J = (jvm_agent_t*)calloc(sizeof(struct jvm_agent), 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 debug = getenv("LIBJVMDB_DEBUG") != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
432 if (debug) debug = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 fprintf(stderr, "Jagent_create: debug=%d\n", debug);
a61af66fc99e Initial load
duke
parents:
diff changeset
436 #ifdef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
437 fprintf(stderr, "Jagent_create: R_SP=%d, R_FP=%d, POINTER_SIZE=%d\n", R_SP, R_FP, POINTER_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 #endif /* X86_COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440
a61af66fc99e Initial load
duke
parents:
diff changeset
441 J->P = P;
a61af66fc99e Initial load
duke
parents:
diff changeset
442
a61af66fc99e Initial load
duke
parents:
diff changeset
443 // Initialize the initial previous frame
a61af66fc99e Initial load
duke
parents:
diff changeset
444
a61af66fc99e Initial load
duke
parents:
diff changeset
445 J->prev_fr.fp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 J->prev_fr.pc = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
447 J->prev_fr.sp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
448 J->prev_fr.sender_sp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
449
a61af66fc99e Initial load
duke
parents:
diff changeset
450 err = find_symbol(J, "__1cHnmethodG__vtbl_", &J->nmethod_vtbl);
a61af66fc99e Initial load
duke
parents:
diff changeset
451 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 err = find_symbol(J, "__1cKBufferBlobG__vtbl_", &J->BufferBlob_vtbl);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 if (err != PS_OK) J->BufferBlob_vtbl = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 err = find_symbol(J, "__1cICodeBlobG__vtbl_", &J->CodeBlob_vtbl);
a61af66fc99e Initial load
duke
parents:
diff changeset
455 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
456 err = find_symbol(J, "__1cLRuntimeStubG__vtbl_", &J->RuntimeStub_vtbl);
a61af66fc99e Initial load
duke
parents:
diff changeset
457 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 err = parse_vmstructs(J);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
461 err = read_volatiles(J);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
463
a61af66fc99e Initial load
duke
parents:
diff changeset
464 return J;
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
467 Jagent_destroy(J);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 void Jagent_destroy(jvm_agent_t *J) {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 if (J != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 free(J);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 static int is_methodOop(jvm_agent_t* J, uint64_t methodOopPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 uint64_t klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
479 int err;
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
480 // If UseCompressedOops, this was a compressed oop.
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
481 if (J->Use_Compressed_Oops != 0) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
482 uint32_t cklass;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
483 err = read_compressed_pointer(J, methodOopPtr + OFFSET_oopDesc_metadata,
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
484 &cklass);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
485 // decode heap oop, same as oop.inline.hpp
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
486 klass = (uint64_t)((uintptr_t)J->Universe_narrow_oop_base +
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 196
diff changeset
487 ((uintptr_t)cklass << J->Universe_narrow_oop_shift));
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
488 } else {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
489 err = read_pointer(J, methodOopPtr + OFFSET_oopDesc_metadata, &klass);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
490 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
491 if (err != PS_OK) goto fail;
a61af66fc99e Initial load
duke
parents:
diff changeset
492 return klass == J->Universe_methodKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
495 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497
a61af66fc99e Initial load
duke
parents:
diff changeset
498 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
499 name_for_methodOop(jvm_agent_t* J, uint64_t methodOopPtr, char * result, size_t size)
a61af66fc99e Initial load
duke
parents:
diff changeset
500 {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 short nameIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
502 short signatureIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
503 uint64_t constantPool;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 uint64_t constMethod;
a61af66fc99e Initial load
duke
parents:
diff changeset
505 uint64_t nameSymbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 uint64_t signatureSymbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 uint64_t klassPtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
508 uint64_t klassSymbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
509 short klassSymbolLength;
a61af66fc99e Initial load
duke
parents:
diff changeset
510 short nameSymbolLength;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 short signatureSymbolLength;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 char * nameString = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
513 char * klassString = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
514 char * signatureString = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
515 int err;
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 err = read_pointer(J, methodOopPtr + OFFSET_methodOopDesc_constants, &constantPool);
a61af66fc99e Initial load
duke
parents:
diff changeset
518 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
519 err = read_pointer(J, methodOopPtr + OFFSET_methodOopDesc_constMethod, &constMethod);
a61af66fc99e Initial load
duke
parents:
diff changeset
520 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522 /* To get name string */
a61af66fc99e Initial load
duke
parents:
diff changeset
523 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_name_index, &nameIndex, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
524 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
525 err = read_pointer(J, constantPool + nameIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &nameSymbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
526 CHECK_FAIL(err);
2344
8a3f8defe568 7019165: Incorrect symbols in pstack output after SymbolTable changes
coleenp
parents: 2177
diff changeset
527 // The symbol is a CPSlot and has lower bit set to indicate metadata
8a3f8defe568 7019165: Incorrect symbols in pstack output after SymbolTable changes
coleenp
parents: 2177
diff changeset
528 nameSymbol &= (~1); // remove metadata lsb
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
529 err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_length, &nameSymbolLength, 2);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
530 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
531 nameString = (char*)calloc(nameSymbolLength + 1, 1);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
532 err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_body, nameString, nameSymbolLength);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
533 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 /* To get signature string */
a61af66fc99e Initial load
duke
parents:
diff changeset
536 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_signature_index, &signatureIndex, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
537 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
538 err = read_pointer(J, constantPool + signatureIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &signatureSymbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
539 CHECK_FAIL(err);
2344
8a3f8defe568 7019165: Incorrect symbols in pstack output after SymbolTable changes
coleenp
parents: 2177
diff changeset
540 signatureSymbol &= (~1); // remove metadata lsb
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
541 err = ps_pread(J->P, signatureSymbol + OFFSET_Symbol_length, &signatureSymbolLength, 2);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
542 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 signatureString = (char*)calloc(signatureSymbolLength + 1, 1);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
544 err = ps_pread(J->P, signatureSymbol + OFFSET_Symbol_body, signatureString, signatureSymbolLength);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
545 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 /* To get klass string */
a61af66fc99e Initial load
duke
parents:
diff changeset
548 err = read_pointer(J, constantPool + OFFSET_constantPoolOopDesc_pool_holder, &klassPtr);
a61af66fc99e Initial load
duke
parents:
diff changeset
549 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
550 err = read_pointer(J, klassPtr + OFFSET_Klass_name + SIZE_oopDesc, &klassSymbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
551 CHECK_FAIL(err);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
552 err = ps_pread(J->P, klassSymbol + OFFSET_Symbol_length, &klassSymbolLength, 2);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
553 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
554 klassString = (char*)calloc(klassSymbolLength + 1, 1);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
555 err = ps_pread(J->P, klassSymbol + OFFSET_Symbol_body, klassString, klassSymbolLength);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
556 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 result[0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
559 strncat(result, klassString, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
560 size -= strlen(klassString);
a61af66fc99e Initial load
duke
parents:
diff changeset
561 strncat(result, ".", size);
a61af66fc99e Initial load
duke
parents:
diff changeset
562 size -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 strncat(result, nameString, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
564 size -= strlen(nameString);
a61af66fc99e Initial load
duke
parents:
diff changeset
565 strncat(result, signatureString, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 if (nameString != NULL) free(nameString);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 if (klassString != NULL) free(klassString);
a61af66fc99e Initial load
duke
parents:
diff changeset
569 if (signatureString != NULL) free(signatureString);
a61af66fc99e Initial load
duke
parents:
diff changeset
570
a61af66fc99e Initial load
duke
parents:
diff changeset
571 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
572
a61af66fc99e Initial load
duke
parents:
diff changeset
573 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
574 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 fprintf(stderr, "name_for_methodOop: FAIL \n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577 if (nameString != NULL) free(nameString);
a61af66fc99e Initial load
duke
parents:
diff changeset
578 if (klassString != NULL) free(klassString);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 if (signatureString != NULL) free(signatureString);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
581 }
a61af66fc99e Initial load
duke
parents:
diff changeset
582
a61af66fc99e Initial load
duke
parents:
diff changeset
583 static int nmethod_info(Nmethod_t *N)
a61af66fc99e Initial load
duke
parents:
diff changeset
584 {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 jvm_agent_t *J = N->J;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 uint64_t nm = N->nm;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589 if (debug > 2 )
a61af66fc99e Initial load
duke
parents:
diff changeset
590 fprintf(stderr, "\t nmethod_info: BEGIN \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
591
a61af66fc99e Initial load
duke
parents:
diff changeset
592 /* Instructions */
1748
3e8fbc61cee8 6978355: renaming for 6961697
twisti
parents: 1579
diff changeset
593 err = ps_pread(J->P, nm + OFFSET_CodeBlob_code_offset, &N->instrs_beg, SZ32);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
594 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
595 err = ps_pread(J->P, nm + OFFSET_CodeBlob_data_offset, &N->instrs_end, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
596 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
597 err = ps_pread(J->P, nm + OFFSET_nmethod_deoptimize_offset, &N->deopt_beg, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 err = ps_pread(J->P, nm + OFFSET_nmethod_orig_pc_offset, &N->orig_pc_offset, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
600 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 /* Oops */
1563
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1123
diff changeset
603 err = ps_pread(J->P, nm + OFFSET_nmethod_oops_offset, &N->oops_beg, SZ32);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
604 CHECK_FAIL(err);
1563
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1123
diff changeset
605 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_data_offset, &N->oops_end, SZ32);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
606 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
607
a61af66fc99e Initial load
duke
parents:
diff changeset
608 /* scopes_pcs */
a61af66fc99e Initial load
duke
parents:
diff changeset
609 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_pcs_offset, &N->scopes_pcs_beg, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
610 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
611 err = ps_pread(J->P, nm + OFFSET_nmethod_handler_table_offset, &N->scopes_pcs_end, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
612 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 /* scopes_data */
a61af66fc99e Initial load
duke
parents:
diff changeset
615 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_data_offset, &N->scopes_data_beg, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
616 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
617
a61af66fc99e Initial load
duke
parents:
diff changeset
618 if (debug > 2 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 N->scopes_data_end = N->scopes_pcs_beg;
a61af66fc99e Initial load
duke
parents:
diff changeset
620
a61af66fc99e Initial load
duke
parents:
diff changeset
621 fprintf(stderr, "\t nmethod_info: instrs_beg: %#x, instrs_end: %#x\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
622 N->instrs_beg, N->instrs_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
623
a61af66fc99e Initial load
duke
parents:
diff changeset
624 fprintf(stderr, "\t nmethod_info: deopt_beg: %#x \n",
a61af66fc99e Initial load
duke
parents:
diff changeset
625 N->deopt_beg);
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 fprintf(stderr, "\t nmethod_info: orig_pc_offset: %#x \n",
a61af66fc99e Initial load
duke
parents:
diff changeset
628 N->orig_pc_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
629
1563
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1123
diff changeset
630 fprintf(stderr, "\t nmethod_info: oops_beg: %#x, oops_end: %#x\n",
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1123
diff changeset
631 N->oops_beg, N->oops_end);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 fprintf(stderr, "\t nmethod_info: scopes_data_beg: %#x, scopes_data_end: %#x\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
634 N->scopes_data_beg, N->scopes_data_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 fprintf(stderr, "\t nmethod_info: scopes_pcs_beg: %#x, scopes_pcs_end: %#x\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
637 N->scopes_pcs_beg, N->scopes_pcs_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
638
a61af66fc99e Initial load
duke
parents:
diff changeset
639 fprintf(stderr, "\t nmethod_info: END \n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
641 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
642
a61af66fc99e Initial load
duke
parents:
diff changeset
643 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
644 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646
a61af66fc99e Initial load
duke
parents:
diff changeset
647 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
648 raw_read_int(jvm_agent_t* J, uint64_t *buffer, int32_t *val)
a61af66fc99e Initial load
duke
parents:
diff changeset
649 {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 int shift = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
651 int value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
652 uint8_t ch = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
653 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
654 int32_t sum;
a61af66fc99e Initial load
duke
parents:
diff changeset
655 // Constants for UNSIGNED5 coding of Pack200
a61af66fc99e Initial load
duke
parents:
diff changeset
656 // see compressedStream.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
657 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 lg_H = 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
659 H = 1<<lg_H,
a61af66fc99e Initial load
duke
parents:
diff changeset
660 BitsPerByte = 8,
a61af66fc99e Initial load
duke
parents:
diff changeset
661 L = (1<<BitsPerByte)-H,
a61af66fc99e Initial load
duke
parents:
diff changeset
662 };
a61af66fc99e Initial load
duke
parents:
diff changeset
663 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 err = ps_pread(J->P, (*buffer)++, &ch, sizeof(uint8_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
666 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
667 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
668 fprintf(stderr, "\t\t\t raw_read_int: *buffer: %#llx, ch: %#x\n", *buffer, ch);
a61af66fc99e Initial load
duke
parents:
diff changeset
669
a61af66fc99e Initial load
duke
parents:
diff changeset
670 sum = ch;
a61af66fc99e Initial load
duke
parents:
diff changeset
671 if ( sum >= L ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
672 int32_t lg_H_i = lg_H;
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // Read maximum of 5 total bytes (we've already read 1).
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // See CompressedReadStream::read_int_mb
a61af66fc99e Initial load
duke
parents:
diff changeset
675 for ( i = 0; i < 4; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
676 err = ps_pread(J->P, (*buffer)++, &ch, sizeof(uint8_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
677 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
678 sum += ch << lg_H_i;
a61af66fc99e Initial load
duke
parents:
diff changeset
679 if (ch < L ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 *val = sum;
a61af66fc99e Initial load
duke
parents:
diff changeset
681 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683 lg_H_i += lg_H;
a61af66fc99e Initial load
duke
parents:
diff changeset
684 }
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
686 *val = sum;
a61af66fc99e Initial load
duke
parents:
diff changeset
687 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
688
a61af66fc99e Initial load
duke
parents:
diff changeset
689 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
690 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
692
a61af66fc99e Initial load
duke
parents:
diff changeset
693 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
694 read_pair(jvm_agent_t* J, uint64_t *buffer, int32_t *bci, int32_t *line)
a61af66fc99e Initial load
duke
parents:
diff changeset
695 {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 uint8_t next = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
697 int32_t bci_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
698 int32_t line_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
699 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
702 fprintf(stderr, "\t\t read_pair: BEGIN\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
703
a61af66fc99e Initial load
duke
parents:
diff changeset
704 err = ps_pread(J->P, (*buffer)++, &next, sizeof(uint8_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
705 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
706
a61af66fc99e Initial load
duke
parents:
diff changeset
707 if (next == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
708 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
709 fprintf(stderr, "\t\t read_pair: END: next == 0\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
710 return 1; /* stream terminated */
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
712 if (next == 0xFF) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
714 fprintf(stderr, "\t\t read_pair: END: next == 0xFF\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
715
a61af66fc99e Initial load
duke
parents:
diff changeset
716 /* Escape character, regular compression used */
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718 err = raw_read_int(J, buffer, &bci_delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
719 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
720
a61af66fc99e Initial load
duke
parents:
diff changeset
721 err = raw_read_int(J, buffer, &line_delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724 *bci += bci_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 *line += line_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
728 fprintf(stderr, "\t\t read_pair: delta = (line %d: %d)\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
729 line_delta, bci_delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 fprintf(stderr, "\t\t read_pair: unpack= (line %d: %d)\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
731 *line, *bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 /* Single byte compression used */
a61af66fc99e Initial load
duke
parents:
diff changeset
735 *bci += next >> 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
736 *line += next & 0x7;
a61af66fc99e Initial load
duke
parents:
diff changeset
737 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
738 fprintf(stderr, "\t\t read_pair: delta = (line %d: %d)\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
739 next & 0x7, next >> 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
740 fprintf(stderr, "\t\t read_pair: unpack= (line %d: %d)\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
741 *line, *bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
742 }
a61af66fc99e Initial load
duke
parents:
diff changeset
743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
744 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
745 fprintf(stderr, "\t\t read_pair: END\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
746 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
747
a61af66fc99e Initial load
duke
parents:
diff changeset
748 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
749 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
750 fprintf(stderr, "\t\t read_pair: FAIL\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
751 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
752 }
a61af66fc99e Initial load
duke
parents:
diff changeset
753
a61af66fc99e Initial load
duke
parents:
diff changeset
754 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
755 line_number_from_bci(jvm_agent_t* J, Vframe_t *vf)
a61af66fc99e Initial load
duke
parents:
diff changeset
756 {
a61af66fc99e Initial load
duke
parents:
diff changeset
757 uint64_t buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
758 uint16_t code_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
759 uint64_t code_end_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
760 uint64_t constMethod;
a61af66fc99e Initial load
duke
parents:
diff changeset
761 int8_t access_flags;
a61af66fc99e Initial load
duke
parents:
diff changeset
762 int32_t best_bci = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
763 int32_t stream_bci = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
764 int32_t stream_line = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
765 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
766
a61af66fc99e Initial load
duke
parents:
diff changeset
767 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
768 char name[256];
a61af66fc99e Initial load
duke
parents:
diff changeset
769 err = name_for_methodOop(J, vf->methodOop, name, 256);
a61af66fc99e Initial load
duke
parents:
diff changeset
770 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
771 fprintf(stderr, "\t line_number_from_bci: BEGIN, method name: %s, targ bci: %d\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
772 name, vf->bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
774
a61af66fc99e Initial load
duke
parents:
diff changeset
775 err = read_pointer(J, vf->methodOop + OFFSET_methodOopDesc_constMethod, &constMethod);
a61af66fc99e Initial load
duke
parents:
diff changeset
776 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
777
a61af66fc99e Initial load
duke
parents:
diff changeset
778 vf->line = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
779 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_flags, &access_flags, sizeof(int8_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
780 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
781
a61af66fc99e Initial load
duke
parents:
diff changeset
782 if (!(access_flags & constMethodOopDesc_has_linenumber_table)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
783 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
784 fprintf(stderr, "\t line_number_from_bci: END: !HAS_LINE_NUMBER_TABLE \n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
785 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
786 }
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788 /* The line numbers are a short array of 2-tuples [start_pc, line_number].
a61af66fc99e Initial load
duke
parents:
diff changeset
789 * Not necessarily sorted and not necessarily one-to-one.
a61af66fc99e Initial load
duke
parents:
diff changeset
790 */
a61af66fc99e Initial load
duke
parents:
diff changeset
791
a61af66fc99e Initial load
duke
parents:
diff changeset
792 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_code_size, &code_size, SZ16);
a61af66fc99e Initial load
duke
parents:
diff changeset
793 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
794
a61af66fc99e Initial load
duke
parents:
diff changeset
795 /* inlined_table_start() */
a61af66fc99e Initial load
duke
parents:
diff changeset
796 code_end_delta = (uint64_t) (access_flags & AccessFlags_NATIVE) ? 2*POINTER_SIZE : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
797 buffer = constMethod + (uint64_t) SIZE_constMethodOopDesc + (uint64_t) code_size + code_end_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
798
a61af66fc99e Initial load
duke
parents:
diff changeset
799 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
800 fprintf(stderr, "\t\t line_number_from_bci: methodOop: %#llx, native: %d\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
801 vf->methodOop, (access_flags & AccessFlags_NATIVE));
a61af66fc99e Initial load
duke
parents:
diff changeset
802 fprintf(stderr, "\t\t line_number_from_bci: buffer: %#llx, code_size: %d\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
803 buffer, (int) code_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 while (read_pair(J, &buffer, &stream_bci, &stream_line) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
807 if (stream_bci == vf->bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 /* perfect match */
a61af66fc99e Initial load
duke
parents:
diff changeset
809 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
810 fprintf(stderr, "\t line_number_from_bci: END: exact line: %ld \n\n", vf->line);
a61af66fc99e Initial load
duke
parents:
diff changeset
811 vf->line = stream_line;
a61af66fc99e Initial load
duke
parents:
diff changeset
812 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
813 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
814 /* update best_bci/line */
a61af66fc99e Initial load
duke
parents:
diff changeset
815 if (stream_bci < vf->bci && stream_bci >= best_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
816 best_bci = stream_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
817 vf->line = stream_line;
a61af66fc99e Initial load
duke
parents:
diff changeset
818 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
819 fprintf(stderr, "\t line_number_from_bci: best_bci: %ld, best_line: %ld\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
820 best_bci, vf->line);
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
822 }
a61af66fc99e Initial load
duke
parents:
diff changeset
823 }
a61af66fc99e Initial load
duke
parents:
diff changeset
824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
825 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
826 fprintf(stderr, "\t line_number_from_bci: END: line: %ld \n\n", vf->line);
a61af66fc99e Initial load
duke
parents:
diff changeset
827 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
828
a61af66fc99e Initial load
duke
parents:
diff changeset
829 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
830 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
831 fprintf(stderr, "\t line_number_from_bci: FAIL\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
832 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834
a61af66fc99e Initial load
duke
parents:
diff changeset
835 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
836 get_real_pc(Nmethod_t *N, uint64_t pc_desc, uint64_t *real_pc)
a61af66fc99e Initial load
duke
parents:
diff changeset
837 {
a61af66fc99e Initial load
duke
parents:
diff changeset
838 int32_t pc_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
839 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
840
a61af66fc99e Initial load
duke
parents:
diff changeset
841 err = ps_pread(N->J->P, pc_desc + OFFSET_PcDesc_pc_offset, &pc_offset, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
842 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
843
a61af66fc99e Initial load
duke
parents:
diff changeset
844 *real_pc = N->nm + N->instrs_beg + pc_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
845 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 fprintf(stderr, "\t\t get_real_pc: pc_offset: %lx, real_pc: %llx\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
847 pc_offset, *real_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
848 }
a61af66fc99e Initial load
duke
parents:
diff changeset
849 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
850
a61af66fc99e Initial load
duke
parents:
diff changeset
851 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
852 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
853 }
a61af66fc99e Initial load
duke
parents:
diff changeset
854
a61af66fc99e Initial load
duke
parents:
diff changeset
855 /* Finds a PcDesc with real-pc equal to N->pc */
a61af66fc99e Initial load
duke
parents:
diff changeset
856 static int pc_desc_at(Nmethod_t *N)
a61af66fc99e Initial load
duke
parents:
diff changeset
857 {
a61af66fc99e Initial load
duke
parents:
diff changeset
858 uint64_t pc_diff;
a61af66fc99e Initial load
duke
parents:
diff changeset
859 int32_t offs;
a61af66fc99e Initial load
duke
parents:
diff changeset
860 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
861
a61af66fc99e Initial load
duke
parents:
diff changeset
862 if (debug > 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
863 fprintf(stderr, "\t pc_desc_at: BEGIN\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
864
a61af66fc99e Initial load
duke
parents:
diff changeset
865 N->vf_cnt = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
866 N->pc_desc = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
867
a61af66fc99e Initial load
duke
parents:
diff changeset
868 for (offs = N->scopes_pcs_beg; offs < N->scopes_pcs_end; offs += SIZE_PcDesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 uint64_t pd;
a61af66fc99e Initial load
duke
parents:
diff changeset
870 uint64_t best_pc_diff = 16; /* some approximation */
a61af66fc99e Initial load
duke
parents:
diff changeset
871 uint64_t real_pc = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
872
a61af66fc99e Initial load
duke
parents:
diff changeset
873 pd = N->nm + offs;
a61af66fc99e Initial load
duke
parents:
diff changeset
874 err = get_real_pc(N, pd, &real_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
875 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
876
a61af66fc99e Initial load
duke
parents:
diff changeset
877 pc_diff = real_pc - N->pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
878
a61af66fc99e Initial load
duke
parents:
diff changeset
879 /* In general, this fragment should work */
a61af66fc99e Initial load
duke
parents:
diff changeset
880 if (pc_diff == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
881 N->pc_desc = pd;
a61af66fc99e Initial load
duke
parents:
diff changeset
882 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
883 fprintf(stderr, "\t pc_desc_at: END: pc_desc: FOUND: %#lx \n\n", pd);
a61af66fc99e Initial load
duke
parents:
diff changeset
884 }
a61af66fc99e Initial load
duke
parents:
diff changeset
885 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
886 }
a61af66fc99e Initial load
duke
parents:
diff changeset
887 /* This fragment is to be able to find out an appropriate
a61af66fc99e Initial load
duke
parents:
diff changeset
888 * pc_desc entry even if pc_desc info is inaccurate.
a61af66fc99e Initial load
duke
parents:
diff changeset
889 */
a61af66fc99e Initial load
duke
parents:
diff changeset
890 if (best_pc_diff > pc_diff && pc_diff > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
891 best_pc_diff = pc_diff;
a61af66fc99e Initial load
duke
parents:
diff changeset
892 N->pc_desc = pd;
a61af66fc99e Initial load
duke
parents:
diff changeset
893 }
a61af66fc99e Initial load
duke
parents:
diff changeset
894 }
a61af66fc99e Initial load
duke
parents:
diff changeset
895 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
896 fprintf(stderr, "\t pc_desc_at: END: pc_desc NOT FOUND");
a61af66fc99e Initial load
duke
parents:
diff changeset
897 if (pc_diff < 20)
a61af66fc99e Initial load
duke
parents:
diff changeset
898 fprintf(stderr, ", best pc_diff: %d\n\n", pc_diff);
a61af66fc99e Initial load
duke
parents:
diff changeset
899 else
a61af66fc99e Initial load
duke
parents:
diff changeset
900 fprintf(stderr, "\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
901 }
a61af66fc99e Initial load
duke
parents:
diff changeset
902 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
903
a61af66fc99e Initial load
duke
parents:
diff changeset
904 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
905 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
906 }
a61af66fc99e Initial load
duke
parents:
diff changeset
907
a61af66fc99e Initial load
duke
parents:
diff changeset
908 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
909 scope_desc_at(Nmethod_t *N, int32_t decode_offset, Vframe_t *vf)
a61af66fc99e Initial load
duke
parents:
diff changeset
910 {
a61af66fc99e Initial load
duke
parents:
diff changeset
911 uint64_t buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
912 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
913
a61af66fc99e Initial load
duke
parents:
diff changeset
914 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
915 fprintf(stderr, "\t\t scope_desc_at: BEGIN \n");
a61af66fc99e Initial load
duke
parents:
diff changeset
916 }
a61af66fc99e Initial load
duke
parents:
diff changeset
917
a61af66fc99e Initial load
duke
parents:
diff changeset
918 buffer = N->nm + N->scopes_data_beg + decode_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
919
a61af66fc99e Initial load
duke
parents:
diff changeset
920 err = raw_read_int(N->J, &buffer, &vf->sender_decode_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
921 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
922
a61af66fc99e Initial load
duke
parents:
diff changeset
923 err = raw_read_int(N->J, &buffer, &vf->methodIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
924 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
925
a61af66fc99e Initial load
duke
parents:
diff changeset
926 err = raw_read_int(N->J, &buffer, &vf->bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
927 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
928
a61af66fc99e Initial load
duke
parents:
diff changeset
929 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
930 fprintf(stderr, "\t\t scope_desc_at: sender_decode_offset: %#x\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
931 vf->sender_decode_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
932 fprintf(stderr, "\t\t scope_desc_at: methodIdx: %d\n", vf->methodIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
933 fprintf(stderr, "\t\t scope_desc_at: bci: %d\n", vf->bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
934
a61af66fc99e Initial load
duke
parents:
diff changeset
935 fprintf(stderr, "\t\t scope_desc_at: END \n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
936 }
a61af66fc99e Initial load
duke
parents:
diff changeset
937 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
938
a61af66fc99e Initial load
duke
parents:
diff changeset
939 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
940 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
943 static int scopeDesc_chain(Nmethod_t *N) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
944 int32_t decode_offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
945 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
946
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
947 if (debug > 2) {
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
948 fprintf(stderr, "\t scopeDesc_chain: BEGIN\n");
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
949 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
950
a61af66fc99e Initial load
duke
parents:
diff changeset
951 err = ps_pread(N->J->P, N->pc_desc + OFFSET_PcDesc_scope_decode_offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
952 &decode_offset, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
953 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
954
a61af66fc99e Initial load
duke
parents:
diff changeset
955 while (decode_offset > 0) {
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
956 Vframe_t *vf = &N->vframes[N->vf_cnt];
0
a61af66fc99e Initial load
duke
parents:
diff changeset
957
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
958 if (debug > 2) {
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
959 fprintf(stderr, "\t scopeDesc_chain: decode_offset: %#x\n", decode_offset);
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
960 }
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
961
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
962 err = scope_desc_at(N, decode_offset, vf);
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
963 CHECK_FAIL(err);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
964
1563
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1123
diff changeset
965 if (vf->methodIdx > ((N->oops_end - N->oops_beg) / POINTER_SIZE)) {
1a5913bf5e19 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1123
diff changeset
966 fprintf(stderr, "\t scopeDesc_chain: (methodIdx > oops length) !\n");
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
967 return -1;
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
968 }
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
969 err = read_pointer(N->J, N->nm + N->oops_beg + (vf->methodIdx-1)*POINTER_SIZE,
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
970 &vf->methodOop);
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
971 CHECK_FAIL(err);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
972
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
973 if (vf->methodOop) {
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
974 N->vf_cnt++;
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
975 err = line_number_from_bci(N->J, vf);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
976 CHECK_FAIL(err);
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
977 if (debug > 2) {
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
978 fprintf(stderr, "\t scopeDesc_chain: methodOop: %#8llx, line: %ld\n",
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
979 vf->methodOop, vf->line);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
980 }
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
981 }
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
982 decode_offset = vf->sender_decode_offset;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
983 }
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
984 if (debug > 2) {
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
985 fprintf(stderr, "\t scopeDesc_chain: END \n\n");
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
986 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
987 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
988
a61af66fc99e Initial load
duke
parents:
diff changeset
989 fail:
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
990 if (debug) {
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
991 fprintf(stderr, "\t scopeDesc_chain: FAIL \n\n");
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
992 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
993 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
994 }
a61af66fc99e Initial load
duke
parents:
diff changeset
995
a61af66fc99e Initial load
duke
parents:
diff changeset
996
a61af66fc99e Initial load
duke
parents:
diff changeset
997 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
998 name_for_nmethod(jvm_agent_t* J,
a61af66fc99e Initial load
duke
parents:
diff changeset
999 uint64_t nm,
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 uint64_t pc,
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 uint64_t methodOop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 char *result,
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 Jframe_t *jframe
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 Nmethod_t *N;
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 Vframe_t *vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 int deoptimized = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 fprintf(stderr, "name_for_nmethod: BEGIN: nmethod: %#llx, pc: %#llx\n", nm, pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 if (J->N == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 J->N = (Nmethod_t *) malloc(sizeof(Nmethod_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 memset(J->N, 0, sizeof(Nmethod_t)); /* Initial stat: all values are zeros */
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 N = J->N;
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 N->J = J;
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 N->nm = nm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 N->pc = pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 N->jframe = jframe;
a61af66fc99e Initial load
duke
parents:
diff changeset
1023
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 err = nmethod_info(N);
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 fprintf(stderr, "name_for_nmethod: pc: %#llx, deopt_pc: %#llx\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 pc, N->nm + N->deopt_beg);
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1030
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 /* check for a deoptimized frame */
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 if ( pc == N->nm + N->deopt_beg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 uint64_t base;
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 fprintf(stderr, "name_for_nmethod: found deoptimized frame\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 if (J->prev_fr.sender_sp != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 base = J->prev_fr.sender_sp + N->orig_pc_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 base = J->curr_fr.sp + N->orig_pc_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 err = read_pointer(J, base, &N->pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 fprintf(stderr, "name_for_nmethod: found deoptimized frame converting pc from %#8llx to %#8llx\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 pc, N->pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 deoptimized = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1050
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 err = pc_desc_at(N);
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1053
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 if (N->pc_desc > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 jframe->locinf = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 err = scopeDesc_chain(N);
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 result[0] = COMP_METHOD_SIGN;
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 vf = &N->vframes[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 if (N->vf_cnt > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 jframe->vf_cnt = N->vf_cnt;
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 jframe->bci = vf->bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 jframe->line = vf->line;
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 err = name_for_methodOop(J, N->vframes[0].methodOop, result+1, size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 err = name_for_methodOop(J, methodOop, result+1, size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 if (deoptimized) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 strncat(result + 1, " [deoptimized frame]; ", size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 strncat(result + 1, " [compiled] ", size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 fprintf(stderr, "name_for_nmethod: END: method name: %s, vf_cnt: %d\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 result, N->vf_cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 fprintf(stderr, "name_for_nmethod: FAIL \n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1086
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 int is_bci(intptr_t bcx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 switch (DATA_MODEL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 case PR_MODEL_LP64:
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 return ((uintptr_t) bcx) <= ((uintptr_t) MAX_METHOD_CODE_SIZE) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 case PR_MODEL_ILP32:
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 return 0 <= bcx && bcx <= MAX_METHOD_CODE_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1096
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 name_for_imethod(jvm_agent_t* J,
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 uint64_t bcx,
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 uint64_t methodOop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 char *result,
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 Jframe_t *jframe
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 uint64_t bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 uint64_t constMethod;
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 Vframe_t vframe = {0};
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 Vframe_t *vf = &vframe;
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1110
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 err = read_pointer(J, methodOop + OFFSET_methodOopDesc_constMethod, &constMethod);
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1113
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 bci = is_bci(bcx) ? bcx : bcx - (constMethod + (uint64_t) SIZE_constMethodOopDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1115
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 fprintf(stderr, "\t name_for_imethod: BEGIN: methodOop: %#llx\n", methodOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1118
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 err = name_for_methodOop(J, methodOop, result, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 fprintf(stderr, "\t name_for_imethod: method name: %s\n", result);
a61af66fc99e Initial load
duke
parents:
diff changeset
1123
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 if (bci > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 vf->methodOop = methodOop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 vf->bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 err = line_number_from_bci(J, vf);
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 jframe->bci = vf->bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 jframe->line = vf->line;
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 jframe->locinf = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1133
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 fprintf(stderr, "\t name_for_imethod: END: bci: %d, line: %d\n\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 vf->bci, vf->line);
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1139
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 fprintf(stderr, "\t name_for_imethod: FAIL\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1145
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 name_for_codecache(jvm_agent_t* J, uint64_t fp, uint64_t pc, char * result,
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 size_t size, Jframe_t *jframe, int* is_interpreted)
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 uint64_t start;
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 uint64_t vtbl;
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 *is_interpreted = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1154
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 result[0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
1156
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 err = find_start(J, pc, &start);
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1159
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 err = read_pointer(J, start, &vtbl);
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 if (vtbl == J->nmethod_vtbl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 uint64_t methodOop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1165
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 err = read_pointer(J, start + OFFSET_nmethod_method, &methodOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1168
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 fprintf(stderr, "name_for_codecache: start: %#8llx, pc: %#8llx, methodOop: %#8llx \n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 start, pc, methodOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 err = name_for_nmethod(J, start, pc, methodOop, result, size, jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 } else if (vtbl == J->BufferBlob_vtbl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 const char * name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1177
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 err = read_string_pointer(J, start + OFFSET_CodeBlob_name, &name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1179
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 * Temporary usage of string "Interpreter".
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 * We need some other way to distinguish "StubRoutines"
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 * and regular interpreted frames.
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 if (err == PS_OK && strncmp(name, "Interpreter", 11) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 *is_interpreted = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 if (is_methodOop(J, J->methodOopPtr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 return name_for_imethod(J, J->bcx, J->methodOopPtr, result, size, jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1191
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 if (err == PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 strncpy(result, name, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 free((void*)name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 strncpy(result, "<unknown BufferBlob>", size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 /* return PS_OK; */
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 const char * name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1201
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 err = read_string_pointer(J, start + OFFSET_CodeBlob_name, &name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 if (err == PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 strncpy(result, name, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 free((void*)name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 strncpy(result, "<unknown CodeBlob>", size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 WARN1("unknown CodeBlob: vtbl = 0x%x", vtbl);
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 result[size-1] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
1212
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 #ifdef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 if (vtbl != J->RuntimeStub_vtbl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 uint64_t trial_pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 int frame_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 err = ps_pread(J->P, start + OFFSET_CodeBlob_frame_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 &frame_size, SZ32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1220
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 // frame_size is in words, we want bytes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 frame_size *= POINTER_SIZE; /* word => byte conversion */
a61af66fc99e Initial load
duke
parents:
diff changeset
1223
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 Because c2 doesn't use FP as a framepointer the value of sp/fp we receive
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 in the initial entry to a set of stack frames containing server frames
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 will pretty much be nonsense. We can detect that nonsense by looking to
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 see if the PC we received is correct if we look at the expected storage
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 location in relation to the FP (ie. POINTER_SIZE(FP) )
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1231
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 err = read_pointer(J, fp + POINTER_SIZE , &trial_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 if ( (err != PS_OK || trial_pc != pc) && frame_size > 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 // Either we couldn't even read at the "fp" or the pc didn't match
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 // both are sure clues that the fp is bogus. We no search the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 // for a reasonable number of words trying to find the bogus fp
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 // and the current pc in adjacent words. The we will be able to
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 // deduce an approximation of the frame pointer and actually get
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 // the correct stack pointer. Which we can then unwind for the
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 // next frame.
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 uint64_t check;
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 uint64_t base = J->curr_fr.sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 uint64_t prev_fp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 for ( i = 0; i < frame_size * 5 ; i++, base += POINTER_SIZE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 err = read_pointer(J, base , &check);
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 if (check == fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 base += POINTER_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 err = read_pointer(J, base , &check);
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 if (check == pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 fprintf(stderr, "name_for_codecache: found matching fp/pc combo at 0x%llx\n", base - POINTER_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 prev_fp = base - 2 * POINTER_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 if ( prev_fp != 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 // real_sp is the sp we should have received for this frame
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 uint64_t real_sp = prev_fp + 2 * POINTER_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 // +POINTER_SIZE because callee owns the return address so caller's sp is +1 word
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 jframe->new_sp = real_sp + frame_size + POINTER_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 err = read_pointer(J, jframe->new_sp - POINTER_SIZE , &jframe->new_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 err = read_pointer(J, jframe->new_sp - 2*POINTER_SIZE, &jframe->new_fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1273
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 /* A prototype to workaround FP absence */
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 * frame_size can be 0 for StubRoutines (1) frame.
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 * In this case it should work with fp as usual.
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 if (frame_size > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 jframe->new_fp = J->prev_fr.fp + frame_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 jframe->new_sp = jframe->new_fp + 2 * POINTER_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 memset(&J->curr_fr, 0, sizeof(Frame_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 err = read_pointer(J, fp, &jframe->new_fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1286
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 err = read_pointer(J, jframe->new_fp + POINTER_SIZE, &jframe->new_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 fprintf(stderr, "name_for_codecache: %s, frame_size=%#lx\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 result, frame_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 fprintf(stderr, "name_for_codecache: prev_fr.fp=%#lx, fp=%#lx\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 J->prev_fr.fp, jframe->new_fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 #endif /* X86_COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1298
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1300
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1304
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 int Jget_vframe(jvm_agent_t* J, int vframe_no,
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 char *name, size_t size, Jframe_t *jframe)
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 Nmethod_t *N = J->N;
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 Vframe_t *vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 int32_t err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1311
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 if (vframe_no >= N->vf_cnt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 (void) sprintf(name, "Wrong inlinedMethod%1d()", vframe_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 vf = N->vframes + vframe_no;
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 name[0] = COMP_METHOD_SIGN;
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 err = name_for_methodOop(J, vf->methodOop, name + 1, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1320
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 jframe->bci = vf->bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 jframe->line = vf->line;
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 fprintf(stderr, "\t Jget_vframe: method name: %s, line: %ld\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 name, vf->line);
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 return PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1328
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 fprintf(stderr, "\t Jget_vframe: FAIL\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1335
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 #define MAX_SYM_SIZE 256
a61af66fc99e Initial load
duke
parents:
diff changeset
1337
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 int Jlookup_by_regs(jvm_agent_t* J, const prgregset_t regs, char *name,
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 size_t size, Jframe_t *jframe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 uintptr_t fp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 uintptr_t pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 /* arguments given to read_pointer need to be worst case sized */
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 uint64_t methodOopPtr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 uint64_t sender_sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 uint64_t bcx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 int is_interpreted = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 int result = PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 int err = PS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1349
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 if (J == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1353
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 jframe->vf_cnt = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 jframe->new_fp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 jframe->new_pc = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 jframe->line = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 jframe->bci = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 jframe->locinf = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1360
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 read_volatiles(J);
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 pc = (uintptr_t) regs[R_PC];
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 J->curr_fr.pc = pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 J->curr_fr.fp = regs[R_FP];
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 J->curr_fr.sp = regs[R_SP];
a61af66fc99e Initial load
duke
parents:
diff changeset
1366
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 fprintf(stderr, "Jlookup_by_regs: BEGINs: fp=%#lx, pc=%#lx\n", regs[R_FP], pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1369
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 #if defined(sparc) || defined(__sparc)
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 /* The following workaround is for SPARC. CALL instruction occupates 8 bytes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 * In the pcDesc structure return pc offset is recorded for CALL instructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 * regs[R_PC] contains a CALL instruction pc offset.
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 pc += 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 bcx = (uintptr_t) regs[R_L1];
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 methodOopPtr = (uintptr_t) regs[R_L2];
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 sender_sp = regs[R_I5];
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 fprintf(stderr, "\nregs[R_I1]=%lx, regs[R_I2]=%lx, regs[R_I5]=%lx, regs[R_L1]=%lx, regs[R_L2]=%lx\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 regs[R_I1], regs[R_I2], regs[R_I5], regs[R_L1], regs[R_L2]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 #elif defined(i386) || defined(__i386) || defined(__amd64)
a61af66fc99e Initial load
duke
parents:
diff changeset
1384
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 fp = (uintptr_t) regs[R_FP];
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 if (J->prev_fr.fp == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 #ifdef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 /* A workaround for top java frames */
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 J->prev_fr.fp = (uintptr_t)(regs[R_SP] - 2 * POINTER_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 J->prev_fr.fp = (uintptr_t)(regs[R_SP] - POINTER_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 #endif /* COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 printf("Jlookup_by_regs: J->prev_fr.fp = %#lx\n", J->prev_fr.fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1397
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 if (read_pointer(J, fp + OFFSET_interpreter_frame_method, &methodOopPtr) != PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 methodOopPtr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 if (read_pointer(J, fp + OFFSET_interpreter_frame_sender_sp, &sender_sp) != PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 sender_sp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 if (read_pointer(J, fp + OFFSET_interpreter_frame_bcx_offset, &bcx) != PS_OK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 bcx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 #endif /* i386 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1408
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 J->methodOopPtr = methodOopPtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 J->bcx = bcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1411
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 /* On x86 with C2 JVM: native frame may have wrong regs[R_FP]
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 * For example: JVM_SuspendThread frame poins to the top interpreted frame.
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 * If we call is_methodOop(J, methodOopPtr) before codecache_contains(J, pc)
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 * then we go over and omit both: nmethod and I2CAdapter frames.
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 * Note, that regs[R_PC] is always correct if frame defined correctly.
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 * So it is better to call codecache_contains(J, pc) from the beginning.
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 #ifndef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 if (is_methodOop(J, J->methodOopPtr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 result = name_for_imethod(J, bcx, J->methodOopPtr, name, size, jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 /* If the methodOopPtr is a method then this is highly likely to be
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 an interpreter frame */
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 if (result >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 is_interpreted = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 #endif /* ! X86_COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1429
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 if (codecache_contains(J, pc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 result = name_for_codecache(J, fp, pc, name, size, jframe, &is_interpreted);
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 #ifdef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 else if (is_methodOop(J, J->methodOopPtr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 result = name_for_imethod(J, bcx, J->methodOopPtr, name, size, jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 /* If the methodOopPtr is a method then this is highly likely to be
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 an interpreter frame */
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 if (result >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 is_interpreted = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 #endif /* X86_COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 if (debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 fprintf(stderr, "Jlookup_by_regs: END with -1\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 result = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 if (!is_interpreted) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 sender_sp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 J->curr_fr.sender_sp = sender_sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1453
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 #ifdef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 if (!J->curr_fr.fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 J->curr_fr.fp = (jframe->new_fp) ? jframe->new_fp : (uintptr_t)regs[R_FP];
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 if (!jframe->new_pc && jframe->new_fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 // This seems dubious
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 read_pointer(J, jframe->new_fp + POINTER_SIZE, &jframe->new_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 CHECK_FAIL(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 if (debug > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 printf("Jlookup_by_regs: (update pc) jframe->new_fp: %#llx, jframe->new_pc: %#llx\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 jframe->new_fp, jframe->new_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1467
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 #endif /* X86_COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 J->prev_fr = J->curr_fr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1470
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 if (debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 fprintf(stderr, "Jlookup_by_regs: END\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1473
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1475
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 fail:
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1479
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 void update_gregs(prgregset_t gregs, Jframe_t jframe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 #ifdef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 if (debug > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 fprintf(stderr, "update_gregs: before update sp = 0x%llx, fp = 0x%llx, pc = 0x%llx\n", gregs[R_SP], gregs[R_FP], gregs[R_PC]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 * A workaround for java C2 frames with unconventional FP.
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 * may have to modify regset with new values for FP/PC/SP when needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 if (jframe.new_sp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 *((uintptr_t *) &gregs[R_SP]) = (uintptr_t) jframe.new_sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 // *((uintptr_t *) &gregs[R_SP]) = (uintptr_t) gregs[R_FP] + 2 * POINTER_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1494
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 if (jframe.new_fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 *((uintptr_t *) &gregs[R_FP]) = (uintptr_t) jframe.new_fp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 if (jframe.new_pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 *((uintptr_t *) &gregs[R_PC]) = (uintptr_t) jframe.new_pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 if (debug > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 fprintf(stderr, "update_gregs: after update sp = 0x%llx, fp = 0x%llx, pc = 0x%llx\n", gregs[R_SP], gregs[R_FP], gregs[R_PC]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 #endif /* X86_COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1506
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 * Iterates over java frames at current location given by 'gregs'.
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 * Returns -1 if no java frames are present or if an error is encountered.
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 * Returns the result of calling 'func' if the return value is non-zero.
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 * Returns 0 otherwise.
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 int Jframe_iter(jvm_agent_t *J, prgregset_t gregs, java_stack_f *func, void* cld) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 char buf[MAX_SYM_SIZE + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 Jframe_t jframe;
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 int i = 0, res;
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 #ifdef X86_COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 if (debug > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 fprintf(stderr, "Jframe_iter: Entry sp = 0x%llx, fp = 0x%llx, pc = 0x%llx\n", gregs[R_SP], gregs[R_FP], gregs[R_PC]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 #endif /* X86_COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1523
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 memset(&jframe, 0, sizeof(Jframe_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 memset(buf, 0, sizeof(buf));
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 res = Jlookup_by_regs(J, gregs, buf, sizeof(buf), &jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 if (res != PS_OK)
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 return (-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1529
a61af66fc99e Initial load
duke
parents:
diff changeset
1530
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 res = func(cld, gregs, buf, (jframe.locinf)? jframe.bci : -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 jframe.line, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 if (res != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 update_gregs(gregs, jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 return (res);
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 for (i = 1; i < jframe.vf_cnt; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 Jget_vframe(J, i, buf, sizeof(buf), &jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 res = func(cld, gregs, buf, (jframe.locinf)? jframe.bci : -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 jframe.line, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 if (res != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 update_gregs(gregs, jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 return (res);
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 update_gregs(gregs, jframe);
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 return (0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 }