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