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