jdk/src/share/back/eventFilter.c
author xdono
Thu, 02 Oct 2008 19:58:32 -0700
changeset 1247 b4c26443dee5
parent 828 ad3f54bd6ae8
child 5506 202f599c92aa
permissions -rw-r--r--
6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1247
b4c26443dee5 6754988: Update copyright year
xdono
parents: 828
diff changeset
     2
 * Copyright 2001-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * eventFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * This module handles event filteration and the enabling/disabling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * of the corresponding events. Used for filters on JDI EventRequests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * and also internal requests.  Our data is in a private hidden section
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * of the HandlerNode's data.  See comment for enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * module eventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "eventFilter.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "eventFilterRestricted.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "eventHandlerRestricted.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "stepControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "SDE.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
typedef struct ClassFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
} ClassFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
typedef struct LocationFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    jlocation location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
} LocationFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
typedef struct ThreadFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
} ThreadFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
typedef struct CountFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
} CountFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
typedef struct ConditionalFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    jint exprID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
} ConditionalFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
typedef struct FieldFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    jfieldID field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
} FieldFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
typedef struct ExceptionFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    jclass exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    jboolean caught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    jboolean uncaught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
} ExceptionFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
typedef struct InstanceFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jobject instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
} InstanceFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
typedef struct StepFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    jint depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
} StepFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
typedef struct MatchFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    char *classPattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
} MatchFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
typedef struct SourceNameFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    char *sourceNamePattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
} SourceNameFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
typedef struct Filter_ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    jbyte modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        struct ClassFilter ClassOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        struct LocationFilter LocationOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        struct ThreadFilter ThreadOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        struct CountFilter Count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        struct ConditionalFilter Conditional;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        struct FieldFilter FieldOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        struct ExceptionFilter ExceptionOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        struct InstanceFilter InstanceOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        struct StepFilter Step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        struct MatchFilter ClassMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        struct MatchFilter ClassExclude;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        struct SourceNameFilter SourceNameOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    } u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
} Filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
/* The filters array is allocated to the specified filterCount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * Theoretically, some compiler could do range checking on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * array - so, we define it to have a ludicrously large size so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * that this range checking won't get upset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * The actual allocated number of bytes is computed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * offset of "filters" and so is not effected by this number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#define MAX_FILTERS 10000
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
typedef struct EventFilters_ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    jint filterCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    Filter filters[MAX_FILTERS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
} EventFilters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
typedef struct EventFilterPrivate_HandlerNode_ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    EventHandlerRestricted_HandlerNode   not_for_us;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    EventFilters                         ef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
} EventFilterPrivate_HandlerNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * The following macros extract filter info (EventFilters) from private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * data at the end of a HandlerNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#define EVENT_FILTERS(node) (&(((EventFilterPrivate_HandlerNode*)(void*)node)->ef))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
#define FILTER_COUNT(node)  (EVENT_FILTERS(node)->filterCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#define FILTERS_ARRAY(node) (EVENT_FILTERS(node)->filters)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
#define FILTER(node,index)  ((FILTERS_ARRAY(node))[index])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#define NODE_EI(node)          (node->ei)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
/***** filter set-up / destruction *****/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * Allocate a HandlerNode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * We do it because eventHandler doesn't know how big to make it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
eventFilterRestricted_alloc(jint filterCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    size_t size = offsetof(EventFilterPrivate_HandlerNode, ef) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                  offsetof(EventFilters, filters) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                  (filterCount * (int)sizeof(Filter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    HandlerNode *node = jvmtiAllocate((jint)size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Filter *filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        (void)memset(node, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        FILTER_COUNT(node) = filterCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        /* Initialize all modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        for (i = 0, filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                    i < filterCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                    i++, filter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            filter->modifier = JDWP_REQUEST_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * Free up global refs held by the filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * free things up at the JNI level if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
clearFilters(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    Filter *filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            case JDWP_REQUEST_MODIFIER(ThreadOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                if ( filter->u.ThreadOnly.thread != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    tossGlobalRef(env, &(filter->u.ThreadOnly.thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            case JDWP_REQUEST_MODIFIER(LocationOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                tossGlobalRef(env, &(filter->u.LocationOnly.clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            case JDWP_REQUEST_MODIFIER(FieldOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                tossGlobalRef(env, &(filter->u.FieldOnly.clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            case JDWP_REQUEST_MODIFIER(ExceptionOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                if ( filter->u.ExceptionOnly.exception != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    tossGlobalRef(env, &(filter->u.ExceptionOnly.exception));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            case JDWP_REQUEST_MODIFIER(InstanceOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if ( filter->u.InstanceOnly.instance != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    tossGlobalRef(env, &(filter->u.InstanceOnly.instance));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            case JDWP_REQUEST_MODIFIER(ClassOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                tossGlobalRef(env, &(filter->u.ClassOnly.clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            case JDWP_REQUEST_MODIFIER(ClassMatch):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                jvmtiDeallocate(filter->u.ClassMatch.classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            case JDWP_REQUEST_MODIFIER(ClassExclude):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                jvmtiDeallocate(filter->u.ClassExclude.classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            case JDWP_REQUEST_MODIFIER(Step): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                jthread thread = filter->u.Step.thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                error = stepControl_endStep(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    tossGlobalRef(env, &(filter->u.Step.thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        FILTER_COUNT(node) = 0; /* blast so we don't clear again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
/***** filtering *****/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * Match a string against a wildcard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * string pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
patternStringMatch(char *classname, const char *pattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    int pattLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    int compLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    char *start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if ( pattern==NULL || classname==NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    pattLen = (int)strlen(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    if ((pattern[0] != '*') && (pattern[pattLen-1] != '*')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        /* An exact match is required when there is no *: bug 4331522 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return strcmp(pattern, classname) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        compLen = pattLen - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        offset = (int)strlen(classname) - compLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (offset < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (pattern[0] == '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                pattern++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                start = classname + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                start = classname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return strncmp(pattern, start, compLen) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
/* Return the object instance in which the event occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
/* Return NULL if static or if an error occurs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
static jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
eventInstance(EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    jobject     object          = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    jthread     thread          ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    jmethodID   method          ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    jint        modifiers       = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    jvmtiError  error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    switch (evinfo->ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        case EI_SINGLE_STEP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        case EI_BREAKPOINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        case EI_FRAME_POP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        case EI_METHOD_ENTRY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        case EI_METHOD_EXIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        case EI_EXCEPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        case EI_EXCEPTION_CATCH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        case EI_MONITOR_CONTENDED_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        case EI_MONITOR_CONTENDED_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        case EI_MONITOR_WAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        case EI_MONITOR_WAITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            thread      = evinfo->thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            method      = evinfo->method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        case EI_FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        case EI_FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            object = evinfo->object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            return object; /* NULL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    error = methodModifiers(method, &modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /* fail if error or static (0x8) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    if (error == JVMTI_ERROR_NONE && thread!=NULL && (modifiers & 0x8) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        FrameNumber fnum            = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        /* get slot zero object "this" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    (gdata->jvmti, thread, fnum, 0, &object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (error != JVMTI_ERROR_NONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            object = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    return object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 * Determine if this event is interesting to this handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * Do so by checking each of the handler's filters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * Return false if any of the filters fail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 * true if the handler wants this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 * Anyone modifying this function should check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 * eventFilterRestricted_passesUnloadFilter and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 * eventFilter_predictFiltering as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 * If shouldDelete is returned true, a count filter has expired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
 * and the corresponding node should be deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
eventFilterRestricted_passesFilter(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                   char *classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                   EventInfo *evinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                   HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                   jboolean *shouldDelete)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    Filter *filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    *shouldDelete = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    thread = evinfo->thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    clazz = evinfo->clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    method = evinfo->method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Suppress most events if they happen in debug threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    if ((evinfo->ei != EI_CLASS_PREPARE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        (evinfo->ei != EI_GC_FINISH) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        (evinfo->ei != EI_CLASS_LOAD) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            case JDWP_REQUEST_MODIFIER(ThreadOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                if (!isSameObject(env, thread, filter->u.ThreadOnly.thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            case JDWP_REQUEST_MODIFIER(ClassOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                /* Class filters catch events in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                 * class and any subclass/subinterface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                if (!JNI_FUNC_PTR(env,IsAssignableFrom)(env, clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                               filter->u.ClassOnly.clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            /* This is kinda cheating assumming the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
             * fields will be in the same locations, but it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
             * true now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            case JDWP_REQUEST_MODIFIER(LocationOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if  (evinfo->method !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                          filter->u.LocationOnly.method ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                     evinfo->location !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                          filter->u.LocationOnly.location ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                     !isSameObject(env, clazz, filter->u.LocationOnly.clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            case JDWP_REQUEST_MODIFIER(FieldOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                /* Field watchpoints can be triggered from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                 * declared class or any subclass/subinterface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                if ((evinfo->u.field_access.field !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                     filter->u.FieldOnly.field) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    !isSameObject(env, evinfo->u.field_access.field_clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                               filter->u.FieldOnly.clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            case JDWP_REQUEST_MODIFIER(ExceptionOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                /* do we want caught/uncaught exceptions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                if (!((evinfo->u.exception.catch_clazz == NULL)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                      filter->u.ExceptionOnly.uncaught :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                      filter->u.ExceptionOnly.caught)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                /* do we care about exception class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                if (filter->u.ExceptionOnly.exception != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    jclass exception = evinfo->object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    /* do we want this exception class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    if (!JNI_FUNC_PTR(env,IsInstanceOf)(env, exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                            filter->u.ExceptionOnly.exception)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            case JDWP_REQUEST_MODIFIER(InstanceOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                jobject eventInst = eventInstance(evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                jobject filterInst = filter->u.InstanceOnly.instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                /* if no error and doesn't match, don't pass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                 * filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                if (eventInst != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                      !isSameObject(env, eventInst, filterInst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            case JDWP_REQUEST_MODIFIER(Count): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                JDI_ASSERT(filter->u.Count.count > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (--filter->u.Count.count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                *shouldDelete = JNI_TRUE;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            case JDWP_REQUEST_MODIFIER(Conditional):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
/***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                if (...  filter->u.Conditional.exprID ...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        case JDWP_REQUEST_MODIFIER(ClassMatch): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if (!patternStringMatch(classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                       filter->u.ClassMatch.classPattern)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        case JDWP_REQUEST_MODIFIER(ClassExclude): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (patternStringMatch(classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                      filter->u.ClassExclude.classPattern)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        case JDWP_REQUEST_MODIFIER(Step):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                if (!isSameObject(env, thread, filter->u.Step.thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                if (!stepControl_handleStep(env, thread, clazz, method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
          case JDWP_REQUEST_MODIFIER(SourceNameMatch): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
              char* desiredNamePattern = filter->u.SourceNameOnly.sourceNamePattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
              if (!searchAllSourceNames(env, clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                           desiredNamePattern) == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                  /* The name isn't in the SDE; try the sourceName in the ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                   * type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                  char *sourceName = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                  jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                            (gdata->jvmti, clazz, &sourceName);
828
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   495
                  if (error == JVMTI_ERROR_NONE &&
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   496
                      sourceName != 0 &&
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   497
                      patternStringMatch(sourceName, desiredNamePattern)) {
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   498
                          // got a hit - report the event
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   499
                          jvmtiDeallocate(sourceName);
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   500
                          break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                  }
828
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   502
                  // We have no match, we have no source file name,
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   503
                  // or we got a JVM TI error. Don't report the event.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                  jvmtiDeallocate(sourceName);
828
ad3f54bd6ae8 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents: 2
diff changeset
   505
                  return JNI_FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"Invalid filter modifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
/* Determine if this event is interesting to this handler.  Do so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
 * by checking each of the handler's filters.  Return false if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
 * of the filters fail, true if the handler wants this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
 * Special version of filter for unloads since they don't have an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
 * event structure or a jclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
 * If shouldDelete is returned true, a count filter has expired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
 * and the corresponding node should be deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
eventFilterRestricted_passesUnloadFilter(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                         char *classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                         HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                         jboolean *shouldDelete)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    Filter *filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    *shouldDelete = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            case JDWP_REQUEST_MODIFIER(Count): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                JDI_ASSERT(filter->u.Count.count > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                if (--filter->u.Count.count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                *shouldDelete = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            case JDWP_REQUEST_MODIFIER(ClassMatch): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                if (!patternStringMatch(classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        filter->u.ClassMatch.classPattern)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            case JDWP_REQUEST_MODIFIER(ClassExclude): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                if (patternStringMatch(classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                       filter->u.ClassExclude.classPattern)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"Invalid filter modifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
 * This function returns true only if it is certain that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
 * all events for the given node in the given stack frame will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
 * be filtered. It is used to optimize stepping. (If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 * function returns true the stepping algorithm does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 * have to step through every instruction in this stack frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 * instead, it can use more efficient method entry/exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
 * events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
eventFilter_predictFiltering(HandlerNode *node, jclass clazz, char *classname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    JNIEnv     *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    jboolean    willBeFiltered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    Filter     *filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    jboolean    done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    int         count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    int         i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    willBeFiltered = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    env            = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    filter         = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    count          = FILTER_COUNT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    done           = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    for (i = 0; (i < count) && (!done); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            case JDWP_REQUEST_MODIFIER(ClassOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                if ( env==NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                if (!JNI_FUNC_PTR(env,IsAssignableFrom)(env, clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                                 filter->u.ClassOnly.clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    willBeFiltered = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    done = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            case JDWP_REQUEST_MODIFIER(Count): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                 * If preceeding filters have determined that events will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                 * be filtered out, that is fine and we won't get here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                 * However, the count must be decremented - even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                 * subsequent filters will filter these events.  We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                 * thus must end now unable to predict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                done = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            case JDWP_REQUEST_MODIFIER(ClassMatch): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                if (!patternStringMatch(classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        filter->u.ClassMatch.classPattern)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    willBeFiltered = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    done = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            case JDWP_REQUEST_MODIFIER(ClassExclude): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                if (patternStringMatch(classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                       filter->u.ClassExclude.classPattern)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    willBeFiltered = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    done = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    return willBeFiltered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
 * Determine if the given breakpoint node is in the specified class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
eventFilterRestricted_isBreakpointInClass(JNIEnv *env, jclass clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                                          HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    Filter *filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            case JDWP_REQUEST_MODIFIER(LocationOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                return isSameObject(env, clazz, filter->u.LocationOnly.clazz);
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 JNI_TRUE; /* should never come here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
/***** filter set-up *****/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
eventFilter_setConditionalFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                 jint exprID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    ConditionalFilter *filter = &FILTER(node, index).u.Conditional;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Conditional);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    filter->exprID = exprID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
eventFilter_setCountFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                           jint count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    CountFilter *filter = &FILTER(node, index).u.Count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    if (count <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        return JDWP_ERROR(INVALID_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        filter->count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
eventFilter_setThreadOnlyFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                                jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    ThreadFilter *filter = &FILTER(node, index).u.ThreadOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    if (NODE_EI(node) == EI_GC_FINISH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    /* Create a thread ref that will live beyond */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    /* the end of this call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    saveGlobalRef(env, thread, &(filter->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(ThreadOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
eventFilter_setLocationOnlyFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                                  jclass clazz, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                  jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    LocationFilter *filter = &FILTER(node, index).u.LocationOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    if ((NODE_EI(node) != EI_BREAKPOINT) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        (NODE_EI(node) != EI_FIELD_ACCESS) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        (NODE_EI(node) != EI_FIELD_MODIFICATION) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        (NODE_EI(node) != EI_SINGLE_STEP) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        (NODE_EI(node) != EI_EXCEPTION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /* Create a class ref that will live beyond */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /* the end of this call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    saveGlobalRef(env, clazz, &(filter->clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(LocationOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    filter->method = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    filter->location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
eventFilter_setFieldOnlyFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                               jclass clazz, jfieldID field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    FieldFilter *filter = &FILTER(node, index).u.FieldOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    if ((NODE_EI(node) != EI_FIELD_ACCESS) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        (NODE_EI(node) != EI_FIELD_MODIFICATION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    /* Create a class ref that will live beyond */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    /* the end of this call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    saveGlobalRef(env, clazz, &(filter->clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(FieldOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    filter->field = field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
eventFilter_setClassOnlyFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                               jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    ClassFilter *filter = &FILTER(node, index).u.ClassOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        (NODE_EI(node) == EI_GC_FINISH) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        (NODE_EI(node) == EI_THREAD_START) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        (NODE_EI(node) == EI_THREAD_END)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    /* Create a class ref that will live beyond */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    /* the end of this call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    saveGlobalRef(env, clazz, &(filter->clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(ClassOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
eventFilter_setExceptionOnlyFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                                   jclass exceptionClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                                   jboolean caught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                   jboolean uncaught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    ExceptionFilter *filter = &FILTER(node, index).u.ExceptionOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    if (NODE_EI(node) != EI_EXCEPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    filter->exception = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    if (exceptionClass != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        /* Create a class ref that will live beyond */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        /* the end of this call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        saveGlobalRef(env, exceptionClass, &(filter->exception));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    FILTER(node, index).modifier =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                       JDWP_REQUEST_MODIFIER(ExceptionOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    filter->caught = caught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    filter->uncaught = uncaught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
eventFilter_setInstanceOnlyFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                                  jobject instance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    InstanceFilter *filter = &FILTER(node, index).u.InstanceOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    filter->instance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    if (instance != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        /* Create an object ref that will live beyond
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
         * the end of this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        saveGlobalRef(env, instance, &(filter->instance));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    FILTER(node, index).modifier =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                       JDWP_REQUEST_MODIFIER(InstanceOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
eventFilter_setClassMatchFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                                char *classPattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    MatchFilter *filter = &FILTER(node, index).u.ClassMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        (NODE_EI(node) == EI_THREAD_START) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        (NODE_EI(node) == EI_THREAD_END)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    FILTER(node, index).modifier =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                       JDWP_REQUEST_MODIFIER(ClassMatch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    filter->classPattern = classPattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
eventFilter_setClassExcludeFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                  char *classPattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    MatchFilter *filter = &FILTER(node, index).u.ClassExclude;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        (NODE_EI(node) == EI_THREAD_START) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        (NODE_EI(node) == EI_THREAD_END)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    FILTER(node, index).modifier =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                       JDWP_REQUEST_MODIFIER(ClassExclude);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    filter->classPattern = classPattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
eventFilter_setStepFilter(HandlerNode *node, jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                          jthread thread, jint size, jint depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    StepFilter *filter = &FILTER(node, index).u.Step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    if (NODE_EI(node) != EI_SINGLE_STEP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    /* Create a thread ref that will live beyond */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    /* the end of this call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    saveGlobalRef(env, thread, &(filter->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    error = stepControl_beginStep(env, filter->thread, size, depth, node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        tossGlobalRef(env, &(filter->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    filter->depth = depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    filter->size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
eventFilter_setSourceNameMatchFilter(HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                                    jint index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                                    char *sourceNamePattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    SourceNameFilter *filter = &FILTER(node, index).u.SourceNameOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    if (index >= FILTER_COUNT(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    if (NODE_EI(node) != EI_CLASS_PREPARE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        return AGENT_ERROR_ILLEGAL_ARGUMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    FILTER(node, index).modifier =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                       JDWP_REQUEST_MODIFIER(SourceNameMatch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    filter->sourceNamePattern = sourceNamePattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
/***** JVMTI event enabling / disabling *****/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
 * Return the Filter that is of the specified type (modifier).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
 * Return NULL if not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
static Filter *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
findFilter(HandlerNode *node, jint modifier)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    Filter *filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    for (i = 0, filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                      i <FILTER_COUNT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                      i++, filter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        if (filter->modifier == modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            return filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
 * Determine if the specified breakpoint node is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
 * same location as the LocationFilter passed in arg.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
 * This is a match function called by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
 * eventHandlerRestricted_iterator invokation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
matchBreakpoint(JNIEnv *env, HandlerNode *node, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    LocationFilter *goal = (LocationFilter *)arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    Filter *filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        case JDWP_REQUEST_MODIFIER(LocationOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            LocationFilter *trial = &(filter->u.LocationOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            if (trial->method == goal->method &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                trial->location == goal->location &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                isSameObject(env, trial->clazz, goal->clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
 * Set a breakpoint if this is the first one at this location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
setBreakpoint(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    Filter *filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    filter = findFilter(node, JDWP_REQUEST_MODIFIER(LocationOnly));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    if (filter == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        /* bp event with no location filter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        LocationFilter *lf = &(filter->u.LocationOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        /* if this is the first handler for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
         * location, set bp at JVMTI level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        if (!eventHandlerRestricted_iterator(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                EI_BREAKPOINT, matchBreakpoint, lf)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            LOG_LOC(("SetBreakpoint at location: method=%p,location=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                        lf->method, (int)lf->location));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            error = JVMTI_FUNC_PTR(gdata->jvmti,SetBreakpoint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                        (gdata->jvmti, lf->method, lf->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
 * Clear a breakpoint if this is the last one at this location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
clearBreakpoint(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    Filter *filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    filter = findFilter(node, JDWP_REQUEST_MODIFIER(LocationOnly));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    if (filter == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        /* bp event with no location filter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        LocationFilter *lf = &(filter->u.LocationOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        /* if this is the last handler for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
         * location, clear bp at JVMTI level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (!eventHandlerRestricted_iterator(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                EI_BREAKPOINT, matchBreakpoint, lf)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            LOG_LOC(("ClearBreakpoint at location: method=%p,location=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                        lf->method, (int)lf->location));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            error = JVMTI_FUNC_PTR(gdata->jvmti,ClearBreakpoint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                        (gdata->jvmti, lf->method, lf->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
 * Return true if a breakpoint is set at the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
isBreakpointSet(jclass clazz, jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    LocationFilter lf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    lf.clazz    = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    lf.method   = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    lf.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    return eventHandlerRestricted_iterator(EI_BREAKPOINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                                           matchBreakpoint, &lf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
 * Determine if the specified watchpoint node has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
 * same field as the FieldFilter passed in arg.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
 * This is a match function called by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
 * eventHandlerRestricted_iterator invokation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
matchWatchpoint(JNIEnv *env, HandlerNode *node, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    FieldFilter *goal = (FieldFilter *)arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    Filter *filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        case JDWP_REQUEST_MODIFIER(FieldOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            FieldFilter *trial = &(filter->u.FieldOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            if (trial->field == goal->field &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                isSameObject(env, trial->clazz, goal->clazz)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
 * Set a watchpoint if this is the first one on this field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
setWatchpoint(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    Filter *filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    filter = findFilter(node, JDWP_REQUEST_MODIFIER(FieldOnly));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    if (filter == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        /* event with no field filter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        FieldFilter *ff = &(filter->u.FieldOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        /* if this is the first handler for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
         * field, set wp at JVMTI level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        if (!eventHandlerRestricted_iterator(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                NODE_EI(node), matchWatchpoint, ff)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            error = (NODE_EI(node) == EI_FIELD_ACCESS) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                JVMTI_FUNC_PTR(gdata->jvmti,SetFieldAccessWatch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                        (gdata->jvmti, ff->clazz, ff->field) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                JVMTI_FUNC_PTR(gdata->jvmti,SetFieldModificationWatch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                        (gdata->jvmti, ff->clazz, ff->field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
 * Clear a watchpoint if this is the last one on this field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
clearWatchpoint(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    Filter *filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    filter = findFilter(node, JDWP_REQUEST_MODIFIER(FieldOnly));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    if (filter == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        /* event with no field filter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        error = AGENT_ERROR_INTERNAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        FieldFilter *ff = &(filter->u.FieldOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        /* if this is the last handler for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
         * field, clear wp at JVMTI level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        if (!eventHandlerRestricted_iterator(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                NODE_EI(node), matchWatchpoint, ff)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            error = (NODE_EI(node) == EI_FIELD_ACCESS) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                JVMTI_FUNC_PTR(gdata->jvmti,ClearFieldAccessWatch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                        (gdata->jvmti, ff->clazz, ff->field) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                JVMTI_FUNC_PTR(gdata->jvmti,ClearFieldModificationWatch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                                (gdata->jvmti, ff->clazz, ff->field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
 * Determine the thread this node is filtered on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
 * NULL if not thread filtered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
static jthread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
requestThread(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    Filter *filter = FILTERS_ARRAY(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        switch (filter->modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            case JDWP_REQUEST_MODIFIER(ThreadOnly):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                return filter->u.ThreadOnly.thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
 * Determine if the specified node has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
 * thread filter with the thread passed in arg.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
 * This is a match function called by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
 * eventHandlerRestricted_iterator invokation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
matchThread(JNIEnv *env, HandlerNode *node, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    jthread goalThread = (jthread)arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    jthread reqThread = requestThread(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    /* If the event's thread and the passed thread are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * (or both are NULL), we have a match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    return isSameObject(env, reqThread, goalThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
 * Do any enabling of events (including setting breakpoints etc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
 * needed to get the events requested by this handler node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
enableEvents(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    switch (NODE_EI(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        /* The stepping code directly enables/disables stepping as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
         * necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        case EI_SINGLE_STEP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        /* Internal thread event handlers are always present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
         * (hardwired in the event hook), so we don't change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
         * notification mode here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        case EI_THREAD_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        case EI_THREAD_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        case EI_VM_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        case EI_VM_DEATH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        case EI_CLASS_PREPARE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        case EI_GC_FINISH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        case EI_FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        case EI_FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            error = setWatchpoint(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        case EI_BREAKPOINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            error = setBreakpoint(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    /* Don't globally enable if the above failed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        jthread thread = requestThread(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        /* If this is the first request of it's kind on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
         * thread (or all threads (thread == NULL)) then enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
         * these events on this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        if (!eventHandlerRestricted_iterator(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                NODE_EI(node), matchThread, thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            error = threadControl_setEventMode(JVMTI_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                                               NODE_EI(node), thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
 * Do any disabling of events (including clearing breakpoints etc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
 * needed to no longer get the events requested by this handler node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
disableEvents(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    jvmtiError error2 = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    switch (NODE_EI(node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        /* The stepping code directly enables/disables stepping as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
         * necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        case EI_SINGLE_STEP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        /* Internal thread event handlers are always present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
         * (hardwired in the event hook), so we don't change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
         * notification mode here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        case EI_THREAD_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        case EI_THREAD_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        case EI_VM_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        case EI_VM_DEATH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        case EI_CLASS_PREPARE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        case EI_GC_FINISH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        case EI_FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        case EI_FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            error = clearWatchpoint(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        case EI_BREAKPOINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            error = clearBreakpoint(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    thread = requestThread(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    /* If this is the last request of it's kind on this thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * (or all threads (thread == NULL)) then disable these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * events on this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * Disable even if the above caused an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    if (!eventHandlerRestricted_iterator(NODE_EI(node), matchThread, thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        error2 = threadControl_setEventMode(JVMTI_DISABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                                            NODE_EI(node), thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    return error != JVMTI_ERROR_NONE? error : error2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
/***** filter (and event) installation and deinstallation *****/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
 * Make the set of event filters that correspond with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
 * node active (including enabling the corresponding events).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
eventFilterRestricted_install(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    return enableEvents(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
 * Make the set of event filters that correspond with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
 * node inactive (including disabling the corresponding events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
 * and freeing resources).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
eventFilterRestricted_deinstall(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    jvmtiError error1, error2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    error1 = disableEvents(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    error2 = clearFilters(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    return error1 != JVMTI_ERROR_NONE? error1 : error2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
}