Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.cpp
40951 views
1
/*
2
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
#include <stdio.h>
25
#include <string.h>
26
#include "jvmti.h"
27
#include "agent_common.h"
28
#include "JVMTITools.h"
29
30
extern "C" {
31
32
33
#define PASSED 0
34
#define STATUS_FAILED 2
35
36
static jvmtiEnv *jvmti = NULL;
37
static jvmtiCapabilities caps;
38
static jint result = PASSED;
39
static jboolean printdump = JNI_FALSE;
40
41
#ifdef STATIC_BUILD
42
JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) {
43
return Agent_Initialize(jvm, options, reserved);
44
}
45
JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk005(JavaVM *jvm, char *options, void *reserved) {
46
return Agent_Initialize(jvm, options, reserved);
47
}
48
JNIEXPORT jint JNI_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) {
49
return JNI_VERSION_1_8;
50
}
51
#endif
52
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
53
jvmtiError err;
54
jint res;
55
56
if (options != NULL && strcmp(options, "printdump") == 0) {
57
printdump = JNI_TRUE;
58
}
59
60
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
61
if (res != JNI_OK || jvmti == NULL) {
62
printf("Wrong result of a valid call to GetEnv!\n");
63
return JNI_ERR;
64
}
65
66
err = jvmti->GetPotentialCapabilities(&caps);
67
if (err != JVMTI_ERROR_NONE) {
68
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
69
TranslateError(err), err);
70
return JNI_ERR;
71
}
72
73
err = jvmti->AddCapabilities(&caps);
74
if (err != JVMTI_ERROR_NONE) {
75
printf("(AddCapabilities) unexpected error: %s (%d)\n",
76
TranslateError(err), err);
77
return JNI_ERR;
78
}
79
80
err = jvmti->GetCapabilities(&caps);
81
if (err != JVMTI_ERROR_NONE) {
82
printf("(GetCapabilities) unexpected error: %s (%d)\n",
83
TranslateError(err), err);
84
return JNI_ERR;
85
}
86
87
if (!caps.can_generate_breakpoint_events) {
88
printf("Warning: Breakpoint is not implemented\n");
89
}
90
91
return JNI_OK;
92
}
93
94
JNIEXPORT jint JNICALL
95
Java_nsk_jvmti_ClearBreakpoint_clrbrk005_check(JNIEnv *env, jclass cls) {
96
jvmtiError err;
97
jmethodID mid;
98
99
if (jvmti == NULL) {
100
printf("JVMTI client was not properly loaded!\n");
101
return STATUS_FAILED;
102
}
103
104
if (!caps.can_generate_breakpoint_events) {
105
return result;
106
}
107
108
mid = env->GetStaticMethodID(cls, "checkPoint", "()V");
109
if (mid == 0) {
110
printf("Cannot find Method ID for method checkPoint\n");
111
return STATUS_FAILED;
112
}
113
114
if (printdump == JNI_TRUE) {
115
printf(">>> invalid method check ...\n");
116
}
117
err = jvmti->ClearBreakpoint(NULL, 0);
118
if (err != JVMTI_ERROR_INVALID_METHODID) {
119
printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n");
120
printf("\tactual: %s (%d)\n", TranslateError(err), err);
121
result = STATUS_FAILED;
122
}
123
124
if (printdump == JNI_TRUE) {
125
printf(">>> not found check ...\n");
126
}
127
err = jvmti->ClearBreakpoint(mid, 0);
128
if (err != JVMTI_ERROR_NOT_FOUND) {
129
printf("Error expected: JVMTI_ERROR_NOT_FOUND,\n");
130
printf("\tactual: %s (%d)\n", TranslateError(err), err);
131
result = STATUS_FAILED;
132
}
133
134
if (printdump == JNI_TRUE) {
135
printf(">>> ... done\n");
136
}
137
138
return result;
139
}
140
141
}
142
143