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