1 /*
2 * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
113 uintptr_t pc;
114 uintptr_t sp;
115 uintptr_t sender_sp; // The unextended sp of the caller
116 } Frame_t;
117
118 typedef struct Nmethod_t {
119 struct jvm_agent* J;
120 Jframe_t *jframe;
121
122 uint64_t nm; /* _nmethod */
123 uint64_t pc;
124 uint64_t pc_desc;
125
126 int32_t orig_pc_offset; /* _orig_pc_offset */
127 int32_t instrs_beg; /* _instructions_offset */
128 int32_t instrs_end;
129 int32_t deopt_beg; /* _deoptimize_offset */
130 int32_t scopes_data_beg; /* _scopes_data_offset */
131 int32_t scopes_data_end;
132 int32_t oops_beg; /* _oops_offset */
133 int32_t oops_len; /* _oops_length */
134 int32_t scopes_pcs_beg; /* _scopes_pcs_offset */
135 int32_t scopes_pcs_end;
136
137 int vf_cnt;
138 Vframe_t vframes[MAX_VFRAMES_CNT];
139 } Nmethod_t;
140
141 struct jvm_agent {
142 struct ps_prochandle* P;
143
144 uint64_t nmethod_vtbl;
145 uint64_t CodeBlob_vtbl;
146 uint64_t BufferBlob_vtbl;
147 uint64_t RuntimeStub_vtbl;
148
149 uint64_t Use_Compressed_Oops_address;
150 uint64_t Universe_methodKlassObj_address;
151 uint64_t Universe_narrow_oop_base_address;
152 uint64_t Universe_narrow_oop_shift_address;
153 uint64_t CodeCache_heap_address;
580 static int nmethod_info(Nmethod_t *N)
581 {
582 jvm_agent_t *J = N->J;
583 uint64_t nm = N->nm;
584 int32_t err;
585
586 if (debug > 2 )
587 fprintf(stderr, "\t nmethod_info: BEGIN \n");
588
589 /* Instructions */
590 err = ps_pread(J->P, nm + OFFSET_CodeBlob_instructions_offset, &N->instrs_beg, SZ32);
591 CHECK_FAIL(err);
592 err = ps_pread(J->P, nm + OFFSET_CodeBlob_data_offset, &N->instrs_end, SZ32);
593 CHECK_FAIL(err);
594 err = ps_pread(J->P, nm + OFFSET_nmethod_deoptimize_offset, &N->deopt_beg, SZ32);
595 CHECK_FAIL(err);
596 err = ps_pread(J->P, nm + OFFSET_nmethod_orig_pc_offset, &N->orig_pc_offset, SZ32);
597 CHECK_FAIL(err);
598
599 /* Oops */
600 err = ps_pread(J->P, nm + OFFSET_CodeBlob_oops_offset, &N->oops_beg, SZ32);
601 CHECK_FAIL(err);
602 err = ps_pread(J->P, nm + OFFSET_CodeBlob_oops_length, &N->oops_len, SZ32);
603 CHECK_FAIL(err);
604
605 /* scopes_pcs */
606 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_pcs_offset, &N->scopes_pcs_beg, SZ32);
607 CHECK_FAIL(err);
608 err = ps_pread(J->P, nm + OFFSET_nmethod_handler_table_offset, &N->scopes_pcs_end, SZ32);
609 CHECK_FAIL(err);
610
611 /* scopes_data */
612 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_data_offset, &N->scopes_data_beg, SZ32);
613 CHECK_FAIL(err);
614
615 if (debug > 2 ) {
616 N->scopes_data_end = N->scopes_pcs_beg;
617
618 fprintf(stderr, "\t nmethod_info: instrs_beg: %#x, instrs_end: %#x\n",
619 N->instrs_beg, N->instrs_end);
620
621 fprintf(stderr, "\t nmethod_info: deopt_beg: %#x \n",
622 N->deopt_beg);
623
624 fprintf(stderr, "\t nmethod_info: orig_pc_offset: %#x \n",
625 N->orig_pc_offset);
626
627 fprintf(stderr, "\t nmethod_info: oops_beg: %#x, oops_len: %#x\n",
628 N->oops_beg, N->oops_len);
629
630 fprintf(stderr, "\t nmethod_info: scopes_data_beg: %#x, scopes_data_end: %#x\n",
631 N->scopes_data_beg, N->scopes_data_end);
632
633 fprintf(stderr, "\t nmethod_info: scopes_pcs_beg: %#x, scopes_pcs_end: %#x\n",
634 N->scopes_pcs_beg, N->scopes_pcs_end);
635
636 fprintf(stderr, "\t nmethod_info: END \n\n");
637 }
638 return PS_OK;
639
640 fail:
641 return err;
642 }
643
644 static int
645 raw_read_int(jvm_agent_t* J, uint64_t *buffer, int32_t *val)
646 {
647 int shift = 0;
648 int value = 0;
942 int32_t err;
943
944 if (debug > 2) {
945 fprintf(stderr, "\t scopeDesc_chain: BEGIN\n");
946 }
947
948 err = ps_pread(N->J->P, N->pc_desc + OFFSET_PcDesc_scope_decode_offset,
949 &decode_offset, SZ32);
950 CHECK_FAIL(err);
951
952 while (decode_offset > 0) {
953 Vframe_t *vf = &N->vframes[N->vf_cnt];
954
955 if (debug > 2) {
956 fprintf(stderr, "\t scopeDesc_chain: decode_offset: %#x\n", decode_offset);
957 }
958
959 err = scope_desc_at(N, decode_offset, vf);
960 CHECK_FAIL(err);
961
962 if (vf->methodIdx > N->oops_len) {
963 fprintf(stderr, "\t scopeDesc_chain: (methodIdx > oops_len) !\n");
964 return -1;
965 }
966 err = read_pointer(N->J, N->nm + N->oops_beg + (vf->methodIdx-1)*POINTER_SIZE,
967 &vf->methodOop);
968 CHECK_FAIL(err);
969
970 if (vf->methodOop) {
971 N->vf_cnt++;
972 err = line_number_from_bci(N->J, vf);
973 CHECK_FAIL(err);
974 if (debug > 2) {
975 fprintf(stderr, "\t scopeDesc_chain: methodOop: %#8llx, line: %ld\n",
976 vf->methodOop, vf->line);
977 }
978 }
979 decode_offset = vf->sender_decode_offset;
980 }
981 if (debug > 2) {
982 fprintf(stderr, "\t scopeDesc_chain: END \n\n");
983 }
|
1 /*
2 * Copyright 2003-2010 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
113 uintptr_t pc;
114 uintptr_t sp;
115 uintptr_t sender_sp; // The unextended sp of the caller
116 } Frame_t;
117
118 typedef struct Nmethod_t {
119 struct jvm_agent* J;
120 Jframe_t *jframe;
121
122 uint64_t nm; /* _nmethod */
123 uint64_t pc;
124 uint64_t pc_desc;
125
126 int32_t orig_pc_offset; /* _orig_pc_offset */
127 int32_t instrs_beg; /* _instructions_offset */
128 int32_t instrs_end;
129 int32_t deopt_beg; /* _deoptimize_offset */
130 int32_t scopes_data_beg; /* _scopes_data_offset */
131 int32_t scopes_data_end;
132 int32_t oops_beg; /* _oops_offset */
133 int32_t oops_end;
134 int32_t scopes_pcs_beg; /* _scopes_pcs_offset */
135 int32_t scopes_pcs_end;
136
137 int vf_cnt;
138 Vframe_t vframes[MAX_VFRAMES_CNT];
139 } Nmethod_t;
140
141 struct jvm_agent {
142 struct ps_prochandle* P;
143
144 uint64_t nmethod_vtbl;
145 uint64_t CodeBlob_vtbl;
146 uint64_t BufferBlob_vtbl;
147 uint64_t RuntimeStub_vtbl;
148
149 uint64_t Use_Compressed_Oops_address;
150 uint64_t Universe_methodKlassObj_address;
151 uint64_t Universe_narrow_oop_base_address;
152 uint64_t Universe_narrow_oop_shift_address;
153 uint64_t CodeCache_heap_address;
580 static int nmethod_info(Nmethod_t *N)
581 {
582 jvm_agent_t *J = N->J;
583 uint64_t nm = N->nm;
584 int32_t err;
585
586 if (debug > 2 )
587 fprintf(stderr, "\t nmethod_info: BEGIN \n");
588
589 /* Instructions */
590 err = ps_pread(J->P, nm + OFFSET_CodeBlob_instructions_offset, &N->instrs_beg, SZ32);
591 CHECK_FAIL(err);
592 err = ps_pread(J->P, nm + OFFSET_CodeBlob_data_offset, &N->instrs_end, SZ32);
593 CHECK_FAIL(err);
594 err = ps_pread(J->P, nm + OFFSET_nmethod_deoptimize_offset, &N->deopt_beg, SZ32);
595 CHECK_FAIL(err);
596 err = ps_pread(J->P, nm + OFFSET_nmethod_orig_pc_offset, &N->orig_pc_offset, SZ32);
597 CHECK_FAIL(err);
598
599 /* Oops */
600 err = ps_pread(J->P, nm + OFFSET_nmethod_oops_offset, &N->oops_beg, SZ32);
601 CHECK_FAIL(err);
602 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_data_offset, &N->oops_end, SZ32);
603 CHECK_FAIL(err);
604
605 /* scopes_pcs */
606 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_pcs_offset, &N->scopes_pcs_beg, SZ32);
607 CHECK_FAIL(err);
608 err = ps_pread(J->P, nm + OFFSET_nmethod_handler_table_offset, &N->scopes_pcs_end, SZ32);
609 CHECK_FAIL(err);
610
611 /* scopes_data */
612 err = ps_pread(J->P, nm + OFFSET_nmethod_scopes_data_offset, &N->scopes_data_beg, SZ32);
613 CHECK_FAIL(err);
614
615 if (debug > 2 ) {
616 N->scopes_data_end = N->scopes_pcs_beg;
617
618 fprintf(stderr, "\t nmethod_info: instrs_beg: %#x, instrs_end: %#x\n",
619 N->instrs_beg, N->instrs_end);
620
621 fprintf(stderr, "\t nmethod_info: deopt_beg: %#x \n",
622 N->deopt_beg);
623
624 fprintf(stderr, "\t nmethod_info: orig_pc_offset: %#x \n",
625 N->orig_pc_offset);
626
627 fprintf(stderr, "\t nmethod_info: oops_beg: %#x, oops_end: %#x\n",
628 N->oops_beg, N->oops_end);
629
630 fprintf(stderr, "\t nmethod_info: scopes_data_beg: %#x, scopes_data_end: %#x\n",
631 N->scopes_data_beg, N->scopes_data_end);
632
633 fprintf(stderr, "\t nmethod_info: scopes_pcs_beg: %#x, scopes_pcs_end: %#x\n",
634 N->scopes_pcs_beg, N->scopes_pcs_end);
635
636 fprintf(stderr, "\t nmethod_info: END \n\n");
637 }
638 return PS_OK;
639
640 fail:
641 return err;
642 }
643
644 static int
645 raw_read_int(jvm_agent_t* J, uint64_t *buffer, int32_t *val)
646 {
647 int shift = 0;
648 int value = 0;
942 int32_t err;
943
944 if (debug > 2) {
945 fprintf(stderr, "\t scopeDesc_chain: BEGIN\n");
946 }
947
948 err = ps_pread(N->J->P, N->pc_desc + OFFSET_PcDesc_scope_decode_offset,
949 &decode_offset, SZ32);
950 CHECK_FAIL(err);
951
952 while (decode_offset > 0) {
953 Vframe_t *vf = &N->vframes[N->vf_cnt];
954
955 if (debug > 2) {
956 fprintf(stderr, "\t scopeDesc_chain: decode_offset: %#x\n", decode_offset);
957 }
958
959 err = scope_desc_at(N, decode_offset, vf);
960 CHECK_FAIL(err);
961
962 if (vf->methodIdx > (N->oops_end - N->oops_beg)) {
963 fprintf(stderr, "\t scopeDesc_chain: (methodIdx > (oops_end - oops_beg)) !\n");
964 return -1;
965 }
966 err = read_pointer(N->J, N->nm + N->oops_beg + (vf->methodIdx-1)*POINTER_SIZE,
967 &vf->methodOop);
968 CHECK_FAIL(err);
969
970 if (vf->methodOop) {
971 N->vf_cnt++;
972 err = line_number_from_bci(N->J, vf);
973 CHECK_FAIL(err);
974 if (debug > 2) {
975 fprintf(stderr, "\t scopeDesc_chain: methodOop: %#8llx, line: %ld\n",
976 vf->methodOop, vf->line);
977 }
978 }
979 decode_offset = vf->sender_decode_offset;
980 }
981 if (debug > 2) {
982 fprintf(stderr, "\t scopeDesc_chain: END \n\n");
983 }
|