src/jdk.jdwp.agent/share/native/libjdwp/util.c
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 47216 71c04702a3d5
child 54649 73a87b1aacc2
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "transport.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "eventHandler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "inStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "invoker.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/* Global data area */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
BackendGlobalData *gdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/* Forward declarations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
static jboolean isInterface(jclass clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
static jboolean isArrayClass(jclass clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
static char * getPropertyUTF8(JNIEnv *env, char *propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/* Save an object reference for use later (create a NewGlobalRef) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
saveGlobalRef(JNIEnv *env, jobject obj, jobject *pobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    jobject newobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    if ( pobj == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"saveGlobalRef pobj");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    if ( *pobj != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"saveGlobalRef *pobj");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    if ( env == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"saveGlobalRef env");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    if ( obj == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"saveGlobalRef obj");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    newobj = JNI_FUNC_PTR(env,NewGlobalRef)(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    if ( newobj == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,"NewGlobalRef");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    *pobj = newobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/* Toss a previously saved object reference */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
tossGlobalRef(JNIEnv *env, jobject *pobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    jobject obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    if ( pobj == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"tossGlobalRef pobj");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    obj = *pobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    if ( env == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"tossGlobalRef env");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    if ( obj == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,"tossGlobalRef obj");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    JNI_FUNC_PTR(env,DeleteGlobalRef)(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    *pobj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    89
jclass
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
findClass(JNIEnv *env, const char * name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    jclass x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    if ( env == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"findClass env");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    if ( name == NULL || name[0] == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"findClass name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    x = JNI_FUNC_PTR(env,FindClass)(env, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    if (x == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        ERROR_MESSAGE(("JDWP Can't find class %s", name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    if ( JNI_FUNC_PTR(env,ExceptionOccurred)(env) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        ERROR_MESSAGE(("JDWP Exception occurred finding class %s", name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   112
jmethodID
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
getMethod(JNIEnv *env, jclass clazz, const char * name, const char *signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    if ( env == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getMethod env");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    if ( clazz == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getMethod clazz");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    if ( name == NULL || name[0] == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getMethod name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    if ( signature == NULL || signature[0] == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getMethod signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    method = JNI_FUNC_PTR(env,GetMethodID)(env, clazz, name, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    if (method == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        ERROR_MESSAGE(("JDWP Can't find method %s with signature %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                name, signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if ( JNI_FUNC_PTR(env,ExceptionOccurred)(env) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        ERROR_MESSAGE(("JDWP Exception occurred finding method %s with signature %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                name, signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
static jmethodID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
getStaticMethod(JNIEnv *env, jclass clazz, const char * name, const char *signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    if ( env == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getStaticMethod env");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    if ( clazz == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getStaticMethod clazz");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    if ( name == NULL || name[0] == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getStaticMethod name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if ( signature == NULL || signature[0] == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"getStaticMethod signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    method = JNI_FUNC_PTR(env,GetStaticMethodID)(env, clazz, name, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    if (method == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        ERROR_MESSAGE(("JDWP Can't find method %s with signature %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                name, signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    if ( JNI_FUNC_PTR(env,ExceptionOccurred)(env) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        ERROR_MESSAGE(("JDWP Exception occurred finding method %s with signature %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                name, signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
util_initialize(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    WITH_LOCAL_REFS(env, 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        jclass localClassClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        jclass localThreadClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        jclass localThreadGroupClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        jclass localClassLoaderClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        jclass localStringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        jclass localSystemClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        jclass localPropertiesClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        jclass localVMSupportClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        jobject localAgentProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        jmethodID getAgentProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        jint groupCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        jthreadGroup *groups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        jthreadGroup localSystemThreadGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        /* Find some standard classes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        localClassClass         = findClass(env,"java/lang/Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        localThreadClass        = findClass(env,"java/lang/Thread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        localThreadGroupClass   = findClass(env,"java/lang/ThreadGroup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        localClassLoaderClass   = findClass(env,"java/lang/ClassLoader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        localStringClass        = findClass(env,"java/lang/String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        localSystemClass        = findClass(env,"java/lang/System");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        localPropertiesClass    = findClass(env,"java/util/Properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        /* Save references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        saveGlobalRef(env, localClassClass,       &(gdata->classClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        saveGlobalRef(env, localThreadClass,      &(gdata->threadClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        saveGlobalRef(env, localThreadGroupClass, &(gdata->threadGroupClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        saveGlobalRef(env, localClassLoaderClass, &(gdata->classLoaderClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        saveGlobalRef(env, localStringClass,      &(gdata->stringClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        saveGlobalRef(env, localSystemClass,      &(gdata->systemClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        /* Find some standard methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        gdata->threadConstructor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                getMethod(env, gdata->threadClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    "<init>", "(Ljava/lang/ThreadGroup;Ljava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        gdata->threadSetDaemon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                getMethod(env, gdata->threadClass, "setDaemon", "(Z)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        gdata->threadResume =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                getMethod(env, gdata->threadClass, "resume", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        gdata->systemGetProperty =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                getStaticMethod(env, gdata->systemClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        gdata->setProperty =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                getMethod(env, localPropertiesClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        /* Find the system thread group */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        groups = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        groupCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetTopThreadGroups)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    (gdata->jvmti, &groupCount, &groups);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            EXIT_ERROR(error, "Can't get system thread group");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if ( groupCount == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            EXIT_ERROR(AGENT_ERROR_NULL_POINTER, "Can't get system thread group");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        localSystemThreadGroup = groups[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        saveGlobalRef(env, localSystemThreadGroup, &(gdata->systemThreadGroup));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        /* Get some basic Java property values we will need at some point */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        gdata->property_java_version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        = getPropertyUTF8(env, "java.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        gdata->property_java_vm_name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        = getPropertyUTF8(env, "java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        gdata->property_java_vm_info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        = getPropertyUTF8(env, "java.vm.info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        gdata->property_java_class_path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        = getPropertyUTF8(env, "java.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        gdata->property_sun_boot_library_path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        = getPropertyUTF8(env, "sun.boot.library.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        gdata->property_path_separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        = getPropertyUTF8(env, "path.separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        gdata->property_user_dir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        = getPropertyUTF8(env, "user.dir");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
36854
84179cb88469 8153181: Move sun.misc.VMSupport to an internal package
chegar
parents: 36511
diff changeset
   260
        /* Get agent properties: invoke VMSupport.getAgentProperties */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        localVMSupportClass = JNI_FUNC_PTR(env,FindClass)
36854
84179cb88469 8153181: Move sun.misc.VMSupport to an internal package
chegar
parents: 36511
diff changeset
   262
                                          (env, "jdk/internal/vm/VMSupport");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (localVMSupportClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            gdata->agent_properties = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            getAgentProperties  =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                getStaticMethod(env, localVMSupportClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                "getAgentProperties", "()Ljava/util/Properties;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            localAgentProperties =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                JNI_FUNC_PTR(env,CallStaticObjectMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            (env, localVMSupportClass, getAgentProperties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            saveGlobalRef(env, localAgentProperties, &(gdata->agent_properties));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                EXIT_ERROR(AGENT_ERROR_INTERNAL,
36854
84179cb88469 8153181: Move sun.misc.VMSupport to an internal package
chegar
parents: 36511
diff changeset
   279
                    "Exception occurred calling VMSupport.getAgentProperties");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
util_reset(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
isObjectTag(jbyte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    return (tag == JDWP_TAG(OBJECT)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
           (tag == JDWP_TAG(STRING)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
           (tag == JDWP_TAG(THREAD)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
           (tag == JDWP_TAG(THREAD_GROUP)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
           (tag == JDWP_TAG(CLASS_LOADER)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
           (tag == JDWP_TAG(CLASS_OBJECT)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
           (tag == JDWP_TAG(ARRAY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
jbyte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
specificTypeKey(JNIEnv *env, jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    if (object == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return JDWP_TAG(OBJECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    } else if (JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->stringClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return JDWP_TAG(STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    } else if (JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->threadClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return JDWP_TAG(THREAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    } else if (JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->threadGroupClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return JDWP_TAG(THREAD_GROUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    } else if (JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->classLoaderClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return JDWP_TAG(CLASS_LOADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    } else if (JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->classClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return JDWP_TAG(CLASS_OBJECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        jboolean classIsArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            classIsArray = isArrayClass(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return (classIsArray ? JDWP_TAG(ARRAY) : JDWP_TAG(OBJECT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
writeFieldValue(JNIEnv *env, PacketOutputStream *out, jobject object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                jfieldID field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    jbyte typeKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    error = fieldSignature(clazz, field, NULL, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    typeKey = signature[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * For primitive types, the type key is bounced back as is. Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * are handled in the switch statement below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    if ((typeKey != JDWP_TAG(OBJECT)) && (typeKey != JDWP_TAG(ARRAY))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        (void)outStream_writeByte(out, typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    switch (typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        case JDWP_TAG(OBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        case JDWP_TAG(ARRAY):   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            jobject value = JNI_FUNC_PTR(env,GetObjectField)(env, object, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            (void)outStream_writeByte(out, specificTypeKey(env, value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            (void)outStream_writeObjectRef(env, out, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            (void)outStream_writeByte(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                      JNI_FUNC_PTR(env,GetByteField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            (void)outStream_writeChar(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                      JNI_FUNC_PTR(env,GetCharField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            (void)outStream_writeFloat(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                      JNI_FUNC_PTR(env,GetFloatField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            (void)outStream_writeDouble(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                      JNI_FUNC_PTR(env,GetDoubleField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            (void)outStream_writeInt(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                      JNI_FUNC_PTR(env,GetIntField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            (void)outStream_writeLong(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                      JNI_FUNC_PTR(env,GetLongField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            (void)outStream_writeShort(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                      JNI_FUNC_PTR(env,GetShortField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            (void)outStream_writeBoolean(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                      JNI_FUNC_PTR(env,GetBooleanField)(env, object, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
writeStaticFieldValue(JNIEnv *env, PacketOutputStream *out, jclass clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                      jfieldID field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    jbyte typeKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    error = fieldSignature(clazz, field, NULL, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    typeKey = signature[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * For primitive types, the type key is bounced back as is. Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * are handled in the switch statement below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    if ((typeKey != JDWP_TAG(OBJECT)) && (typeKey != JDWP_TAG(ARRAY))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        (void)outStream_writeByte(out, typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    switch (typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        case JDWP_TAG(OBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        case JDWP_TAG(ARRAY):   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            jobject value = JNI_FUNC_PTR(env,GetStaticObjectField)(env, clazz, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            (void)outStream_writeByte(out, specificTypeKey(env, value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            (void)outStream_writeObjectRef(env, out, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            (void)outStream_writeByte(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                      JNI_FUNC_PTR(env,GetStaticByteField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            (void)outStream_writeChar(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                      JNI_FUNC_PTR(env,GetStaticCharField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            (void)outStream_writeFloat(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                      JNI_FUNC_PTR(env,GetStaticFloatField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            (void)outStream_writeDouble(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                      JNI_FUNC_PTR(env,GetStaticDoubleField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            (void)outStream_writeInt(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                      JNI_FUNC_PTR(env,GetStaticIntField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            (void)outStream_writeLong(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                      JNI_FUNC_PTR(env,GetStaticLongField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            (void)outStream_writeShort(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                      JNI_FUNC_PTR(env,GetStaticShortField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            (void)outStream_writeBoolean(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                      JNI_FUNC_PTR(env,GetStaticBooleanField)(env, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
sharedGetFieldValues(PacketInputStream *in, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                     jboolean isStatic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    jint length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    jobject object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    object = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    clazz  = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    if (isStatic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        clazz = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        object = inStream_readObjectRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    length = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    WITH_LOCAL_REFS(env, length + 1) { /* +1 for class with instance fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        (void)outStream_writeInt(out, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        for (i = 0; (i < length) && !outStream_error(out); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            jfieldID field = inStream_readFieldID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            if (isStatic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                writeStaticFieldValue(env, out, clazz, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                writeFieldValue(env, out, object, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
sharedInvoke(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    jvalue *arguments = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    jint options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    jbyte invokeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    jint argumentCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    jobject instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Instance methods start with the instance, thread and class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * and statics and constructors start with the class and then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    if (inStream_command(in) == JDWP_COMMAND(ObjectReference, InvokeMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        instance = inStream_readObjectRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        clazz = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    } else { /* static method or constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        instance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        clazz = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * ... and the rest of the packet is identical for all commands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    method = inStream_readMethodID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    argumentCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /* If count == 0, don't try and allocate 0 bytes, you'll get NULL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    if ( argumentCount > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        arguments = jvmtiAllocate(argumentCount * (jint)sizeof(*arguments));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (arguments == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        for (i = 0; (i < argumentCount) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            arguments[i] = inStream_readValue(in, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    options = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if ( arguments != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            jvmtiDeallocate(arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    if (inStream_command(in) == JDWP_COMMAND(ClassType, NewInstance)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        invokeType = INVOKE_CONSTRUCTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    } else if (inStream_command(in) == JDWP_COMMAND(ClassType, InvokeMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        invokeType = INVOKE_STATIC;
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   592
    } else if (inStream_command(in) == JDWP_COMMAND(InterfaceType, InvokeMethod)) {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   593
        invokeType = INVOKE_STATIC;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    } else if (inStream_command(in) == JDWP_COMMAND(ObjectReference, InvokeMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        invokeType = INVOKE_INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        outStream_setError(out, JDWP_ERROR(INTERNAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if ( arguments != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            jvmtiDeallocate(arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Request the invoke. If there are no errors in the request,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * the interrupting thread will actually do the invoke and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * reply will be generated subsequently, so we don't reply here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    error = invoker_requestInvoke(invokeType, (jbyte)options, inStream_id(in),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                                  thread, clazz, method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                  instance, arguments, argumentCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        if ( arguments != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            jvmtiDeallocate(arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    return JNI_FALSE;   /* Don't reply */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
uniqueID(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    static jint currentID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    return currentID++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
filterDebugThreads(jthread *threads, int count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    int current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /* Squish out all of the debugger-spawned threads */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    for (i = 0, current = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        jthread thread = threads[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if (!threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            if (i > current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                threads[current] = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    return current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
jbyte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
referenceTypeTag(jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    jbyte tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    if (isInterface(clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        tag = JDWP_TYPE_TAG(INTERFACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    } else if (isArrayClass(clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        tag = JDWP_TYPE_TAG(ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        tag = JDWP_TYPE_TAG(CLASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    return tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
 * Get field modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
fieldModifiers(jclass clazz, jfieldID field, jint *pmodifiers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    *pmodifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetFieldModifiers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            (gdata->jvmti, clazz, field, pmodifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
 * Get method modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
methodModifiers(jmethodID method, jint *pmodifiers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    *pmodifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetMethodModifiers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            (gdata->jvmti, method, pmodifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
/* Returns a local ref to the declaring class for a method, or NULL. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
methodClass(jmethodID method, jclass *pclazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    *pclazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    error = FUNC_PTR(gdata->jvmti,GetMethodDeclaringClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                                (gdata->jvmti, method, pclazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
/* Returns a local ref to the declaring class for a method, or NULL. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
methodLocation(jmethodID method, jlocation *ploc1, jlocation *ploc2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetMethodLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                                (gdata->jvmti, method, ploc1, ploc2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
 * Get method signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
methodSignature(jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        char **pname, char **psignature, char **pgeneric_signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    char *name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    char *generic_signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    error = FUNC_PTR(gdata->jvmti,GetMethodName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            (gdata->jvmti, method, &name, &signature, &generic_signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    if ( pname != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        *pname = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    } else if ( name != NULL )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        jvmtiDeallocate(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    if ( psignature != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        *psignature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    } else if ( signature != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    if ( pgeneric_signature != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        *pgeneric_signature = generic_signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    } else if ( generic_signature != NULL )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        jvmtiDeallocate(generic_signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
 * Get the return type key of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
 *     V or B C D F I J S Z L  [
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
methodReturnType(jmethodID method, char *typeKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    char       *signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    jvmtiError  error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    error     = methodSignature(method, NULL, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        if (signature == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            error = AGENT_ERROR_INVALID_TAG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            char * xx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            xx = strchr(signature, ')');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            if (xx == NULL || *(xx + 1) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                error = AGENT_ERROR_INVALID_TAG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
               *typeKey = *(xx + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
 * Return class loader for a class (must be inside a WITH_LOCAL_REFS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
classLoader(jclass clazz, jobject *pclazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    *pclazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            (gdata->jvmti, clazz, pclazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
 * Get field signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
fieldSignature(jclass clazz, jfieldID field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        char **pname, char **psignature, char **pgeneric_signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    char *name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    char *generic_signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetFieldName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            (gdata->jvmti, clazz, field, &name, &signature, &generic_signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    if ( pname != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        *pname = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    } else if ( name != NULL )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        jvmtiDeallocate(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    if ( psignature != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        *psignature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    } else if ( signature != NULL )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    if ( pgeneric_signature != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        *pgeneric_signature = generic_signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    } else if ( generic_signature != NULL )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        jvmtiDeallocate(generic_signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
JNIEnv *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
getEnv(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    JNIEnv *env = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    jint rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    rc = FUNC_PTR(gdata->jvm,GetEnv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                (gdata->jvm, (void **)&env, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    if (rc != JNI_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        ERROR_MESSAGE(("JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                rc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        EXIT_ERROR(AGENT_ERROR_NO_JNI_ENV,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    return env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
spawnNewThread(jvmtiStartFunction func, void *arg, char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    LOG_MISC(("Spawning new thread: %s", name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    WITH_LOCAL_REFS(env, 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        jstring nameString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        nameString = JNI_FUNC_PTR(env,NewStringUTF)(env, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            error = AGENT_ERROR_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        thread = JNI_FUNC_PTR(env,NewObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                        (env, gdata->threadClass, gdata->threadConstructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                   gdata->systemThreadGroup, nameString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            error = AGENT_ERROR_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         * Make the debugger thread a daemon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        JNI_FUNC_PTR(env,CallVoidMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        (env, thread, gdata->threadSetDaemon, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            error = AGENT_ERROR_JNI_EXCEPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        error = threadControl_addDebugThread(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
             * Debugger threads need cycles in all sorts of strange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
             * situations (e.g. infinite cpu-bound loops), so give the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
             * thread a high priority. Note that if the VM has an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
             * thread running at the max priority, there is still a chance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
             * that debugger threads will be starved. (There needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
             * a way to give debugger threads a priority higher than any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
             * application thread).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            error = JVMTI_FUNC_PTR(gdata->jvmti,RunAgentThread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                        (gdata->jvmti, thread, func, arg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                        JVMTI_THREAD_MAX_PRIORITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        err: ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
jvmtiGetCapabilities(jvmtiCapabilities *caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    if ( gdata->vmDead ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        return AGENT_ERROR_VM_DEAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    if (!gdata->haveCachedJvmtiCapabilities) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetCapabilities)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                        (gdata->jvmti, &(gdata->cachedJvmtiCapabilities));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        gdata->haveCachedJvmtiCapabilities = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    *caps = gdata->cachedJvmtiCapabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
jvmtiVersion(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    if (gdata->cachedJvmtiVersion == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetVersionNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                        (gdata->jvmti, &(gdata->cachedJvmtiVersion));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            EXIT_ERROR(error, "on getting the JVMTI version number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    return gdata->cachedJvmtiVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
jvmtiMajorVersion(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    return (jvmtiVersion() & JVMTI_VERSION_MASK_MAJOR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                    >> JVMTI_VERSION_SHIFT_MAJOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
jvmtiMinorVersion(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    return (jvmtiVersion() & JVMTI_VERSION_MASK_MINOR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    >> JVMTI_VERSION_SHIFT_MINOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
jvmtiMicroVersion(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    return (jvmtiVersion() & JVMTI_VERSION_MASK_MICRO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    >> JVMTI_VERSION_SHIFT_MICRO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
canSuspendResumeThreadLists(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    jvmtiCapabilities cap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    error = jvmtiGetCapabilities(&cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    return (error == JVMTI_ERROR_NONE && cap.can_suspend);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
getSourceDebugExtension(jclass clazz, char **extensionPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    return JVMTI_FUNC_PTR(gdata->jvmti,GetSourceDebugExtension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                (gdata->jvmti, clazz, extensionPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
 * Convert the signature "Ljava/lang/Foo;" to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
 * classname "java.lang.Foo" compatible with the pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
 * Signature is overwritten in-place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
convertSignatureToClassname(char *convert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    char *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    p = convert + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    while ((*p != ';') && (*p != '\0')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        char c = *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        if (c == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            *(p-1) = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            *(p-1) = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    *(p-1) = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
handleInterrupt(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * An interrupt is handled:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * 1) for running application threads by deferring the interrupt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * until the current event handler has concluded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * 2) for debugger threads by ignoring the interrupt; this is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * most robust solution since debugger threads don't use interrupts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * to signal any condition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * 3) for application threads that have not started or already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * ended by ignoring the interrupt. In the former case, the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * is relying on timing to determine whether or not the thread sees
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * the interrupt; in the latter case, the interrupt is meaningless.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    jthread thread = threadControl_currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    if ((thread != NULL) && (!threadControl_isDebugThread(thread))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        threadControl_setPendingInterrupt(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
ignore_vm_death(jvmtiError error)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    if (error == JVMTI_ERROR_WRONG_PHASE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        LOG_MISC(("VM_DEAD, in debugMonitor*()?"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        return JVMTI_ERROR_NONE; /* JVMTI does this, not JVMDI? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
debugMonitorEnter(jrawMonitorID monitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    while (JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        error = FUNC_PTR(gdata->jvmti,RawMonitorEnter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                        (gdata->jvmti, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        error = ignore_vm_death(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        if (error == JVMTI_ERROR_INTERRUPT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            handleInterrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        EXIT_ERROR(error, "on raw monitor enter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
debugMonitorExit(jrawMonitorID monitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    error = FUNC_PTR(gdata->jvmti,RawMonitorExit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                (gdata->jvmti, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    error = ignore_vm_death(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        EXIT_ERROR(error, "on raw monitor exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
debugMonitorWait(jrawMonitorID monitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    error = FUNC_PTR(gdata->jvmti,RawMonitorWait)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        (gdata->jvmti, monitor, ((jlong)(-1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * According to the JLS (17.8), here we have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * either :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * a- been notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * b- gotten a suprious wakeup
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * c- been interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * If both a and c have happened, the VM must choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * which way to return - a or c.  If it chooses c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * then the notify is gone - either to some other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * thread that is also waiting, or it is dropped
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * on the floor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * a is what we expect.  b won't hurt us any -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * callers should be programmed to handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * spurious wakeups.  In case of c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * then the interrupt has been cleared, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * we don't want to consume it.  It came from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * user code and is intended for user code, not us.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * So, we will remember that the interrupt has
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
  1095
     * occurred and re-activate it when this thread
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * goes back into user code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * That being said, what do we do here?  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * we could have been notified too, here we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * just pretend that we have been.  It won't hurt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * anything to return in the same way as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * we were notified since callers have to be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * handle spurious wakeups anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    if (error == JVMTI_ERROR_INTERRUPT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        handleInterrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    error = ignore_vm_death(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        EXIT_ERROR(error, "on raw monitor wait");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
debugMonitorTimedWait(jrawMonitorID monitor, jlong millis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    error = FUNC_PTR(gdata->jvmti,RawMonitorWait)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        (gdata->jvmti, monitor, millis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    if (error == JVMTI_ERROR_INTERRUPT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        /* See comment above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        handleInterrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    error = ignore_vm_death(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        EXIT_ERROR(error, "on raw monitor timed wait");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
debugMonitorNotify(jrawMonitorID monitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    error = FUNC_PTR(gdata->jvmti,RawMonitorNotify)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                (gdata->jvmti, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    error = ignore_vm_death(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        EXIT_ERROR(error, "on raw monitor notify");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
debugMonitorNotifyAll(jrawMonitorID monitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    error = FUNC_PTR(gdata->jvmti,RawMonitorNotifyAll)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                (gdata->jvmti, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    error = ignore_vm_death(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        EXIT_ERROR(error, "on raw monitor notify all");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
jrawMonitorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
debugMonitorCreate(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    jrawMonitorID monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    error = FUNC_PTR(gdata->jvmti,CreateRawMonitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                (gdata->jvmti, name, &monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        EXIT_ERROR(error, "on creation of a raw monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    return monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
debugMonitorDestroy(jrawMonitorID monitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    error = FUNC_PTR(gdata->jvmti,DestroyRawMonitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                (gdata->jvmti, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    error = ignore_vm_death(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        EXIT_ERROR(error, "on destruction of raw monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
 * Return array of all threads (must be inside a WITH_LOCAL_REFS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
jthread *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
allThreads(jint *count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    jthread *threads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    *count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    threads = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetAllThreads)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                (gdata->jvmti, count, &threads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    if (error == AGENT_ERROR_OUT_OF_MEMORY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        return NULL; /* Let caller deal with no memory? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        EXIT_ERROR(error, "getting all threads");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    return threads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
 * Fill the passed in structure with thread group info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
 * name field is JVMTI allocated.  parent is global ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
threadGroupInfo(jthreadGroup group, jvmtiThreadGroupInfo *info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadGroupInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                (gdata->jvmti, group, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        EXIT_ERROR(error, "on getting thread group info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
 * Return class signature string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
classSignature(jclass clazz, char **psignature, char **pgeneric_signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * pgeneric_signature can be NULL, and GetClassSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * accepts NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    error = FUNC_PTR(gdata->jvmti,GetClassSignature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                (gdata->jvmti, clazz, &signature, pgeneric_signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    if ( psignature != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        *psignature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    } else if ( signature != NULL )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
/* Get class name (not signature) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
getClassname(jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    char *classname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    classname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    if ( clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        if (classSignature(clazz, &classname, NULL) != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            classname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            /* Convert in place */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            convertSignatureToClassname(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    return classname; /* Caller must free this memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
writeGenericSignature(PacketOutputStream *out, char *genericSignature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    if (genericSignature == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        (void)outStream_writeString(out, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        (void)outStream_writeString(out, genericSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
classStatus(jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    jint status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetClassStatus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                (gdata->jvmti, clazz, &status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        EXIT_ERROR(error, "on getting class status");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
isArrayClass(jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    jboolean isArray = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    error = JVMTI_FUNC_PTR(gdata->jvmti,IsArrayClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                (gdata->jvmti, clazz, &isArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        EXIT_ERROR(error, "on checking for an array class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    return isArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
isInterface(jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    jboolean isInterface = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    error = JVMTI_FUNC_PTR(gdata->jvmti,IsInterface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                (gdata->jvmti, clazz, &isInterface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        EXIT_ERROR(error, "on checking for an interface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    return isInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
isFieldSynthetic(jclass clazz, jfieldID field, jboolean *psynthetic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    error = JVMTI_FUNC_PTR(gdata->jvmti,IsFieldSynthetic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                (gdata->jvmti, clazz, field, psynthetic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    if ( error == JVMTI_ERROR_MUST_POSSESS_CAPABILITY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        /* If the query is not supported, we assume it is not synthetic. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        *psynthetic = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
isMethodSynthetic(jmethodID method, jboolean *psynthetic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    error = JVMTI_FUNC_PTR(gdata->jvmti,IsMethodSynthetic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                (gdata->jvmti, method, psynthetic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    if ( error == JVMTI_ERROR_MUST_POSSESS_CAPABILITY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        /* If the query is not supported, we assume it is not synthetic. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        *psynthetic = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
isMethodNative(jmethodID method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    jboolean isNative = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    error = JVMTI_FUNC_PTR(gdata->jvmti,IsMethodNative)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                (gdata->jvmti, method, &isNative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        EXIT_ERROR(error, "on checking for a native interface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    return isNative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
isSameObject(JNIEnv *env, jobject o1, jobject o2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    if ( o1==o2 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    return FUNC_PTR(env,IsSameObject)(env, o1, o2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
objectHashCode(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    jint hashCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    if ( object!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetObjectHashCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                    (gdata->jvmti, object, &hashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            EXIT_ERROR(error, "on getting an object hash code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    return hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
/* Get all implemented interfaces (must be inside a WITH_LOCAL_REFS) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
allInterfaces(jclass clazz, jclass **ppinterfaces, jint *pcount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    *pcount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    *ppinterfaces = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetImplementedInterfaces)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                (gdata->jvmti, clazz, pcount, ppinterfaces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
/* Get all loaded classes (must be inside a WITH_LOCAL_REFS) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
allLoadedClasses(jclass **ppclasses, jint *pcount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    *pcount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    *ppclasses = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetLoadedClasses)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                (gdata->jvmti, pcount, ppclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
/* Get all loaded classes for a loader (must be inside a WITH_LOCAL_REFS) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
allClassLoaderClasses(jobject loader, jclass **ppclasses, jint *pcount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    *pcount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    *ppclasses = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetClassLoaderClasses)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                (gdata->jvmti, loader, pcount, ppclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
is_a_nested_class(char *outer_sig, int outer_sig_len, char *sig, int sep)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    char *inner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    /* Assumed outer class signature is  "LOUTERCLASSNAME;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     *         inner class signature is  "LOUTERCLASSNAME$INNERNAME;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * INNERNAME can take the form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     *    [0-9][1-9]*        anonymous class somewhere in the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     *    [0-9][1-9]*NAME    local class somewhere in the OUTER class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     *    NAME               nested class in OUTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * If NAME itself contains a $ (sep) then classname is further nested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     *    inside another class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    /* Check prefix first */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    if ( strncmp(sig, outer_sig, outer_sig_len-1) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    /* Prefix must be followed by a $ (sep) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    if ( sig[outer_sig_len-1] != sep ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        return JNI_FALSE;  /* No sep follows the match, must not be nested. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    /* Walk past any digits, if we reach the end, must be pure anonymous */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    inner = sig + outer_sig_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
#if 1 /* We want to return local classes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    while ( *inner && isdigit(*inner) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        inner++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    /* But anonymous class names can't be trusted. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    if ( *inner == ';' ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        return JNI_FALSE;  /* A pure anonymous class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    if ( *inner && isdigit(*inner) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        return JNI_FALSE;  /* A pure anonymous or local class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    /* Nested deeper? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    if ( strchr(inner, sep) != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        return JNI_FALSE;  /* Nested deeper than we want? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
/* Get all nested classes for a class (must be inside a WITH_LOCAL_REFS) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
allNestedClasses(jclass parent_clazz, jclass **ppnested, jint *pcount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    jobject parent_loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    jclass *classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
    char *signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    size_t len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    jint ncount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    *ppnested   = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    *pcount     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    parent_loader = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    classes       = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    signature     = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    count         = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    ncount        = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    error = classLoader(parent_clazz, &parent_loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    error = classSignature(parent_clazz, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    len = strlen(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    error = allClassLoaderClasses(parent_loader, &classes, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    for (i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        char *candidate_signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        clazz = classes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        candidate_signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        error = classSignature(clazz, &candidate_signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        if ( is_a_nested_class(signature, (int)len, candidate_signature, '$') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
             is_a_nested_class(signature, (int)len, candidate_signature, '#') ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
            /* Float nested classes to top */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
            classes[i] = classes[ncount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            classes[ncount++] = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        jvmtiDeallocate(candidate_signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    if ( count != 0 &&  ncount == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        jvmtiDeallocate(classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        classes = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    *ppnested = classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    *pcount = ncount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
createLocalRefSpace(JNIEnv *env, jint capacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     * Save current exception since it might get overwritten by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * the calls below. Note we must depend on space in the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     * frame because asking for a new frame may generate an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    jobject throwable = JNI_FUNC_PTR(env,ExceptionOccurred)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * Use the current frame if necessary; otherwise create a new one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
    if (JNI_FUNC_PTR(env,PushLocalFrame)(env, capacity) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"PushLocalFrame: Unable to push JNI frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * TO DO: This could be more efficient if it used EnsureLocalCapacity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     * but that would not work if two functions on the call stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     * use this function. We would need to either track reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
     * references on a per-thread basis or come up with a convention
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     * that would prevent two functions from depending on this function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * at the same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * Restore exception state from before call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    if (throwable != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        JNI_FUNC_PTR(env,Throw)(env, throwable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
isClass(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    return JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->classClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
isThread(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    return JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->threadClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
isThreadGroup(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    return JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->threadGroupClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
isString(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    return JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->stringClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
isClassLoader(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    return JNI_FUNC_PTR(env,IsInstanceOf)(env, object, gdata->classLoaderClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
isArray(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    jboolean is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        is = isArrayClass(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    return is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
 * Return property value as jstring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
static jstring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
getPropertyValue(JNIEnv *env, char *propertyName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    jstring valueString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    jstring nameString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    valueString = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    /* Create new String object to hold the property name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    nameString = JNI_FUNC_PTR(env,NewStringUTF)(env, propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        /* NULL will be returned below */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        /* Call valueString = System.getProperty(nameString) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        valueString = JNI_FUNC_PTR(env,CallStaticObjectMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            (env, gdata->systemClass, gdata->systemGetProperty, nameString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            valueString = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
    return valueString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
 * Set an agent property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
setAgentPropertyValue(JNIEnv *env, char *propertyName, char* propertyValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    jstring nameString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    jstring valueString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    if (gdata->agent_properties == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        /* VMSupport doesn't exist; so ignore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    /* Create jstrings for property name and value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    nameString = JNI_FUNC_PTR(env,NewStringUTF)(env, propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
    if (nameString != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
        valueString = JNI_FUNC_PTR(env,NewStringUTF)(env, propertyValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        if (valueString != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            /* invoke Properties.setProperty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            JNI_FUNC_PTR(env,CallObjectMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                (env, gdata->agent_properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                 gdata->setProperty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                 nameString, valueString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
    if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
 * Return property value as JDWP allocated string in UTF8 encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
getPropertyUTF8(JNIEnv *env, char *propertyName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    jvmtiError  error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    char       *value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    value = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetSystemProperty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                (gdata->jvmti, (const char *)propertyName, &value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        jstring valueString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        value = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        valueString = getPropertyValue(env, propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        if (valueString != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            const char *utf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            /* Get the UTF8 encoding for this property value string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            utf = JNI_FUNC_PTR(env,GetStringUTFChars)(env, valueString, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            /* Make a copy for returning, release the JNI copy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            value = jvmtiAllocate((int)strlen(utf) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                (void)strcpy(value, utf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            JNI_FUNC_PTR(env,ReleaseStringUTFChars)(env, valueString, utf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    if ( value == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        ERROR_MESSAGE(("JDWP Can't get property value for %s", propertyName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
isMethodObsolete(jmethodID method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    jboolean obsolete = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    if ( method != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        error = JVMTI_FUNC_PTR(gdata->jvmti,IsMethodObsolete)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                    (gdata->jvmti, method, &obsolete);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            obsolete = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
    return obsolete;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
/* Get the jvmti environment to be used with tags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
static jvmtiEnv *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
getSpecialJvmti(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
    jvmtiEnv  *jvmti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    int        rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    /* Get one time use JVMTI Env */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
    jvmtiCapabilities caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
    rc = JVM_FUNC_PTR(gdata->jvm,GetEnv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                     (gdata->jvm, (void **)&jvmti, JVMTI_VERSION_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
    if (rc != JNI_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    (void)memset(&caps, 0, (int)sizeof(caps));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
    caps.can_tag_objects = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    error = JVMTI_FUNC_PTR(jvmti,AddCapabilities)(jvmti, &caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
    if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
    return jvmti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
writeCodeLocation(PacketOutputStream *out, jclass clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                       jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
    jbyte tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
    if (clazz != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        tag = referenceTypeTag(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        tag = JDWP_TYPE_TAG(CLASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
    (void)outStream_writeByte(out, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
    (void)outStream_writeObjectRef(getEnv(), out, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    (void)outStream_writeMethodID(out, isMethodObsolete(method)?NULL:method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    (void)outStream_writeLocation(out, location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
jvmtiAllocate(jint numBytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
    void *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    if ( numBytes == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    error = FUNC_PTR(gdata->jvmti,Allocate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                (gdata->jvmti, numBytes, (unsigned char**)&ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    if (error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        EXIT_ERROR(error, "Can't allocate jvmti memory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    return ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
jvmtiDeallocate(void *ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    if ( ptr == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    error = FUNC_PTR(gdata->jvmti,Deallocate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                (gdata->jvmti, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
    if (error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        EXIT_ERROR(error, "Can't deallocate jvmti memory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
/* Rarely needed, transport library uses JDWP errors, only use? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
map2jvmtiError(jdwpError error)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
    switch ( error ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        case JDWP_ERROR(NONE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        case JDWP_ERROR(INVALID_THREAD):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            return JVMTI_ERROR_INVALID_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        case JDWP_ERROR(INVALID_THREAD_GROUP):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            return JVMTI_ERROR_INVALID_THREAD_GROUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        case JDWP_ERROR(INVALID_PRIORITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            return JVMTI_ERROR_INVALID_PRIORITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        case JDWP_ERROR(THREAD_NOT_SUSPENDED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        case JDWP_ERROR(THREAD_SUSPENDED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            return JVMTI_ERROR_THREAD_SUSPENDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        case JDWP_ERROR(INVALID_OBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
            return JVMTI_ERROR_INVALID_OBJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        case JDWP_ERROR(INVALID_CLASS):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            return JVMTI_ERROR_INVALID_CLASS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        case JDWP_ERROR(CLASS_NOT_PREPARED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
            return JVMTI_ERROR_CLASS_NOT_PREPARED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        case JDWP_ERROR(INVALID_METHODID):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
            return JVMTI_ERROR_INVALID_METHODID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        case JDWP_ERROR(INVALID_LOCATION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            return JVMTI_ERROR_INVALID_LOCATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        case JDWP_ERROR(INVALID_FIELDID):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            return JVMTI_ERROR_INVALID_FIELDID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        case JDWP_ERROR(INVALID_FRAMEID):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            return AGENT_ERROR_INVALID_FRAMEID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        case JDWP_ERROR(NO_MORE_FRAMES):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            return JVMTI_ERROR_NO_MORE_FRAMES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        case JDWP_ERROR(OPAQUE_FRAME):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            return JVMTI_ERROR_OPAQUE_FRAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        case JDWP_ERROR(NOT_CURRENT_FRAME):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            return AGENT_ERROR_NOT_CURRENT_FRAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        case JDWP_ERROR(TYPE_MISMATCH):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            return JVMTI_ERROR_TYPE_MISMATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        case JDWP_ERROR(INVALID_SLOT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            return JVMTI_ERROR_INVALID_SLOT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        case JDWP_ERROR(DUPLICATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            return JVMTI_ERROR_DUPLICATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
        case JDWP_ERROR(NOT_FOUND):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            return JVMTI_ERROR_NOT_FOUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        case JDWP_ERROR(INVALID_MONITOR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            return JVMTI_ERROR_INVALID_MONITOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
        case JDWP_ERROR(NOT_MONITOR_OWNER):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            return JVMTI_ERROR_NOT_MONITOR_OWNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        case JDWP_ERROR(INTERRUPT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            return JVMTI_ERROR_INTERRUPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
        case JDWP_ERROR(INVALID_CLASS_FORMAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
            return JVMTI_ERROR_INVALID_CLASS_FORMAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        case JDWP_ERROR(CIRCULAR_CLASS_DEFINITION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        case JDWP_ERROR(FAILS_VERIFICATION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            return JVMTI_ERROR_FAILS_VERIFICATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
        case JDWP_ERROR(ADD_METHOD_NOT_IMPLEMENTED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        case JDWP_ERROR(SCHEMA_CHANGE_NOT_IMPLEMENTED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        case JDWP_ERROR(INVALID_TYPESTATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
            return JVMTI_ERROR_INVALID_TYPESTATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        case JDWP_ERROR(HIERARCHY_CHANGE_NOT_IMPLEMENTED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        case JDWP_ERROR(DELETE_METHOD_NOT_IMPLEMENTED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        case JDWP_ERROR(UNSUPPORTED_VERSION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            return JVMTI_ERROR_UNSUPPORTED_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        case JDWP_ERROR(NAMES_DONT_MATCH):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            return JVMTI_ERROR_NAMES_DONT_MATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
        case JDWP_ERROR(CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
        case JDWP_ERROR(METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED;
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
  1891
        case JDWP_ERROR(CLASS_ATTRIBUTE_CHANGE_NOT_IMPLEMENTED):
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
  1892
            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        case JDWP_ERROR(NOT_IMPLEMENTED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            return JVMTI_ERROR_NOT_AVAILABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        case JDWP_ERROR(NULL_POINTER):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            return JVMTI_ERROR_NULL_POINTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        case JDWP_ERROR(ABSENT_INFORMATION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            return JVMTI_ERROR_ABSENT_INFORMATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        case JDWP_ERROR(INVALID_EVENT_TYPE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            return JVMTI_ERROR_INVALID_EVENT_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        case JDWP_ERROR(ILLEGAL_ARGUMENT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
            return JVMTI_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        case JDWP_ERROR(OUT_OF_MEMORY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            return JVMTI_ERROR_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        case JDWP_ERROR(ACCESS_DENIED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            return JVMTI_ERROR_ACCESS_DENIED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        case JDWP_ERROR(VM_DEAD):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            return JVMTI_ERROR_WRONG_PHASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        case JDWP_ERROR(UNATTACHED_THREAD):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
            return JVMTI_ERROR_UNATTACHED_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        case JDWP_ERROR(INVALID_TAG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            return AGENT_ERROR_INVALID_TAG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        case JDWP_ERROR(ALREADY_INVOKING):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            return AGENT_ERROR_ALREADY_INVOKING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        case JDWP_ERROR(INVALID_INDEX):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            return AGENT_ERROR_INVALID_INDEX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        case JDWP_ERROR(INVALID_LENGTH):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            return AGENT_ERROR_INVALID_LENGTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        case JDWP_ERROR(INVALID_STRING):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            return AGENT_ERROR_INVALID_STRING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        case JDWP_ERROR(INVALID_CLASS_LOADER):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            return AGENT_ERROR_INVALID_CLASS_LOADER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        case JDWP_ERROR(INVALID_ARRAY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            return AGENT_ERROR_INVALID_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        case JDWP_ERROR(TRANSPORT_LOAD):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            return AGENT_ERROR_TRANSPORT_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        case JDWP_ERROR(TRANSPORT_INIT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            return AGENT_ERROR_TRANSPORT_INIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        case JDWP_ERROR(NATIVE_METHOD):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            return AGENT_ERROR_NATIVE_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        case JDWP_ERROR(INVALID_COUNT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            return AGENT_ERROR_INVALID_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        case JDWP_ERROR(INTERNAL):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            return AGENT_ERROR_JDWP_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
    return AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
static jvmtiEvent index2jvmti[EI_max-EI_min+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
static jdwpEvent  index2jdwp [EI_max-EI_min+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
eventIndexInit(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
    (void)memset(index2jvmti, 0, (int)sizeof(index2jvmti));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    (void)memset(index2jdwp,  0, (int)sizeof(index2jdwp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
    index2jvmti[EI_SINGLE_STEP        -EI_min] = JVMTI_EVENT_SINGLE_STEP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
    index2jvmti[EI_BREAKPOINT         -EI_min] = JVMTI_EVENT_BREAKPOINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
    index2jvmti[EI_FRAME_POP          -EI_min] = JVMTI_EVENT_FRAME_POP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    index2jvmti[EI_EXCEPTION          -EI_min] = JVMTI_EVENT_EXCEPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
    index2jvmti[EI_THREAD_START       -EI_min] = JVMTI_EVENT_THREAD_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
    index2jvmti[EI_THREAD_END         -EI_min] = JVMTI_EVENT_THREAD_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    index2jvmti[EI_CLASS_PREPARE      -EI_min] = JVMTI_EVENT_CLASS_PREPARE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
    index2jvmti[EI_GC_FINISH          -EI_min] = JVMTI_EVENT_GARBAGE_COLLECTION_FINISH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    index2jvmti[EI_CLASS_LOAD         -EI_min] = JVMTI_EVENT_CLASS_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
    index2jvmti[EI_FIELD_ACCESS       -EI_min] = JVMTI_EVENT_FIELD_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    index2jvmti[EI_FIELD_MODIFICATION -EI_min] = JVMTI_EVENT_FIELD_MODIFICATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
    index2jvmti[EI_EXCEPTION_CATCH    -EI_min] = JVMTI_EVENT_EXCEPTION_CATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    index2jvmti[EI_METHOD_ENTRY       -EI_min] = JVMTI_EVENT_METHOD_ENTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
    index2jvmti[EI_METHOD_EXIT        -EI_min] = JVMTI_EVENT_METHOD_EXIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    index2jvmti[EI_MONITOR_CONTENDED_ENTER      -EI_min] = JVMTI_EVENT_MONITOR_CONTENDED_ENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
    index2jvmti[EI_MONITOR_CONTENDED_ENTERED    -EI_min] = JVMTI_EVENT_MONITOR_CONTENDED_ENTERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
    index2jvmti[EI_MONITOR_WAIT       -EI_min] = JVMTI_EVENT_MONITOR_WAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
    index2jvmti[EI_MONITOR_WAITED     -EI_min] = JVMTI_EVENT_MONITOR_WAITED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    index2jvmti[EI_VM_INIT            -EI_min] = JVMTI_EVENT_VM_INIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    index2jvmti[EI_VM_DEATH           -EI_min] = JVMTI_EVENT_VM_DEATH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    index2jdwp[EI_SINGLE_STEP         -EI_min] = JDWP_EVENT(SINGLE_STEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
    index2jdwp[EI_BREAKPOINT          -EI_min] = JDWP_EVENT(BREAKPOINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    index2jdwp[EI_FRAME_POP           -EI_min] = JDWP_EVENT(FRAME_POP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    index2jdwp[EI_EXCEPTION           -EI_min] = JDWP_EVENT(EXCEPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    index2jdwp[EI_THREAD_START        -EI_min] = JDWP_EVENT(THREAD_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
    index2jdwp[EI_THREAD_END          -EI_min] = JDWP_EVENT(THREAD_END);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
    index2jdwp[EI_CLASS_PREPARE       -EI_min] = JDWP_EVENT(CLASS_PREPARE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
    index2jdwp[EI_GC_FINISH           -EI_min] = JDWP_EVENT(CLASS_UNLOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
    index2jdwp[EI_CLASS_LOAD          -EI_min] = JDWP_EVENT(CLASS_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
    index2jdwp[EI_FIELD_ACCESS        -EI_min] = JDWP_EVENT(FIELD_ACCESS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    index2jdwp[EI_FIELD_MODIFICATION  -EI_min] = JDWP_EVENT(FIELD_MODIFICATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
    index2jdwp[EI_EXCEPTION_CATCH     -EI_min] = JDWP_EVENT(EXCEPTION_CATCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
    index2jdwp[EI_METHOD_ENTRY        -EI_min] = JDWP_EVENT(METHOD_ENTRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
    index2jdwp[EI_METHOD_EXIT         -EI_min] = JDWP_EVENT(METHOD_EXIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
    index2jdwp[EI_MONITOR_CONTENDED_ENTER             -EI_min] = JDWP_EVENT(MONITOR_CONTENDED_ENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
    index2jdwp[EI_MONITOR_CONTENDED_ENTERED           -EI_min] = JDWP_EVENT(MONITOR_CONTENDED_ENTERED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
    index2jdwp[EI_MONITOR_WAIT        -EI_min] = JDWP_EVENT(MONITOR_WAIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
    index2jdwp[EI_MONITOR_WAITED      -EI_min] = JDWP_EVENT(MONITOR_WAITED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
    index2jdwp[EI_VM_INIT             -EI_min] = JDWP_EVENT(VM_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
    index2jdwp[EI_VM_DEATH            -EI_min] = JDWP_EVENT(VM_DEATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
jdwpEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
eventIndex2jdwp(EventIndex i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    if ( i < EI_min || i > EI_max ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        EXIT_ERROR(AGENT_ERROR_INVALID_INDEX,"bad EventIndex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
    return index2jdwp[i-EI_min];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
jvmtiEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
eventIndex2jvmti(EventIndex i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    if ( i < EI_min || i > EI_max ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        EXIT_ERROR(AGENT_ERROR_INVALID_INDEX,"bad EventIndex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    return index2jvmti[i-EI_min];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
EventIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
jdwp2EventIndex(jdwpEvent eventType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
    switch ( eventType ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        case JDWP_EVENT(SINGLE_STEP):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            return EI_SINGLE_STEP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        case JDWP_EVENT(BREAKPOINT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            return EI_BREAKPOINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        case JDWP_EVENT(FRAME_POP):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            return EI_FRAME_POP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        case JDWP_EVENT(EXCEPTION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            return EI_EXCEPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        case JDWP_EVENT(THREAD_START):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            return EI_THREAD_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        case JDWP_EVENT(THREAD_END):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            return EI_THREAD_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        case JDWP_EVENT(CLASS_PREPARE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
            return EI_CLASS_PREPARE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        case JDWP_EVENT(CLASS_UNLOAD):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
            return EI_GC_FINISH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
        case JDWP_EVENT(CLASS_LOAD):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
            return EI_CLASS_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        case JDWP_EVENT(FIELD_ACCESS):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
            return EI_FIELD_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        case JDWP_EVENT(FIELD_MODIFICATION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            return EI_FIELD_MODIFICATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        case JDWP_EVENT(EXCEPTION_CATCH):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            return EI_EXCEPTION_CATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        case JDWP_EVENT(METHOD_ENTRY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            return EI_METHOD_ENTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
        case JDWP_EVENT(METHOD_EXIT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
            return EI_METHOD_EXIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
        case JDWP_EVENT(METHOD_EXIT_WITH_RETURN_VALUE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
            return EI_METHOD_EXIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        case JDWP_EVENT(MONITOR_CONTENDED_ENTER):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            return EI_MONITOR_CONTENDED_ENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        case JDWP_EVENT(MONITOR_CONTENDED_ENTERED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
            return EI_MONITOR_CONTENDED_ENTERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        case JDWP_EVENT(MONITOR_WAIT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
            return EI_MONITOR_WAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        case JDWP_EVENT(MONITOR_WAITED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            return EI_MONITOR_WAITED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        case JDWP_EVENT(VM_INIT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            return EI_VM_INIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
        case JDWP_EVENT(VM_DEATH):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
            return EI_VM_DEATH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * Event type not recognized - don't exit with error as caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * may wish to return error to debugger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
    return (EventIndex)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
EventIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
jvmti2EventIndex(jvmtiEvent kind)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
    switch ( kind ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
        case JVMTI_EVENT_SINGLE_STEP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
            return EI_SINGLE_STEP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
        case JVMTI_EVENT_BREAKPOINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
            return EI_BREAKPOINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
        case JVMTI_EVENT_FRAME_POP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            return EI_FRAME_POP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        case JVMTI_EVENT_EXCEPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            return EI_EXCEPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
        case JVMTI_EVENT_THREAD_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            return EI_THREAD_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        case JVMTI_EVENT_THREAD_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            return EI_THREAD_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        case JVMTI_EVENT_CLASS_PREPARE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            return EI_CLASS_PREPARE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            return EI_GC_FINISH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        case JVMTI_EVENT_CLASS_LOAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            return EI_CLASS_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        case JVMTI_EVENT_FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            return EI_FIELD_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
        case JVMTI_EVENT_FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            return EI_FIELD_MODIFICATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
        case JVMTI_EVENT_EXCEPTION_CATCH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            return EI_EXCEPTION_CATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
        case JVMTI_EVENT_METHOD_ENTRY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            return EI_METHOD_ENTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
        case JVMTI_EVENT_METHOD_EXIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            return EI_METHOD_EXIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
         * There is no JVMTI_EVENT_METHOD_EXIT_WITH_RETURN_VALUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
         * The normal JVMTI_EVENT_METHOD_EXIT always contains the return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
        case JVMTI_EVENT_MONITOR_CONTENDED_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
            return EI_MONITOR_CONTENDED_ENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
        case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            return EI_MONITOR_CONTENDED_ENTERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        case JVMTI_EVENT_MONITOR_WAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
            return EI_MONITOR_WAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
        case JVMTI_EVENT_MONITOR_WAITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
            return EI_MONITOR_WAITED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
        case JVMTI_EVENT_VM_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
            return EI_VM_INIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
        case JVMTI_EVENT_VM_DEATH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            return EI_VM_DEATH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            EXIT_ERROR(AGENT_ERROR_INVALID_INDEX,"JVMTI to EventIndex mapping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    return (EventIndex)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
/* This routine is commonly used, maps jvmti and agent errors to the best
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
 *    jdwp error code we can map to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
map2jdwpError(jvmtiError error)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
{
22934
705df2581571 8033758: gcc warnings compiling jdk/src/share/back
alanb
parents: 21278
diff changeset
  2127
    switch ( (int)error ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        case JVMTI_ERROR_NONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        case AGENT_ERROR_INVALID_THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        case JVMTI_ERROR_INVALID_THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
            return JDWP_ERROR(INVALID_THREAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
        case JVMTI_ERROR_INVALID_THREAD_GROUP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
            return JDWP_ERROR(INVALID_THREAD_GROUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
        case JVMTI_ERROR_INVALID_PRIORITY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
            return JDWP_ERROR(INVALID_PRIORITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
        case JVMTI_ERROR_THREAD_NOT_SUSPENDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
            return JDWP_ERROR(THREAD_NOT_SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
        case JVMTI_ERROR_THREAD_SUSPENDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
            return JDWP_ERROR(THREAD_SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        case JVMTI_ERROR_THREAD_NOT_ALIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
            return JDWP_ERROR(INVALID_THREAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
        case AGENT_ERROR_INVALID_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        case JVMTI_ERROR_INVALID_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
            return JDWP_ERROR(INVALID_OBJECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
        case JVMTI_ERROR_INVALID_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            return JDWP_ERROR(INVALID_CLASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
        case JVMTI_ERROR_CLASS_NOT_PREPARED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
            return JDWP_ERROR(CLASS_NOT_PREPARED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        case JVMTI_ERROR_INVALID_METHODID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            return JDWP_ERROR(INVALID_METHODID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        case JVMTI_ERROR_INVALID_LOCATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            return JDWP_ERROR(INVALID_LOCATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        case JVMTI_ERROR_INVALID_FIELDID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            return JDWP_ERROR(INVALID_FIELDID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        case AGENT_ERROR_NO_MORE_FRAMES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        case JVMTI_ERROR_NO_MORE_FRAMES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            return JDWP_ERROR(NO_MORE_FRAMES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        case JVMTI_ERROR_OPAQUE_FRAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            return JDWP_ERROR(OPAQUE_FRAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
        case JVMTI_ERROR_TYPE_MISMATCH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            return JDWP_ERROR(TYPE_MISMATCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
        case JVMTI_ERROR_INVALID_SLOT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            return JDWP_ERROR(INVALID_SLOT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
        case JVMTI_ERROR_DUPLICATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
            return JDWP_ERROR(DUPLICATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
        case JVMTI_ERROR_NOT_FOUND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
            return JDWP_ERROR(NOT_FOUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
        case JVMTI_ERROR_INVALID_MONITOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            return JDWP_ERROR(INVALID_MONITOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
        case JVMTI_ERROR_NOT_MONITOR_OWNER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
            return JDWP_ERROR(NOT_MONITOR_OWNER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
        case JVMTI_ERROR_INTERRUPT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
            return JDWP_ERROR(INTERRUPT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
        case JVMTI_ERROR_INVALID_CLASS_FORMAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
            return JDWP_ERROR(INVALID_CLASS_FORMAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
        case JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
            return JDWP_ERROR(CIRCULAR_CLASS_DEFINITION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        case JVMTI_ERROR_FAILS_VERIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            return JDWP_ERROR(FAILS_VERIFICATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        case JVMTI_ERROR_INVALID_TYPESTATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            return JDWP_ERROR(INVALID_TYPESTATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        case JVMTI_ERROR_UNSUPPORTED_VERSION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            return JDWP_ERROR(UNSUPPORTED_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
        case JVMTI_ERROR_NAMES_DONT_MATCH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            return JDWP_ERROR(NAMES_DONT_MATCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        case AGENT_ERROR_NULL_POINTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
        case JVMTI_ERROR_NULL_POINTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
            return JDWP_ERROR(NULL_POINTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
        case JVMTI_ERROR_ABSENT_INFORMATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
            return JDWP_ERROR(ABSENT_INFORMATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
        case AGENT_ERROR_INVALID_EVENT_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
        case JVMTI_ERROR_INVALID_EVENT_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
            return JDWP_ERROR(INVALID_EVENT_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        case AGENT_ERROR_ILLEGAL_ARGUMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
        case JVMTI_ERROR_ILLEGAL_ARGUMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
            return JDWP_ERROR(ILLEGAL_ARGUMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
        case JVMTI_ERROR_OUT_OF_MEMORY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        case AGENT_ERROR_OUT_OF_MEMORY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
            return JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        case JVMTI_ERROR_ACCESS_DENIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            return JDWP_ERROR(ACCESS_DENIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        case JVMTI_ERROR_WRONG_PHASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        case AGENT_ERROR_VM_DEAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
        case AGENT_ERROR_NO_JNI_ENV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            return JDWP_ERROR(VM_DEAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        case AGENT_ERROR_JNI_EXCEPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
        case JVMTI_ERROR_UNATTACHED_THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
            return JDWP_ERROR(UNATTACHED_THREAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        case JVMTI_ERROR_NOT_AVAILABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
        case JVMTI_ERROR_MUST_POSSESS_CAPABILITY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
            return JDWP_ERROR(NOT_IMPLEMENTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
            return JDWP_ERROR(HIERARCHY_CHANGE_NOT_IMPLEMENTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
            return JDWP_ERROR(DELETE_METHOD_NOT_IMPLEMENTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
            return JDWP_ERROR(ADD_METHOD_NOT_IMPLEMENTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            return JDWP_ERROR(SCHEMA_CHANGE_NOT_IMPLEMENTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            return JDWP_ERROR(CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
            return JDWP_ERROR(METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED);
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
  2225
        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED:
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
  2226
            return JDWP_ERROR(CLASS_ATTRIBUTE_CHANGE_NOT_IMPLEMENTED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        case AGENT_ERROR_NOT_CURRENT_FRAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
            return JDWP_ERROR(NOT_CURRENT_FRAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
        case AGENT_ERROR_INVALID_TAG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
            return JDWP_ERROR(INVALID_TAG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        case AGENT_ERROR_ALREADY_INVOKING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
            return JDWP_ERROR(ALREADY_INVOKING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        case AGENT_ERROR_INVALID_INDEX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
            return JDWP_ERROR(INVALID_INDEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        case AGENT_ERROR_INVALID_LENGTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
            return JDWP_ERROR(INVALID_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        case AGENT_ERROR_INVALID_STRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
            return JDWP_ERROR(INVALID_STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
        case AGENT_ERROR_INVALID_CLASS_LOADER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
            return JDWP_ERROR(INVALID_CLASS_LOADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
        case AGENT_ERROR_INVALID_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
            return JDWP_ERROR(INVALID_ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        case AGENT_ERROR_TRANSPORT_LOAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            return JDWP_ERROR(TRANSPORT_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        case AGENT_ERROR_TRANSPORT_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            return JDWP_ERROR(TRANSPORT_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        case AGENT_ERROR_NATIVE_METHOD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
            return JDWP_ERROR(NATIVE_METHOD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        case AGENT_ERROR_INVALID_COUNT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
            return JDWP_ERROR(INVALID_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        case AGENT_ERROR_INVALID_FRAMEID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
            return JDWP_ERROR(INVALID_FRAMEID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
        case JVMTI_ERROR_INTERNAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
        case JVMTI_ERROR_INVALID_ENVIRONMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
        case AGENT_ERROR_INTERNAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        case AGENT_ERROR_JVMTI_INTERNAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
        case AGENT_ERROR_JDWP_INTERNAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
            return JDWP_ERROR(INTERNAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
    return JDWP_ERROR(INTERNAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
map2jdwpSuspendStatus(jint state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
    jint status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    if ( ( state & JVMTI_THREAD_STATE_SUSPENDED ) != 0 )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        status = JDWP_SUSPEND_STATUS(SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
    return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
jdwpThreadStatus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
map2jdwpThreadStatus(jint state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
    jdwpThreadStatus status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
    status = (jdwpThreadStatus)(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    if ( ! ( state & JVMTI_THREAD_STATE_ALIVE ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        if ( state & JVMTI_THREAD_STATE_TERMINATED ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
            status = JDWP_THREAD_STATUS(ZOMBIE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
            /* FIXUP? New JDWP #define for not started? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
            status = (jdwpThreadStatus)(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        if ( state & JVMTI_THREAD_STATE_SLEEPING ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
            status = JDWP_THREAD_STATUS(SLEEPING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        } else if ( state & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
            status = JDWP_THREAD_STATUS(MONITOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        } else if ( state & JVMTI_THREAD_STATE_WAITING ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            status = JDWP_THREAD_STATUS(WAIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        } else if ( state & JVMTI_THREAD_STATE_RUNNABLE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            status = JDWP_THREAD_STATUS(RUNNING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
    return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
map2jdwpClassStatus(jint classStatus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
    jint status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
    if ( ( classStatus & JVMTI_CLASS_STATUS_VERIFIED ) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        status |= JDWP_CLASS_STATUS(VERIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    if ( ( classStatus & JVMTI_CLASS_STATUS_PREPARED ) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
        status |= JDWP_CLASS_STATUS(PREPARED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
    if ( ( classStatus & JVMTI_CLASS_STATUS_INITIALIZED ) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
        status |= JDWP_CLASS_STATUS(INITIALIZED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
    if ( ( classStatus & JVMTI_CLASS_STATUS_ERROR ) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
        status |= JDWP_CLASS_STATUS(ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
    return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
log_debugee_location(const char *func,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        jthread thread, jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
    int logging_locations = LOG_TEST(JDWP_LOG_LOC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
    if ( logging_locations ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
        char *method_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
        char *class_sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
        jvmtiThreadInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        jint state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        /* Get thread information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
        info.name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
        error = FUNC_PTR(gdata->jvmti,GetThreadInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
                                (gdata->jvmti, thread, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
        if ( error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            info.name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        error = FUNC_PTR(gdata->jvmti,GetThreadState)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                                (gdata->jvmti, thread, &state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        if ( error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            state = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        /* Get method if necessary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
        if ( method==NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            error = FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                        (gdata->jvmti, thread, 0, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
            if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                method = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
                location = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        /* Get method name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
        method_name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
        if ( method != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
            error = methodSignature(method, &method_name, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                method_name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
        /* Get class signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        class_sig = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
        if ( method != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
            jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            error = methodClass(method, &clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                error = classSignature(clazz, &class_sig, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
                if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                    class_sig = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
        /* Issue log message */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        LOG_LOC(("%s: debugee: thread=%p(%s:0x%x),method=%p(%s@%d;%s)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                func,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
                thread, info.name==NULL ? "?" : info.name, state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
                method, method_name==NULL ? "?" : method_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                (int)location, class_sig==NULL ? "?" : class_sig));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        /* Free memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
        if ( class_sig != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
            jvmtiDeallocate(class_sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
        if ( method_name != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
            jvmtiDeallocate(method_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        if ( info.name != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
            jvmtiDeallocate(info.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
/* ********************************************************************* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
/* JDK 6.0: Use of new Heap Iteration functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
/* ********************************************************************* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
/* ********************************************************************* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
/* Instances */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
/* Structure to hold class instances heap iteration data (arg user_data) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
typedef struct ClassInstancesData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
    jint         instCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    jint         maxInstances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
    jlong        objTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
    jvmtiError   error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
} ClassInstancesData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
/* Callback for instance object tagging (heap_reference_callback). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
static jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
cbObjectTagInstance(jvmtiHeapReferenceKind reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     const jvmtiHeapReferenceInfo* reference_info, jlong class_tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     jlong referrer_class_tag, jlong size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     jlong* tag_ptr, jlong* referrer_tag_ptr, jint length, void* user_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
    ClassInstancesData  *data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
    /* Check data structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
    data = (ClassInstancesData*)user_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
    if (data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
    /* If we have tagged enough objects, just abort */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
    if ( data->maxInstances != 0 && data->instCount >= data->maxInstances ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
    /* If tagged already, just continue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
    if ( (*tag_ptr) != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    /* Tag the object so we don't count it again, and so we can retrieve it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
    (*tag_ptr) = data->objTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    data->instCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
/* Get instances for one class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
classInstances(jclass klass, ObjectBatch *instances, int maxInstances)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
    ClassInstancesData data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
    jvmtiHeapCallbacks heap_callbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
    jvmtiError         error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
    jvmtiEnv          *jvmti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
    /* Check interface assumptions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
    if (klass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
        return AGENT_ERROR_INVALID_OBJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
    if ( maxInstances < 0 || instances == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
    /* Initialize return information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
    instances->count   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
    instances->objects = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
    /* Get jvmti environment to use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
    jvmti = getSpecialJvmti();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
    if ( jvmti == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        return AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
    /* Setup data to passed around the callbacks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
    data.instCount    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
    data.maxInstances = maxInstances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
    data.objTag       = (jlong)1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
    data.error        = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
    /* Clear out callbacks structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
    (void)memset(&heap_callbacks,0,sizeof(heap_callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
    /* Set the callbacks we want */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
    heap_callbacks.heap_reference_callback = &cbObjectTagInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
    /* Follow references, no initiating object, just this class, all objects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
    error = JVMTI_FUNC_PTR(jvmti,FollowReferences)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
                 (jvmti, 0, klass, NULL, &heap_callbacks, &data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
        error = data.error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
    /* Get all the instances now that they are tagged */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        error = JVMTI_FUNC_PTR(jvmti,GetObjectsWithTags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                      (jvmti, 1, &(data.objTag), &(instances->count),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                       &(instances->objects), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        /* Verify we got the count we expected */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        if ( data.instCount != instances->count ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
    /* Dispose of any special jvmti environment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
    (void)JVMTI_FUNC_PTR(jvmti,DisposeEnvironment)(jvmti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
/* ********************************************************************* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
/* Instance counts. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
/* Macros to convert a class or instance tag to an index and back again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
#define INDEX2CLASSTAG(i)      ((jlong)((i)+1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
#define CLASSTAG2INDEX(t)      (((int)(t))-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
#define JLONG_ABS(x)           (((x)<(jlong)0)?-(x):(x))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
/* Structure to hold class count heap traversal data (arg user_data) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
typedef struct ClassCountData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
    int          classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
    jlong       *counts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
    jlong        negObjTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
    jvmtiError   error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
} ClassCountData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
/* Two different cbObjectCounter's, one for FollowReferences, one for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
 *    IterateThroughHeap. Pick a card, any card.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
/* Callback for object count heap traversal (heap_reference_callback) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
static jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
cbObjectCounterFromRef(jvmtiHeapReferenceKind reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
     const jvmtiHeapReferenceInfo* reference_info, jlong class_tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     jlong referrer_class_tag, jlong size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     jlong* tag_ptr, jlong* referrer_tag_ptr, jint length, void* user_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    ClassCountData  *data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
    int              index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
    jlong            jindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    jlong            tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
    /* Check data structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
    data = (ClassCountData*)user_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
    if (data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
    /* Classes with no class_tag should have been filtered out. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
    if ( class_tag == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
        data->error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
    /* Class tag not one we really want (jclass not in supplied list) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
    if ( class_tag == data->negObjTag ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
    /* If object tag is negative, just continue, we counted it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
    tag = (*tag_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
    if ( tag < (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
    /* Tag the object with a negative value just so we don't count it again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
    if ( tag == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
        /* This object had no tag value, so we give it the negObjTag value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        (*tag_ptr) = data->negObjTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
        /* If this object had a positive tag value, it must be one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
         *    jclass objects we tagged. We need to preserve the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
         *    this tag for later objects that might have this as a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
         *    tag, so we just make the existing tag value negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
        (*tag_ptr) = -tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
    /* Absolute value of class tag is an index into the counts[] array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
    jindex = JLONG_ABS(class_tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
    index = CLASSTAG2INDEX(jindex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
    if (index < 0 || index >= data->classCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
        data->error = AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
    /* Bump instance count on this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
    data->counts[index]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
/* Callback for instance count heap traversal (heap_iteration_callback) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
static jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
cbObjectCounter(jlong class_tag, jlong size, jlong* tag_ptr, jint length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
                        void* user_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
    ClassCountData  *data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
    int              index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
    /* Check data structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
    data = (ClassCountData*)user_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
    if (data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
    /* Classes with no tag should be filtered out. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
    if ( class_tag == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
        data->error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
    /* Class tag is actually an index into data arrays */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
    index = CLASSTAG2INDEX(class_tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
    if (index < 0 || index >= data->classCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
        data->error = AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    /* Bump instance count on this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
    data->counts[index]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
/* Get instance counts for a set of classes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
classInstanceCounts(jint classCount, jclass *classes, jlong *counts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
    jvmtiHeapCallbacks heap_callbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
    ClassCountData     data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
    jvmtiError         error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    jvmtiEnv          *jvmti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
    int                i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
    /* Check interface assumptions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
    if ( classes == NULL || classCount <= 0 || counts == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    /* Initialize return information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
    for ( i = 0 ; i < classCount ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
        counts[i] = (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
    /* Get jvmti environment to use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
    jvmti = getSpecialJvmti();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
    if ( jvmti == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        return AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
    /* Setup class data structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
    data.error        = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
    data.classCount   = classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
    data.counts       = counts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
    error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
    /* Set tags on classes, use index in classes[] as the tag value. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
    error             = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
    for ( i = 0 ; i < classCount ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
        if (classes[i] != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
            jlong tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
            tag = INDEX2CLASSTAG(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            error = JVMTI_FUNC_PTR(jvmti,SetTag) (jvmti, classes[i], tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
            if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
    /* Traverse heap, two ways to do this for instance counts. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
        /* Clear out callbacks structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
        (void)memset(&heap_callbacks,0,sizeof(heap_callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
        /* Check debug flags to see how to do this. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
        if ( (gdata->debugflags & USE_ITERATE_THROUGH_HEAP) == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
            /* Using FollowReferences only gives us live objects, but we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
             *   need to tag the objects to avoid counting them twice since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
             *   the callback is per reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
             *   The jclass objects have been tagged with their index in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
             *   supplied list, and that tag may flip to negative if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
             *   is also an object of interest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
             *   All other objects being counted that weren't in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
             *   supplied classes list will have a negative classCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
             *   tag value. So all objects counted will have negative tags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
             *   If the absolute tag value is an index in the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
             *   list, then it's one of the supplied classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
            data.negObjTag = -INDEX2CLASSTAG(classCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
            /* Setup callbacks, only using object reference callback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
            heap_callbacks.heap_reference_callback = &cbObjectCounterFromRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
            /* Follow references, no initiating object, tagged classes only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
            error = JVMTI_FUNC_PTR(jvmti,FollowReferences)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
                          (jvmti, JVMTI_HEAP_FILTER_CLASS_UNTAGGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
                           NULL, NULL, &heap_callbacks, &data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
            /* Using IterateThroughHeap means that we will visit each object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
             *   once, so no special tag tricks here. Just simple counting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
             *   However in this case the object might not be live, so we do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
             *   a GC beforehand to make sure we minimize this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
            /* FIXUP: Need some kind of trigger here to avoid excessive GC's? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            error = JVMTI_FUNC_PTR(jvmti,ForceGarbageCollection)(jvmti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
            if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
                /* Setup callbacks, just need object callback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
                heap_callbacks.heap_iteration_callback = &cbObjectCounter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
                /* Iterate through entire heap, tagged classes only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
                error = JVMTI_FUNC_PTR(jvmti,IterateThroughHeap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                              (jvmti, JVMTI_HEAP_FILTER_CLASS_UNTAGGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
                               NULL, &heap_callbacks, &data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
        /* Use data error if needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
        if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
            error = data.error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
    /* Dispose of any special jvmti environment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
    (void)JVMTI_FUNC_PTR(jvmti,DisposeEnvironment)(jvmti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
/* ********************************************************************* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
/* Referrers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
/* Structure to hold object referrer heap traversal data (arg user_data) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
typedef struct ReferrerData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
  int        refCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
  int        maxObjects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
  jlong      refTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
  jlong      objTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
  jboolean   selfRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
  jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
} ReferrerData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
/* Callback for referrers object tagging (heap_reference_callback). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
static jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
cbObjectTagReferrer(jvmtiHeapReferenceKind reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     const jvmtiHeapReferenceInfo* reference_info, jlong class_tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     jlong referrer_class_tag, jlong size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
     jlong* tag_ptr, jlong* referrer_tag_ptr, jint length, void* user_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
    ReferrerData  *data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
    /* Check data structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
    data = (ReferrerData*)user_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
    if (data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
    /* If we have tagged enough objects, just abort */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
    if ( data->maxObjects != 0 && data->refCount >= data->maxObjects ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
        return JVMTI_VISIT_ABORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
    /* If not of interest, just continue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
    if ( (*tag_ptr) != data->objTag ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
    /* Self reference that we haven't counted? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
    if ( tag_ptr == referrer_tag_ptr ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
        if ( data->selfRef == JNI_FALSE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
            data->selfRef = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
            data->refCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
    /* If the referrer can be tagged, and hasn't been tagged, tag it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
    if ( referrer_tag_ptr != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
        if ( (*referrer_tag_ptr) == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            *referrer_tag_ptr = data->refTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            data->refCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
/* Heap traversal to find referrers of an object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
objectReferrers(jobject obj, ObjectBatch *referrers, int maxObjects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
    jvmtiHeapCallbacks heap_callbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
    ReferrerData       data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
    jvmtiError         error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
    jvmtiEnv          *jvmti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
    /* Check interface assumptions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
    if (obj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
        return AGENT_ERROR_INVALID_OBJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
    if (referrers == NULL || maxObjects < 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
    /* Initialize return information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
    referrers->count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
    referrers->objects = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
    /* Get jvmti environment to use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
    jvmti = getSpecialJvmti();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
    if ( jvmti == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        return AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
    /* Fill in the data structure passed around the callbacks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
    data.refCount   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
    data.maxObjects = maxObjects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
    data.objTag     = (jlong)1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
    data.refTag     = (jlong)2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
    data.selfRef    = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
    data.error      = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
    /* Tag the object of interest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
    error = JVMTI_FUNC_PTR(jvmti,SetTag) (jvmti, obj, data.objTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
    /* No need to go any further if we can't tag the object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
        /* Clear out callbacks structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
        (void)memset(&heap_callbacks,0,sizeof(heap_callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
        /* Setup callbacks we want */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
        heap_callbacks.heap_reference_callback = &cbObjectTagReferrer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        /* Follow references, no initiating object, all classes, 1 tagged objs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
        error = JVMTI_FUNC_PTR(jvmti,FollowReferences)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
                      (jvmti, JVMTI_HEAP_FILTER_UNTAGGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
                       NULL, NULL, &heap_callbacks, &data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
        /* Use data error if needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
        if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            error = data.error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
    /* Watch out for self-reference */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
    if ( error == JVMTI_ERROR_NONE && data.selfRef == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
        /* Tag itself as a referer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
        error = JVMTI_FUNC_PTR(jvmti,SetTag) (jvmti, obj, data.refTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
    /* Get the jobjects for the tagged referrer objects.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
        error = JVMTI_FUNC_PTR(jvmti,GetObjectsWithTags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
                    (jvmti, 1, &(data.refTag), &(referrers->count),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                          &(referrers->objects), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
        /* Verify we got the count we expected */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
        if ( data.refCount != referrers->count ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
            error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
    /* Dispose of any special jvmti environment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
    (void)JVMTI_FUNC_PTR(jvmti,DisposeEnvironment)(jvmti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
}