hotspot/src/jdk.hotspot.agent/share/native/libsaproc/sadis.c
author dsamersoff
Wed, 23 Dec 2015 13:12:15 +0300
changeset 35217 ce4b5303a813
parent 28162 hotspot/agent/src/share/native/sadis.c@cf13d6e8e46f
permissions -rw-r--r--
8067194: Restructure hotspot/agent/src to conform the modular source layout Summary: Move sources under jdk.hotspot.agent Reviewed-by: ihse, erikj, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
     1
/*
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 14847
diff changeset
     2
 * Copyright (c) 2012, 2013, 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
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    29
 *  dissasembler.  It should compile on Linux/Solaris and Windows.
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
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    67
static int getLastErrorString(char *buf, size_t len)
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    68
{
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    69
    long errval;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    70
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    71
    if ((errval = GetLastError()) != 0)
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    72
    {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    73
      /* DOS error */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    74
      size_t n = (size_t)FormatMessage(
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    75
            FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    76
            NULL,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    77
            errval,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    78
            0,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    79
            buf,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    80
            (DWORD)len,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    81
            NULL);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    82
      if (n > 3) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    83
        /* Drop final '.', CR, LF */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    84
        if (buf[n - 1] == '\n') n--;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    85
        if (buf[n - 1] == '\r') n--;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    86
        if (buf[n - 1] == '.') n--;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    87
        buf[n] = '\0';
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    88
      }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    89
      return (int)n;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    90
    }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    91
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    92
    if (errno != 0)
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    93
    {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    94
      /* 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
    95
      strerror_s(buf, len, errno);
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
    96
      return strlen(buf);
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    97
    }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
    98
    return 0;
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
#endif /* _WINDOWS */
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
/*
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   103
 * Class:     sun_jvm_hotspot_asm_Disassembler
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   104
 * Method:    load_library
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   105
 * Signature: (Ljava/lang/String;)L
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   106
 */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   107
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
   108
                                                                           jclass disclass,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   109
                                                                           jstring jrepath_s,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   110
                                                                           jstring libname_s) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   111
  uintptr_t func = 0;
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   112
  const char *error_message = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   113
  const char *jrepath = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   114
  const char *libname = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   115
  char buffer[128];
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   116
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   117
#ifdef _WINDOWS
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   118
  HINSTANCE hsdis_handle = (HINSTANCE) NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   119
#else
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   120
  void* hsdis_handle = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   121
#endif
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   122
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   123
  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
   124
  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
   125
    return 0;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   126
  }
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   127
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   128
  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
   129
  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
   130
    (*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
   131
    return 0;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   132
  }
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   133
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   134
  /* Load the hsdis library */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   135
