test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.cpp
author iignatyev
Tue, 28 Aug 2018 14:37:34 -0700
changeset 51551 e409244ce72e
parent 50260 test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMInit/vminit001/vminit001.c@46c67f5e27c2
child 51729 1ebe04845112
permissions -rw-r--r--
8209611: use C++ compiler for hotspot tests Reviewed-by: vlivanov, ihse, erikj, jcbeyler
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 <stdio.h>
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    25
#include <string.h>
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    26
#include "jvmti.h"
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    27
#include "agent_common.h"
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    28
#include "JVMTITools.h"
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    29
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    30
#ifdef __cplusplus
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    31
extern "C" {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    32
#endif
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    33
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    34
#ifndef JNI_ENV_ARG
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
#ifdef __cplusplus
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    37
#define JNI_ENV_ARG(x, y) y
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    38
#define JNI_ENV_PTR(x) x
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    39
#else
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    40
#define JNI_ENV_ARG(x,y) x, y
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    41
#define JNI_ENV_PTR(x) (*x)
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    42
#endif
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    43
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
#define PASSED 0
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    47
#define STATUS_FAILED 2
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    48
#define WAIT_TIME 1000
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    49
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    50
static jvmtiEnv *jvmti = NULL;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    51
static jvmtiEventCallbacks callbacks;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    52
static jint result = PASSED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    53
static jboolean printdump = JNI_FALSE;
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
    54
static const char *name = "main";
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    55
static int mainStarted = 0;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    56
static int eventsCount = 0;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    57
static int eventsExpected = 1;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    58
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    59
void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    60
    jvmtiError err;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    61
    jrawMonitorID wait_lock;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    62
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    63
    if (printdump == JNI_TRUE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    64
        printf(">>> VM init event #%d\n", eventsCount);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    65
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    66
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
    67
    err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE,
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    68
            JVMTI_EVENT_THREAD_START, NULL);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    69
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    70
        printf("Failed to enable JVMTI_EVENT_THREAD_START: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    71
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    72
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    73
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    74
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
    75
    err = jvmti_env->CreateRawMonitor("_wait_lock", &wait_lock);
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    76
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    77
        printf("(CreateRawMonitor) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    78
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    79
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    80
    }
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
    81
    err = jvmti_env->RawMonitorEnter(wait_lock);
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    82
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    83
        printf("(RawMonitorEnter) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    84
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    85
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    86
    }
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
    87
    err = jvmti_env->RawMonitorWait(wait_lock, (jlong)WAIT_TIME);
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    88
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    89
        printf("(RawMonitorWait) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    90
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    91
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    92
    }
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
    93
    err = jvmti_env->RawMonitorExit(wait_lock);
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    94
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    95
        printf("(RawMonitorExit) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    96
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    97
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
    98
    }
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
    99
    err = jvmti_env->DestroyRawMonitor(wait_lock);
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   100
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   101
        printf("(DestroyRawMonitor) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   102
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   103
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   104
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   105
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   106
    eventsCount++;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   107
}
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
void JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   110
    jvmtiError err;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   111
    jvmtiThreadInfo inf;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   112
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
   113
    err = jvmti_env->GetThreadInfo(thread, &inf);
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   114
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   115
        printf("(GetThreadInfo) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   116
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   117
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   118
        return;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   119
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   120
    if (printdump == JNI_TRUE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   121
        printf(">>> thread start: %s\n", inf.name);
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 (inf.name != NULL && strcmp(name, inf.name) == 0) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   124
        mainStarted++;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   125
        if (eventsCount == 0) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   126
            printf("ThreadStart event for the main thread occurs\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   127
            printf("before the VMInit event does return.\n");
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
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   131
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   132
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   133
#ifdef STATIC_BUILD
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   134
JNIEXPORT jint JNICALL Agent_OnLoad_vminit001(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   135
    return Agent_Initialize(jvm, options, reserved);
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
JNIEXPORT jint JNICALL Agent_OnAttach_vminit001(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   138
    return Agent_Initialize(jvm, options, reserved);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   139
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   140
JNIEXPORT jint JNI_OnLoad_vminit001(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   141
    return JNI_VERSION_1_8;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   142
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   143
#endif
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   144
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   145
    jvmtiError err;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   146
    jint res;
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
    if (options != NULL && strcmp(options, "printdump") == 0) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   149
        printdump = JNI_TRUE;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   150
    }
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
    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
   153
        JVMTI_VERSION_1_1);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   154
    if (res != JNI_OK || jvmti == NULL) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   155
        printf("Wrong result of a valid call to GetEnv!\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   156
        return JNI_ERR;
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
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   159
    callbacks.VMInit = &VMInit;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   160
    callbacks.ThreadStart = &ThreadStart;
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
   161
    err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   162
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   163
        printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   164
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   165
        return JNI_ERR;
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
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50260
diff changeset
   168
    err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
50260
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   169
            JVMTI_EVENT_VM_INIT, NULL);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   170
    if (err != JVMTI_ERROR_NONE) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   171
        printf("Failed to enable JVMTI_EVENT_VM_INIT: %s (%d)\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   172
               TranslateError(err), err);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   173
        return JNI_ERR;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   174
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   175
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   176
    return JNI_OK;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   177
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   178
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   179
JNIEXPORT jint JNICALL
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   180
Java_nsk_jvmti_VMInit_vminit001_check(JNIEnv *env, jclass cls) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   181
    if (jvmti == NULL) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   182
        printf("JVMTI client was not properly loaded!\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   183
        return STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   184
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   185
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   186
    if (eventsCount != eventsExpected) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   187
        printf("Wrong number of VM init events: %d, expected: %d\n",
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   188
            eventsCount, eventsExpected);
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   189
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   190
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   191
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   192
    if (!mainStarted) {
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   193
        printf("Missing ThreadStart event for the main thread\n");
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   194
        result = STATUS_FAILED;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   195
    }
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   196
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   197
    return result;
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   198
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   199
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   200
#ifdef __cplusplus
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   201
}
46c67f5e27c2 8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff changeset
   202
#endif