test/hotspot/jtreg/vmTestbase/nsk/jvmti/MethodEntry/mentry001/mentry001.c
author iignatyev
Thu, 24 May 2018 17:12:15 -0700
changeset 50260 46c67f5e27c2
permissions -rw-r--r--
8199383: [TESTBUG] Open source VM testbase JVMTI tests Reviewed-by: sspitsyn, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     1
/*
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     4
 *
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     8
 *
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    14
 *
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    18
 *
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    21
 * questions.
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    22
 */
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    23
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    24
#include <inttypes.h>
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    25
#include <stdio.h>
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    26
#include <string.h>
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    27
#include "jvmti.h"
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    28
#include "agent_common.h"
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    29
#include "jni_tools.h"
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    30
#include "JVMTITools.h"
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    31
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    32
#ifdef __cplusplus
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    33
extern "C" {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    34
#endif
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    35
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    36
#ifndef JNI_ENV_ARG
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    37
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    38
#ifdef __cplusplus
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    39
#define JNI_ENV_ARG(x, y) y
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    40
#define JNI_ENV_PTR(x) x
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    41
#else
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    42
#define JNI_ENV_ARG(x,y) x, y
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    43
#define JNI_ENV_PTR(x) (*x)
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    44
#endif
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    45
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    46
#endif
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    47
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    48
#define PASSED 0
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    49
#define STATUS_FAILED 2
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    50
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    51
typedef struct {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    52
    char *name;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    53
    char *sig;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    54
    jlocation loc;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    55
} entry_info;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    56
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    57
static jvmtiEnv *jvmti = NULL;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    58
static jvmtiCapabilities caps;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    59
static jvmtiEventCallbacks callbacks;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    60
static jint result = PASSED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    61
static jboolean printdump = JNI_FALSE;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    62
static size_t eventsExpected = 0;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    63
static size_t eventsCount = 0;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    64
static entry_info entries[] = {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    65
    {"check", "()I", -1},
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    66
    {"dummy", "()V", 0},
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    67
    {"chain", "()V", -1}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    68
};
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    69
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    70
void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env,
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    71
        jthread thr, jmethodID method) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    72
    jvmtiError err;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    73
    char *cls_sig, *generic;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    74
    entry_info entry;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    75
    jclass cls;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    76
    jmethodID mid;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    77
    char buffer[32];
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    78
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    79
    err = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &cls);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    80
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    81
        printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    82
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    83
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    84
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    85
    err = (*jvmti_env)->GetClassSignature(jvmti_env, cls, &cls_sig, &generic);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    86
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    87
        printf("(GetClassSignature) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    88
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    89
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    90
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    91
    if (cls_sig != NULL &&
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    92
            strcmp(cls_sig, "Lnsk/jvmti/MethodEntry/mentry001;") == 0) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    93
        if (printdump == JNI_TRUE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    94
            printf(">>> retrieving method entry info ...\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    95
        }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    96
        err = (*jvmti_env)->GetMethodName(jvmti_env, method,
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    97
            &entry.name, &entry.sig, &generic);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    98
        if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    99
            printf("(GetMethodName) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   100
                   TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   101
            result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   102
        }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   103
        err = (*jvmti_env)->GetFrameLocation(jvmti_env, thr, 0, &mid, &entry.loc);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   104
        if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   105
            printf("(GetFrameLocation) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   106
                   TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   107
            result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   108
        }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   109
        if (printdump == JNI_TRUE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   110
            printf(">>>      class: \"%s\"\n", cls_sig);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   111
            printf(">>>     method: \"%s%s\"\n", entry.name, entry.sig);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   112
            printf(">>>   location: %s\n", jlong_to_string(entry.loc, buffer));
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   113
            printf(">>> ... done\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   114
        }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   115
        if (eventsCount < sizeof(entries)/sizeof(entry_info)) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   116
            if (entry.name == NULL ||
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   117
                    strcmp(entry.name, entries[eventsCount].name) != 0) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   118
                printf("(entry#%" PRIuPTR ") wrong method name: \"%s\"",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   119
                       eventsCount, entry.name);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   120
                printf(", expected: \"%s\"\n", entries[eventsCount].name);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   121
                result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   122
            }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   123
            if (entry.sig == NULL ||
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   124
                    strcmp(entry.sig, entries[eventsCount].sig) != 0) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   125
                printf("(entry#%" PRIuPTR ") wrong method sig: \"%s\"",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   126
                       eventsCount, entry.sig);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   127
                printf(", expected: \"%s\"\n", entries[eventsCount].sig);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   128
                result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   129
            }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   130
            if (entry.loc != entries[eventsCount].loc) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   131
                printf("(entry#%" PRIuPTR ") wrong location: %s",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   132
                       eventsCount, jlong_to_string(entry.loc, buffer));
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   133
                printf(", expected: %s\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   134
                       jlong_to_string(entries[eventsCount].loc, buffer));
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   135
                result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   136
            }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   137
        } else {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   138
            printf("Unexpected method entry catched:");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   139
            printf("     class: \"%s\"\n", cls_sig);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   140
            printf("    method: \"%s%s\"\n", entry.name, entry.sig);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   141
            printf("  location: %s\n", jlong_to_string(entry.loc, buffer));
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   142
            result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   143
        }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   144
        eventsCount++;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   145
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   146
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   147
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   148
#ifdef STATIC_BUILD
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   149
JNIEXPORT jint JNICALL Agent_OnLoad_mentry001(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   150
    return Agent_Initialize(jvm, options, reserved);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   151
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   152
JNIEXPORT jint JNICALL Agent_OnAttach_mentry001(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   153
    return Agent_Initialize(jvm, options, reserved);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   154
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   155
JNIEXPORT jint JNI_OnLoad_mentry001(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   156
    return JNI_VERSION_1_8;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   157
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   158
#endif
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   159
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   160
    jvmtiError err;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   161
    jint res;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   162
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   163
    if (options != NULL && strcmp(options, "printdump") == 0) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   164
        printdump = JNI_TRUE;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   165
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   166
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   167
    res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   168
        JVMTI_VERSION_1_1);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   169
    if (res != JNI_OK || jvmti == NULL) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   170
        printf("Wrong result of a valid call to GetEnv!\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   171
        return JNI_ERR;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   172
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   173
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   174
    err = (*jvmti)->GetPotentialCapabilities(jvmti, &caps);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   175
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   176
        printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   177
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   178
        return JNI_ERR;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   179
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   180
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   181
    err = (*jvmti)->AddCapabilities(jvmti, &caps);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   182
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   183
        printf("(AddCapabilities) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   184
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   185
        return JNI_ERR;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   186
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   187
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   188
    err = (*jvmti)->GetCapabilities(jvmti, &caps);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   189
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   190
        printf("(GetCapabilities) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   191
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   192
        return JNI_ERR;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   193
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   194
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   195
    if (caps.can_generate_method_entry_events) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   196
        callbacks.MethodEntry = &MethodEntry;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   197
        err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   198
        if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   199
            printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   200
                   TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   201
            return JNI_ERR;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   202
        }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   203
    } else {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   204
        printf("Warning: MethodEntry event is not implemented\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   205
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   206
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   207
    return JNI_OK;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   208
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   209
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   210
JNIEXPORT void JNICALL
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   211
Java_nsk_jvmti_MethodEntry_mentry001_enable(JNIEnv *env, jclass cls) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   212
    jvmtiError err;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   213
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   214
    if (jvmti == NULL) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   215
        return;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   216
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   217
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   218
    if (!caps.can_generate_method_entry_events) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   219
        return;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   220
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   221
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   222
    err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   223
            JVMTI_EVENT_METHOD_ENTRY, NULL);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   224
    if (err == JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   225
        eventsExpected = sizeof(entries)/sizeof(entry_info);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   226
    } else {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   227
        printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   228
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   229
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   230
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   231
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   232
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   233
JNIEXPORT jint JNICALL
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   234
Java_nsk_jvmti_MethodEntry_mentry001_check(JNIEnv *env, jclass cls) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   235
    jmethodID mid;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   236
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   237
    mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls),
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   238
        "dummy", "()V");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   239
    if (mid == NULL) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   240
        printf("Cannot find metod \"dummy()\"!\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   241
        return STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   242
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   243
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   244
    JNI_ENV_PTR(env)->CallStaticVoidMethod(JNI_ENV_ARG(env, cls), mid);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   245
    if (eventsCount != eventsExpected) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   246
        printf("Wrong number of MethodEntry events: %" PRIuPTR ", expected: %" PRIuPTR "\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   247
            eventsCount, eventsExpected);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   248
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   249
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   250
    return result;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   251
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   252
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   253
JNIEXPORT void JNICALL
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   254
Java_nsk_jvmti_MethodEntry_mentry001_chain(JNIEnv *env, jclass cls) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   255
    jvmtiError err;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   256
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   257
    if (jvmti == NULL) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   258
        printf("JVMTI client was not properly loaded!\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   259
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   260
        return;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   261
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   262
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   263
    if (!caps.can_generate_method_entry_events) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   264
        return;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   265
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   266
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   267
    err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE,
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   268
            JVMTI_EVENT_METHOD_ENTRY, NULL);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   269
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   270
        printf("Failed to disable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   271
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   272
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   273
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   274
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   275
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   276
#ifdef __cplusplus
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   277
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   278
#endif