#ifdef _WINDOWS
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   136
  hsdis_handle = LoadLibrary(libname);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   137
  if (hsdis_handle == NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   138
    snprintf(buffer, sizeof(buffer), "%s%s", jrepath, libname);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   139
    hsdis_handle = LoadLibrary(buffer);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   140
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   141
  if (hsdis_handle != NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   142
    func = (uintptr_t)GetProcAddress(hsdis_handle, "decode_instructions_virtual");
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   143
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   144
  if (func == 0) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   145
    getLastErrorString(buffer, sizeof(buffer));
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   146
    error_message = buffer;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   147
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   148
#else
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   149
  hsdis_handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   150
  if (hsdis_handle == NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   151
    snprintf(buffer, sizeof(buffer), "%s%s", jrepath, libname);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   152
    hsdis_handle = dlopen(buffer, RTLD_LAZY | RTLD_GLOBAL);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   153
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   154
  if (hsdis_handle != NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   155
    func = (uintptr_t)dlsym(hsdis_handle, "decode_instructions_virtual");
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   156
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   157
  if (func == 0) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   158
    error_message = dlerror();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   159
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   160
#endif
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
  (*env)->ReleaseStringUTFChars(env, libname_s, libname);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   163
  (*env)->ReleaseStringUTFChars(env, jrepath_s, jrepath);
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
    /* Couldn't find entry point.  error_message should contain some
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   167
     * platform dependent error message.
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   168
     */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   169
    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
   170
    if ((*env)->ExceptionOccurred(env)) {
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   171
      /* 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
   172
      return (jlong) 0;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   173
    }
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   174
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   175
    (*env)->ThrowNew(env, eclass, 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
  return (jlong)func;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   178
}
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   179
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   180
/* signature of decode_instructions_virtual from hsdis.h */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   181
typedef void* (*decode_func)(uintptr_t start_va, uintptr_t end_va,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   182
                             unsigned char* start, uintptr_t length,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   183
                             void* (*event_callback)(void*, const char*, void*),
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   184
                             void* event_stream,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   185
                             int (*printf_callback)(void*, const char*, ...),
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   186
                             void* printf_stream,
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 14847
diff changeset
   187
                             const char* options,
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 14847
diff changeset
   188
                             int newline);
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   189
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   190
/* container for call back state when decoding instructions */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   191
typedef struct {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   192
  JNIEnv* env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   193
  jobject dis;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   194
  jobject visitor;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   195
  jmethodID handle_event;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   196
  jmethodID raw_print;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   197
  char buffer[4096];
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   198
} decode_env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   199
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   200
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   201
/* event callback binding to Disassembler.handleEvent */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   202
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
   203
  jlong result = 0;
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   204
  decode_env* denv = (decode_env*)env_pv;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   205
  JNIEnv* env = denv->env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   206
  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
   207
  if ((*env)->ExceptionOccurred(env)) {
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   208
    return NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   209
  }
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   210
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   211
  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
   212
                                  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
   213
  if ((*env)->ExceptionOccurred(env)) {
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   214
    /* ignore exceptions for now */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   215
    (*env)->ExceptionClear(env);
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   216
    return NULL;
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   217
  }
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   218
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   219
  return (void*)(uintptr_t)result;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   220
}
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   221
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   222
/* printing callback binding to Disassembler.rawPrint */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   223
static int printf_to_env(void* env_pv, const char* format, ...) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   224
  jstring output;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   225
  va_list ap;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   226
  int cnt;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   227
  decode_env* denv = (decode_env*)env_pv;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   228
  JNIEnv* env = denv->env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   229
  size_t flen = strlen(format);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   230
  const char* raw = NULL;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   231
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   232
  if (flen == 0)  return 0;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   233
  if (flen < 2 ||
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   234
      strchr(format, '%') == NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   235
    raw = format;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   236
  } else if (format[0] == '%' && format[1] == '%' &&
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   237
             strchr(format+2, '%') == NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   238
    // happens a lot on machines with names like %foo
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   239
    flen--;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   240
    raw = format+1;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   241
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   242
  if (raw != NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   243
    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
   244
    if (!(*env)->ExceptionOccurred(env)) {
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   245
      /* 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
   246
      (*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
   247
    }
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   248
    if ((*env)->ExceptionOccurred(env)) {
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   249
      /* ignore exceptions for now */
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   250
        (*env)->ExceptionClear(env);
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   251
    }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   252
    return (int) flen;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   253
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   254
  va_start(ap, format);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   255
  cnt = vsnprintf(denv->buffer, sizeof(denv->buffer), format, ap);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   256
  va_end(ap);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   257
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   258
  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
   259
  if (!(*env)->ExceptionOccurred(env)) {
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   260
    /* 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
   261
    (*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
   262
  }
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   263
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   264
  if ((*env)->ExceptionOccurred(env)) {
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   265
    /* ignore exceptions for now */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   266
    (*env)->ExceptionClear(env);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   267
  }
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   268
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   269
  return cnt;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   270
}
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   271
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   272
/*
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   273
 * Class:     sun_jvm_hotspot_asm_Disassembler
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   274
 * Method:    decode
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   275
 * Signature: (Lsun/jvm/hotspot/asm/InstructionVisitor;J[BLjava/lang/String;J)V
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   276
 */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   277
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_asm_Disassembler_decode(JNIEnv * env,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   278
                                                                    jobject dis,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   279
                                                                    jobject visitor,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   280
                                                                    jlong startPc,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   281
                                                                    jbyteArray code,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   282
                                                                    jstring options_s,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   283
                                                                    jlong decode_instructions_virtual) {
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   284
  jbyte *start = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   285
  jbyte *end = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   286
  jclass disclass = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   287
  const char *options = NULL;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   288
  decode_env denv;
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   289
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   290
  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
   291
  if ((*env)->ExceptionOccurred(env)) {
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   292
    return;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   293
  }
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   294
  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
   295
  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
   296
  if ((*env)->ExceptionOccurred(env)) {
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   297
    (*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
   298
    return;
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   299
  }
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   300
  disclass = (*env)->GetObjectClass(env, dis);
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   301
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   302
  denv.env = env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   303
  denv.dis = dis;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   304
  denv.visitor = visitor;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   305
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   306
  /* find Disassembler.handleEvent callback */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   307
  denv.handle_event = (*env)->GetMethodID(env, disclass, "handleEvent",
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   308
                                          "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;J)J");
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   309
  if ((*env)->ExceptionOccurred(env)) {
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   310
    (*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
   311
    (*env)->ReleaseStringUTFChars(env, options_s, options);
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   312
    return;
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
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   315
  /* find Disassembler.rawPrint callback */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   316
  denv.raw_print = (*env)->GetMethodID(env, disclass, "rawPrint",
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   317
                                       "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;)V");
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   318
  if ((*env)->ExceptionOccurred(env)) {
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   319
    (*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
   320
    (*env)->ReleaseStringUTFChars(env, options_s, options);
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   321
    return;
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
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   324
  /* decode the buffer */
28162
cf13d6e8e46f 8028773: warnings from b116 for hotspot.agent.src.share.native: JNI exception pending
dsamersoff
parents: 16351
diff changeset
   325
  (*(decode_func)(uintptr_t)decode_instructions_virtual)((uintptr_t) startPc,
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   326
                                                         startPc + end - start,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   327
                                                         (unsigned char*)start,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   328
                                                         end - start,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   329
                                                         &event_to_env,  (void*) &denv,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   330
                                                         &printf_to_env, (void*) &denv,
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 14847
diff changeset
   331
                                                         options, 0 /* newline */);
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   332
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   333
  /* cleanup */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   334
  (*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   335
  (*env)->ReleaseStringUTFChars(env, options_s, options);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents:
diff changeset
   336
}